test_bower.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Alexander Pyatkin <asp@thexyz.net
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import salt.utils.json
  7. import salt.utils.path
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import destructiveTest, slowTest
  10. from tests.support.mixins import SaltReturnAssertsMixin
  11. from tests.support.unit import skipIf
  12. @skipIf(salt.utils.path.which("bower") is None, "bower not installed")
  13. class BowerStateTest(ModuleCase, SaltReturnAssertsMixin):
  14. @destructiveTest
  15. @slowTest
  16. def test_bower_installed_removed(self):
  17. """
  18. Basic test to determine if Bower package was successfully installed and
  19. removed.
  20. """
  21. ret = self.run_state("file.directory", name="/salt_test_bower_1", makedirs=True)
  22. self.assertSaltTrueReturn(ret)
  23. ret = self.run_state(
  24. "bower.installed", name="underscore", dir="/salt_test_bower_1"
  25. )
  26. self.assertSaltTrueReturn(ret)
  27. ret = self.run_state(
  28. "bower.removed", name="underscore", dir="/salt_test_bower_1"
  29. )
  30. self.assertSaltTrueReturn(ret)
  31. ret = self.run_state("file.absent", name="/salt_test_bower_1")
  32. self.assertSaltTrueReturn(ret)
  33. @destructiveTest
  34. @slowTest
  35. def test_bower_installed_pkgs(self):
  36. """
  37. Basic test to determine if Bower package successfully installs multiple
  38. packages.
  39. """
  40. ret = self.run_state("file.directory", name="/salt_test_bower_2", makedirs=True)
  41. self.assertSaltTrueReturn(ret)
  42. ret = self.run_state(
  43. "bower.installed",
  44. name="test",
  45. dir="/salt_test_bower_2",
  46. pkgs=["numeral", "underscore"],
  47. )
  48. self.assertSaltTrueReturn(ret)
  49. ret = self.run_state("file.absent", name="/salt_test_bower_2")
  50. self.assertSaltTrueReturn(ret)
  51. @destructiveTest
  52. @slowTest
  53. def test_bower_installed_from_file(self):
  54. ret = self.run_state("file.directory", name="/salt_test_bower_3", makedirs=True)
  55. self.assertSaltTrueReturn(ret)
  56. bower_json = salt.utils.json.dumps(
  57. {
  58. "name": "salt_test_bower_3",
  59. "dependencies": {"numeral": "~1.5.3", "underscore": "~1.7.0"},
  60. }
  61. )
  62. ret = self.run_state(
  63. "file.managed", name="/salt_test_bower_3/bower.json", contents=bower_json
  64. )
  65. self.assertSaltTrueReturn(ret)
  66. ret = self.run_state("bower.bootstrap", name="/salt_test_bower_3")
  67. self.assertSaltTrueReturn(ret)
  68. ret = self.run_state("file.absent", name="/salt_test_bower_3")
  69. self.assertSaltTrueReturn(ret)