1
0

test_chocolatey.py 3.7 KB

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