test_chocolatey.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for the Chocolatey State
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import logging
  7. import pytest
  8. import salt.utils.platform
  9. from tests.support.case import ModuleCase
  10. from tests.support.mixins import SaltReturnAssertsMixin
  11. from tests.support.unit import skipIf
  12. log = logging.getLogger(__name__)
  13. @pytest.mark.destructive_test
  14. @skipIf(not salt.utils.platform.is_windows(), "Windows Specific Test")
  15. class ChocolateyTest(ModuleCase, SaltReturnAssertsMixin):
  16. """
  17. Chocolatey State Tests
  18. These tests are destructive as the install and remove software
  19. """
  20. @classmethod
  21. def setUpClass(cls):
  22. cls.chocolatey_bootstrapped = False
  23. @classmethod
  24. def tearDownClass(cls):
  25. cls.chocolatey_bootstrapped = False
  26. def setUp(self):
  27. """
  28. Ensure that Chocolatey is installed
  29. """
  30. super(ChocolateyTest, self).setUp()
  31. if self.chocolatey_bootstrapped is False:
  32. self.run_function("chocolatey.bootstrap")
  33. self.chocolatey_bootstrapped = True
  34. def test_chocolatey(self):
  35. """
  36. Test the following:
  37. - `chocolatey.installed`
  38. - `chocolatey.upgraded`
  39. - `chocolatey.uninstalled`
  40. """
  41. # If this assert fails, we need to find new targets, this test needs to
  42. # be able to test successful installation of packages, so this package
  43. # needs to NOT be installed before we run the states below
  44. target = "firefox"
  45. pre_version = "52.0.2"
  46. upg_version = "57.0.2"
  47. log.debug("Making sure %s is not installed", target)
  48. self.assertFalse(self.run_function("chocolatey.version", [target]))
  49. try:
  50. ####################################################
  51. # Test `chocolatey.installed`
  52. ####################################################
  53. # Install the package
  54. log.debug("Testing chocolatey.installed")
  55. ret = self.run_state(
  56. "chocolatey.installed", name=target, version=pre_version
  57. )
  58. self.assertSaltTrueReturn(ret)
  59. # Verify the package is installed
  60. log.debug("Verifying install success")
  61. ret = self.run_function("chocolatey.version", [target])
  62. self.assertEqual(ret, {"Firefox": [pre_version]})
  63. ####################################################
  64. # Test `chocolatey.upgraded`
  65. ####################################################
  66. # Upgrade the package
  67. log.debug("Testing chocolatey.upgraded")
  68. ret = self.run_state(
  69. "chocolatey.upgraded", name=target, version=upg_version
  70. )
  71. self.assertSaltTrueReturn(ret)
  72. # Verify the package is upgraded
  73. log.debug("Verifying upgrade success")
  74. ret = self.run_function("chocolatey.version", [target])
  75. self.assertEqual(ret, {"Firefox": [upg_version]})
  76. ####################################################
  77. # Test `chocolatey.uninstalled`
  78. ####################################################
  79. # uninstall the package
  80. log.debug("Testing chocolatey.uninstalled")
  81. ret = self.run_state("chocolatey.uninstalled", name=target)
  82. self.assertSaltTrueReturn(ret)
  83. # Verify the package is uninstalled
  84. log.debug("Verifying uninstall success")
  85. ret = self.run_function("chocolatey.version", [target])
  86. self.assertEqual(ret, {})
  87. finally:
  88. # Always uninstall
  89. log.debug("Uninstalling %s", target)
  90. self.run_function("chocolatey.uninstall", [target])