test_decorators.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.case import ModuleCase
  6. class DecoratorTest(ModuleCase):
  7. def test_module(self):
  8. self.assertTrue(
  9. self.run_function(
  10. 'runtests_decorators.working_function'
  11. )
  12. )
  13. def test_depends(self):
  14. ret = self.run_function('runtests_decorators.depends')
  15. self.assertTrue(isinstance(ret, dict))
  16. self.assertTrue(ret['ret'])
  17. self.assertTrue(isinstance(ret['time'], float))
  18. def test_missing_depends(self):
  19. self.assertEqual(
  20. {'runtests_decorators.missing_depends_will_fallback': None,
  21. 'runtests_decorators.missing_depends': "'runtests_decorators.missing_depends' is not available."},
  22. self.run_function('runtests_decorators.missing_depends'
  23. )
  24. )
  25. def test_bool_depends(self):
  26. # test True
  27. self.assertTrue(
  28. self.run_function(
  29. 'runtests_decorators.booldependsTrue'
  30. )
  31. )
  32. # test False
  33. self.assertIn(
  34. 'is not available',
  35. self.run_function('runtests_decorators.booldependsFalse'
  36. )
  37. )
  38. def test_depends_will_not_fallback(self):
  39. ret = self.run_function('runtests_decorators.depends_will_not_fallback')
  40. self.assertTrue(isinstance(ret, dict))
  41. self.assertTrue(ret['ret'])
  42. self.assertTrue(isinstance(ret['time'], float))
  43. def test_missing_depends_will_fallback(self):
  44. self.assertListEqual(
  45. [False, 'fallback'],
  46. self.run_function(
  47. 'runtests_decorators.missing_depends_will_fallback'
  48. )
  49. )
  50. def test_command_success_retcode(self):
  51. ret = self.run_function('runtests_decorators.command_success_retcode')
  52. self.assertIs(ret, True)
  53. def test_command_failure_retcode(self):
  54. ret = self.run_function('runtests_decorators.command_failure_retcode')
  55. self.assertEqual(
  56. ret,
  57. "'runtests_decorators.command_failure_retcode' is not available."
  58. )
  59. def test_command_success_nonzero_retcode_true(self):
  60. ret = self.run_function('runtests_decorators.command_success_nonzero_retcode_true')
  61. self.assertIs(ret, True)
  62. def test_command_failure_nonzero_retcode_true(self):
  63. ret = self.run_function('runtests_decorators.command_failure_nonzero_retcode_true')
  64. self.assertEqual(
  65. ret,
  66. "'runtests_decorators.command_failure_nonzero_retcode_true' is not available."
  67. )
  68. def test_command_success_nonzero_retcode_false(self):
  69. ret = self.run_function('runtests_decorators.command_success_nonzero_retcode_false')
  70. self.assertIs(ret, True)
  71. def test_command_failure_nonzero_retcode_false(self):
  72. ret = self.run_function('runtests_decorators.command_failure_nonzero_retcode_false')
  73. self.assertEqual(
  74. ret,
  75. "'runtests_decorators.command_failure_nonzero_retcode_false' is not available."
  76. )