Changeset 117:2503218c0e95 for wokkel
- Timestamp:
- Oct 17, 2008, 10:47:01 PM (14 years ago)
- Branch:
- wokkel-muc-client-support-24
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@111
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r116 r117 280 280 self.status = 0 281 281 282 self.entity_id = jid.internJID(name+'@'+server+'/'+nick)282 self.entity_id = self.entityId() 283 283 284 284 self.roster = {} 285 285 286 286 def entityId(self): 287 """ 288 """ 289 self.entity_id = jid.internJID(self.name+'@'+self.server+'/'+self.nick) 290 291 return self.entity_id 287 292 288 293 def addUser(self, user): … … 608 613 def configure(self, room_jid, fields=[]): 609 614 """Configure a room 615 616 @param room_jid: The room jabber/xmpp entity id for the requested configuration form. 617 @type room_jid: L{jid.JID} 618 610 619 """ 611 620 request = ConfigureRequest(self.xmlstream, method='set', fields=fields) … … 615 624 616 625 def getConfigureForm(self, room_jid): 626 """Grab the configuration form from the room. This sends an iq request to the room. 627 628 @param room_jid: The room jabber/xmpp entity id for the requested configuration form. 629 @type room_jid: L{jid.JID} 630 631 """ 617 632 request = ConfigureRequest(self.xmlstream) 618 633 request['to'] = room_jid … … 621 636 622 637 def join(self, server, room, nick): 623 """ 638 """ Join a MUC room by sending presence to it. Returns a defered that is called when 639 the entity is in the room or an error has occurred. 640 641 @param server: The server where the room is located. 642 @type server: L{unicode} 643 644 @param room: The room name the entity is joining. 645 @type room: L{unicode} 646 647 @param nick: The nick name for the entitity joining the room. 648 @type nick: L{unicode} 649 624 650 """ 625 651 d = defer.Deferred() … … 637 663 return d 638 664 665 def _changedNick(self, d, room_jid, prs): 666 """Callback for changing the nick. 667 """ 668 669 r = self._getRoom(room_jid) 670 671 d.callback(r) 672 673 674 def nick(self, room_jid, new_nick): 675 """ Change an entities nick name in a MUC room. 676 677 See: http://xmpp.org/extensions/xep-0045.html#changenick 678 679 @param room_jid: The room jabber/xmpp entity id for the requested configuration form. 680 @type room_jid: L{jid.JID} 681 682 @param new_nick: The nick name for the entitity joining the room. 683 @type new_nick: L{unicode} 684 685 """ 686 687 d = defer.Deferred() 688 r = self._getRoom(room_jid) 689 if r is None: 690 raise Exception, 'Room not found' 691 r.nick = new_nick # change the nick 692 # create presence 693 # make sure we call the method to generate the new entity xmpp id 694 p = BasicPresence(to=r.entityId()) 695 self.xmlstream.send(p) 696 697 # add observer for joining the room 698 self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()), 699 self._changedNick, 1, d, room_jid) 700 701 return d 702 639 703 640 704 -
wokkel/test/test_muc.py
r116 r117 58 58 59 59 def _createRoom(self): 60 """A helper method to create a test room. 61 """ 60 62 # create a room 61 63 self.current_room = muc.Room(self.test_room, self.test_srv, self.test_nick) … … 71 73 72 74 def test_userJoinedRoom(self): 73 """T est receiving a user joined event.75 """The client receives presence from an entity joining the room. 74 76 """ 75 77 p = muc.UserPresence() … … 91 93 92 94 def test_groupChat(self): 93 """T est receiving room presence95 """The client receives a groupchat message from an entity in the room. 94 96 """ 95 97 m = muc.GroupChat('test@test.com',body='test') … … 109 111 110 112 def test_discoServerSupport(self): 111 """ Test for disco support from aserver.113 """Disco support from client to server. 112 114 """ 113 115 test_srv = 'shakespeare.lit' … … 138 140 139 141 def test_joinRoom(self): 140 """Test joining a room 141 """ 142 143 142 """Joining a room 143 """ 144 144 145 def cb(room): 145 146 self.assertEquals(self.test_room, room.name) … … 159 160 160 161 def test_joinRoomForbidden(self): 161 """ Test joining a room and getting an error162 """Client joining a room and getting a forbidden error. 162 163 """ 163 164 … … 183 184 184 185 def test_partRoom(self): 185 186 """Client leaves a room 187 """ 186 188 def cb(left): 187 189 self.failUnless(left, 'did not leave room') … … 204 206 205 207 def test_ban(self): 206 208 """Ban an entity in a room. 209 """ 207 210 banned = JID('ban@jabber.org/TroubleMakger') 208 211 def cb(banned): … … 225 228 226 229 def test_kick(self): 227 230 """Kick an entity from a room. 231 """ 228 232 kicked = JID('kick@jabber.org/TroubleMakger') 229 233 def cb(kicked): … … 247 251 248 252 def test_password(self): 249 """ Test sending a password via presence to a password protected room.253 """Sending a password via presence to a password protected room. 250 254 """ 251 255 … … 258 262 259 263 def test_history(self): 260 """ Test receiving history on room join.264 """Receiving history on room join. 261 265 """ 262 266 m = muc.HistoryMessage(self.room_jid.userhost(), self.protocol._makeTimeStamp(), body='test') … … 276 280 277 281 def test_oneToOneChat(self): 278 """ Test converting a one to one chat282 """Converting a one to one chat to a multi-user chat. 279 283 """ 280 284 archive = [] … … 308 312 309 313 def test_invite(self): 314 """Invite a user to a room 315 """ 310 316 other_jid = 'test@jabber.org' 311 317 … … 319 325 320 326 def test_privateMessage(self): 321 """ Test sendingprivate messages to muc entities.327 """Send private messages to muc entities. 322 328 """ 323 329 other_nick = self.room_jid.userhost()+'/OtherNick' … … 331 337 332 338 def test_register(self): 333 """ Test client registering with a room. http://xmpp.org/extensions/xep-0045.html#register339 """Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register 334 340 335 341 """ … … 343 349 344 350 iq = self.stub.output[-1] 345 print iq.toXml()346 351 self.failUnless(xpath.matches("/iq/query[@xmlns='%s']" % (muc.NS_REQUEST), iq), 'Invalid iq register request') 347 352 … … 352 357 353 358 def test_voice(self): 354 """ 359 """ Client requesting voice for a room. 355 360 """ 356 361 self.protocol.voice(self.room_jid.userhost()) … … 362 367 363 368 def test_roomConfigure(self): 364 """ 369 """ Default configure and changing the room name. 365 370 """ 366 371 … … 386 391 387 392 393 def test_nickChange(self): 394 """Send a nick change to the server. 395 """ 396 test_nick = 'newNick' 397 398 self._createRoom() 399 400 def cb(room): 401 self.assertEquals(self.test_room, room.name) 402 self.assertEquals(test_nick, room.nick) 403 404 d = self.protocol.nick(self.room_jid, test_nick) 405 d.addCallback(cb) 406 407 prs = self.stub.output[-1] 408 self.failUnless(prs.name=='presence', "Need to be presence") 409 self.failUnless(getattr(prs, 'x', None), 'No muc x element') 410 411 # send back user presence, they joined 412 response = muc.UserPresence(frm=self.test_room+'@'+self.test_srv+'/'+test_nick) 413 414 self.stub.send(response) 415 return d 416 417
Note: See TracChangeset
for help on using the changeset viewer.