Changeset 130:45c3ce4fe4eb for wokkel/test/test_muc.py
- Timestamp:
- Jun 9, 2009, 7:33:41 PM (13 years ago)
- Branch:
- wokkel-muc-client-support-24
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/test/test_muc.py
r129 r130 18 18 from twisted.words.protocols.jabber.xmlstream import toResponse 19 19 20 NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin' 20 21 21 22 def calledAsync(fn): … … 55 56 56 57 def _createRoom(self): 57 """A helper method to create a test room. 58 """ 59 A helper method to create a test room. 58 60 """ 59 61 # create a room 60 62 self.current_room = muc.Room(self.test_room, self.test_srv, self.test_nick) 61 self.protocol._ setRoom(self.current_room)63 self.protocol._addRoom(self.current_room) 62 64 63 65 … … 70 72 71 73 def test_userJoinedRoom(self): 72 """The client receives presence from an entity joining the room. 74 """ 75 The client receives presence from an entity joining the room. 73 76 74 77 This tests the class L{muc.UserPresence} and the userJoinedRoom event method. … … 85 88 86 89 def userPresence(room, user): 87 self.failUnless(room. name==self.test_room, 'Wrong room name')90 self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name') 88 91 self.failUnless(room.inRoster(user), 'User not in roster') 89 92 … … 95 98 96 99 def test_groupChat(self): 97 """The client receives a groupchat message from an entity in the room. 100 """ 101 The client receives a groupchat message from an entity in the room. 98 102 """ 99 103 m = muc.GroupChat('test@test.com',body='test') … … 104 108 def groupChat(room, user, message): 105 109 self.failUnless(message=='test', "Wrong group chat message") 106 self.failUnless(room. name==self.test_room, 'Wrong room name')110 self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name') 107 111 108 112 … … 112 116 113 117 114 def test_discoServerSupport(self):115 """Disco support from client to server.116 """117 test_srv = 'shakespeare.lit'118 119 def cb(query):120 # check namespace121 self.failUnless(query.uri==disco.NS_INFO, 'Wrong namespace')122 123 124 d = self.protocol.disco(test_srv)125 d.addCallback(cb)126 127 iq = self.stub.output[-1]128 129 # send back a response130 response = toResponse(iq, 'result')131 response.addElement('query', disco.NS_INFO)132 # need to add information to response133 response.query.addChild(disco.DiscoFeature(muc.NS_MUC))134 response.query.addChild(disco.DiscoIdentity(category='conference',135 name='Macbeth Chat Service',136 type='text'))137 138 self.stub.send(response)139 return d140 141 142 118 def test_joinRoom(self): 143 """Joining a room 119 """ 120 Joining a room 144 121 """ 145 122 146 123 def cb(room): 147 self.assertEquals(self.test_room, room. name)124 self.assertEquals(self.test_room, room.roomIdentifier) 148 125 149 126 d = self.protocol.join(self.test_srv, self.test_room, self.test_nick) … … 161 138 162 139 def test_joinRoomForbidden(self): 163 """Client joining a room and getting a forbidden error. 140 """ 141 Client joining a room and getting a forbidden error. 164 142 """ 165 143 … … 187 165 188 166 def test_joinRoomBadJid(self): 189 """Client joining a room and getting a forbidden error. 167 """ 168 Client joining a room and getting a forbidden error. 190 169 """ 191 170 … … 213 192 214 193 def test_partRoom(self): 215 """Client leaves a room 194 """ 195 Client leaves a room 216 196 """ 217 197 def cb(left): … … 219 199 220 200 201 self._createRoom() 221 202 d = self.protocol.leave(self.room_jid) 222 203 d.addCallback(cb) … … 235 216 236 217 def test_userPartsRoom(self): 237 """An entity leaves the room, a presence of type unavailable is received by the client. 218 """ 219 An entity leaves the room, a presence of type unavailable is received by the client. 238 220 """ 239 221 … … 251 233 252 234 def userPresence(room, user): 253 self.failUnless(room. name==self.test_room, 'Wrong room name')235 self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name') 254 236 self.failUnless(room.inRoster(user)==False, 'User in roster') 255 237 … … 260 242 261 243 def test_ban(self): 262 """Ban an entity in a room. 244 """ 245 Ban an entity in a room. 263 246 """ 264 247 banned = JID('ban@jabber.org/TroubleMakger') … … 282 265 283 266 def test_kick(self): 284 """Kick an entity from a room. 267 """ 268 Kick an entity from a room. 285 269 """ 286 270 kicked = JID('kick@jabber.org/TroubleMakger') … … 304 288 305 289 def test_password(self): 306 """Sending a password via presence to a password protected room. 290 """ 291 Sending a password via presence to a password protected room. 307 292 """ 308 293 … … 315 300 316 301 def test_history(self): 317 """Receiving history on room join. 302 """ 303 Receiving history on room join. 318 304 """ 319 305 m = muc.HistoryMessage(self.room_jid.userhost(), self.protocol._makeTimeStamp(), body='test') … … 333 319 334 320 def test_oneToOneChat(self): 335 """Converting a one to one chat to a multi-user chat. 321 """ 322 Converting a one to one chat to a multi-user chat. 336 323 """ 337 324 archive = [] … … 365 352 366 353 def test_invite(self): 367 """Invite a user to a room 368 """ 369 other_jid = 'test@jabber.org' 370 371 self.protocol.invite(other_jid, 'This is a test') 354 """ 355 Invite a user to a room 356 """ 357 bareRoomJID = self.room_jid.userhostJID() 358 invitee = JID('test@jabber.org') 359 360 self.protocol.invite(bareRoomJID, 'This is a test', invitee) 372 361 373 362 msg = self.stub.output[-1] 374 363 375 self.failUnless(xpath.matches("/message[@to='%s']/x/invite/reason" % (other_jid,), msg), 'Wrong message type') 364 query = u"/message[@to='%s']/x/invite/reason" % bareRoomJID 365 self.failUnless(xpath.matches(query, msg), 'Wrong message type') 376 366 377 367 378 368 def test_privateMessage(self): 379 """Send private messages to muc entities. 369 """ 370 Send private messages to muc entities. 380 371 """ 381 372 other_nick = self.room_jid.userhost()+'/OtherNick' … … 389 380 390 381 def test_register(self): 391 """Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register 382 """ 383 Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register 392 384 393 385 """ … … 410 402 411 403 def test_voice(self): 412 """ Client requesting voice for a room. 404 """ 405 Client requesting voice for a room. 413 406 """ 414 407 self.protocol.voice(self.room_jid.userhost()) … … 420 413 421 414 def test_roomConfigure(self): 422 """ Default configure and changing the room name. 415 """ 416 Default configure and changing the room name. 423 417 """ 424 418 … … 445 439 446 440 def test_roomDestroy(self): 447 """ Destroy a room. 441 """ 442 Destroy a room. 448 443 """ 449 444 … … 463 458 464 459 def test_nickChange(self): 465 """Send a nick change to the server. 460 """ 461 Send a nick change to the server. 466 462 """ 467 463 test_nick = 'newNick' … … 470 466 471 467 def cb(room): 472 self.assertEquals(self.test_room, room. name)468 self.assertEquals(self.test_room, room.roomIdentifier) 473 469 self.assertEquals(test_nick, room.nick) 474 470 … … 488 484 489 485 def test_grantVoice(self): 490 """Test granting voice to a user. 486 """ 487 Test granting voice to a user. 491 488 492 489 """ … … 511 508 512 509 def test_changeStatus(self): 513 """Change status 510 """ 511 Change status 514 512 """ 515 513 self._createRoom() … … 519 517 520 518 def cb(room): 521 self.assertEquals(self.test_room, room. name)519 self.assertEquals(self.test_room, room.roomIdentifier) 522 520 u = room.getUser(self.room_jid.resource) 523 521 self.failUnless(u is not None, 'User not found') … … 539 537 self.stub.send(response) 540 538 return d 539 540 541 def test_getMemberList(self): 542 def cb(room): 543 members = room.members 544 self.assertEqual(1, len(members)) 545 user = members[0] 546 self.assertEquals(JID(u'hag66@shakespeare.lit'), user.entity) 547 self.assertEquals(u'thirdwitch', user.nick) 548 self.assertEquals(u'participant', user.role) 549 550 self._createRoom() 551 bareRoomJID = self.room_jid.userhostJID() 552 d = self.protocol.getMemberList(bareRoomJID) 553 d.addCallback(cb) 554 555 iq = self.stub.output[-1] 556 query = iq.query 557 self.assertNotIdentical(None, query) 558 self.assertEquals(NS_MUC_ADMIN, query.uri) 559 560 response = toResponse(iq, 'result') 561 query = response.addElement((NS_MUC_ADMIN, 'query')) 562 item = query.addElement('item') 563 item['affiliation'] ='member' 564 item['jid'] = 'hag66@shakespeare.lit' 565 item['nick'] = 'thirdwitch' 566 item['role'] = 'participant' 567 self.stub.send(response) 568 569 return d 570 571
Note: See TracChangeset
for help on using the changeset viewer.