summaryrefslogtreecommitdiffstats
path: root/test/unit/modify_yaml_tests.py
diff options
context:
space:
mode:
authorRodolfo Carvalho <rhcarvalho@gmail.com>2016-11-04 16:50:33 +0100
committerLuke Meyer <lmeyer@redhat.com>2017-04-25 12:13:50 -0400
commitff8356b9266a4a6ec216e3aa31e6ff0408212975 (patch)
treedcc470082999c33410a2809cd9e90c74e8bf99f4 /test/unit/modify_yaml_tests.py
parentd5a3602931c2a3f273d32caa5036fa2adc98eb30 (diff)
downloadopenshift-ff8356b9266a4a6ec216e3aa31e6ff0408212975.tar.gz
openshift-ff8356b9266a4a6ec216e3aa31e6ff0408212975.tar.bz2
openshift-ff8356b9266a4a6ec216e3aa31e6ff0408212975.tar.xz
openshift-ff8356b9266a4a6ec216e3aa31e6ff0408212975.zip
Move Python unit tests to subdirectory
To make room for integration tests.
Diffstat (limited to 'test/unit/modify_yaml_tests.py')
-rw-r--r--test/unit/modify_yaml_tests.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/unit/modify_yaml_tests.py b/test/unit/modify_yaml_tests.py
new file mode 100644
index 000000000..65b2db44c
--- /dev/null
+++ b/test/unit/modify_yaml_tests.py
@@ -0,0 +1,37 @@
+""" Tests for the modify_yaml Ansible module. """
+# pylint: disable=missing-docstring,invalid-name
+
+import os
+import sys
+import unittest
+
+sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../../library/")] + sys.path
+
+# pylint: disable=import-error
+from modify_yaml import set_key # noqa: E402
+
+
+class ModifyYamlTests(unittest.TestCase):
+
+ def test_simple_nested_value(self):
+ cfg = {"section": {"a": 1, "b": 2}}
+ changes = set_key(cfg, 'section.c', 3)
+ self.assertEquals(1, len(changes))
+ self.assertEquals(3, cfg['section']['c'])
+
+ # Tests a previous bug where property would land in section above where it should,
+ # if the destination section did not yet exist:
+ def test_nested_property_in_new_section(self):
+ cfg = {
+ "masterClients": {
+ "externalKubernetesKubeConfig": "",
+ "openshiftLoopbackKubeConfig": "openshift-master.kubeconfig",
+ },
+ }
+
+ yaml_key = 'masterClients.externalKubernetesClientConnectionOverrides.acceptContentTypes'
+ yaml_value = 'application/vnd.kubernetes.protobuf,application/json'
+ set_key(cfg, yaml_key, yaml_value)
+ self.assertEquals(yaml_value, cfg['masterClients']
+ ['externalKubernetesClientConnectionOverrides']
+ ['acceptContentTypes'])