2016-03-22 20:11:40 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Nicole Thomas <nicole@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2017-04-04 17:57:27 +00:00
|
|
|
from tests.support.helpers import destructiveTest, skip_if_not_root
|
2016-03-22 20:11:40 +00:00
|
|
|
|
|
|
|
OSA_SCRIPT = '/usr/bin/osascript'
|
|
|
|
|
|
|
|
|
|
|
|
@destructiveTest
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
2017-04-03 16:04:09 +00:00
|
|
|
class MacAssistiveTest(ModuleCase):
|
2016-03-22 20:11:40 +00:00
|
|
|
'''
|
|
|
|
Integration tests for the mac_assistive module.
|
|
|
|
'''
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
'''
|
|
|
|
Sets up test requirements
|
|
|
|
'''
|
|
|
|
os_grain = self.run_function('grains.item', ['kernel'])
|
|
|
|
if os_grain['kernel'] not in 'Darwin':
|
|
|
|
self.skipTest(
|
|
|
|
'Test not applicable to \'{kernel}\' kernel'.format(
|
|
|
|
**os_grain
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Let's install a bundle to use in tests
|
|
|
|
self.run_function('assistive.install', [OSA_SCRIPT, True])
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
'''
|
|
|
|
Clean up after tests
|
|
|
|
'''
|
|
|
|
# Delete any bundles that were installed
|
2016-05-04 21:34:03 +00:00
|
|
|
osa_script = self.run_function('assistive.installed', [OSA_SCRIPT])
|
2016-03-22 20:11:40 +00:00
|
|
|
if osa_script:
|
2016-05-04 21:34:03 +00:00
|
|
|
self.run_function('assistive.remove', [OSA_SCRIPT])
|
2016-03-22 20:11:40 +00:00
|
|
|
|
|
|
|
smile_bundle = 'com.smileonmymac.textexpander'
|
2016-05-04 21:34:03 +00:00
|
|
|
smile_bundle_present = self.run_function('assistive.installed', [smile_bundle])
|
2016-03-22 20:11:40 +00:00
|
|
|
if smile_bundle_present:
|
2016-05-04 21:34:03 +00:00
|
|
|
self.run_function('assistive.remove', [smile_bundle])
|
2016-03-22 20:11:40 +00:00
|
|
|
|
2017-03-29 18:15:15 +00:00
|
|
|
def test_install_and_remove(self):
|
2016-03-22 20:11:40 +00:00
|
|
|
'''
|
|
|
|
Tests installing and removing a bundled ID or command to use assistive access.
|
|
|
|
'''
|
|
|
|
new_bundle = 'com.smileonmymac.textexpander'
|
|
|
|
self.assertTrue(
|
2016-05-04 21:34:03 +00:00
|
|
|
self.run_function('assistive.install', [new_bundle])
|
2016-03-22 20:11:40 +00:00
|
|
|
)
|
|
|
|
self.assertTrue(
|
2016-05-04 21:34:03 +00:00
|
|
|
self.run_function('assistive.remove', [new_bundle])
|
2016-03-22 20:11:40 +00:00
|
|
|
)
|
|
|
|
|
2017-03-29 18:15:15 +00:00
|
|
|
def test_installed(self):
|
2016-03-22 20:11:40 +00:00
|
|
|
'''
|
|
|
|
Tests the True and False return of assistive.installed.
|
|
|
|
'''
|
|
|
|
# OSA script should have been installed in setUp function
|
|
|
|
self.assertTrue(
|
2016-05-04 21:34:03 +00:00
|
|
|
self.run_function('assistive.installed', [OSA_SCRIPT])
|
2016-03-22 20:11:40 +00:00
|
|
|
)
|
|
|
|
# Clean up install
|
|
|
|
self.run_function('assistive.remove', [OSA_SCRIPT])
|
|
|
|
# Installed should now return False
|
|
|
|
self.assertFalse(
|
|
|
|
self.run_function('assistive.installed', [OSA_SCRIPT])
|
|
|
|
)
|
|
|
|
|
2017-03-29 18:15:15 +00:00
|
|
|
def test_enable(self):
|
2016-03-22 20:11:40 +00:00
|
|
|
'''
|
|
|
|
Tests setting the enabled status of a bundled ID or command.
|
|
|
|
'''
|
|
|
|
# OSA script should have been installed and enabled in setUp function
|
|
|
|
# Now let's disable it, which should return True.
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('assistive.enable', [OSA_SCRIPT, False])
|
|
|
|
)
|
|
|
|
# Double check the script was disabled, as intended.
|
|
|
|
self.assertFalse(
|
|
|
|
self.run_function('assistive.enabled', [OSA_SCRIPT])
|
|
|
|
)
|
|
|
|
# Now re-enable
|
|
|
|
self.assertTrue(
|
2016-05-04 21:34:03 +00:00
|
|
|
self.run_function('assistive.enable', [OSA_SCRIPT])
|
2016-03-22 20:11:40 +00:00
|
|
|
)
|
|
|
|
# Double check the script was enabled, as intended.
|
|
|
|
self.assertTrue(
|
2016-05-04 21:34:03 +00:00
|
|
|
self.run_function('assistive.enabled', [OSA_SCRIPT])
|
2016-03-22 20:11:40 +00:00
|
|
|
)
|
|
|
|
|
2017-03-29 18:15:15 +00:00
|
|
|
def test_enabled(self):
|
2016-03-22 20:11:40 +00:00
|
|
|
'''
|
|
|
|
Tests if a bundled ID or command is listed in assistive access returns True.
|
|
|
|
'''
|
|
|
|
# OSA script should have been installed in setUp function, which sets
|
|
|
|
# enabled to True by default.
|
|
|
|
self.assertTrue(
|
2016-05-04 21:34:03 +00:00
|
|
|
self.run_function('assistive.enabled', [OSA_SCRIPT])
|
2016-03-22 20:11:40 +00:00
|
|
|
)
|
|
|
|
# Disable OSA Script
|
|
|
|
self.run_function('assistive.enable', [OSA_SCRIPT, False])
|
|
|
|
# Assert against new disabled status
|
|
|
|
self.assertFalse(
|
|
|
|
self.run_function('assistive.enabled', [OSA_SCRIPT])
|
|
|
|
)
|