test_mac_power.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. '''
  3. mac_power tests
  4. '''
  5. # Import python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing Libs
  8. from tests.support.unit import TestCase
  9. # Import Salt Libs
  10. import salt.modules.mac_power as mac_power
  11. from salt.exceptions import SaltInvocationError
  12. class MacPowerTestCase(TestCase):
  13. '''
  14. test mac_power execution module
  15. '''
  16. def test_validate_sleep_valid_number(self):
  17. '''
  18. test _validate_sleep function with valid number
  19. '''
  20. self.assertEqual(mac_power._validate_sleep(179),
  21. 179)
  22. def test_validate_sleep_invalid_number(self):
  23. '''
  24. test _validate_sleep function with invalid number
  25. '''
  26. self.assertRaises(SaltInvocationError,
  27. mac_power._validate_sleep,
  28. 181)
  29. def test_validate_sleep_valid_string(self):
  30. '''
  31. test _validate_sleep function with valid string
  32. '''
  33. self.assertEqual(mac_power._validate_sleep('never'),
  34. 'Never')
  35. self.assertEqual(mac_power._validate_sleep('off'),
  36. 'Never')
  37. def test_validate_sleep_invalid_string(self):
  38. '''
  39. test _validate_sleep function with invalid string
  40. '''
  41. self.assertRaises(SaltInvocationError,
  42. mac_power._validate_sleep,
  43. 'bob')
  44. def test_validate_sleep_bool_true(self):
  45. '''
  46. test _validate_sleep function with True
  47. '''
  48. self.assertRaises(SaltInvocationError,
  49. mac_power._validate_sleep,
  50. True)
  51. def test_validate_sleep_bool_false(self):
  52. '''
  53. test _validate_sleep function with False
  54. '''
  55. self.assertEqual(mac_power._validate_sleep(False),
  56. 'Never')
  57. def test_validate_sleep_unexpected(self):
  58. '''
  59. test _validate_sleep function with True
  60. '''
  61. self.assertRaises(SaltInvocationError,
  62. mac_power._validate_sleep,
  63. 172.7)