Changeset 125:edb21c02197b for wokkel


Ignore:
Timestamp:
Oct 21, 2008, 12:32:00 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@121
Message:

docstrings, tests and bug fixes

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r124 r125  
    282282    def __init__(self, xs, method='get', role='none', a_jid=None, reason=None):
    283283        AdminRequest.__init__(self, xs, method)
    284 
    285284        i = self.query.addElement('item')
    286285
     
    291290        if reason:
    292291            i.addElement('reason', None, reason)
    293 
     292       
    294293class GroupChat(domish.Element):
    295294    """
     
    660659
    661660    def _onGroupChat(self, msg):
    662         """
     661        """ A group chat message has been received from a MUC room.
     662       
     663        There are a few event methods that may get called here. receviedGroupChat and receivedHistory
    663664        """
    664665        if not msg.hasAttribute('from'):
     
    686687
    687688    def _onSubject(self, msg):
    688         """
     689        """A subject has been sent from a MUC room.
    689690        """
    690691        if not msg.hasAttribute('from'):
     
    702703
    703704    def _makeTimeStamp(self, stamp=None):
     705        # create a timestamp
    704706        if stamp is None:
    705707            stamp = datetime.datetime.now()
     
    754756
    755757    def userJoinedRoom(self, room, user):
    756         """User has joined a room
     758        """User has joined a MUC room.
     759
     760        This method will need to be modified inorder for clients to
     761        do something when this event occurs.
     762
     763        @param room: The room the user has joined.
     764        @type  room: L{Room}
     765
     766        @param user: The user that joined the MUC room.
     767        @type  user: L{User}
     768
    757769        """
    758770        pass
    759771
    760772    def userLeftRoom(self, room, user):
    761         """User has left a room
     773        """User has left a room.
     774       
     775        This method will need to be modified inorder for clients to
     776        do something when this event occurs.
     777
     778        @param room: The room the user has joined.
     779        @type  room: L{Room}
     780
     781        @param user: The user that joined the MUC room.
     782        @type  user: L{User}
     783
    762784        """
    763785        pass
     
    766788    def userUpdatedStatus(self, room, user, show, status):
    767789        """User Presence has been received
     790       
     791        This method will need to be modified inorder for clients to
     792        do something when this event occurs.
     793       
    768794        """
    769795        pass
     
    772798    def receivedSubject(self, room, subject):
    773799        """
     800        This method will need to be modified inorder for clients to
     801        do something when this event occurs.
     802
    774803        """
    775804        pass
     
    778807    def receivedHistory(self, room, user, message, history, frm=None):
    779808        """
     809        This method will need to be modified inorder for clients to
     810        do something when this event occurs.
    780811        """
    781812        pass
     
    790821    def sendDeferred(self,  obj, timeout):
    791822        """ Send data or a domish element, adding a deferred with a timeout.
     823       
     824        @param obj: The object to send over the wire.
     825        @type  obj: L{domish.Element} or L{unicode}
     826
     827        @param timeout: The number of seconds to wait before the deferred is timed out.
     828        @type  timeout: L{int}
     829
     830        The deferred object L{defer.Deferred} is returned.
    792831        """
    793832        d = defer.Deferred()
     
    817856
    818857    def disco(self, entity, type='info'):
    819         """Send disco queries to a XMPP entity
     858        """Send disco queries to a XMPP entity.
     859
     860        @param entity: The server or entity where we want discovery information from.
     861        @type  entity: L{jid.JID}
     862
     863        @param type: The optional disco type.
     864        @type  type: L{unicode}
     865
    820866        """
    821867
     
    831877        @param room_jid: The room jabber/xmpp entity id for the requested configuration form.
    832878        @type  room_jid: L{jid.JID}
     879
     880        @param fields: The fields we want to modify.
     881        @type  fields: A L{list} or L{dataform.Field}
    833882
    834883        """
     
    9771026
    9781027    def _sendMessage(self, msg, children=None):
    979 
     1028        # send a message
    9801029        if children:
    9811030            for c in children:
     
    9911040        self._sendMessage(msg, children=children)
    9921041
    993     def chat(self, to, message, children=None):
    994         msg = PrivateChat(to, body=message)
     1042    def chat(self, room_jid, message, children=None):
     1043        """Send a private chat message to a user in a MUC room.
     1044       
     1045        See: http://xmpp.org/extensions/xep-0045.html#privatemessage
     1046
     1047        @param room_jid: The room entity id.
     1048        @type  room_jid: L{jid.JID}
     1049
     1050        """
     1051
     1052        msg = PrivateChat(room_jid, body=message)
    9951053
    9961054        self._sendMessage(msg, children=children)
    9971055       
    998     def invite(self, to, reason=None, full_jid=None):
    999         """
    1000         """
    1001         msg = InviteMessage(to, reason=reason, full_jid=full_jid)
     1056    def invite(self, room_jid, reason=None, full_jid=None):
     1057        """Invite a xmpp entity to a MUC room.
     1058
     1059        See: http://xmpp.org/extensions/xep-0045.html#invite
     1060
     1061        @param room_jid: The room entity id.
     1062        @type  room_jid: L{jid.JID}
     1063       
     1064        @param reason: The reason for the invite.
     1065        @type  reason: L{unicode}
     1066
     1067        @param full_jid: The xmpp user's entity id.
     1068        @type  full_jid: L{jid.JID}
     1069
     1070        """
     1071        msg = InviteMessage(room_jid, reason=reason, full_jid=full_jid)
    10021072        self._sendMessage(msg)
    10031073
    10041074
    1005     def password(self, to, password):
    1006         p = PasswordPresence(to, password)
     1075    def password(self, room_jid, password):
     1076        """Send a password to a room so the entity can join.
     1077       
     1078        See: http://xmpp.org/extensions/xep-0045.html#enter-pw
     1079
     1080        @param room_jid: The room entity id.
     1081        @type  room_jid: L{jid.JID}
     1082       
     1083        @param password: The MUC room password.
     1084        @type  password: L{unicode}
     1085       
     1086        """
     1087        p = PasswordPresence(room_jid, password)
    10071088
    10081089        self.xmlstream.send(p)
    10091090   
    10101091    def register(self, to, fields=[]):
     1092        """
     1093        """
    10111094        iq = RegisterRequest(self.xmlstream, method='set', fields=fields)
    10121095        iq['to'] = to
     
    10241107
    10251108    def _getRoleList(self, room_jid, role):
     1109        # send a role request
    10261110        iq = RoleRequest(self.xmlstream,
    10271111                                method='get',
     
    10331117
    10341118    def _setAffiliationList(self, affiliation, room_jid, iq):
     1119        # set a rooms affiliation list
    10351120        r = self._getRoom(room_jid)
    10361121        if r is not None:
     
    11751260                         role=role,
    11761261                         reason=reason)
     1262       
    11771263        iq['to'] = room_jid.userhost() # this is a room jid, only send to room
    11781264        iq['from'] = frm.full()
     
    11861272        return r
    11871273
    1188     def grantVoice(self, frm, room_jid, reason=None):
    1189         return self._setRole(frm, room_jid, role='participant', reason=reason)
     1274    def grantVoice(self, frm, room_jid, voice_jid=None, reason=None):
     1275        return self._setRole(frm, room_jid, role='participant', a_jid=voice_jid, reason=reason)
    11901276
    11911277    def grantVisitor(self, frm, room_jid, reason=None):
  • wokkel/test/test_muc.py

    r120 r125  
    7474    def test_userJoinedRoom(self):
    7575        """The client receives presence from an entity joining the room.
     76
     77        This tests the class L{muc.UserPresence} and the userJoinedRoom event method.
     78
     79        The test sends the user presence and tests if the event method is called.
     80
    7681        """
    7782        p = muc.UserPresence()
     
    184189        self.stub.send(response)
    185190        return d       
     191
     192
     193    def test_joinRoomBadJid(self):
     194        """Client joining a room and getting a forbidden error.
     195        """
     196
     197        def cb(error):
     198           
     199            self.failUnless(error.value.mucCondition=='jid-malformed','Wrong muc condition')
     200
     201           
     202           
     203        d = self.protocol.join(self.test_srv, self.test_room, self.test_nick)
     204        d.addBoth(cb)
     205
     206        prs = self.stub.output[-1]
     207        self.failUnless(prs.name=='presence', "Need to be presence")
     208        self.failUnless(getattr(prs, 'x', None), 'No muc x element')
     209        # send back user presence, they joined
     210       
     211        response = muc.PresenceError(error=muc.MUCError('modify',
     212                                                        'jid-malformed'
     213                                                        ),
     214                                     frm=self.room_jid.full())
     215        self.stub.send(response)
     216        return d       
     217
     218
    186219
    187220    def test_partRoom(self):
     
    442475        return d
    443476
    444        
     477    def test_grantVoice(self):
     478        """Test granting voice to a user.
     479
     480        """
     481        give_voice = JID('ban@jabber.org/TroubleMakger')
     482        def cb(give_voice):
     483            self.failUnless(give_voice, 'Did not give voice user')
     484
     485           
     486        d = self.protocol.grantVoice(self.user_jid, self.room_jid, give_voice)
     487        d.addCallback(cb)
     488
     489        iq = self.stub.output[-1]
     490       
     491        self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@role='participant']" % (self.room_jid.userhost(),), iq), 'Wrong voice stanza')
     492
     493        response = toResponse(iq, 'result')
     494
     495        self.stub.send(response)
     496
     497        return d
     498
     499       
Note: See TracChangeset for help on using the changeset viewer.