Changeset 126:f6c8a769e38e for wokkel


Ignore:
Timestamp:
Oct 21, 2008, 12:57:32 AM (12 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@122
Message:

make sure we change status and add a test

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r125 r126  
    639639            # not in the room yet
    640640            return
    641 
    642         # check if user is in roster
    643         user = room.getUser(room_jid.resource)
    644         if user is None: # create a user that does not exist
    645             user = User(room_jid.resource)
    646            
    647        
     641        user = self._changeUserStatus(room, room_jid, status, show)
     642
    648643        if room.inRoster(user):
    649644            # we changed status or nick
     
    930925        return d
    931926   
     927    def _changeUserStatus(self, r, room_jid, status, show):
     928        # check if user is in roster
     929        user = r.getUser(room_jid.resource)
     930        if user is None: # create a user that does not exist
     931            user = User(room_jid.resource)
     932
     933        if status is not None:
     934            user.status = str(status)
     935        if show is not None:
     936            user.show   = str(show)
     937
     938        return user
     939
    932940    def _changed(self, d, room_jid, prs):
    933941        """Callback for changing the nick and status.
    934942        """
    935943
     944        status = getattr(prs, 'status', None)
     945        show   = getattr(prs, 'show', None)
     946
    936947        r = self._getRoom(room_jid)
     948
     949        user = self._changeUserStatus(r, room_jid, status, show)
    937950
    938951        d.callback(r)
  • wokkel/test/test_muc.py

    r125 r126  
    479479
    480480        """
    481         give_voice = JID('ban@jabber.org/TroubleMakger')
     481        give_voice = JID('voice@jabber.org/TroubleMakger')
    482482        def cb(give_voice):
    483483            self.failUnless(give_voice, 'Did not give voice user')
     
    497497        return d
    498498
    499        
     499
     500    def test_changeStatus(self):
     501        """Change status
     502        """
     503        self._createRoom()
     504        r = self.protocol._getRoom(self.room_jid)
     505        u = muc.User(self.room_jid.resource)
     506        r.addUser(u)
     507
     508        def cb(room):
     509            self.assertEquals(self.test_room, room.name)
     510            u = room.getUser(self.room_jid.resource)
     511            self.failUnless(u is not None, 'User not found')
     512            self.failUnless(u.status == 'testing MUC', 'Wrong status')
     513            self.failUnless(u.show == 'xa', 'Wrong show')
     514           
     515        d = self.protocol.status(self.room_jid, 'xa', 'testing MUC')
     516        d.addCallback(cb)
     517
     518        prs = self.stub.output[-1]
     519
     520        self.failUnless(prs.name=='presence', "Need to be presence")
     521        self.failUnless(getattr(prs, 'x', None), 'No muc x element')
     522
     523        # send back user presence, they joined       
     524        response = muc.UserPresence(frm=self.room_jid.full())
     525        response.addElement('show', None, 'xa')
     526        response.addElement('status', None, 'testing MUC')
     527        self.stub.send(response)
     528        return d       
Note: See TracChangeset for help on using the changeset viewer.