test_mac_assistive.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import pytest
  7. from tests.support.case import ModuleCase
  8. OSA_SCRIPT = "/usr/bin/osascript"
  9. @pytest.mark.destructive_test
  10. @pytest.mark.skip_if_not_root
  11. @pytest.mark.skip_unless_on_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. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  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. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  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. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  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. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  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]))