2016-02-01 14:24:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-02-19 22:28:46 +00:00
|
|
|
import salt.modules.mac_defaults as macdefaults
|
2016-02-01 14:24:02 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-19 22:28:46 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase
|
|
|
|
from tests.support.mock import (
|
2016-02-01 14:24:02 +00:00
|
|
|
MagicMock,
|
|
|
|
patch
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-02-19 22:28:46 +00:00
|
|
|
class MacDefaultsTestCase(TestCase, LoaderModuleMockMixin):
|
|
|
|
loader_module = macdefaults
|
2016-02-01 14:24:02 +00:00
|
|
|
|
|
|
|
def test_write_default(self):
|
|
|
|
'''
|
|
|
|
Test writing a default setting
|
|
|
|
'''
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(macdefaults.__salt__, {'cmd.run_all': mock}):
|
|
|
|
macdefaults.write('com.apple.CrashReporter', 'DialogType', 'Server')
|
|
|
|
mock.assert_called_once_with('defaults write "com.apple.CrashReporter" "DialogType" -string "Server"',
|
|
|
|
runas=None)
|
|
|
|
|
|
|
|
def test_write_with_user(self):
|
|
|
|
'''
|
|
|
|
Test writing a default setting with a specific user
|
|
|
|
'''
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(macdefaults.__salt__, {'cmd.run_all': mock}):
|
|
|
|
macdefaults.write('com.apple.CrashReporter', 'DialogType', 'Server', user="frank")
|
|
|
|
mock.assert_called_once_with('defaults write "com.apple.CrashReporter" "DialogType" -string "Server"',
|
|
|
|
runas="frank")
|
|
|
|
|
|
|
|
def test_write_default_boolean(self):
|
|
|
|
'''
|
|
|
|
Test writing a default setting
|
|
|
|
'''
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(macdefaults.__salt__, {'cmd.run_all': mock}):
|
|
|
|
macdefaults.write('com.apple.CrashReporter', 'Crash', True, type="boolean")
|
|
|
|
mock.assert_called_once_with('defaults write "com.apple.CrashReporter" "Crash" -boolean "TRUE"',
|
|
|
|
runas=None)
|
|
|
|
|
|
|
|
def test_read_default(self):
|
|
|
|
'''
|
|
|
|
Test reading a default setting
|
|
|
|
'''
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(macdefaults.__salt__, {'cmd.run': mock}):
|
|
|
|
macdefaults.read('com.apple.CrashReporter', 'Crash')
|
|
|
|
mock.assert_called_once_with('defaults read "com.apple.CrashReporter" "Crash"', runas=None)
|
|
|
|
|
|
|
|
def test_read_default_with_user(self):
|
|
|
|
'''
|
|
|
|
Test reading a default setting as a specific user
|
|
|
|
'''
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(macdefaults.__salt__, {'cmd.run': mock}):
|
|
|
|
macdefaults.read('com.apple.CrashReporter', 'Crash', user="frank")
|
|
|
|
mock.assert_called_once_with('defaults read "com.apple.CrashReporter" "Crash"', runas="frank")
|
|
|
|
|
2016-06-17 13:25:42 +00:00
|
|
|
def test_delete_default(self):
|
|
|
|
'''
|
|
|
|
Test delete a default setting
|
|
|
|
'''
|
|
|
|
mock = MagicMock()
|
2016-06-17 14:13:38 +00:00
|
|
|
with patch.dict(macdefaults.__salt__, {'cmd.run_all': mock}):
|
2016-06-17 13:25:42 +00:00
|
|
|
macdefaults.delete('com.apple.CrashReporter', 'Crash')
|
|
|
|
mock.assert_called_once_with('defaults delete "com.apple.CrashReporter" "Crash"', output_loglevel='debug', runas=None)
|
|
|
|
|
|
|
|
def test_delete_default_with_user(self):
|
|
|
|
'''
|
|
|
|
Test delete a default setting as a specific user
|
|
|
|
'''
|
|
|
|
mock = MagicMock()
|
2016-06-17 14:13:38 +00:00
|
|
|
with patch.dict(macdefaults.__salt__, {'cmd.run_all': mock}):
|
2016-06-17 13:25:42 +00:00
|
|
|
macdefaults.delete('com.apple.CrashReporter', 'Crash', user="frank")
|
|
|
|
mock.assert_called_once_with('defaults delete "com.apple.CrashReporter" "Crash"', output_loglevel='debug', runas="frank")
|