Ignore:
Timestamp:
Sep 30, 2008, 7:08:45 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@69
Message:

add basic errors and disco stuff, still need iq and message parts re #24

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_muc.py

    r107 r108  
    1414from twisted.words.protocols.jabber.jid import JID
    1515
    16 from wokkel import data_form, iwokkel, muc, shim
     16from wokkel import data_form, iwokkel, muc, shim, disco
    1717from wokkel.generic import parseXml
    1818from wokkel.test.helpers import XmlStreamStub
     
    5858
    5959
    60     def test_presence(self):
    61         """Test receiving room presence
     60
     61    def test_discoServerSupport(self):
     62        """Test for disco support from a server.
    6263        """
    63         p = muc.UserPresence()
     64        test_srv = 'shakespeare.lit'
    6465
    65         def userPresence(prs):
    66             self.failUnless(len(prs.children)==1, 'Not enough children')
    67             self.failUnless(getattr(prs,'x',None), 'No x element')
     66        def cb(query):
     67            # check namespace
     68            self.failUnless(query.uri==disco.NS_INFO, 'Wrong namespace')
    6869           
    6970
    70         d, self.protocol.userPresence = calledAsync(userPresence)
    71         self.stub.send(p)
     71        d = self.protocol.disco(test_srv)
     72        d.addCallback(cb)
     73
     74        iq = self.stub.output[-1]
     75       
     76        # send back a response
     77        response = toResponse(iq, 'result')
     78        response.addElement('query', disco.NS_INFO)
     79        # need to add information to response
     80        response.query.addChild(disco.DiscoFeature(muc.NS))
     81        response.query.addChild(disco.DiscoIdentity(category='conference',
     82                                                    name='Macbeth Chat Service',
     83                                                    type='text'))
     84       
     85        self.stub.send(response)
    7286        return d
     87       
    7388
     89       
    7490    def test_joinRoom(self):
    7591        """Test joining a room
     
    7995        test_nick = 'Nick'
    8096
    81         # p = muc.BasicPresenc(to=)
    82 
    8397        def cb(room):
    8498            self.assertEquals(test_room, room.name)
    8599
    86         d = self.protocol.joinRoom(test_srv, test_room, test_nick)
     100        d = self.protocol.join(test_srv, test_room, test_nick)
    87101        d.addCallback(cb)
     102
     103        prs = self.stub.output[-1]
     104        self.failUnless(prs.name=='presence', "Need to be presence")
     105        self.failUnless(getattr(prs, 'x', None), 'No muc x element')
     106
     107        # send back user presence, they joined       
     108        response = muc.UserPresence(frm=test_room+'@'+test_srv+'/'+test_nick)
     109        self.stub.send(response)
     110        return d
     111
     112
     113    def test_joinRoomForbidden(self):
     114        """Test joining a room and getting an error
     115        """
     116        test_room = 'test'
     117        test_srv  = 'conference.example.org'
     118        test_nick = 'Nick'
     119
     120        # p = muc.BasicPresenc(to=)
     121
     122        def cb(error):
     123            self.failUnless(isinstance(error.value,muc.PresenceError), 'Wrong type')
     124            self.failUnless(error.value['type']=='error', 'Not an error returned')
     125           
     126           
     127        d = self.protocol.join(test_srv, test_room, test_nick)
     128        d.addBoth(cb)
    88129
    89130        prs = self.stub.output[-1]
     
    92133        # send back user presence, they joined
    93134       
    94         response = muc.UserPresence()
    95         print response.toXml()
     135        response = muc.PresenceError(error=muc.MUCError('auth',
     136                                                        'forbidden'
     137                                                        ),
     138                                     frm=test_room+'@'+test_srv+'/'+test_nick)
    96139        self.stub.send(response)
    97         return d
    98 
    99 class MucServiceTest(unittest.TestCase):
    100     """
    101     Tests for L{muc.MUCService}.
    102     """
    103 
    104     def setUp(self):
    105         self.service = muc.MUCService()
    106 
    107     def handleRequest(self, xml):
    108         """
    109         Find a handler and call it directly
    110         """
    111         handler = None
    112         iq = parseXml(xml)
    113         for queryString, method in self.service.iqHandlers.iteritems():
    114             if xpath.internQuery(queryString).matches(iq):
    115                 handler = getattr(self.service, method)
    116 
    117         if handler:
    118             d = defer.maybeDeferred(handler, iq)
    119         else:
    120             d = defer.fail(NotImplementedError())
    121 
    122         return d
    123 
    124 
    125     def test_interface(self):
    126         """
    127         Do instances of L{muc.MucService} provide L{iwokkel.IMucService}?
    128         """
    129         verify.verifyObject(iwokkel.IMUCService, self.service)
    130 
    131 
     140        return d       
Note: See TracChangeset for help on using the changeset viewer.