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.

Location:
wokkel/test
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_client.py

    r96 r165  
    1313from twisted.words.protocols.jabber.xmlstream import STREAM_AUTHD_EVENT
    1414from twisted.words.protocols.jabber.xmlstream import INIT_FAILED_EVENT
    15 
    16 try:
    17     from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    18 except ImportError:
    19     from wokkel.subprotocols import XMPPHandler
     15from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    2016
    2117from wokkel import client
    22 from wokkel.test.test_compat import BootstrapMixinTest
    2318
    2419class XMPPClientTest(unittest.TestCase):
     
    4944
    5045
    51 class DeferredClientFactoryTest(BootstrapMixinTest):
     46class DeferredClientFactoryTest(unittest.TestCase):
    5247    """
    5348    Tests for L{client.DeferredClientFactory}.
     
    10499            pass
    105100
    106         xs = self.factory.buildProtocol(None)
     101        self.factory.buildProtocol(None)
    107102        self.factory.clientConnectionFailed(self, TestException())
    108103        self.assertFailure(self.factory.deferred, TestException)
  • 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
  • wokkel/test/test_component.py

    r96 r165  
    88from zope.interface.verify import verifyObject
    99
    10 from twisted.internet import defer
    1110from twisted.python import failure
    1211from twisted.trial import unittest
    13 from twisted.words.protocols.jabber import ijabber, xmlstream
     12from twisted.words.protocols.jabber import xmlstream
     13from twisted.words.protocols.jabber.ijabber import IXMPPHandlerCollection
    1414from twisted.words.protocols.jabber.jid import JID
     15from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    1516from twisted.words.xish import domish
    16 
    17 try:
    18     from twisted.words.protocols.jabber.ijabber import IXMPPHandlerCollection
    19     from twisted.words.protocols.jabber.xmlstream import XMPPHandler
    20 except ImportError:
    21     from wokkel.subprotocols import IXMPPHandlerCollection, XMPPHandler
    2217
    2318from wokkel import component
     
    4035        """
    4136        verifyObject(IXMPPHandlerCollection, self.component)
    42 
    4337
    4438
  • wokkel/test/test_generic.py

    r102 r165  
    3434        iq['to'] = 'example.org'
    3535        iq['type'] = 'get'
    36         query = iq.addElement((NS_VERSION, 'query'))
     36        iq.addElement((NS_VERSION, 'query'))
    3737        self.stub.send(iq)
    3838
  • wokkel/test/test_subprotocols.py

    r101 r165  
    1414from twisted.python import failure
    1515from twisted.words.xish import domish
    16 from twisted.words.protocols.jabber import error, xmlstream
    17 
    18 from wokkel import generic, iwokkel, subprotocols
     16from twisted.words.protocols.jabber import error, ijabber, xmlstream
     17
     18from wokkel import generic, subprotocols
     19
     20class DeprecationTest(unittest.TestCase):
     21    """
     22    Deprecation test for L{wokkel.subprotocols}.
     23    """
     24
     25    def lookForDeprecationWarning(self, testmethod, attributeName, newName):
     26        """
     27        Importing C{testmethod} emits a deprecation warning.
     28        """
     29        warningsShown = self.flushWarnings([testmethod])
     30        self.assertEqual(len(warningsShown), 1)
     31        self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
     32        self.assertEqual(
     33            warningsShown[0]['message'],
     34            "wokkel.subprotocols." + attributeName + " "
     35            "was deprecated in Wokkel 0.7.0: Use " + newName + " instead.")
     36
     37
     38    def test_xmppHandlerCollection(self):
     39        """
     40        L{subprotocols.XMPPHandlerCollection} is deprecated.
     41        """
     42        from wokkel.subprotocols import XMPPHandlerCollection
     43        XMPPHandlerCollection
     44        self.lookForDeprecationWarning(
     45                self.test_xmppHandlerCollection,
     46                "XMPPHandlerCollection",
     47                "twisted.words.protocols.jabber.xmlstream."
     48                    "XMPPHandlerCollection")
     49
     50
    1951
    2052class DummyFactory(object):
     
    88120    def test_interface(self):
    89121        """
    90         L{xmlstream.XMPPHandler} implements L{iwokkel.IXMPPHandler}.
    91         """
    92         verifyObject(iwokkel.IXMPPHandler, subprotocols.XMPPHandler())
     122        L{xmlstream.XMPPHandler} implements L{ijabber.IXMPPHandler}.
     123        """
     124        verifyObject(ijabber.IXMPPHandler, subprotocols.XMPPHandler())
    93125
    94126
     
    155187        self.assertIdentical(request, handler.parent.requests[-1])
    156188        return d
    157 
    158 
    159 
    160 class XMPPHandlerCollectionTest(unittest.TestCase):
    161     """
    162     Tests for L{subprotocols.XMPPHandlerCollection}.
    163     """
    164 
    165     def setUp(self):
    166         self.collection = subprotocols.XMPPHandlerCollection()
    167 
    168 
    169     def test_interface(self):
    170         """
    171         L{subprotocols.StreamManager} implements L{iwokkel.IXMPPHandlerCollection}.
    172         """
    173         verifyObject(iwokkel.IXMPPHandlerCollection, self.collection)
    174 
    175 
    176     def test_addHandler(self):
    177         """
    178         Test the addition of a protocol handler.
    179         """
    180         handler = DummyXMPPHandler()
    181         handler.setHandlerParent(self.collection)
    182         self.assertIn(handler, self.collection)
    183         self.assertIdentical(self.collection, handler.parent)
    184 
    185 
    186     def test_removeHandler(self):
    187         """
    188         Test removal of a protocol handler.
    189         """
    190         handler = DummyXMPPHandler()
    191         handler.setHandlerParent(self.collection)
    192         handler.disownHandlerParent(self.collection)
    193         self.assertNotIn(handler, self.collection)
    194         self.assertIdentical(None, handler.parent)
    195189
    196190
     
    319313        handler = FailureReasonXMPPHandler()
    320314        handler.setHandlerParent(sm)
    321         xs = xmlstream.XmlStream(xmlstream.Authenticator())
     315        xmlstream.XmlStream(xmlstream.Authenticator())
    322316        sm._disconnected(failure.Failure(Exception("no reason")))
    323317        self.assertEquals(True, handler.gotFailureReason)
Note: See TracChangeset for help on using the changeset viewer.