salt/tests/unit/modules/mac_desktop_test.py

88 lines
2.2 KiB
Python
Raw Normal View History

2015-02-09 12:54:45 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Python Libs
from __future__ import absolute_import
2016-01-23 00:27:18 +00:00
# Import Salt Libs
from salt.modules import mac_desktop
2015-02-09 12:54:45 +00:00
# Import Salt Testing Libs
from salttesting import TestCase, skipIf
from salttesting.mock import (
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
# Globals
2016-01-23 02:24:38 +00:00
mac_desktop.__salt__ = {}
2015-02-09 12:54:45 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2016-01-23 02:24:38 +00:00
class MacDesktopTestCase(TestCase):
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
'''
# 'get_output_volume' function tests: 1
def test_get_output_volume(self):
'''
Test if it get the output volume (range 0 to 100)
'''
mock = MagicMock(return_value=True)
2016-01-23 02:24:38 +00:00
with patch.dict(mac_desktop.__salt__, {'cmd.run': mock}):
self.assertTrue(mac_desktop.get_output_volume())
2015-02-09 12:54:45 +00:00
# 'set_output_volume' function tests: 1
def test_set_output_volume(self):
'''
Test if it set the volume of sound (range 0 to 100)
'''
mock = MagicMock(return_value=True)
2016-01-23 02:24:38 +00:00
with patch.dict(mac_desktop.__salt__, {'cmd.run': mock}):
self.assertTrue(mac_desktop.set_output_volume('my-volume'))
2015-02-09 12:54:45 +00:00
# 'screensaver' function tests: 1
def test_screensaver(self):
'''
Test if it launch the screensaver
'''
mock = MagicMock(return_value=True)
2016-01-23 02:24:38 +00:00
with patch.dict(mac_desktop.__salt__, {'cmd.run': mock}):
self.assertTrue(mac_desktop.screensaver())
2015-02-09 12:54:45 +00:00
# 'lock' function tests: 1
def test_lock(self):
'''
Test if it lock the desktop session
'''
mock = MagicMock(return_value=True)
2016-01-23 02:24:38 +00:00
with patch.dict(mac_desktop.__salt__, {'cmd.run': mock}):
self.assertTrue(mac_desktop.lock())
2015-02-09 12:54:45 +00:00
# 'say' function tests: 1
def test_say(self):
'''
Test if it says some words.
'''
mock = MagicMock(return_value=True)
2016-01-23 02:24:38 +00:00
with patch.dict(mac_desktop.__salt__, {'cmd.run': mock}):
self.assertTrue(mac_desktop.say())
2015-02-09 12:54:45 +00:00
if __name__ == '__main__':
from integration import run_tests
2016-01-23 02:24:38 +00:00
run_tests(MacDesktopTestCase, needs_daemon=False)