test_xmpproutertap.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{twisted.words.xmpproutertap}.
  5. """
  6. from twisted.application import internet
  7. from twisted.trial import unittest
  8. from twisted.words import xmpproutertap as tap
  9. from twisted.words.protocols.jabber import component
  10. class XMPPRouterTapTests(unittest.TestCase):
  11. def test_port(self):
  12. """
  13. The port option is recognised as a parameter.
  14. """
  15. opt = tap.Options()
  16. opt.parseOptions(['--port', '7001'])
  17. self.assertEqual(opt['port'], '7001')
  18. def test_portDefault(self):
  19. """
  20. The port option has '5347' as default value
  21. """
  22. opt = tap.Options()
  23. opt.parseOptions([])
  24. self.assertEqual(opt['port'], 'tcp:5347:interface=127.0.0.1')
  25. def test_secret(self):
  26. """
  27. The secret option is recognised as a parameter.
  28. """
  29. opt = tap.Options()
  30. opt.parseOptions(['--secret', 'hushhush'])
  31. self.assertEqual(opt['secret'], 'hushhush')
  32. def test_secretDefault(self):
  33. """
  34. The secret option has 'secret' as default value
  35. """
  36. opt = tap.Options()
  37. opt.parseOptions([])
  38. self.assertEqual(opt['secret'], 'secret')
  39. def test_verbose(self):
  40. """
  41. The verbose option is recognised as a flag.
  42. """
  43. opt = tap.Options()
  44. opt.parseOptions(['--verbose'])
  45. self.assertTrue(opt['verbose'])
  46. def test_makeService(self):
  47. """
  48. The service gets set up with a router and factory.
  49. """
  50. opt = tap.Options()
  51. opt.parseOptions([])
  52. s = tap.makeService(opt)
  53. self.assertIsInstance(s, internet.StreamServerEndpointService)
  54. self.assertEqual('127.0.0.1', s.endpoint._interface)
  55. self.assertEqual(5347, s.endpoint._port)
  56. factory = s.factory
  57. self.assertIsInstance(factory, component.XMPPComponentServerFactory)
  58. self.assertIsInstance(factory.router, component.Router)
  59. self.assertEqual('secret', factory.secret)
  60. self.assertFalse(factory.logTraffic)
  61. def test_makeServiceVerbose(self):
  62. """
  63. The verbose flag enables traffic logging.
  64. """
  65. opt = tap.Options()
  66. opt.parseOptions(['--verbose'])
  67. s = tap.makeService(opt)
  68. self.assertTrue(s.factory.logTraffic)