Ejemplo n.º 1
0
    def setUp(self):
        self.handler = mock.Mock()
        directlyProvides(self.handler, ILogHandler)

        self.endpoint = mock.Mock()
        directlyProvides(self.endpoint, IStreamServerEndpoint)

        self.port = mock.Mock()

        def _listen(*args, **kwargs):
            return succeed(self.port)

        self.endpoint.listen.side_effect = _listen

        self.service = ScribeServerService(self.endpoint, self.handler)

        self.transport = StringTransport()
Ejemplo n.º 2
0
def makeService(config):
    endpoint = serverFromString(reactor, config['port'])
    if config['handlerFactory'] is None:
        handlerFactory = TwistedLogHandler
    else:
        handlerFactory = namedAny(config['handlerFactory'])

    return ScribeServerService(endpoint, handlerFactory())
Ejemplo n.º 3
0
class ScribeServerServiceTests(TestCase):
    def setUp(self):
        self.handler = mock.Mock()
        directlyProvides(self.handler, ILogHandler)

        self.endpoint = mock.Mock()
        directlyProvides(self.endpoint, IStreamServerEndpoint)

        self.port = mock.Mock()

        def _listen(*args, **kwargs):
            return succeed(self.port)

        self.endpoint.listen.side_effect = _listen

        self.service = ScribeServerService(self.endpoint, self.handler)

        self.transport = StringTransport()

    def test_startService(self):
        self.service.startService()
        self.assertEqual(self.endpoint.listen.call_count, 1)

    def test_stopService(self):
        self.service.startService()
        self.service.stopService()

        self.assertEqual(self.port.stopListening.call_count, 1)