2016-03-01 19:19:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
mac_power tests
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
|
|
|
from salttesting import TestCase, skipIf
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
|
|
|
# Import Salt Libs
|
|
|
|
from salt.modules import mac_power
|
|
|
|
from salt.exceptions import SaltInvocationError
|
|
|
|
|
|
|
|
|
|
|
|
class MacPowerTestCase(TestCase):
|
|
|
|
'''
|
|
|
|
test mac_power execution module
|
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
def test_validate_sleep_valid_number(self):
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
test _validate_sleep function with valid number
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
self.assertEqual(mac_power._validate_sleep(179),
|
|
|
|
179)
|
2016-03-02 17:20:00 +00:00
|
|
|
|
2016-03-03 15:54:03 +00:00
|
|
|
def test_validate_sleep_invalid_number(self):
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
test _validate_sleep function with invalid number
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
self.assertRaises(SaltInvocationError,
|
|
|
|
mac_power._validate_sleep,
|
|
|
|
181)
|
2016-03-02 17:20:00 +00:00
|
|
|
|
2016-03-03 15:54:03 +00:00
|
|
|
def test_validate_sleep_valid_string(self):
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
test _validate_sleep function with valid string
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
self.assertEqual(mac_power._validate_sleep('never'),
|
|
|
|
'never')
|
|
|
|
self.assertEqual(mac_power._validate_sleep('off'),
|
|
|
|
'off')
|
2016-03-02 17:20:00 +00:00
|
|
|
|
2016-03-03 15:54:03 +00:00
|
|
|
def test_validate_sleep_invalid_string(self):
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
test _validate_sleep function with invalid string
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
self.assertRaises(SaltInvocationError,
|
|
|
|
mac_power._validate_sleep,
|
|
|
|
'bob')
|
2016-03-02 17:20:00 +00:00
|
|
|
|
2016-03-03 15:54:03 +00:00
|
|
|
def test_validate_sleep_bool_true(self):
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
test _validate_sleep function with True
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
self.assertRaises(SaltInvocationError,
|
|
|
|
mac_power._validate_sleep,
|
|
|
|
True)
|
2016-03-02 17:20:00 +00:00
|
|
|
|
2016-03-03 15:54:03 +00:00
|
|
|
def test_validate_sleep_bool_false(self):
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
test _validate_sleep function with False
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
self.assertEqual(mac_power._validate_sleep(False),
|
|
|
|
'never')
|
2016-03-02 17:20:00 +00:00
|
|
|
|
2016-03-03 15:54:03 +00:00
|
|
|
def test_validate_sleep_unexpected(self):
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
test _validate_sleep function with True
|
2016-03-02 17:20:00 +00:00
|
|
|
'''
|
2016-03-03 15:54:03 +00:00
|
|
|
self.assertRaises(SaltInvocationError,
|
|
|
|
mac_power._validate_sleep,
|
|
|
|
172.7)
|
2016-03-02 17:20:00 +00:00
|
|
|
|
|
|
|
|
2016-03-01 19:19:04 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(MacPowerTestCase, needs_daemon=False)
|