1
0

test_mac_assistive.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing Libs
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import destructiveTest, skip_if_not_root
  10. OSA_SCRIPT = '/usr/bin/osascript'
  11. @destructiveTest
  12. @skip_if_not_root
  13. class MacAssistiveTest(ModuleCase):
  14. '''
  15. Integration tests for the mac_assistive module.
  16. '''
  17. def setUp(self):
  18. '''
  19. Sets up test requirements
  20. '''
  21. os_grain = self.run_function('grains.item', ['kernel'])
  22. if os_grain['kernel'] not in 'Darwin':
  23. self.skipTest(
  24. 'Test not applicable to \'{kernel}\' kernel'.format(
  25. **os_grain
  26. )
  27. )
  28. # Let's install a bundle to use in tests
  29. self.run_function('assistive.install', [OSA_SCRIPT, True])
  30. def tearDown(self):
  31. '''
  32. Clean up after tests
  33. '''
  34. # Delete any bundles that were installed
  35. osa_script = self.run_function('assistive.installed', [OSA_SCRIPT])
  36. if osa_script:
  37. self.run_function('assistive.remove', [OSA_SCRIPT])
  38. smile_bundle = 'com.smileonmymac.textexpander'
  39. smile_bundle_present = self.run_function('assistive.installed', [smile_bundle])
  40. if smile_bundle_present:
  41. self.run_function('assistive.remove', [smile_bundle])
  42. def test_install_and_remove(self):
  43. '''
  44. Tests installing and removing a bundled ID or command to use assistive access.
  45. '''
  46. new_bundle = 'com.smileonmymac.textexpander'
  47. self.assertTrue(
  48. self.run_function('assistive.install', [new_bundle])
  49. )
  50. self.assertTrue(
  51. self.run_function('assistive.remove', [new_bundle])
  52. )
  53. def test_installed(self):
  54. '''
  55. Tests the True and False return of assistive.installed.
  56. '''
  57. # OSA script should have been installed in setUp function
  58. self.assertTrue(
  59. self.run_function('assistive.installed', [OSA_SCRIPT])
  60. )
  61. # Clean up install
  62. self.run_function('assistive.remove', [OSA_SCRIPT])
  63. # Installed should now return False
  64. self.assertFalse(
  65. self.run_function('assistive.installed', [OSA_SCRIPT])
  66. )
  67. def test_enable(self):
  68. '''
  69. Tests setting the enabled status of a bundled ID or command.
  70. '''
  71. # OSA script should have been installed and enabled in setUp function
  72. # Now let's disable it, which should return True.
  73. self.assertTrue(
  74. self.run_function('assistive.enable', [OSA_SCRIPT, False])
  75. )
  76. # Double check the script was disabled, as intended.
  77. self.assertFalse(
  78. self.run_function('assistive.enabled', [OSA_SCRIPT])
  79. )
  80. # Now re-enable
  81. self.assertTrue(
  82. self.run_function('assistive.enable', [OSA_SCRIPT])
  83. )
  84. # Double check the script was enabled, as intended.
  85. self.assertTrue(
  86. self.run_function('assistive.enabled', [OSA_SCRIPT])
  87. )
  88. def test_enabled(self):
  89. '''
  90. Tests if a bundled ID or command is listed in assistive access returns True.
  91. '''
  92. # OSA script should have been installed in setUp function, which sets
  93. # enabled to True by default.
  94. self.assertTrue(
  95. self.run_function('assistive.enabled', [OSA_SCRIPT])
  96. )
  97. # Disable OSA Script
  98. self.run_function('assistive.enable', [OSA_SCRIPT, False])
  99. # Assert against new disabled status
  100. self.assertFalse(
  101. self.run_function('assistive.enabled', [OSA_SCRIPT])
  102. )