test_yaml.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 TestCase
  9. from tests.support.mock import (
  10. MagicMock,
  11. patch)
  12. # Import Salt libs
  13. import salt.sdb.yaml as sdb
  14. class TestYamlRenderer(TestCase):
  15. '''
  16. Test case for the YAML SDB module
  17. '''
  18. def test_plaintext(self):
  19. '''
  20. Retrieve a value from the top level of the dictionary
  21. '''
  22. plain = {'foo': 'bar'}
  23. with patch('salt.sdb.yaml._get_values', MagicMock(return_value=plain)):
  24. self.assertEqual(sdb.get('foo'), 'bar')
  25. def test_nested(self):
  26. '''
  27. Retrieve a value from a nested level of the dictionary
  28. '''
  29. plain = {'foo': {'bar': 'baz'}}
  30. with patch('salt.sdb.yaml._get_values', MagicMock(return_value=plain)):
  31. self.assertEqual(sdb.get('foo:bar'), 'baz')
  32. def test_encrypted(self):
  33. '''
  34. Assume the content is plaintext if GPG is not configured
  35. '''
  36. plain = {'foo': 'bar'}
  37. with patch('salt.sdb.yaml._decrypt', MagicMock(return_value=plain)):
  38. with patch('salt.sdb.yaml._get_values', MagicMock(return_value=None)):
  39. self.assertEqual(sdb.get('foo', profile={'gpg': True}), 'bar')