Ignore:
Timestamp:
Jun 4, 2009, 5:44:50 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
wokkel-muc-client-support-24
Message:

Whitespace and pyflakes changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_muc.py

    r127 r129  
    1 # Copyright (c) 2003-2008 Ralph Meijer
     1# Copyright (c) 2003-2009 Ralph Meijer
    22# See LICENSE for details.
    33
     
    1111from twisted.internet import defer
    1212from twisted.words.xish import domish, xpath
    13 from twisted.words.protocols.jabber import error
    1413from twisted.words.protocols.jabber.jid import JID
    1514
    16 from wokkel import data_form, iwokkel, muc, shim, disco
    17 from wokkel.generic import parseXml
     15from wokkel import data_form, iwokkel, muc, disco
    1816from wokkel.test.helpers import XmlStreamStub
    1917
    20 try:
    21     from twisted.words.protocols.jabber.xmlstream import toResponse
    22 except ImportError:
    23     from wokkel.compat import toResponse
     18from twisted.words.protocols.jabber.xmlstream import toResponse
    2419
    2520
     
    3934
    4035    return d, func
     36
    4137
    4238
     
    5753        self.user_jid = JID('test@jabber.org/Testing')
    5854
     55
    5956    def _createRoom(self):
    6057        """A helper method to create a test room.
     
    8178        """
    8279        p = muc.UserPresence()
    83         p['to'] = self.user_jid.full()
     80        p['to'] = self.user_jid.full()
    8481        p['from'] = self.room_jid.full()
    8582
     
    9087            self.failUnless(room.name==self.test_room, 'Wrong room name')
    9188            self.failUnless(room.inRoster(user), 'User not in roster')
    92                            
    93        
     89
     90
    9491        d, self.protocol.userJoinedRoom = calledAsync(userPresence)
    9592        self.stub.send(p)
     
    10198        """
    10299        m = muc.GroupChat('test@test.com',body='test')
    103         m['from'] = self.room_jid.full()
     100        m['from'] = self.room_jid.full()
    104101
    105102        self._createRoom()
     
    108105            self.failUnless(message=='test', "Wrong group chat message")
    109106            self.failUnless(room.name==self.test_room, 'Wrong room name')
    110                            
    111        
     107
     108
    112109        d, self.protocol.receivedGroupChat = calledAsync(groupChat)
    113110        self.stub.send(m)
     
    123120            # check namespace
    124121            self.failUnless(query.uri==disco.NS_INFO, 'Wrong namespace')
    125            
     122
    126123
    127124        d = self.protocol.disco(test_srv)
     
    129126
    130127        iq = self.stub.output[-1]
    131        
     128
    132129        # send back a response
    133130        response = toResponse(iq, 'result')
     
    138135                                                    name='Macbeth Chat Service',
    139136                                                    type='text'))
    140        
    141         self.stub.send(response)
    142         return d
    143        
    144 
    145        
     137
     138        self.stub.send(response)
     139        return d
     140
     141
    146142    def test_joinRoom(self):
    147143        """Joining a room
    148144        """
    149        
     145
    150146        def cb(room):
    151147            self.assertEquals(self.test_room, room.name)
     
    158154        self.failUnless(getattr(prs, 'x', None), 'No muc x element')
    159155
    160         # send back user presence, they joined       
     156        # send back user presence, they joined
    161157        response = muc.UserPresence(frm=self.test_room+'@'+self.test_srv+'/'+self.test_nick)
    162158        self.stub.send(response)
    163159        return d
    164160
    165    
    166161
    167162    def test_joinRoomForbidden(self):
     
    170165
    171166        def cb(error):
    172            
     167
    173168            self.failUnless(error.value.mucCondition=='forbidden','Wrong muc condition')
    174169
    175            
    176            
     170
     171
    177172        d = self.protocol.join(self.test_srv, self.test_room, self.test_nick)
    178173        d.addBoth(cb)
     
    182177        self.failUnless(getattr(prs, 'x', None), 'No muc x element')
    183178        # send back user presence, they joined
    184        
     179
    185180        response = muc.PresenceError(error=muc.MUCError('auth',
    186181                                                        'forbidden'
     
    188183                                     frm=self.room_jid.full())
    189184        self.stub.send(response)
    190         return d       
     185        return d
    191186
    192187
     
    196191
    197192        def cb(error):
    198            
     193
    199194            self.failUnless(error.value.mucCondition=='jid-malformed','Wrong muc condition')
    200195
    201            
    202            
     196
     197
    203198        d = self.protocol.join(self.test_srv, self.test_room, self.test_nick)
    204199        d.addBoth(cb)
     
    208203        self.failUnless(getattr(prs, 'x', None), 'No muc x element')
    209204        # send back user presence, they joined
    210        
     205
    211206        response = muc.PresenceError(error=muc.MUCError('modify',
    212207                                                        'jid-malformed'
     
    214209                                     frm=self.room_jid.full())
    215210        self.stub.send(response)
    216         return d       
    217 
     211        return d
    218212
    219213
     
    229223
    230224        prs = self.stub.output[-1]
    231        
     225
    232226        self.failUnless(prs['type']=='unavailable', 'Unavailable is not being sent')
    233        
     227
    234228        response = prs
    235229        response['from'] = response['to']
     
    238232        self.stub.send(response)
    239233        return d
    240        
     234
    241235
    242236    def test_userPartsRoom(self):
     
    245239
    246240        p = muc.UnavailableUserPresence()
    247         p['to'] = self.user_jid.full()
     241        p['to'] = self.user_jid.full()
    248242        p['from'] = self.room_jid.full()
    249243
     
    259253            self.failUnless(room.name==self.test_room, 'Wrong room name')
    260254            self.failUnless(room.inRoster(user)==False, 'User in roster')
    261                            
     255
    262256        d, self.protocol.userLeftRoom = calledAsync(userPresence)
    263257        self.stub.send(p)
    264258        return d
    265        
     259
    266260
    267261    def test_ban(self):
     
    272266            self.failUnless(banned, 'Did not ban user')
    273267
    274            
     268
    275269        d = self.protocol.ban(self.room_jid, banned, self.user_jid, reason='Spam')
    276270        d.addCallback(cb)
    277271
    278272        iq = self.stub.output[-1]
    279        
     273
    280274        self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@affiliation='outcast']" % (self.room_jid.userhost(),), iq), 'Wrong ban stanza')
    281275
     
    294288            self.failUnless(kicked, 'Did not kick user')
    295289
    296            
     290
    297291        d = self.protocol.kick(self.room_jid, kicked, self.user_jid, reason='Spam')
    298292        d.addCallback(cb)
    299293
    300294        iq = self.stub.output[-1]
    301        
     295
    302296        self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@affiliation='none']" % (self.room_jid.userhost(),), iq), 'Wrong kick stanza')
    303297
     
    308302        return d
    309303
    310        
    311304
    312305    def test_password(self):
    313306        """Sending a password via presence to a password protected room.
    314307        """
    315        
     308
    316309        self.protocol.password(self.room_jid, 'secret')
    317        
    318         prs = self.stub.output[-1]
    319        
     310
     311        prs = self.stub.output[-1]
     312
    320313        self.failUnless(xpath.matches("/presence[@to='%s']/x/password[text()='secret']" % (self.room_jid.full(),), prs), 'Wrong presence stanza')
    321314
     
    325318        """
    326319        m = muc.HistoryMessage(self.room_jid.userhost(), self.protocol._makeTimeStamp(), body='test')
    327         m['from'] = self.room_jid.full()
    328        
     320        m['from'] = self.room_jid.full()
     321
    329322        self._createRoom()
    330323
     
    332325            self.failUnless(body=='test', "wrong message body")
    333326            self.failUnless(stamp, 'Does not have a history stamp')
    334                    
     327
    335328
    336329        d, self.protocol.receivedHistory = calledAsync(roomHistory)
     
    369362            self.failUnless(m.name=='message', 'Wrong stanza')
    370363            self.failUnless(xpath.matches("/message/delay", m), 'Invalid history stanza')
    371        
     364
    372365
    373366    def test_invite(self):
     
    383376
    384377
    385        
    386378    def test_privateMessage(self):
    387379        """Send private messages to muc entities.
     
    400392
    401393        """
    402        
     394
    403395        def cb(iq):
    404396            # check for a result
    405397            self.failUnless(iq['type']=='result', 'We did not get a result')
    406        
     398
    407399        d = self.protocol.register(self.room_jid)
    408400        d.addCallback(cb)
     
    410402        iq = self.stub.output[-1]
    411403        self.failUnless(xpath.matches("/iq/query[@xmlns='%s']" % (muc.NS_REQUEST), iq), 'Invalid iq register request')
    412        
    413         response = toResponse(iq, 'result')
    414        
    415         self.stub.send(response)
    416         return d
     404
     405        response = toResponse(iq, 'result')
     406
     407        self.stub.send(response)
     408        return d
     409
    417410
    418411    def test_voice(self):
     
    422415
    423416        m = self.stub.output[-1]
    424        
     417
    425418        self.failUnless(xpath.matches("/message/x[@type='submit']/field/value[text()='%s']" % (muc.NS_MUC_REQUEST,), m), 'Invalid voice message stanza')
    426419
     
    432425        def cb(iq):
    433426            self.failUnless(iq['type']=='result', 'Not a result')
    434            
     427
    435428
    436429        fields = []
     
    439432                                      var='muc#roomconfig_roomname',
    440433                                      value=self.test_room))
    441        
     434
    442435        d = self.protocol.configure(self.room_jid.userhost(), fields)
    443436        d.addCallback(cb)
     
    445438        iq = self.stub.output[-1]
    446439        self.failUnless(xpath.matches("/iq/query[@xmlns='%s']/x"% (muc.NS_MUC_OWNER,), iq), 'Bad configure request')
    447        
     440
    448441        response = toResponse(iq, 'result')
    449442        self.stub.send(response)
     
    457450        def cb(destroyed):
    458451            self.failUnless(destroyed==True, 'Room not destroyed.')
    459                    
     452
    460453        d = self.protocol.destroy(self.room_jid)
    461454        d.addCallback(cb)
     
    463456        iq = self.stub.output[-1]
    464457        self.failUnless(xpath.matches("/iq/query[@xmlns='%s']/destroy"% (muc.NS_MUC_OWNER,), iq), 'Bad configure request')
    465        
     458
    466459        response = toResponse(iq, 'result')
    467460        self.stub.send(response)
     
    473466        """
    474467        test_nick = 'newNick'
    475        
     468
    476469        self._createRoom()
    477470
     
    487480        self.failUnless(getattr(prs, 'x', None), 'No muc x element')
    488481
    489         # send back user presence, they joined       
     482        # send back user presence, they joined
    490483        response = muc.UserPresence(frm=self.test_room+'@'+self.test_srv+'/'+test_nick)
    491        
    492         self.stub.send(response)
    493         return d
     484
     485        self.stub.send(response)
     486        return d
     487
    494488
    495489    def test_grantVoice(self):
     
    501495            self.failUnless(give_voice, 'Did not give voice user')
    502496
    503            
     497
    504498        d = self.protocol.grantVoice(self.user_jid, self.room_jid, give_voice)
    505499        d.addCallback(cb)
    506500
    507501        iq = self.stub.output[-1]
    508        
     502
    509503        self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@role='participant']" % (self.room_jid.userhost(),), iq), 'Wrong voice stanza')
    510504
     
    530524            self.failUnless(u.status == 'testing MUC', 'Wrong status')
    531525            self.failUnless(u.show == 'xa', 'Wrong show')
    532            
     526
    533527        d = self.protocol.status(self.room_jid, 'xa', 'testing MUC')
    534528        d.addCallback(cb)
     
    539533        self.failUnless(getattr(prs, 'x', None), 'No muc x element')
    540534
    541         # send back user presence, they joined       
     535        # send back user presence, they joined
    542536        response = muc.UserPresence(frm=self.room_jid.full())
    543537        response.addElement('show', None, 'xa')
    544538        response.addElement('status', None, 'testing MUC')
    545539        self.stub.send(response)
    546         return d       
     540        return d
Note: See TracChangeset for help on using the changeset viewer.