mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Fix unit tests
This commit is contained in:
parent
0d9c56e540
commit
32c5014eb6
@ -21,7 +21,7 @@ from tests.support.mock import (
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class PowerCfgTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
Validate the powercfg state
|
||||
Validate the powercfg state
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
@ -40,76 +40,103 @@ class PowerCfgTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
def test_set_monitor_timeout(self):
|
||||
'''
|
||||
Test to make sure we can set the monitor timeout value
|
||||
Test to make sure we can set the monitor timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock = MagicMock(return_value=0)
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
mock_retcode = MagicMock(return_value=0)
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
powercfg.set_monitor_timeout(0, "dc")
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_VIDEO VIDEOIDLE 0', python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
with patch.dict(powercfg.__salt__, {'cmd.retcode': mock_retcode}):
|
||||
powercfg.set_monitor_timeout(0, 'dc')
|
||||
mock.assert_called_once_with(
|
||||
'powercfg /getactivescheme',
|
||||
python_shell=False)
|
||||
mock_retcode.assert_called_once_with(
|
||||
'powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_VIDEO VIDEOIDLE 0',
|
||||
python_shell=False)
|
||||
|
||||
def test_set_disk_timeout(self):
|
||||
'''
|
||||
Test to make sure we can set the disk timeout value
|
||||
Test to make sure we can set the disk timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
mock_retcode = MagicMock(return_value=0)
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
powercfg.set_disk_timeout(0, "dc")
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_DISK DISKIDLE 0', python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
with patch.dict(powercfg.__salt__, {'cmd.retcode': mock_retcode}):
|
||||
powercfg.set_disk_timeout(0, 'dc')
|
||||
mock.assert_called_once_with(
|
||||
'powercfg /getactivescheme',
|
||||
python_shell=False)
|
||||
mock_retcode.assert_called_once_with(
|
||||
'powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_DISK DISKIDLE 0',
|
||||
python_shell=False)
|
||||
|
||||
def test_set_standby_timeout(self):
|
||||
'''
|
||||
Test to make sure we can set the standby timeout value
|
||||
Test to make sure we can set the standby timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock = MagicMock(return_value=0)
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
mock_retcode = MagicMock(return_value=0)
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
powercfg.set_standby_timeout(0, "dc")
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP STANDBYIDLE 0', python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
with patch.dict(powercfg.__salt__, {'cmd.retcode': mock_retcode}):
|
||||
powercfg.set_standby_timeout(0, 'dc')
|
||||
mock.assert_called_once_with(
|
||||
'powercfg /getactivescheme',
|
||||
python_shell=False)
|
||||
mock_retcode.assert_called_once_with(
|
||||
'powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP STANDBYIDLE 0',
|
||||
python_shell=False)
|
||||
|
||||
def test_set_hibernate_timeout(self):
|
||||
'''
|
||||
Test to make sure we can set the hibernate timeout value
|
||||
Test to make sure we can set the hibernate timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock = MagicMock(return_value=0)
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
mock_retcode = MagicMock(return_value=0)
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
powercfg.set_hibernate_timeout(0, "dc")
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP HIBERNATEIDLE 0', python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
with patch.dict(powercfg.__salt__, {'cmd.retcode': mock_retcode}):
|
||||
powercfg.set_hibernate_timeout(0, 'dc')
|
||||
mock.assert_called_once_with(
|
||||
'powercfg /getactivescheme',
|
||||
python_shell=False)
|
||||
mock_retcode.assert_called_once_with(
|
||||
'powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP HIBERNATEIDLE 0',
|
||||
python_shell=False)
|
||||
|
||||
def test_get_monitor_timeout(self):
|
||||
'''
|
||||
Test to make sure we can get the monitor timeout value
|
||||
Test to make sure we can get the monitor timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
ret = powercfg.get_monitor_timeout()
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_VIDEO VIDEOIDLE', python_shell=False)
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_VIDEO VIDEOIDLE',
|
||||
python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
|
||||
@ -117,16 +144,19 @@ class PowerCfgTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
def test_get_disk_timeout(self):
|
||||
'''
|
||||
Test to make sure we can get the disk timeout value
|
||||
Test to make sure we can get the disk timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
ret = powercfg.get_disk_timeout()
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_DISK DISKIDLE', python_shell=False)
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_DISK DISKIDLE',
|
||||
python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
|
||||
@ -134,16 +164,19 @@ class PowerCfgTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
def test_get_standby_timeout(self):
|
||||
'''
|
||||
Test to make sure we can get the standby timeout value
|
||||
Test to make sure we can get the standby timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
ret = powercfg.get_standby_timeout()
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP STANDBYIDLE', python_shell=False)
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP STANDBYIDLE',
|
||||
python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
|
||||
@ -151,16 +184,19 @@ class PowerCfgTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
def test_get_hibernate_timeout(self):
|
||||
'''
|
||||
Test to make sure we can get the hibernate timeout value
|
||||
Test to make sure we can get the hibernate timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
ret = powercfg.get_hibernate_timeout()
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP HIBERNATEIDLE', python_shell=False)
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP HIBERNATEIDLE',
|
||||
python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
|
||||
@ -168,17 +204,20 @@ class PowerCfgTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
def test_windows_7(self):
|
||||
'''
|
||||
Test to make sure we can get the hibernate timeout value on windows 7
|
||||
Test to make sure we can get the hibernate timeout value on windows 7
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)", self.query_output]
|
||||
mock.side_effect = [
|
||||
'Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)',
|
||||
self.query_output]
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
with patch.dict(powercfg.__grains__, {'osrelease': '7'}):
|
||||
ret = powercfg.get_hibernate_timeout()
|
||||
calls = [
|
||||
call('powercfg /getactivescheme', python_shell=False),
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP', python_shell=False)
|
||||
call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP',
|
||||
python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
|
||||
@ -186,30 +225,29 @@ class PowerCfgTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
def test_set_hibernate_timeout_scheme(self):
|
||||
'''
|
||||
Test to make sure we can set the hibernate timeout value
|
||||
Test to make sure we can set the hibernate timeout value
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock = MagicMock(return_value=0)
|
||||
mock.side_effect = [self.query_output]
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
powercfg.set_hibernate_timeout(0, "dc", scheme="SCHEME_MIN")
|
||||
calls = [
|
||||
call('powercfg /setdcvalueindex SCHEME_MIN SUB_SLEEP HIBERNATEIDLE 0', python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
with patch.dict(powercfg.__salt__, {'cmd.retcode': mock}):
|
||||
powercfg.set_hibernate_timeout(0, 'dc', scheme='SCHEME_MIN')
|
||||
mock.assert_called_once_with(
|
||||
'powercfg /setdcvalueindex SCHEME_MIN SUB_SLEEP HIBERNATEIDLE 0',
|
||||
python_shell=False)
|
||||
|
||||
def test_get_hibernate_timeout_scheme(self):
|
||||
'''
|
||||
Test to make sure we can get the hibernate timeout value with a specified scheme
|
||||
Test to make sure we can get the hibernate timeout value with a
|
||||
specified scheme
|
||||
'''
|
||||
mock = MagicMock()
|
||||
mock.side_effect = [self.query_output]
|
||||
|
||||
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
|
||||
ret = powercfg.get_hibernate_timeout(scheme="SCHEME_MIN")
|
||||
calls = [
|
||||
call('powercfg /q SCHEME_MIN SUB_SLEEP HIBERNATEIDLE', python_shell=False)
|
||||
]
|
||||
mock.assert_has_calls(calls)
|
||||
ret = powercfg.get_hibernate_timeout(scheme='SCHEME_MIN')
|
||||
mock.assert_called_once_with(
|
||||
'powercfg /q SCHEME_MIN SUB_SLEEP HIBERNATEIDLE',
|
||||
python_shell=False)
|
||||
|
||||
self.assertEqual({'ac': 30, 'dc': 15}, ret)
|
||||
|
Loading…
Reference in New Issue
Block a user