1
0

test_pagerduty.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. patch)
  13. # Import Salt Libs
  14. import salt.states.pagerduty as pagerduty
  15. class PagerdutyTestCase(TestCase, LoaderModuleMockMixin):
  16. '''
  17. Test cases for salt.states.pagerduty
  18. '''
  19. def setup_loader_modules(self):
  20. return {pagerduty: {}}
  21. # 'create_event' function tests: 1
  22. def test_create_event(self):
  23. '''
  24. Test to create an event on the PagerDuty service.
  25. '''
  26. name = 'This is a server warning message'
  27. details = 'This is a much more detailed message'
  28. service_key = '9abcd123456789efabcde362783cdbaf'
  29. profile = 'my-pagerduty-account'
  30. ret = {'name': name,
  31. 'result': None,
  32. 'comment': '',
  33. 'changes': {}}
  34. with patch.dict(pagerduty.__opts__, {'test': True}):
  35. comt = ('Need to create event: {0}'.format(name))
  36. ret.update({'comment': comt})
  37. self.assertDictEqual(pagerduty.create_event(name, details,
  38. service_key, profile),
  39. ret)
  40. with patch.dict(pagerduty.__opts__, {'test': False}):
  41. mock_t = MagicMock(return_value=True)
  42. with patch.dict(pagerduty.__salt__,
  43. {'pagerduty.create_event': mock_t}):
  44. comt = ('Created event: {0}'.format(name))
  45. ret.update({'comment': comt, 'result': True})
  46. self.assertDictEqual(pagerduty.create_event(name, details,
  47. service_key,
  48. profile), ret)