1
0

test_boto_lc.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. """
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Libs
  8. import salt.states.boto_lc as boto_lc
  9. from salt.exceptions import SaltInvocationError
  10. # Import Salt Testing Libs
  11. from tests.support.mixins import LoaderModuleMockMixin
  12. from tests.support.mock import MagicMock, patch
  13. from tests.support.unit import TestCase
  14. class BotoLcTestCase(TestCase, LoaderModuleMockMixin):
  15. """
  16. Test cases for salt.states.boto_lc
  17. """
  18. def setup_loader_modules(self):
  19. return {boto_lc: {}}
  20. # 'present' function tests: 1
  21. def test_present(self):
  22. """
  23. Test to ensure the launch configuration exists.
  24. """
  25. name = "mylc"
  26. image_id = "ami-0b9c9f62"
  27. ret = {"name": name, "result": True, "changes": {}, "comment": ""}
  28. self.assertRaises(
  29. SaltInvocationError,
  30. boto_lc.present,
  31. name,
  32. image_id,
  33. user_data=True,
  34. cloud_init=True,
  35. )
  36. mock = MagicMock(side_effect=[True, False])
  37. with patch.dict(
  38. boto_lc.__salt__, {"boto_asg.launch_configuration_exists": mock}
  39. ):
  40. comt = "Launch configuration present."
  41. ret.update({"comment": comt})
  42. self.assertDictEqual(boto_lc.present(name, image_id), ret)
  43. with patch.dict(boto_lc.__opts__, {"test": True}):
  44. comt = "Launch configuration set to be created."
  45. ret.update({"comment": comt, "result": None})
  46. self.assertDictEqual(boto_lc.present(name, image_id), ret)
  47. # 'absent' function tests: 1
  48. def test_absent(self):
  49. """
  50. Test to ensure the named launch configuration is deleted.
  51. """
  52. name = "mylc"
  53. ret = {"name": name, "result": True, "changes": {}, "comment": ""}
  54. mock = MagicMock(side_effect=[False, True])
  55. with patch.dict(
  56. boto_lc.__salt__, {"boto_asg.launch_configuration_exists": mock}
  57. ):
  58. comt = "Launch configuration does not exist."
  59. ret.update({"comment": comt})
  60. self.assertDictEqual(boto_lc.absent(name), ret)
  61. with patch.dict(boto_lc.__opts__, {"test": True}):
  62. comt = "Launch configuration set to be deleted."
  63. ret.update({"comment": comt, "result": None})
  64. self.assertDictEqual(boto_lc.absent(name), ret)