Ignore:
Timestamp:
Jun 9, 2009, 7:33:41 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
wokkel-muc-client-support-24
Message:

Another round of cleanups, renames. Also removed disco support.

  • Whitespace and other PEP-8 cleanups
  • Naming changes to clarify and adhere to Twisted style guide.
  • Removed disco method, should use DiscoClientProtocol.requestInfo
  • Redid invite code, some of the parameters were actually not optional, and passwords should be sent by the service, not the client.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_muc.py

    r129 r130  
    1818from twisted.words.protocols.jabber.xmlstream import toResponse
    1919
     20NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin'
    2021
    2122def calledAsync(fn):
     
    5556
    5657    def _createRoom(self):
    57         """A helper method to create a test room.
     58        """
     59        A helper method to create a test room.
    5860        """
    5961        # create a room
    6062        self.current_room = muc.Room(self.test_room, self.test_srv, self.test_nick)
    61         self.protocol._setRoom(self.current_room)
     63        self.protocol._addRoom(self.current_room)
    6264
    6365
     
    7072
    7173    def test_userJoinedRoom(self):
    72         """The client receives presence from an entity joining the room.
     74        """
     75        The client receives presence from an entity joining the room.
    7376
    7477        This tests the class L{muc.UserPresence} and the userJoinedRoom event method.
     
    8588
    8689        def userPresence(room, user):
    87             self.failUnless(room.name==self.test_room, 'Wrong room name')
     90            self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name')
    8891            self.failUnless(room.inRoster(user), 'User not in roster')
    8992
     
    9598
    9699    def test_groupChat(self):
    97         """The client receives a groupchat message from an entity in the room.
     100        """
     101        The client receives a groupchat message from an entity in the room.
    98102        """
    99103        m = muc.GroupChat('test@test.com',body='test')
     
    104108        def groupChat(room, user, message):
    105109            self.failUnless(message=='test', "Wrong group chat message")
    106             self.failUnless(room.name==self.test_room, 'Wrong room name')
     110            self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name')
    107111
    108112
     
    112116
    113117
    114     def test_discoServerSupport(self):
    115         """Disco support from client to server.
    116         """
    117         test_srv = 'shakespeare.lit'
    118 
    119         def cb(query):
    120             # check namespace
    121             self.failUnless(query.uri==disco.NS_INFO, 'Wrong namespace')
    122 
    123 
    124         d = self.protocol.disco(test_srv)
    125         d.addCallback(cb)
    126 
    127         iq = self.stub.output[-1]
    128 
    129         # send back a response
    130         response = toResponse(iq, 'result')
    131         response.addElement('query', disco.NS_INFO)
    132         # need to add information to response
    133         response.query.addChild(disco.DiscoFeature(muc.NS_MUC))
    134         response.query.addChild(disco.DiscoIdentity(category='conference',
    135                                                     name='Macbeth Chat Service',
    136                                                     type='text'))
    137 
    138         self.stub.send(response)
    139         return d
    140 
    141 
    142118    def test_joinRoom(self):
    143         """Joining a room
     119        """
     120        Joining a room
    144121        """
    145122
    146123        def cb(room):
    147             self.assertEquals(self.test_room, room.name)
     124            self.assertEquals(self.test_room, room.roomIdentifier)
    148125
    149126        d = self.protocol.join(self.test_srv, self.test_room, self.test_nick)
     
    161138
    162139    def test_joinRoomForbidden(self):
    163         """Client joining a room and getting a forbidden error.
     140        """
     141        Client joining a room and getting a forbidden error.
    164142        """
    165143
     
    187165
    188166    def test_joinRoomBadJid(self):
    189         """Client joining a room and getting a forbidden error.
     167        """
     168        Client joining a room and getting a forbidden error.
    190169        """
    191170
     
    213192
    214193    def test_partRoom(self):
    215         """Client leaves a room
     194        """
     195        Client leaves a room
    216196        """
    217197        def cb(left):
     
    219199
    220200
     201        self._createRoom()
    221202        d = self.protocol.leave(self.room_jid)
    222203        d.addCallback(cb)
     
    235216
    236217    def test_userPartsRoom(self):
    237         """An entity leaves the room, a presence of type unavailable is received by the client.
     218        """
     219        An entity leaves the room, a presence of type unavailable is received by the client.
    238220        """
    239221
     
    251233
    252234        def userPresence(room, user):
    253             self.failUnless(room.name==self.test_room, 'Wrong room name')
     235            self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name')
    254236            self.failUnless(room.inRoster(user)==False, 'User in roster')
    255237
     
    260242
    261243    def test_ban(self):
    262         """Ban an entity in a room.
     244        """
     245        Ban an entity in a room.
    263246        """
    264247        banned = JID('ban@jabber.org/TroubleMakger')
     
    282265
    283266    def test_kick(self):
    284         """Kick an entity from a room.
     267        """
     268        Kick an entity from a room.
    285269        """
    286270        kicked = JID('kick@jabber.org/TroubleMakger')
     
    304288
    305289    def test_password(self):
    306         """Sending a password via presence to a password protected room.
     290        """
     291        Sending a password via presence to a password protected room.
    307292        """
    308293
     
    315300
    316301    def test_history(self):
    317         """Receiving history on room join.
     302        """
     303        Receiving history on room join.
    318304        """
    319305        m = muc.HistoryMessage(self.room_jid.userhost(), self.protocol._makeTimeStamp(), body='test')
     
    333319
    334320    def test_oneToOneChat(self):
    335         """Converting a one to one chat to a multi-user chat.
     321        """
     322        Converting a one to one chat to a multi-user chat.
    336323        """
    337324        archive = []
     
    365352
    366353    def test_invite(self):
    367         """Invite a user to a room
    368         """
    369         other_jid = 'test@jabber.org'
    370 
    371         self.protocol.invite(other_jid, 'This is a test')
     354        """
     355        Invite a user to a room
     356        """
     357        bareRoomJID = self.room_jid.userhostJID()
     358        invitee = JID('test@jabber.org')
     359
     360        self.protocol.invite(bareRoomJID, 'This is a test', invitee)
    372361
    373362        msg = self.stub.output[-1]
    374363
    375         self.failUnless(xpath.matches("/message[@to='%s']/x/invite/reason" % (other_jid,), msg), 'Wrong message type')
     364        query = u"/message[@to='%s']/x/invite/reason" % bareRoomJID
     365        self.failUnless(xpath.matches(query, msg), 'Wrong message type')
    376366
    377367
    378368    def test_privateMessage(self):
    379         """Send private messages to muc entities.
     369        """
     370        Send private messages to muc entities.
    380371        """
    381372        other_nick = self.room_jid.userhost()+'/OtherNick'
     
    389380
    390381    def test_register(self):
    391         """Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register
     382        """
     383        Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register
    392384
    393385        """
     
    410402
    411403    def test_voice(self):
    412         """ Client requesting voice for a room.
     404        """
     405        Client requesting voice for a room.
    413406        """
    414407        self.protocol.voice(self.room_jid.userhost())
     
    420413
    421414    def test_roomConfigure(self):
    422         """ Default configure and changing the room name.
     415        """
     416        Default configure and changing the room name.
    423417        """
    424418
     
    445439
    446440    def test_roomDestroy(self):
    447         """ Destroy a room.
     441        """
     442        Destroy a room.
    448443        """
    449444
     
    463458
    464459    def test_nickChange(self):
    465         """Send a nick change to the server.
     460        """
     461        Send a nick change to the server.
    466462        """
    467463        test_nick = 'newNick'
     
    470466
    471467        def cb(room):
    472             self.assertEquals(self.test_room, room.name)
     468            self.assertEquals(self.test_room, room.roomIdentifier)
    473469            self.assertEquals(test_nick, room.nick)
    474470
     
    488484
    489485    def test_grantVoice(self):
    490         """Test granting voice to a user.
     486        """
     487        Test granting voice to a user.
    491488
    492489        """
     
    511508
    512509    def test_changeStatus(self):
    513         """Change status
     510        """
     511        Change status
    514512        """
    515513        self._createRoom()
     
    519517
    520518        def cb(room):
    521             self.assertEquals(self.test_room, room.name)
     519            self.assertEquals(self.test_room, room.roomIdentifier)
    522520            u = room.getUser(self.room_jid.resource)
    523521            self.failUnless(u is not None, 'User not found')
     
    539537        self.stub.send(response)
    540538        return d
     539
     540
     541    def test_getMemberList(self):
     542        def cb(room):
     543            members = room.members
     544            self.assertEqual(1, len(members))
     545            user = members[0]
     546            self.assertEquals(JID(u'hag66@shakespeare.lit'), user.entity)
     547            self.assertEquals(u'thirdwitch', user.nick)
     548            self.assertEquals(u'participant', user.role)
     549
     550        self._createRoom()
     551        bareRoomJID = self.room_jid.userhostJID()
     552        d = self.protocol.getMemberList(bareRoomJID)
     553        d.addCallback(cb)
     554
     555        iq = self.stub.output[-1]
     556        query = iq.query
     557        self.assertNotIdentical(None, query)
     558        self.assertEquals(NS_MUC_ADMIN, query.uri)
     559
     560        response = toResponse(iq, 'result')
     561        query = response.addElement((NS_MUC_ADMIN, 'query'))
     562        item = query.addElement('item')
     563        item['affiliation'] ='member'
     564        item['jid'] = 'hag66@shakespeare.lit'
     565        item['nick'] = 'thirdwitch'
     566        item['role'] = 'participant'
     567        self.stub.send(response)
     568
     569        return d
     570
     571
Note: See TracChangeset for help on using the changeset viewer.