Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / words / test / test_xmpproutertap.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.words.xmpproutertap}.
6 """
7
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
12
13 class XMPPRouterTapTest(unittest.TestCase):
14
15     def test_port(self):
16         """
17         The port option is recognised as a parameter.
18         """
19         opt = tap.Options()
20         opt.parseOptions(['--port', '7001'])
21         self.assertEqual(opt['port'], '7001')
22
23
24     def test_portDefault(self):
25         """
26         The port option has '5347' as default value
27         """
28         opt = tap.Options()
29         opt.parseOptions([])
30         self.assertEqual(opt['port'], 'tcp:5347:interface=127.0.0.1')
31
32
33     def test_secret(self):
34         """
35         The secret option is recognised as a parameter.
36         """
37         opt = tap.Options()
38         opt.parseOptions(['--secret', 'hushhush'])
39         self.assertEqual(opt['secret'], 'hushhush')
40
41
42     def test_secretDefault(self):
43         """
44         The secret option has 'secret' as default value
45         """
46         opt = tap.Options()
47         opt.parseOptions([])
48         self.assertEqual(opt['secret'], 'secret')
49
50
51     def test_verbose(self):
52         """
53         The verbose option is recognised as a flag.
54         """
55         opt = tap.Options()
56         opt.parseOptions(['--verbose'])
57         self.assertTrue(opt['verbose'])
58
59
60     def test_makeService(self):
61         """
62         The service gets set up with a router and factory.
63         """
64         opt = tap.Options()
65         opt.parseOptions([])
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)
70         factory = s.factory
71         self.assertIsInstance(factory, component.XMPPComponentServerFactory)
72         self.assertIsInstance(factory.router, component.Router)
73         self.assertEqual('secret', factory.secret)
74         self.assertFalse(factory.logTraffic)
75
76
77     def test_makeServiceVerbose(self):
78         """
79         The verbose flag enables traffic logging.
80         """
81         opt = tap.Options()
82         opt.parseOptions(['--verbose'])
83         s = tap.makeService(opt)
84         self.assertTrue(s.factory.logTraffic)