test_decorators.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. import pytest
  7. @pytest.mark.windows_whitelisted
  8. class DecoratorTest(ModuleCase):
  9. def test_module(self):
  10. self.assertTrue(
  11. self.run_function(
  12. 'runtests_decorators.working_function'
  13. )
  14. )
  15. def test_depends(self):
  16. ret = self.run_function('runtests_decorators.depends')
  17. self.assertTrue(isinstance(ret, dict))
  18. self.assertTrue(ret['ret'])
  19. self.assertTrue(isinstance(ret['time'], float))
  20. def test_missing_depends(self):
  21. self.assertEqual(
  22. {'runtests_decorators.missing_depends_will_fallback': None,
  23. 'runtests_decorators.missing_depends': "'runtests_decorators.missing_depends' is not available."},
  24. self.run_function('runtests_decorators.missing_depends'
  25. )
  26. )
  27. def test_bool_depends(self):
  28. # test True
  29. self.assertTrue(
  30. self.run_function(
  31. 'runtests_decorators.booldependsTrue'
  32. )
  33. )
  34. # test False
  35. self.assertIn(
  36. 'is not available',
  37. self.run_function('runtests_decorators.booldependsFalse'
  38. )
  39. )
  40. def test_depends_will_not_fallback(self):
  41. ret = self.run_function('runtests_decorators.depends_will_not_fallback')
  42. self.assertTrue(isinstance(ret, dict))
  43. self.assertTrue(ret['ret'])
  44. self.assertTrue(isinstance(ret['time'], float))
  45. def test_missing_depends_will_fallback(self):
  46. self.assertListEqual(
  47. [False, 'fallback'],
  48. self.run_function(
  49. 'runtests_decorators.missing_depends_will_fallback'
  50. )
  51. )
  52. def test_command_success_retcode(self):
  53. ret = self.run_function('runtests_decorators.command_success_retcode')
  54. self.assertIs(ret, True)
  55. def test_command_failure_retcode(self):
  56. ret = self.run_function('runtests_decorators.command_failure_retcode')
  57. self.assertEqual(
  58. ret,
  59. "'runtests_decorators.command_failure_retcode' is not available."
  60. )
  61. def test_command_success_nonzero_retcode_true(self):
  62. ret = self.run_function('runtests_decorators.command_success_nonzero_retcode_true')
  63. self.assertIs(ret, True)
  64. def test_command_failure_nonzero_retcode_true(self):
  65. ret = self.run_function('runtests_decorators.command_failure_nonzero_retcode_true')
  66. self.assertEqual(
  67. ret,
  68. "'runtests_decorators.command_failure_nonzero_retcode_true' is not available."
  69. )
  70. def test_command_success_nonzero_retcode_false(self):
  71. ret = self.run_function('runtests_decorators.command_success_nonzero_retcode_false')
  72. self.assertIs(ret, True)
  73. def test_command_failure_nonzero_retcode_false(self):
  74. ret = self.run_function('runtests_decorators.command_failure_nonzero_retcode_false')
  75. self.assertEqual(
  76. ret,
  77. "'runtests_decorators.command_failure_nonzero_retcode_false' is not available."
  78. )