1
0

test_yaml.py 1.3 KB

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