1
0

test_makeconf.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import
  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.makeconf as makeconf
  15. class MakeconfTestCase(TestCase, LoaderModuleMockMixin):
  16. '''
  17. Test cases for salt.states.makeconf
  18. '''
  19. def setup_loader_modules(self):
  20. return {makeconf: {}}
  21. # 'present' function tests: 1
  22. def test_present(self):
  23. '''
  24. Test to verify that the variable is in the ``make.conf``
  25. and has the provided settings.
  26. '''
  27. name = 'makeopts'
  28. ret = {'name': name,
  29. 'result': True,
  30. 'comment': '',
  31. 'changes': {}}
  32. mock_t = MagicMock(return_value=True)
  33. with patch.dict(makeconf.__salt__, {'makeconf.get_var': mock_t}):
  34. comt = ('Variable {0} is already present in make.conf'.format(name))
  35. ret.update({'comment': comt})
  36. self.assertDictEqual(makeconf.present(name), ret)
  37. # 'absent' function tests: 1
  38. def test_absent(self):
  39. '''
  40. Test to verify that the variable is not in the ``make.conf``.
  41. '''
  42. name = 'makeopts'
  43. ret = {'name': name,
  44. 'result': True,
  45. 'comment': '',
  46. 'changes': {}}
  47. mock = MagicMock(return_value=None)
  48. with patch.dict(makeconf.__salt__, {'makeconf.get_var': mock}):
  49. comt = ('Variable {0} is already absent from make.conf'
  50. .format(name))
  51. ret.update({'comment': comt})
  52. self.assertDictEqual(makeconf.absent(name), ret)