test_yaml.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Test case for the YAML SDB module
  4. '''
  5. # Import python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing libs
  8. from tests.support.unit import skipIf, TestCase
  9. from tests.support.mock import (
  10. NO_MOCK,
  11. NO_MOCK_REASON,
  12. MagicMock,
  13. patch)
  14. # Import Salt libs
  15. import salt.sdb.yaml as sdb
  16. @skipIf(NO_MOCK, NO_MOCK_REASON)
  17. class TestYamlRenderer(TestCase):
  18. '''
  19. Test case for the YAML SDB module
  20. '''
  21. def test_plaintext(self):
  22. '''
  23. Retrieve a value from the top level of the dictionary
  24. '''
  25. plain = {'foo': 'bar'}
  26. with patch('salt.sdb.yaml._get_values', MagicMock(return_value=plain)):
  27. self.assertEqual(sdb.get('foo'), 'bar')
  28. def test_nested(self):
  29. '''
  30. Retrieve a value from a nested level of the dictionary
  31. '''
  32. plain = {'foo': {'bar': 'baz'}}
  33. with patch('salt.sdb.yaml._get_values', MagicMock(return_value=plain)):
  34. self.assertEqual(sdb.get('foo:bar'), 'baz')
  35. def test_encrypted(self):
  36. '''
  37. Assume the content is plaintext if GPG is not configured
  38. '''
  39. plain = {'foo': 'bar'}
  40. with patch('salt.sdb.yaml._decrypt', MagicMock(return_value=plain)):
  41. with patch('salt.sdb.yaml._get_values', MagicMock(return_value=None)):
  42. self.assertEqual(sdb.get('foo', profile={'gpg': True}), 'bar')