1
0

test_net_napalm_yang.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Anthony Shaw <anthonyshaw@apache.org>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Libs
  8. import salt.states.net_napalm_yang as netyang
  9. # Import Salt Testing Libs
  10. from tests.support.mixins import LoaderModuleMockMixin
  11. from tests.support.unit import TestCase
  12. from tests.support.mock import (
  13. MagicMock,
  14. patch
  15. )
  16. TEST_DATA = {
  17. 'foo': 'bar'
  18. }
  19. class NetyangTestCase(TestCase, LoaderModuleMockMixin):
  20. def setup_loader_modules(self):
  21. return {netyang: {}}
  22. def test_managed(self):
  23. ret = {'changes': {}, 'comment': 'Loaded.',
  24. 'name': 'test', 'result': False}
  25. parse = MagicMock(return_value='abcdef')
  26. temp_file = MagicMock(return_value='')
  27. compliance_report = MagicMock(return_value={'complies': False})
  28. load_config = MagicMock(return_value={'comment': 'Loaded.'})
  29. file_remove = MagicMock()
  30. with patch('salt.utils.files.fopen'):
  31. with patch.dict(netyang.__salt__,
  32. {'temp.file': temp_file,
  33. 'napalm_yang.parse': parse,
  34. 'napalm_yang.load_config': load_config,
  35. 'napalm_yang.compliance_report': compliance_report,
  36. 'file.remove': file_remove}):
  37. with patch.dict(netyang.__opts__, {'test': False}):
  38. self.assertDictEqual(netyang.managed('test', 'test', models=('model1',)), ret)
  39. assert parse.called
  40. assert temp_file.called
  41. assert compliance_report.called
  42. assert load_config.called
  43. assert file_remove.called
  44. def test_configured(self):
  45. ret = {'changes': {}, 'comment': 'Loaded.',
  46. 'name': 'test', 'result': False}
  47. load_config = MagicMock(return_value={'comment': 'Loaded.'})
  48. with patch('salt.utils.files.fopen'):
  49. with patch.dict(netyang.__salt__,
  50. {'napalm_yang.load_config': load_config}):
  51. with patch.dict(netyang.__opts__, {'test': False}):
  52. self.assertDictEqual(netyang.configured('test', 'test', models=('model1',)), ret)
  53. assert load_config.called