1
0

test_bower.py 2.8 KB

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