Ignore:
Timestamp:
Oct 10, 2008, 4:35:43 PM (14 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@88
Message:

Backport XmlStreamServerFactory?.

Author: ralphm.
Fixes #29.

This also replaces XmlStreamFactoryMixin? with BootstrapMixin? for DeferredClientFactory?.

Location:
wokkel/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_client.py

    r8 r34  
    77
    88from twisted.trial import unittest
     9from twisted.words.protocols.jabber import xmlstream
     10from twisted.words.protocols.jabber.client import XMPPAuthenticator
    911from twisted.words.protocols.jabber.jid import JID
    1012from twisted.words.protocols.jabber.xmlstream import STREAM_AUTHD_EVENT
     
    1214
    1315from wokkel.client import DeferredClientFactory
     16from wokkel.test.test_compat import BootstrapMixinTest
    1417
    15 class DeferredClientFactoryTest(unittest.TestCase):
     18class DeferredClientFactoryTest(BootstrapMixinTest):
     19
     20
     21    def setUp(self):
     22        self.factory = DeferredClientFactory(JID('user@example.org'), 'secret')
     23
     24
     25    def test_buildProtocol(self):
     26        """
     27        The authenticator factory should be passed to its protocol and it
     28        should instantiate the authenticator and save it.
     29        L{xmlstream.XmlStream}s do that, but we also want to ensure it really
     30        is one.
     31        """
     32        xs = self.factory.buildProtocol(None)
     33        self.assertIdentical(self.factory, xs.factory)
     34        self.assertIsInstance(xs, xmlstream.XmlStream)
     35        self.assertIsInstance(xs.authenticator, XMPPAuthenticator)
     36
    1637
    1738    def test_deferredOnInitialized(self):
     
    2041        """
    2142
    22         f = DeferredClientFactory(JID('user@example.org'), 'secret')
    23         xmlstream = f.buildProtocol(None)
    24         xmlstream.dispatch(xmlstream, STREAM_AUTHD_EVENT)
    25         return f.deferred
     43        xs = self.factory.buildProtocol(None)
     44        xs.dispatch(xs, STREAM_AUTHD_EVENT)
     45        return self.factory.deferred
     46
    2647
    2748    def test_deferredOnNotInitialized(self):
     
    3051        """
    3152
    32         f = DeferredClientFactory(JID('user@example.org'), 'secret')
    33         xmlstream = f.buildProtocol(None)
    34 
    3553        class TestException(Exception):
    3654            pass
    3755
    38         xmlstream.dispatch(TestException(), INIT_FAILED_EVENT)
    39         self.assertFailure(f.deferred, TestException)
    40         return f.deferred
     56        xs = self.factory.buildProtocol(None)
     57        xs.dispatch(TestException(), INIT_FAILED_EVENT)
     58        self.assertFailure(self.factory.deferred, TestException)
     59        return self.factory.deferred
     60
    4161
    4262    def test_deferredOnConnectionFailure(self):
     
    4565        """
    4666
    47         f = DeferredClientFactory(JID('user@example.org'), 'secret')
    48         xmlstream = f.buildProtocol(None)
    49 
    5067        class TestException(Exception):
    5168            pass
    5269
    53         f.clientConnectionFailed(self, TestException())
    54         self.assertFailure(f.deferred, TestException)
    55         return f.deferred
     70        xs = self.factory.buildProtocol(None)
     71        self.factory.clientConnectionFailed(self, TestException())
     72        self.assertFailure(self.factory.deferred, TestException)
     73        return self.factory.deferred
  • wokkel/test/test_compat.py

    r8 r34  
    1010from twisted.trial import unittest
    1111from twisted.words.xish import domish, utility
    12 from wokkel.compat import toResponse, XmlStreamFactoryMixin
     12from wokkel.compat import toResponse, BootstrapMixin
    1313
    1414class DummyProtocol(protocol.Protocol, utility.EventDispatcher):
     
    1616    I am a protocol with an event dispatcher without further processing.
    1717
    18     This protocol is only used for testing XmlStreamFactoryMixin to make
     18    This protocol is only used for testing BootstrapMixin to make
    1919    sure the bootstrap observers are added to the protocol instance.
    2020    """
     
    2828
    2929
    30 class XmlStreamFactoryMixinTest(unittest.TestCase):
    3130
    32     def test_buildProtocol(self):
     31class BootstrapMixinTest(unittest.TestCase):
     32    """
     33    Tests for L{BootstrapMixin}.
     34
     35    @ivar factory: Instance of the factory or mixin under test.
     36    """
     37
     38    def setUp(self):
     39        self.factory = BootstrapMixin()
     40
     41
     42    def test_installBootstraps(self):
    3343        """
    34         Test building of protocol.
    35 
    36         Arguments passed to Factory should be passed to protocol on
    37         instantiation. Bootstrap observers should be setup.
     44        Dispatching an event should fire registered bootstrap observers.
    3845        """
    3946        d = defer.Deferred()
     47        dispatcher = DummyProtocol()
     48        self.factory.addBootstrap('//event/myevent', d.callback)
     49        self.factory.installBootstraps(dispatcher)
     50        dispatcher.dispatch(None, '//event/myevent')
     51        return d
    4052
    41         f = XmlStreamFactoryMixin(None, test=None)
    42         f.protocol = DummyProtocol
    43         f.addBootstrap('//event/myevent', d.callback)
    44         xs = f.buildProtocol(None)
    45 
    46         self.assertEquals(f, xs.factory)
    47         self.assertEquals((None,), xs.args)
    48         self.assertEquals({'test': None}, xs.kwargs)
    49         xs.dispatch(None, '//event/myevent')
    50         return d
    5153
    5254    def test_addAndRemoveBootstrap(self):
     
    5759            pass
    5860
    59         f = XmlStreamFactoryMixin(None, test=None)
     61        self.factory.addBootstrap('//event/myevent', cb)
     62        self.assertIn(('//event/myevent', cb), self.factory.bootstraps)
    6063
    61         f.addBootstrap('//event/myevent', cb)
    62         self.assertIn(('//event/myevent', cb), f.bootstraps)
     64        self.factory.removeBootstrap('//event/myevent', cb)
     65        self.assertNotIn(('//event/myevent', cb), self.factory.bootstraps)
    6366
    64         f.removeBootstrap('//event/myevent', cb)
    65         self.assertNotIn(('//event/myevent', cb), f.bootstraps)
     67
    6668
    6769class ToResponseTest(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.