Changeset 117:2503218c0e95


Ignore:
Timestamp:
Oct 17, 2008, 10:47:01 PM (13 years ago)
Author:
Christopher Zorn <tofu@…>
Branch:
wokkel-muc-client-support-24
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@111
Message:

we now have basic support with nick change, also added some doc strings, still need more re #24

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r116 r117  
    280280        self.status = 0
    281281
    282         self.entity_id = jid.internJID(name+'@'+server+'/'+nick)
     282        self.entity_id = self.entityId()
    283283               
    284284        self.roster = {}
    285285
    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
    287292
    288293    def addUser(self, user):
     
    608613    def configure(self, room_jid, fields=[]):
    609614        """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
    610619        """
    611620        request = ConfigureRequest(self.xmlstream, method='set', fields=fields)
     
    615624
    616625    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        """
    617632        request = ConfigureRequest(self.xmlstream)
    618633        request['to'] = room_jid
     
    621636
    622637    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       
    624650        """
    625651        d = defer.Deferred()
     
    637663        return d
    638664   
     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       
    639703
    640704   
  • wokkel/test/test_muc.py

    r116 r117  
    5858
    5959    def _createRoom(self):
     60        """A helper method to create a test room.
     61        """
    6062        # create a room
    6163        self.current_room = muc.Room(self.test_room, self.test_srv, self.test_nick)
     
    7173
    7274    def test_userJoinedRoom(self):
    73         """Test receiving a user joined event.
     75        """The client receives presence from an entity joining the room.
    7476        """
    7577        p = muc.UserPresence()
     
    9193
    9294    def test_groupChat(self):
    93         """Test receiving room presence
     95        """The client receives a groupchat message from an entity in the room.
    9496        """
    9597        m = muc.GroupChat('test@test.com',body='test')
     
    109111
    110112    def test_discoServerSupport(self):
    111         """Test for disco support from a server.
     113        """Disco support from client to server.
    112114        """
    113115        test_srv = 'shakespeare.lit'
     
    138140       
    139141    def test_joinRoom(self):
    140         """Test joining a room
    141         """
    142        
    143 
     142        """Joining a room
     143        """
     144       
    144145        def cb(room):
    145146            self.assertEquals(self.test_room, room.name)
     
    159160
    160161    def test_joinRoomForbidden(self):
    161         """Test joining a room and getting an error
     162        """Client joining a room and getting a forbidden error.
    162163        """
    163164
     
    183184
    184185    def test_partRoom(self):
    185        
     186        """Client leaves a room
     187        """
    186188        def cb(left):
    187189            self.failUnless(left, 'did not leave room')
     
    204206
    205207    def test_ban(self):
    206        
     208        """Ban an entity in a room.
     209        """
    207210        banned = JID('ban@jabber.org/TroubleMakger')
    208211        def cb(banned):
     
    225228
    226229    def test_kick(self):
    227 
     230        """Kick an entity from a room.
     231        """
    228232        kicked = JID('kick@jabber.org/TroubleMakger')
    229233        def cb(kicked):
     
    247251
    248252    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.
    250254        """
    251255       
     
    258262
    259263    def test_history(self):
    260         """Test receiving history on room join.
     264        """Receiving history on room join.
    261265        """
    262266        m = muc.HistoryMessage(self.room_jid.userhost(), self.protocol._makeTimeStamp(), body='test')
     
    276280
    277281    def test_oneToOneChat(self):
    278         """Test converting a one to one chat
     282        """Converting a one to one chat to a multi-user chat.
    279283        """
    280284        archive = []
     
    308312
    309313    def test_invite(self):
     314        """Invite a user to a room
     315        """
    310316        other_jid = 'test@jabber.org'
    311317
     
    319325       
    320326    def test_privateMessage(self):
    321         """Test sending private messages to muc entities.
     327        """Send private messages to muc entities.
    322328        """
    323329        other_nick = self.room_jid.userhost()+'/OtherNick'
     
    331337
    332338    def test_register(self):
    333         """Test client registering with a room. http://xmpp.org/extensions/xep-0045.html#register
     339        """Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register
    334340
    335341        """
     
    343349
    344350        iq = self.stub.output[-1]
    345         print iq.toXml()
    346351        self.failUnless(xpath.matches("/iq/query[@xmlns='%s']" % (muc.NS_REQUEST), iq), 'Invalid iq register request')
    347352       
     
    352357
    353358    def test_voice(self):
    354         """
     359        """ Client requesting voice for a room.
    355360        """
    356361        self.protocol.voice(self.room_jid.userhost())
     
    362367
    363368    def test_roomConfigure(self):
    364         """
     369        """ Default configure and changing the room name.
    365370        """
    366371
     
    386391
    387392
     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.