test_mac_assistive.py 3.3 KB

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