1
0

test_znc.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. patch,
  13. )
  14. # Import Salt Libs
  15. import salt.modules.znc as znc
  16. class ZncTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. TestCase for salt.modules.znc
  19. '''
  20. def setup_loader_modules(self):
  21. return {znc: {}}
  22. # 'buildmod' function tests: 1
  23. def test_buildmod(self):
  24. '''
  25. Tests build module using znc-buildmod
  26. '''
  27. with patch('os.path.exists', MagicMock(return_value=False)):
  28. self.assertEqual(znc.buildmod('modules.cpp'),
  29. 'Error: The file (modules.cpp) does not exist.')
  30. def test_buildmod_module(self):
  31. '''
  32. Tests build module using znc-buildmod
  33. '''
  34. mock = MagicMock(return_value='SALT')
  35. with patch.dict(znc.__salt__, {'cmd.run': mock}), \
  36. patch('os.path.exists', MagicMock(return_value=True)):
  37. self.assertEqual(znc.buildmod('modules.cpp'), 'SALT')
  38. # 'dumpconf' function tests: 1
  39. def test_dumpconf(self):
  40. '''
  41. Tests write the active configuration state to config file
  42. '''
  43. mock = MagicMock(return_value='SALT')
  44. with patch.dict(znc.__salt__, {'ps.pkill': mock}), \
  45. patch.object(znc, 'signal', MagicMock()):
  46. self.assertEqual(znc.dumpconf(), 'SALT')
  47. # 'rehashconf' function tests: 1
  48. def test_rehashconf(self):
  49. '''
  50. Tests rehash the active configuration state from config file
  51. '''
  52. mock = MagicMock(return_value='SALT')
  53. with patch.dict(znc.__salt__, {'ps.pkill': mock}), \
  54. patch.object(znc, 'signal', MagicMock()):
  55. self.assertEqual(znc.rehashconf(), 'SALT')
  56. # 'version' function tests: 1
  57. def test_version(self):
  58. '''
  59. Tests return server version from znc --version
  60. '''
  61. mock = MagicMock(return_value='ZNC 1.2 - http://znc.in')
  62. with patch.dict(znc.__salt__, {'cmd.run': mock}):
  63. self.assertEqual(znc.version(), 'ZNC 1.2')