source: wokkel/test/test_client.py @ 34:5d34b8c88a55

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

Backport XmlStreamServerFactory?.

Author: ralphm.
Fixes #29.

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

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.trial import unittest
9from twisted.words.protocols.jabber import xmlstream
10from twisted.words.protocols.jabber.client import XMPPAuthenticator
11from twisted.words.protocols.jabber.jid import JID
12from twisted.words.protocols.jabber.xmlstream import STREAM_AUTHD_EVENT
13from twisted.words.protocols.jabber.xmlstream import INIT_FAILED_EVENT
14
15from wokkel.client import DeferredClientFactory
16from wokkel.test.test_compat import BootstrapMixinTest
17
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
37
38    def test_deferredOnInitialized(self):
39        """
40        Test the factory's deferred on stream initialization.
41        """
42
43        xs = self.factory.buildProtocol(None)
44        xs.dispatch(xs, STREAM_AUTHD_EVENT)
45        return self.factory.deferred
46
47
48    def test_deferredOnNotInitialized(self):
49        """
50        Test the factory's deferred on failed stream initialization.
51        """
52
53        class TestException(Exception):
54            pass
55
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
61
62    def test_deferredOnConnectionFailure(self):
63        """
64        Test the factory's deferred on connection faulure.
65        """
66
67        class TestException(Exception):
68            pass
69
70        xs = self.factory.buildProtocol(None)
71        self.factory.clientConnectionFailed(self, TestException())
72        self.assertFailure(self.factory.deferred, TestException)
73        return self.factory.deferred
Note: See TracBrowser for help on using the repository browser.