test_layman.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 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.layman as layman
  15. class LaymanTestCase(TestCase, LoaderModuleMockMixin):
  16. '''
  17. Test cases for salt.states.layman
  18. '''
  19. def setup_loader_modules(self):
  20. return {layman: {}}
  21. # 'present' function tests: 1
  22. def test_present(self):
  23. '''
  24. Test to verify that the overlay is present.
  25. '''
  26. name = 'sunrise'
  27. ret = {'name': name,
  28. 'result': True,
  29. 'comment': '',
  30. 'changes': {}}
  31. mock = MagicMock(side_effect=[[name], []])
  32. with patch.dict(layman.__salt__, {'layman.list_local': mock}):
  33. comt = ('Overlay {0} already present'.format(name))
  34. ret.update({'comment': comt})
  35. self.assertDictEqual(layman.present(name), ret)
  36. with patch.dict(layman.__opts__, {'test': True}):
  37. comt = ('Overlay {0} is set to be added'.format(name))
  38. ret.update({'comment': comt, 'result': None})
  39. self.assertDictEqual(layman.present(name), ret)
  40. # 'absent' function tests: 1
  41. def test_absent(self):
  42. '''
  43. Test to verify that the overlay is absent.
  44. '''
  45. name = 'sunrise'
  46. ret = {'name': name,
  47. 'result': True,
  48. 'comment': '',
  49. 'changes': {}}
  50. mock = MagicMock(side_effect=[[], [name]])
  51. with patch.dict(layman.__salt__, {'layman.list_local': mock}):
  52. comt = ('Overlay {0} already absent'.format(name))
  53. ret.update({'comment': comt})
  54. self.assertDictEqual(layman.absent(name), ret)
  55. with patch.dict(layman.__opts__, {'test': True}):
  56. comt = ('Overlay {0} is set to be deleted'.format(name))
  57. ret.update({'comment': comt, 'result': None})
  58. self.assertDictEqual(layman.absent(name), ret)