source: wokkel/test/test_client.py @ 36:aaa55b057292

Last change on this file since 36:aaa55b057292 was 36:aaa55b057292, checked in by Ralph Meijer <ralphm@…>, 14 years ago

Remove unused import.

File size: 2.2 KB
Line 
1# Copyright (c) 2003-2007 Ralph Meijer
2# See LICENSE for details.
3
4"""
5Tests for L{wokkel.client}.
6"""
7
8from twisted.words.protocols.jabber import xmlstream
9from twisted.words.protocols.jabber.client import XMPPAuthenticator
10from twisted.words.protocols.jabber.jid import JID
11from twisted.words.protocols.jabber.xmlstream import STREAM_AUTHD_EVENT
12from twisted.words.protocols.jabber.xmlstream import INIT_FAILED_EVENT
13
14from wokkel.client import DeferredClientFactory
15from wokkel.test.test_compat import BootstrapMixinTest
16
17class DeferredClientFactoryTest(BootstrapMixinTest):
18
19
20    def setUp(self):
21        self.factory = DeferredClientFactory(JID('user@example.org'), 'secret')
22
23
24    def test_buildProtocol(self):
25        """
26        The authenticator factory should be passed to its protocol and it
27        should instantiate the authenticator and save it.
28        L{xmlstream.XmlStream}s do that, but we also want to ensure it really
29        is one.
30        """
31        xs = self.factory.buildProtocol(None)
32        self.assertIdentical(self.factory, xs.factory)
33        self.assertIsInstance(xs, xmlstream.XmlStream)
34        self.assertIsInstance(xs.authenticator, XMPPAuthenticator)
35
36
37    def test_deferredOnInitialized(self):
38        """
39        Test the factory's deferred on stream initialization.
40        """
41
42        xs = self.factory.buildProtocol(None)
43        xs.dispatch(xs, STREAM_AUTHD_EVENT)
44        return self.factory.deferred
45
46
47    def test_deferredOnNotInitialized(self):
48        """
49        Test the factory's deferred on failed stream initialization.
50        """
51
52        class TestException(Exception):
53            pass
54
55        xs = self.factory.buildProtocol(None)
56        xs.dispatch(TestException(), INIT_FAILED_EVENT)
57        self.assertFailure(self.factory.deferred, TestException)
58        return self.factory.deferred
59
60
61    def test_deferredOnConnectionFailure(self):
62        """
63        Test the factory's deferred on connection faulure.
64        """
65
66        class TestException(Exception):
67            pass
68
69        xs = self.factory.buildProtocol(None)
70        self.factory.clientConnectionFailed(self, TestException())
71        self.assertFailure(self.factory.deferred, TestException)
72        return self.factory.deferred
Note: See TracBrowser for help on using the repository browser.