Changeset 144:6786830f3cd5 for wokkel
- Timestamp:
- Aug 6, 2011, 2:26:32 PM (11 years ago)
- Branch:
- wokkel-muc-client-support-24
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r143 r144 1241 1241 """ 1242 1242 msg = GroupChat(roomJID.userhostJID(), subject=subject) 1243 self.xmlstream.send(msg )1243 self.xmlstream.send(msg.toElement()) 1244 1244 1245 1245 -
wokkel/test/test_muc.py
r143 r144 48 48 self.protocol.xmlstream = self.stub.xmlstream 49 49 self.protocol.connectionInitialized() 50 self.test_room = 'test' 51 self.test_srv = 'conference.example.org' 52 self.test_nick = 'Nick' 53 54 self.room_jid = JID(tuple=(self.test_room, 55 self.test_srv, 56 self.test_nick)) 57 self.user_jid = JID('test@jabber.org/Testing') 50 self.roomIdentifier = 'test' 51 self.service = 'conference.example.org' 52 self.nick = 'Nick' 53 54 self.occupantJID = JID(tuple=(self.roomIdentifier, 55 self.service, 56 self.nick)) 57 self.roomJID = self.occupantJID.userhostJID() 58 self.userJID = JID('test@example.org/Testing') 58 59 59 60 … … 63 64 """ 64 65 # create a room 65 self.current_room = muc.Room(self.test_room,66 self.test_srv,67 self.test_nick)68 self.protocol._addRoom( self.current_room)66 room = muc.Room(self.roomIdentifier, 67 self.service, 68 self.nick) 69 self.protocol._addRoom(room) 69 70 70 71 … … 78 79 def test_userJoinedRoom(self): 79 80 """ 80 The client receives presence from an entity joining the room. 81 82 This tests the class L{muc.UserPresence} and the userJoinedRoom event method. 83 84 The test sends the user presence and tests if the event method is called. 85 81 Joins by others to a room we're in are passed to userJoinedRoom 86 82 """ 87 83 xml = """ … … 91 87 </x> 92 88 </presence> 93 """ % (self.user _jid.full(), self.room_jid.full())89 """ % (self.userJID.full(), self.occupantJID.full()) 94 90 95 91 # create a room … … 97 93 98 94 def userJoinedRoom(room, user): 99 self.assertEquals(self. test_room, room.roomIdentifier,95 self.assertEquals(self.roomIdentifier, room.roomIdentifier, 100 96 'Wrong room name') 101 97 self.assertTrue(room.inRoster(user), 'User not in roster') … … 106 102 107 103 108 def test_ groupChat(self):109 """ 110 The client receives a groupchat message from an entity in the room.111 """ 112 xml = """104 def test_receivedGroupChat(self): 105 """ 106 Messages received from a room we're in are passed to receivedGroupChat. 107 """ 108 xml = u""" 113 109 <message to='test@test.com' from='%s' type='groupchat'> 114 110 <body>test</body> 115 111 </message> 116 """ % (self. room_jid.full())117 118 self._createRoom() 119 120 def groupChat(room, user, message):112 """ % (self.occupantJID) 113 114 self._createRoom() 115 116 def receivedGroupChat(room, user, message): 121 117 self.assertEquals('test', message.body, "Wrong group chat message") 122 self.assertEquals(self. test_room, room.roomIdentifier,118 self.assertEquals(self.roomIdentifier, room.roomIdentifier, 123 119 'Wrong room name') 124 120 125 d, self.protocol.receivedGroupChat = calledAsync( groupChat)126 self.stub.send(parseXml(xml)) 127 return d 128 129 130 def test_ groupChatNoNick(self):131 """ 132 Message received from the room itself, no nickname133 """ 134 xml = """121 d, self.protocol.receivedGroupChat = calledAsync(receivedGroupChat) 122 self.stub.send(parseXml(xml)) 123 return d 124 125 126 def test_receivedGroupChatRoom(self): 127 """ 128 Messages received from the room itself have C{user} set to C{None}. 129 """ 130 xml = u""" 135 131 <message to='test@test.com' from='%s' type='groupchat'> 136 132 <body>test</body> 137 133 </message> 138 """ % (self.room_jid.userhost()) 139 140 self._createRoom() 141 142 def groupChat(room, user, message): 143 self.assertEquals('test', message.body, 144 "Wrong group chat message") 145 self.assertEquals(self.test_room, room.roomIdentifier, 146 'Wrong room name') 147 148 149 d, self.protocol.receivedGroupChat = calledAsync(groupChat) 134 """ % (self.roomJID) 135 136 self._createRoom() 137 138 def receivedGroupChat(room, user, message): 139 self.assertIdentical(None, user) 140 141 d, self.protocol.receivedGroupChat = calledAsync(receivedGroupChat) 150 142 self.stub.send(parseXml(xml)) 151 143 return d … … 154 146 def test_joinRoom(self): 155 147 """ 156 Joining a room 148 Joining a room waits for confirmation, deferred fires room. 157 149 """ 158 150 159 151 def cb(room): 160 self.assertEquals(self. test_room, room.roomIdentifier)161 162 d = self.protocol.join(self. test_srv, self.test_room, self.test_nick)152 self.assertEquals(self.roomIdentifier, room.roomIdentifier) 153 154 d = self.protocol.join(self.service, self.roomIdentifier, self.nick) 163 155 d.addCallback(cb) 164 156 … … 174 166 </x> 175 167 </presence> 176 """ % (self. test_room, self.test_srv, self.test_nick)168 """ % (self.roomIdentifier, self.service, self.nick) 177 169 self.stub.send(parseXml(xml)) 178 170 return d … … 188 180 'Wrong muc condition') 189 181 190 d = self.protocol.join(self. test_srv, self.test_room, self.test_nick)182 d = self.protocol.join(self.service, self.roomIdentifier, self.nick) 191 183 d.addBoth(cb) 192 184 … … 196 188 197 189 # send back error, forbidden 198 xml = """190 xml = u""" 199 191 <presence from='%s' type='error'> 200 192 <error type='auth'> … … 202 194 </error> 203 195 </presence> 204 """ % (self. room_jid.full())196 """ % (self.occupantJID) 205 197 self.stub.send(parseXml(xml)) 206 198 return d … … 216 208 'Wrong muc condition') 217 209 218 d = self.protocol.join(self. test_srv, self.test_room, self.test_nick)210 d = self.protocol.join(self.service, self.roomIdentifier, self.nick) 219 211 d.addBoth(cb) 220 212 … … 224 216 225 217 # send back error, bad JID 226 xml = """218 xml = u""" 227 219 <presence from='%s' type='error'> 228 220 <error type='modify'> … … 230 222 </error> 231 223 </presence> 232 """ % (self. room_jid.full())224 """ % (self.occupantJID) 233 225 self.stub.send(parseXml(xml)) 234 226 return d … … 243 235 244 236 self._createRoom() 245 d = self.protocol.leave(self. room_jid)237 d = self.protocol.leave(self.occupantJID) 246 238 d.addCallback(cb) 247 239 … … 251 243 'Unavailable is not being sent') 252 244 253 xml = """254 <presence to=' test@jabber.org' from='%s' type='unavailable'/>255 """ % (self. room_jid.full())245 xml = u""" 246 <presence to='%s' from='%s' type='unavailable'/> 247 """ % (self.userJID, self.occupantJID) 256 248 self.stub.send(parseXml(xml)) 257 249 return d … … 263 255 """ 264 256 265 xml = """257 xml = u""" 266 258 <presence to='%s' from='%s' type='unavailable'/> 267 """ % (self.user _jid.full(), self.room_jid.full())259 """ % (self.userJID, self.occupantJID) 268 260 269 261 # create a room … … 271 263 272 264 # add user to room 273 user = muc.User(self. room_jid.resource)274 room = self.protocol._getRoom(self. room_jid)265 user = muc.User(self.nick) 266 room = self.protocol._getRoom(self.occupantJID) 275 267 room.addUser(user) 276 268 277 269 def userPresence(room, user): 278 self.assertEquals(self. test_room, room.roomIdentifier,270 self.assertEquals(self.roomIdentifier, room.roomIdentifier, 279 271 'Wrong room name') 280 272 self.assertFalse(room.inRoster(user), 'User in roster') … … 294 286 self.assertTrue(banned, 'Did not ban user') 295 287 296 d = self.protocol.ban(self. room_jid, banned, reason='Spam',297 sender=self.user _jid)288 d = self.protocol.ban(self.occupantJID, banned, reason='Spam', 289 sender=self.userJID) 298 290 d.addCallback(cb) 299 291 … … 301 293 302 294 self.assertTrue(xpath.matches( 303 "/iq[@type='set' and @to='%s']/query/item"304 "[@affiliation='outcast']" % (self.room _jid.userhost(),),295 u"/iq[@type='set' and @to='%s']/query/item" 296 "[@affiliation='outcast']" % (self.roomJID,), 305 297 iq), 306 298 'Wrong ban stanza') … … 321 313 self.assertTrue(kicked, 'Did not kick user') 322 314 323 d = self.protocol.kick(self. room_jid, nick, reason='Spam',324 sender=self.user _jid)315 d = self.protocol.kick(self.occupantJID, nick, reason='Spam', 316 sender=self.userJID) 325 317 d.addCallback(cb) 326 318 … … 328 320 329 321 self.assertTrue(xpath.matches( 330 "/iq[@type='set' and @to='%s']/query/item"331 "[@affiliation='none']" % (self.room _jid.userhost(),),322 u"/iq[@type='set' and @to='%s']/query/item" 323 "[@affiliation='none']" % (self.roomJID,), 332 324 iq), 333 325 'Wrong kick stanza') … … 344 336 """ 345 337 346 self.protocol.password(self. room_jid, 'secret')338 self.protocol.password(self.occupantJID, 'secret') 347 339 348 340 prs = self.stub.output[-1] 349 341 350 342 self.assertTrue(xpath.matches( 351 "/presence[@to='%s']/x/password"352 "[text()='secret']" % (self. room_jid.full(),),343 u"/presence[@to='%s']/x/password" 344 "[text()='secret']" % (self.occupantJID,), 353 345 prs), 354 346 'Wrong presence stanza') … … 359 351 Receiving history on room join. 360 352 """ 361 xml = """353 xml = u""" 362 354 <message to='test@test.com' from='%s' type='groupchat'> 363 355 <body>test</body> … … 365 357 from="%s"/> 366 358 </message> 367 """ % (self. room_jid.full(), self.user_jid.full())359 """ % (self.occupantJID, self.userJID) 368 360 369 361 self._createRoom() … … 408 400 tzinfo=tzutc())}) 409 401 410 self.protocol.history(self. room_jid, archive)402 self.protocol.history(self.occupantJID, archive) 411 403 412 404 … … 422 414 Invite a user to a room 423 415 """ 424 bareRoomJID = self.room_jid.userhostJID() 425 invitee = JID('test@jabber.org') 426 427 self.protocol.invite(bareRoomJID, invitee, 'This is a test') 428 429 msg = self.stub.output[-1] 430 431 query = u"/message[@to='%s']/x/invite/reason" % bareRoomJID 432 self.assertTrue(xpath.matches(query, msg), 'Wrong message type') 433 434 435 def test_privateMessage(self): 416 invitee = JID('other@example.org') 417 418 self.protocol.invite(self.roomJID, invitee, u'This is a test') 419 420 message = self.stub.output[-1] 421 422 self.assertEquals('message', message.name) 423 self.assertEquals(self.roomJID.full(), message.getAttribute('to')) 424 self.assertEquals(muc.NS_MUC_USER, message.x.uri) 425 self.assertEquals(muc.NS_MUC_USER, message.x.invite.uri) 426 self.assertEquals(invitee.full(), message.x.invite.getAttribute('to')) 427 self.assertEquals(muc.NS_MUC_USER, message.x.invite.reason.uri) 428 self.assertEquals(u'This is a test', unicode(message.x.invite.reason)) 429 430 431 def test_groupChat(self): 436 432 """ 437 433 Send private messages to muc entities. 438 434 """ 439 other_nick = JID(self.room_jid.userhost()+'/OtherNick') 440 441 self.protocol.chat(other_nick, 'This is a test') 442 443 msg = self.stub.output[-1] 444 445 query = "/message[@type='chat' and @to='%s']/body" % other_nick.full() 446 self.assertTrue(xpath.matches(query, msg), 'Wrong message type') 435 self.protocol.groupChat(self.roomJID, u'This is a test') 436 437 message = self.stub.output[-1] 438 439 self.assertEquals('message', message.name) 440 self.assertEquals(self.roomJID.full(), message.getAttribute('to')) 441 self.assertEquals('groupchat', message.getAttribute('type')) 442 self.assertEquals(u'This is a test', unicode(message.body)) 443 444 445 def test_chat(self): 446 """ 447 Send private messages to muc entities. 448 """ 449 otherOccupantJID = JID(self.occupantJID.userhost()+'/OtherNick') 450 451 self.protocol.chat(otherOccupantJID, u'This is a test') 452 453 message = self.stub.output[-1] 454 455 self.assertEquals('message', message.name) 456 self.assertEquals(otherOccupantJID.full(), message.getAttribute('to')) 457 self.assertEquals('chat', message.getAttribute('type')) 458 self.assertEquals(u'This is a test', unicode(message.body)) 447 459 448 460 … … 453 465 http://xmpp.org/extensions/xep-0045.html#register 454 466 """ 467 468 # FIXME: this doesn't really test the registration 455 469 456 470 def cb(iq): … … 458 472 self.assertEquals('result', iq['type'], 'We did not get a result') 459 473 460 d = self.protocol.register(self.room _jid)474 d = self.protocol.register(self.roomJID) 461 475 d.addCallback(cb) 462 476 … … 474 488 Client requesting voice for a room. 475 489 """ 476 self.protocol.voice(self. room_jid)490 self.protocol.voice(self.occupantJID) 477 491 478 492 m = self.stub.output[-1] … … 496 510 fields.append(data_form.Field(label='Natural-Language Room Name', 497 511 var='muc#roomconfig_roomname', 498 value=self. test_room))499 500 d = self.protocol.configure(self.room _jid.userhost(), fields)512 value=self.roomIdentifier)) 513 514 d = self.protocol.configure(self.roomJID, fields) 501 515 d.addCallback(cb) 502 516 … … 510 524 511 525 512 def test_ roomDestroy(self):526 def test_destroy(self): 513 527 """ 514 528 Destroy a room. … … 518 532 self.assertTrue(destroyed, 'Room not destroyed.') 519 533 520 d = self.protocol.destroy(self. room_jid)534 d = self.protocol.destroy(self.occupantJID) 521 535 d.addCallback(cb) 522 536 … … 530 544 531 545 546 def test_subject(self): 547 """ 548 Change subject of the room. 549 """ 550 self.protocol.subject(self.roomJID, u'This is a test') 551 552 message = self.stub.output[-1] 553 554 self.assertEquals('message', message.name) 555 self.assertEquals(self.roomJID.full(), message.getAttribute('to')) 556 self.assertEquals('groupchat', message.getAttribute('type')) 557 self.assertEquals(u'This is a test', unicode(message.subject)) 558 559 532 560 def test_nickChange(self): 533 561 """ … … 539 567 540 568 def cb(room): 541 self.assertEquals(self. test_room, room.roomIdentifier)569 self.assertEquals(self.roomIdentifier, room.roomIdentifier) 542 570 self.assertEquals(test_nick, room.nick) 543 571 544 d = self.protocol.nick(self. room_jid, test_nick)572 d = self.protocol.nick(self.occupantJID, test_nick) 545 573 d.addCallback(cb) 546 574 … … 556 584 </x> 557 585 </presence> 558 """ % (self. test_room, self.test_srv, test_nick)586 """ % (self.roomIdentifier, self.service, test_nick) 559 587 self.stub.send(parseXml(xml)) 560 588 return d … … 570 598 self.assertTrue(give_voice, 'Did not give voice user') 571 599 572 d = self.protocol.grantVoice(self. room_jid, nick, sender=self.user_jid)600 d = self.protocol.grantVoice(self.occupantJID, nick, sender=self.userJID) 573 601 d.addCallback(cb) 574 602 575 603 iq = self.stub.output[-1] 576 604 577 query = ( "/iq[@type='set' and @to='%s']/query/item"578 "[@role='participant']") % self.room _jid.userhost()605 query = (u"/iq[@type='set' and @to='%s']/query/item" 606 "[@role='participant']") % self.roomJID 579 607 self.assertTrue(xpath.matches(query, iq), 'Wrong voice stanza') 580 608 … … 589 617 """ 590 618 self._createRoom() 591 room = self.protocol._getRoom(self. room_jid)592 user = muc.User(self. room_jid.resource)619 room = self.protocol._getRoom(self.occupantJID) 620 user = muc.User(self.nick) 593 621 room.addUser(user) 594 622 595 623 def cb(room): 596 self.assertEquals(self. test_room, room.roomIdentifier)597 user = room.getUser(self. room_jid.resource)624 self.assertEquals(self.roomIdentifier, room.roomIdentifier) 625 user = room.getUser(self.nick) 598 626 self.assertNotIdentical(None, user, 'User not found') 599 627 self.assertEquals('testing MUC', user.status, 'Wrong status') 600 628 self.assertEquals('xa', user.show, 'Wrong show') 601 629 602 d = self.protocol.status(self. room_jid, 'xa', 'testing MUC')630 d = self.protocol.status(self.occupantJID, 'xa', 'testing MUC') 603 631 d.addCallback(cb) 604 632 … … 609 637 610 638 # send back user presence, status changed 611 xml = """639 xml = u""" 612 640 <presence from='%s'> 613 641 <x xmlns='http://jabber.org/protocol/muc#user'> … … 617 645 <status>testing MUC</status> 618 646 </presence> 619 """ % self. room_jid.full()647 """ % self.occupantJID 620 648 self.stub.send(parseXml(xml)) 621 649 return d … … 632 660 633 661 self._createRoom() 634 bareRoomJID = self.room_jid.userhostJID() 635 d = self.protocol.getMemberList(bareRoomJID) 662 d = self.protocol.getMemberList(self.roomJID) 636 663 d.addCallback(cb) 637 664 … … 651 678 652 679 return d 653 654
Note: See TracChangeset
for help on using the changeset viewer.