2016-03-01 19:19:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
mac_power tests
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import python libs
|
2018-01-24 20:47:14 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals, print_function
|
2016-03-01 19:19:04 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import NO_MOCK, NO_MOCK_REASON
|
2016-03-01 19:19:04 +00:00
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.mac_power as mac_power
|
2016-03-01 19:19:04 +00:00
|
|
|
from salt.exceptions import SaltInvocationError
|
|
|
|
|
|
|
|
|
2016-03-03 17:45:57 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2016-03-01 19:19:04 +00:00
|
|
|
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'),
|
2016-03-21 18:15:08 +00:00
|
|
|
'Never')
|
2016-03-03 15:54:03 +00:00
|
|
|
self.assertEqual(mac_power._validate_sleep('off'),
|
2016-03-21 18:15:08 +00:00
|
|
|
'Never')
|
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),
|
2016-03-21 18:15:08 +00:00
|
|
|
'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)
|