Ignore:
Timestamp:
Jan 22, 2012, 2:51:25 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Cleanups leading up to Wokkel 0.7.0.

As we now depend on Twisted 10.0.0 or higher, the following classes and
interfaces were deprecated:

This also resolves all Pyflakes warnings, changes links for www.xmpp.org to
xmpp.org and fixes the copyright notice in LICENSE to include 2012.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_compat.py

    r160 r165  
    88
    99from zope.interface import implements
    10 from zope.interface.verify import verifyObject
    11 from twisted.internet import protocol, task
    12 from twisted.internet.interfaces import IProtocolFactory, IReactorTime
     10from twisted.internet import task
     11from twisted.internet.interfaces import IReactorTime
    1312from twisted.trial import unittest
    14 from twisted.words.xish import utility
    1513from twisted.words.protocols.jabber import xmlstream
    1614
    17 from wokkel.compat import BootstrapMixin, IQ, XmlStreamServerFactory
     15from wokkel.compat import IQ
    1816from wokkel.compat import NamedConstant, Names, ValueConstant, Values
    1917
    20 class DummyProtocol(protocol.Protocol, utility.EventDispatcher):
    21     """
    22     I am a protocol with an event dispatcher without further processing.
    23 
    24     This protocol is only used for testing BootstrapMixin to make
    25     sure the bootstrap observers are added to the protocol instance.
    26     """
    27 
    28     def __init__(self, *args, **kwargs):
    29         self.args = args
    30         self.kwargs = kwargs
    31         self.observers = []
    32 
    33         utility.EventDispatcher.__init__(self)
    34 
    35 
    36 
    37 class BootstrapMixinTest(unittest.TestCase):
    38     """
    39     Tests for L{BootstrapMixin}.
    40 
    41     @ivar factory: Instance of the factory or mixin under test.
    42     """
    43 
    44     def setUp(self):
    45         self.factory = BootstrapMixin()
    46 
    47 
    48     def test_installBootstraps(self):
    49         """
    50         Dispatching an event should fire registered bootstrap observers.
    51         """
    52         called = []
    53 
    54         def cb(data):
    55             called.append(data)
    56 
    57         dispatcher = DummyProtocol()
    58         self.factory.addBootstrap('//event/myevent', cb)
    59         self.factory.installBootstraps(dispatcher)
    60 
    61         dispatcher.dispatch(None, '//event/myevent')
    62         self.assertEquals(1, len(called))
    63 
    64 
    65     def test_addAndRemoveBootstrap(self):
    66         """
    67         Test addition and removal of a bootstrap event handler.
    68         """
    69 
    70         called = []
    71 
    72         def cb(data):
    73             called.append(data)
    74 
    75         self.factory.addBootstrap('//event/myevent', cb)
    76         self.factory.removeBootstrap('//event/myevent', cb)
    77 
    78         dispatcher = DummyProtocol()
    79         self.factory.installBootstraps(dispatcher)
    80 
    81         dispatcher.dispatch(None, '//event/myevent')
    82         self.assertFalse(called)
    83 
    84 
    85 
    86 class XmlStreamServerFactoryTest(BootstrapMixinTest):
    87     """
    88     Tests for L{XmlStreamServerFactory}.
    89     """
    90 
    91     def setUp(self):
    92         """
    93         Set up a server factory with a authenticator factory function.
    94         """
    95         class TestAuthenticator(object):
    96             def __init__(self):
    97                 self.xmlstreams = []
    98 
    99             def associateWithStream(self, xs):
    100                 self.xmlstreams.append(xs)
    101 
    102         def authenticatorFactory():
    103             return TestAuthenticator()
    104 
    105         self.factory = XmlStreamServerFactory(authenticatorFactory)
    106 
    107 
    108     def test_interface(self):
    109         """
    110         L{XmlStreamServerFactory} is a L{Factory}.
    111         """
    112         verifyObject(IProtocolFactory, self.factory)
    113 
    114 
    115     def test_buildProtocolAuthenticatorInstantiation(self):
    116         """
    117         The authenticator factory should be used to instantiate the
    118         authenticator and pass it to the protocol.
    119 
    120         The default protocol, L{XmlStream} stores the authenticator it is
    121         passed, and calls its C{associateWithStream} method. so we use that to
    122         check whether our authenticator factory is used and the protocol
    123         instance gets an authenticator.
    124         """
    125         xs = self.factory.buildProtocol(None)
    126         self.assertEquals([xs], xs.authenticator.xmlstreams)
    127 
    128 
    129     def test_buildProtocolXmlStream(self):
    130         """
    131         The protocol factory creates Jabber XML Stream protocols by default.
    132         """
    133         xs = self.factory.buildProtocol(None)
    134         self.assertIsInstance(xs, xmlstream.XmlStream)
    135 
    136 
    137     def test_buildProtocolTwice(self):
    138         """
    139         Subsequent calls to buildProtocol should result in different instances
    140         of the protocol, as well as their authenticators.
    141         """
    142         xs1 = self.factory.buildProtocol(None)
    143         xs2 = self.factory.buildProtocol(None)
    144         self.assertNotIdentical(xs1, xs2)
    145         self.assertNotIdentical(xs1.authenticator, xs2.authenticator)
    146 
    147 
    148     def test_buildProtocolInstallsBootstraps(self):
    149         """
    150         The protocol factory installs bootstrap event handlers on the protocol.
    151         """
    152         called = []
    153 
    154         def cb(data):
    155             called.append(data)
    156 
    157         self.factory.addBootstrap('//event/myevent', cb)
    158 
    159         xs = self.factory.buildProtocol(None)
    160         xs.dispatch(None, '//event/myevent')
    161 
    162         self.assertEquals(1, len(called))
    163 
    164 
    165     def test_buildProtocolStoresFactory(self):
    166         """
    167         The protocol factory is saved in the protocol.
    168         """
    169         xs = self.factory.buildProtocol(None)
    170         self.assertIdentical(self.factory, xs.factory)
     18class DeprecationTest(unittest.TestCase):
     19    """
     20    Deprecation tests for L{wokkel.compat}.
     21    """
     22
     23    def lookForDeprecationWarning(self, testmethod, attributeName, newName):
     24        """
     25        Importing C{testmethod} emits a deprecation warning.
     26        """
     27        warningsShown = self.flushWarnings([testmethod])
     28        self.assertEqual(len(warningsShown), 1)
     29        self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
     30        self.assertEqual(
     31            warningsShown[0]['message'],
     32            "wokkel.compat." + attributeName + " "
     33            "was deprecated in Wokkel 0.7.0: Use " + newName + " instead.")
     34
     35
     36    def test_bootstrapMixinTest(self):
     37        """
     38        L{compat.BootstrapMixin} is deprecated.
     39        """
     40        from wokkel.compat import BootstrapMixin
     41        BootstrapMixin
     42        self.lookForDeprecationWarning(
     43                self.test_bootstrapMixinTest,
     44                "BootstrapMixin",
     45                "twisted.words.xish.xmlstream.BootstrapMixin")
     46
     47
     48    def test_xmlStreamServerFactory(self):
     49        """
     50        L{compat.XmlStreamServerFactory} is deprecated.
     51        """
     52        from wokkel.compat import XmlStreamServerFactory
     53        XmlStreamServerFactory
     54        self.lookForDeprecationWarning(
     55                self.test_xmlStreamServerFactory,
     56                "XmlStreamServerFactory",
     57                "twisted.words.protocols.jabber.xmlstream."
     58                    "XmlStreamServerFactory")
    17159
    17260
Note: See TracChangeset for help on using the changeset viewer.