Changeset 72:d48789c4c484


Ignore:
Timestamp:
07/21/2009 20:00:12 (12 months ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
convert_revision:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@190
Message:

Add a jid attribute to XMPPClient that is updated with the current JID.

Author: ralphm.
Fixes #18.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/client.py

    r71 r72  
    8080 
    8181 
     82 
    8283class XMPPClient(StreamManager, service.Service): 
    8384    """ 
     
    8687 
    8788    def __init__(self, jid, password, host=None, port=5222): 
     89        self.jid = jid 
    8890        self.domain = jid.host 
    8991        self.host = host 
     
    9496        StreamManager.__init__(self, factory) 
    9597 
     98 
    9699    def startService(self): 
    97100        service.Service.startService(self) 
    98101 
    99102        self._connection = self._getConnection() 
     103 
    100104 
    101105    def stopService(self): 
     
    104108        self.factory.stopTrying() 
    105109        self._connection.disconnect() 
     110 
     111 
     112    def _authd(self, xs): 
     113        """ 
     114        Called when the stream has been initialized. 
     115 
     116        Save the JID that we were assigned by the server, as the resource might 
     117        differ from the JID we asked for. This is stored on the authenticator 
     118        by its constituent initializers. 
     119        """ 
     120        self.jid = self.factory.authenticator.jid 
     121        StreamManager._authd(self, xs) 
     122 
    106123 
    107124    def initializationFailed(self, reason): 
     
    115132        reason.raiseException() 
    116133 
     134 
    117135    def _getConnection(self): 
    118136        if self.host: 
     
    122140            c.connect() 
    123141            return c 
     142 
    124143 
    125144 
  • wokkel/test/test_client.py

    r61 r72  
    2121from wokkel import client 
    2222from wokkel.test.test_compat import BootstrapMixinTest 
     23 
     24class XMPPClientTest(unittest.TestCase): 
     25    """ 
     26    Tests for L{client.XMPPClient}. 
     27    """ 
     28 
     29    def setUp(self): 
     30        self.client = client.XMPPClient(JID('user@example.org'), 'secret') 
     31 
     32 
     33    def test_jid(self): 
     34        """ 
     35        Make sure the JID we pass is stored on the client. 
     36        """ 
     37        self.assertEquals(JID('user@example.org'), self.client.jid) 
     38 
     39 
     40    def test_jidWhenInitialized(self): 
     41        """ 
     42        Make sure that upon login, the JID is updated from the authenticator. 
     43        """ 
     44        xs = self.client.factory.buildProtocol(None) 
     45        self.client.factory.authenticator.jid = JID('user@example.org/test') 
     46        xs.dispatch(xs, xmlstream.STREAM_AUTHD_EVENT) 
     47        self.assertEquals(JID('user@example.org/test'), self.client.jid) 
     48 
     49 
    2350 
    2451class DeferredClientFactoryTest(BootstrapMixinTest): 
Note: See TracChangeset for help on using the changeset viewer.