test_smartos.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Libs
  5. import salt.states.smartos as smartos
  6. # Import Salt Testing Libs
  7. from tests.support.mixins import LoaderModuleMockMixin
  8. from tests.support.unit import TestCase
  9. from tests.support.mock import patch
  10. class SmartOsTestCase(TestCase, LoaderModuleMockMixin):
  11. '''
  12. TestCase for salt.states.smartos
  13. '''
  14. def setup_loader_modules(self):
  15. return {smartos: {
  16. '__opts__': {'test': False}}
  17. }
  18. def test_config_present_does_not_exist(self):
  19. '''
  20. Test salt.states.smartos.config_present
  21. when the config files does not exist
  22. '''
  23. name = 'test'
  24. value = 'test_value'
  25. with patch('os.path.isfile', return_value=False):
  26. with patch('salt.utils.atomicfile.atomic_open', side_effect=IOError):
  27. ret = smartos.config_present(name=name, value=value)
  28. assert not ret['result']
  29. assert ret['comment'] == 'Could not add property {0} with value "{1}" to config'.format(name, value)