source: wokkel/test/test_client.py @ 120:9548851ca5ac

Last change on this file since 120:9548851ca5ac was 8:af29fb9001cb, checked in by Ralph Meijer <ralphm@…>, 15 years ago

Add compatiblity module to have wokkel work with Twisted Words 0.5.

Author: ralphm
Fixes #5.

File size: 1.6 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.jid import JID
10from twisted.words.protocols.jabber.xmlstream import STREAM_AUTHD_EVENT
11from twisted.words.protocols.jabber.xmlstream import INIT_FAILED_EVENT
12
13from wokkel.client import DeferredClientFactory
14
15class DeferredClientFactoryTest(unittest.TestCase):
16
17    def test_deferredOnInitialized(self):
18        """
19        Test the factory's deferred on stream initialization.
20        """
21
22        f = DeferredClientFactory(JID('user@example.org'), 'secret')
23        xmlstream = f.buildProtocol(None)
24        xmlstream.dispatch(xmlstream, STREAM_AUTHD_EVENT)
25        return f.deferred
26
27    def test_deferredOnNotInitialized(self):
28        """
29        Test the factory's deferred on failed stream initialization.
30        """
31
32        f = DeferredClientFactory(JID('user@example.org'), 'secret')
33        xmlstream = f.buildProtocol(None)
34
35        class TestException(Exception):
36            pass
37
38        xmlstream.dispatch(TestException(), INIT_FAILED_EVENT)
39        self.assertFailure(f.deferred, TestException)
40        return f.deferred
41
42    def test_deferredOnConnectionFailure(self):
43        """
44        Test the factory's deferred on connection faulure.
45        """
46
47        f = DeferredClientFactory(JID('user@example.org'), 'secret')
48        xmlstream = f.buildProtocol(None)
49
50        class TestException(Exception):
51            pass
52
53        f.clientConnectionFailed(self, TestException())
54        self.assertFailure(f.deferred, TestException)
55        return f.deferred
Note: See TracBrowser for help on using the repository browser.