Ignore:
Timestamp:
Oct 11, 2008, 9:43:57 PM (14 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@104
Message:

Add missing tests for server factory and fix small naming error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_compat.py

    r37 r38  
    77"""
    88
     9from zope.interface.verify import verifyObject
    910from twisted.internet import defer, protocol
     11from twisted.internet.interfaces import IProtocolFactory
    1012from twisted.trial import unittest
    1113from twisted.words.xish import domish, utility
    12 from wokkel.compat import toResponse, BootstrapMixin
     14from twisted.words.protocols.jabber import xmlstream
     15from wokkel.compat import toResponse, BootstrapMixin, XmlStreamServerFactory
    1316
    1417class DummyProtocol(protocol.Protocol, utility.EventDispatcher):
     
    133136        response = toResponse(stanza)
    134137        self.failIf(response.hasAttribute('type'))
     138
     139
     140
     141class XmlStreamServerFactoryTest(BootstrapMixinTest):
     142    """
     143    Tests for L{XmlStreamServerFactory}.
     144    """
     145
     146    def setUp(self):
     147        """
     148        Set up a server factory with a authenticator factory function.
     149        """
     150        def authenticatorFactory():
     151            return xmlstream.Authenticator()
     152
     153        self.factory = XmlStreamServerFactory(authenticatorFactory)
     154
     155
     156    def test_interface(self):
     157        """
     158        L{XmlStreamServerFactory} is a L{Factory}.
     159        """
     160        verifyObject(IProtocolFactory, self.factory)
     161
     162
     163    def test_buildProtocol(self):
     164        """
     165        The authenticator factory should be passed to its protocol and it
     166        should instantiate the authenticator and save it.
     167        L{xmlstream.XmlStream}s do that, but we also want to ensure it really
     168        is one.
     169        """
     170        xs = self.factory.buildProtocol(None)
     171        self.assertIdentical(self.factory, xs.factory)
     172        self.assertIsInstance(xs, xmlstream.XmlStream)
     173        self.assertIsInstance(xs.authenticator, xmlstream.Authenticator)
     174
     175
     176    def test_buildProtocolTwice(self):
     177        """
     178        Subsequent calls to buildProtocol should result in different instances
     179        of the protocol, as well as their authenticators.
     180        """
     181        xs1 = self.factory.buildProtocol(None)
     182        xs2 = self.factory.buildProtocol(None)
     183        self.assertNotIdentical(xs1, xs2)
     184        self.assertNotIdentical(xs1.authenticator, xs2.authenticator)
Note: See TracChangeset for help on using the changeset viewer.