Exemplo n.º 1
0
 def testUnlistenersCallable(self):
     s = service.MultiService()
     c = compat.IOldApplication(s)
     self.assert_(callable(c.unlistenTCP))
     self.assert_(callable(c.unlistenUNIX))
     self.assert_(callable(c.unlistenUDP))
     self.assert_(callable(c.unlistenSSL))
Exemplo n.º 2
0
 def testCalling(self):
     s = service.MultiService()
     c = compat.IOldApplication(s)
     c.listenWith(None)
     self.assertEqual(list(s)[0].args[0], None)
     c.listenTCP(None, None)
     self.assertEqual(list(s)[1].args[:2], (None, ) * 2)
     c.listenSSL(None, None, None)
     self.assertEqual(list(s)[2].args[:3], (None, ) * 3)
     c.listenUDP(None, None)
     self.assertEqual(list(s)[3].args[:2], (None, ) * 2)
     c.listenUNIX(None, None)
     self.assertEqual(list(s)[4].args[:2], (None, ) * 2)
     for ch in s:
         self.assert_(ch.privileged)
     c.connectWith(None)
     self.assertEqual(list(s)[5].args[0], None)
     c.connectTCP(None, None, None)
     self.assertEqual(list(s)[6].args[:3], (None, ) * 3)
     c.connectSSL(None, None, None, None)
     self.assertEqual(list(s)[7].args[:4], (None, ) * 4)
     c.connectUDP(None, None, None)
     self.assertEqual(list(s)[8].args[:3], (None, ) * 3)
     c.connectUNIX(None, None)
     self.assertEqual(list(s)[9].args[:2], (None, ) * 2)
     self.assertEqual(len(list(s)), 10)
     for ch in s:
         self.failIf(ch.kwargs)
         self.assertEqual(ch.name, None)
Exemplo n.º 3
0
    def testTCP(self):
        s = service.MultiService()
        c = compat.IOldApplication(s)
        factory = protocol.ServerFactory()
        factory.protocol = TestEcho
        TestEcho.d = defer.Deferred()
        c.listenTCP(0, factory)
        s.privilegedStartService()
        s.startService()
        num = list(s)[0]._port.getHost().port

        class Foo(basic.LineReceiver):
            def connectionMade(self):
                self.transport.write('lalala\r\n')

            def lineReceived(self, line):
                self.factory.line = line
                self.transport.loseConnection()

        factory = protocol.ClientFactory()
        factory.protocol = Foo
        factory.line = None
        c.connectTCP('127.0.0.1', num, factory)
        util.spinWhile(lambda: factory.line is None)
        util.wait(defer.maybeDeferred(s.stopService))
        self.assertEqual(factory.line, 'lalala')

        # Cleanup the reactor
        util.wait(TestEcho.d)
Exemplo n.º 4
0
    def testUNIX(self):
        if not interfaces.IReactorUNIX(reactor, None):
            raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
        s = service.MultiService()
        c = compat.IOldApplication(s)
        factory = protocol.ServerFactory()
        factory.protocol = TestEcho
        TestEcho.d = defer.Deferred()
        if os.path.exists('.hello.skt'):
            os.remove('hello.skt')
        c.listenUNIX('./hello.skt', factory)

        class Foo(basic.LineReceiver):
            def connectionMade(self):
                self.transport.write('lalala\r\n')

            def lineReceived(self, line):
                self.factory.line = line
                self.transport.loseConnection()

        factory = protocol.ClientFactory()
        factory.protocol = Foo
        factory.line = None
        c.connectUNIX('./hello.skt', factory)
        s.privilegedStartService()
        s.startService()
        util.spinWhile(lambda: factory.line is None)
        util.wait(defer.maybeDeferred(s.stopService))
        self.assertEqual(factory.line, 'lalala')

        # Cleanup the reactor
        util.wait(TestEcho.d)
Exemplo n.º 5
0
def makeService(mod, name, options):
    if hasattr(mod, 'updateApplication'):
        ser = service.MultiService()
        oldapp = compat.IOldApplication(ser)
        oldapp.name = name
        mod.updateApplication(oldapp, options)
    else:
        ser = mod.makeService(options)
    return ser
Exemplo n.º 6
0
 def testService(self):
     # test old services with new application
     s = service.MultiService()
     c = compat.IOldApplication(s)
     from twisted.internet.app import ApplicationService
     svc = ApplicationService("foo", serviceParent=c)
     self.assertEquals(c.getServiceNamed("foo"), svc)
     self.assertEquals(s.getServiceNamed("foo").name, "foo")
     c.removeService(svc)
Exemplo n.º 7
0
 def testServices(self):
     s = service.MultiService()
     c = compat.IOldApplication(s)
     ch = service.Service()
     ch.setName("lala")
     ch.setServiceParent(c)
     self.assertEqual(c.getServiceNamed("lala"), ch)
     ch.disownServiceParent()
     self.assertEqual(list(s), [])
Exemplo n.º 8
0
 def testTCP(self):
     s = service.MultiService()
     c = compat.IOldApplication(s)
     factory = protocol.ServerFactory()
     factory.protocol = TestEcho
     TestEcho.d = defer.Deferred()
     c.listenTCP(0, factory)
     s.privilegedStartService()
     s.startService()
     num = list(s)[0]._port.getHost().port
     factory = protocol.ClientFactory()
     factory.d = defer.Deferred()
     factory.protocol = Foo
     factory.line = None
     c.connectTCP('127.0.0.1', num, factory)
     factory.d.addCallback(self.assertEqual, 'lalala')
     factory.d.addCallback(lambda x: s.stopService())
     factory.d.addCallback(lambda x: TestEcho.d)
     return factory.d
Exemplo n.º 9
0
 def testUNIX(self):
     if not interfaces.IReactorUNIX(reactor, None):
         raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
     s = service.MultiService()
     c = compat.IOldApplication(s)
     factory = protocol.ServerFactory()
     factory.protocol = TestEcho
     TestEcho.d = defer.Deferred()
     if os.path.exists('.hello.skt'):
         os.remove('hello.skt')
     c.listenUNIX('./hello.skt', factory)
     factory = protocol.ClientFactory()
     factory.d = defer.Deferred()
     factory.protocol = Foo
     factory.line = None
     c.connectUNIX('./hello.skt', factory)
     s.privilegedStartService()
     s.startService()
     factory.d.addCallback(self.assertEqual, 'lalala')
     factory.d.addCallback(lambda x: s.stopService())
     factory.d.addCallback(lambda x: TestEcho.d)
     return factory.d
Exemplo n.º 10
0
 def testInterface(self):
     s = service.MultiService()
     c = compat.IOldApplication(s)
     for key in compat.IOldApplication.__dict__.keys():
         if callable(getattr(compat.IOldApplication, key)):
             self.assert_(callable(getattr(c, key)))