1
0

test_toml.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.renderers.toml as toml
  6. import salt.serializers.toml
  7. # Import Salt Testing libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase, skipIf
  10. @skipIf(not salt.serializers.toml.available, "The 'toml' library is missing")
  11. class TOMLRendererTestCase(TestCase, LoaderModuleMockMixin):
  12. def setup_loader_modules(self):
  13. return {toml: {}}
  14. def test_toml_render_string(self):
  15. data = """[[user-sshkey."ssh_auth.present"]]
  16. user = "username"
  17. [[user-sshkey."ssh_auth.present"]]
  18. config = "%h/.ssh/authorized_keys"
  19. [[user-sshkey."ssh_auth.present"]]
  20. names = [
  21. "hereismykey",
  22. "anotherkey"
  23. ]
  24. """
  25. expected_result = {
  26. "user-sshkey": {
  27. "ssh_auth.present": [
  28. {"user": "username"},
  29. {"config": "%h/.ssh/authorized_keys"},
  30. {"names": ["hereismykey", "anotherkey"]},
  31. ]
  32. }
  33. }
  34. result = toml.render(data)
  35. self.assertEqual(result, expected_result)