salt/tests/unit/modules/test_mac_desktop.py

129 lines
4.2 KiB
Python
Raw Normal View History

2015-02-09 12:54:45 +00:00
# -*- coding: utf-8 -*-
'''
Unit Tests for the mac_desktop execution module.
2015-02-09 12:54:45 +00:00
'''
# Import Python Libs
from __future__ import absolute_import
2015-02-09 12:54:45 +00:00
# Import Salt Testing Libs
2017-03-22 16:42:17 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
2015-02-09 12:54:45 +00:00
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
import salt.modules.mac_desktop as mac_desktop
from salt.exceptions import CommandExecutionError
2015-02-09 12:54:45 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-22 16:42:17 +00:00
class MacDesktopTestCase(TestCase, LoaderModuleMockMixin):
2015-02-09 12:54:45 +00:00
'''
2016-01-23 02:24:38 +00:00
Test cases for salt.modules.mac_desktop
2015-02-09 12:54:45 +00:00
'''
2017-03-22 16:42:17 +00:00
def setup_loader_modules(self):
return {mac_desktop: {}}
# 'get_output_volume' function tests: 2
2015-02-09 12:54:45 +00:00
def test_get_output_volume(self):
'''
Test if it get the output volume (range 0 to 100)
'''
mock = MagicMock(return_value={'retcode': 0, 'stdout': '25'})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
self.assertEqual(mac_desktop.get_output_volume(), '25')
2015-02-09 12:54:45 +00:00
def test_get_output_volume_error(self):
'''
Tests that an error is raised when cmd.run_all errors
'''
mock = MagicMock(return_value={'retcode': 1})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
self.assertRaises(CommandExecutionError,
mac_desktop.get_output_volume)
2015-02-09 12:54:45 +00:00
# 'set_output_volume' function tests: 2
@patch('salt.modules.mac_desktop.get_output_volume',
MagicMock(return_value='25'))
2015-02-09 12:54:45 +00:00
def test_set_output_volume(self):
'''
Test if it set the volume of sound (range 0 to 100)
'''
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mac_desktop.set_output_volume('25'))
def test_set_output_volume_error(self):
'''
Tests that an error is raised when cmd.run_all errors
'''
mock = MagicMock(return_value={'retcode': 1})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
self.assertRaises(CommandExecutionError,
mac_desktop.set_output_volume,
'25')
2015-02-09 12:54:45 +00:00
# 'screensaver' function tests: 2
2015-02-09 12:54:45 +00:00
def test_screensaver(self):
'''
Test if it launch the screensaver
'''
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
2016-01-23 02:24:38 +00:00
self.assertTrue(mac_desktop.screensaver())
2015-02-09 12:54:45 +00:00
def test_screensaver_error(self):
'''
Tests that an error is raised when cmd.run_all errors
'''
mock = MagicMock(return_value={'retcode': 1})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
self.assertRaises(CommandExecutionError,
mac_desktop.screensaver)
# 'lock' function tests: 2
2015-02-09 12:54:45 +00:00
def test_lock(self):
'''
Test if it lock the desktop session
'''
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
2016-01-23 02:24:38 +00:00
self.assertTrue(mac_desktop.lock())
2015-02-09 12:54:45 +00:00
def test_lock_error(self):
'''
Tests that an error is raised when cmd.run_all errors
'''
mock = MagicMock(return_value={'retcode': 1})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
self.assertRaises(CommandExecutionError,
mac_desktop.lock)
# 'say' function tests: 2
2015-02-09 12:54:45 +00:00
def test_say(self):
'''
Test if it says some words.
'''
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
2016-01-23 02:24:38 +00:00
self.assertTrue(mac_desktop.say())
2015-02-09 12:54:45 +00:00
def test_say_error(self):
'''
Tests that an error is raised when cmd.run_all errors
'''
mock = MagicMock(return_value={'retcode': 1})
with patch.dict(mac_desktop.__salt__, {'cmd.run_all': mock}):
self.assertRaises(CommandExecutionError,
mac_desktop.say)