1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Tests for L{twisted.words.xmpproutertap}.
8 from twisted.application import internet
9 from twisted.trial import unittest
10 from twisted.words import xmpproutertap as tap
11 from twisted.words.protocols.jabber import component
13 class XMPPRouterTapTest(unittest.TestCase):
17 The port option is recognised as a parameter.
20 opt.parseOptions(['--port', '7001'])
21 self.assertEqual(opt['port'], '7001')
24 def test_portDefault(self):
26 The port option has '5347' as default value
30 self.assertEqual(opt['port'], 'tcp:5347:interface=127.0.0.1')
33 def test_secret(self):
35 The secret option is recognised as a parameter.
38 opt.parseOptions(['--secret', 'hushhush'])
39 self.assertEqual(opt['secret'], 'hushhush')
42 def test_secretDefault(self):
44 The secret option has 'secret' as default value
48 self.assertEqual(opt['secret'], 'secret')
51 def test_verbose(self):
53 The verbose option is recognised as a flag.
56 opt.parseOptions(['--verbose'])
57 self.assertTrue(opt['verbose'])
60 def test_makeService(self):
62 The service gets set up with a router and factory.
66 s = tap.makeService(opt)
67 self.assertIsInstance(s, internet.StreamServerEndpointService)
68 self.assertEqual('127.0.0.1', s.endpoint._interface)
69 self.assertEqual(5347, s.endpoint._port)
71 self.assertIsInstance(factory, component.XMPPComponentServerFactory)
72 self.assertIsInstance(factory.router, component.Router)
73 self.assertEqual('secret', factory.secret)
74 self.assertFalse(factory.logTraffic)
77 def test_makeServiceVerbose(self):
79 The verbose flag enables traffic logging.
82 opt.parseOptions(['--verbose'])
83 s = tap.makeService(opt)
84 self.assertTrue(s.factory.logTraffic)