summaryrefslogtreecommitdiffstats
path: root/test/units
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2016-04-04 12:28:12 -0400
committerKenny Woodson <kwoodson@redhat.com>2016-04-04 12:28:12 -0400
commit0a8227ff3671c19fe46fa7b9bb483a3142b90c95 (patch)
tree1ec93ec4bd961010f8eefdd9a907b46906de1f95 /test/units
parent3f80411aa15121295d0ef3099194842a99cd5548 (diff)
parentfcf8e6f1af68797e4a54efb22a47095fc4e3bedf (diff)
downloadopenshift-0a8227ff3671c19fe46fa7b9bb483a3142b90c95.tar.gz
openshift-0a8227ff3671c19fe46fa7b9bb483a3142b90c95.tar.bz2
openshift-0a8227ff3671c19fe46fa7b9bb483a3142b90c95.tar.xz
openshift-0a8227ff3671c19fe46fa7b9bb483a3142b90c95.zip
Merge pull request #1693 from kwoodson/yedit_enhancements
Adding list editing support to yaml editor
Diffstat (limited to 'test/units')
-rwxr-xr-xtest/units/yedit_test.py68
1 files changed, 59 insertions, 9 deletions
diff --git a/test/units/yedit_test.py b/test/units/yedit_test.py
index e701cfa7c..09a65e888 100755
--- a/test/units/yedit_test.py
+++ b/test/units/yedit_test.py
@@ -16,7 +16,7 @@ class YeditTest(unittest.TestCase):
Test class for yedit
'''
data = {'a': 'a',
- 'b': {'c': {'d': ['e', 'f', 'g']}},
+ 'b': {'c': {'d': [{'e': 'x'}, 'f', 'g']}},
}
filename = 'yedit_test.yml'
@@ -27,10 +27,9 @@ class YeditTest(unittest.TestCase):
yed.yaml_dict = YeditTest.data
yed.write()
- def test_get(self):
+ def test_load(self):
''' Testing a get '''
yed = Yedit('yedit_test.yml')
-
self.assertEqual(yed.yaml_dict, self.data)
def test_write(self):
@@ -38,7 +37,6 @@ class YeditTest(unittest.TestCase):
yed = Yedit('yedit_test.yml')
yed.put('key1', 1)
yed.write()
- yed.get()
self.assertTrue(yed.yaml_dict.has_key('key1'))
self.assertEqual(yed.yaml_dict['key1'], 1)
@@ -47,14 +45,15 @@ class YeditTest(unittest.TestCase):
yed = Yedit('yedit_test.yml')
yed.put('x.y.z', 'modified')
yed.write()
- self.assertEqual(Yedit.get_entry(yed.get(), 'x.y.z'), 'modified')
+ yed.load()
+ self.assertEqual(yed.get('x.y.z'), 'modified')
def test_delete_a(self):
'''Testing a simple delete '''
yed = Yedit('yedit_test.yml')
yed.delete('a')
yed.write()
- yed.get()
+ yed.load()
self.assertTrue(not yed.yaml_dict.has_key('a'))
def test_delete_b_c(self):
@@ -62,7 +61,7 @@ class YeditTest(unittest.TestCase):
yed = Yedit('yedit_test.yml')
yed.delete('b.c')
yed.write()
- yed.get()
+ yed.load()
self.assertTrue(yed.yaml_dict.has_key('b'))
self.assertFalse(yed.yaml_dict['b'].has_key('c'))
@@ -72,7 +71,7 @@ class YeditTest(unittest.TestCase):
yed = Yedit('yedit_test.yml')
yed.create('foo', 'bar')
yed.write()
- yed.get()
+ yed.load()
self.assertTrue(yed.yaml_dict.has_key('foo'))
self.assertTrue(yed.yaml_dict['foo'] == 'bar')
@@ -81,10 +80,61 @@ class YeditTest(unittest.TestCase):
content = {"foo": "bar"}
yed = Yedit("yedit_test.yml", content)
yed.write()
- yed.get()
+ yed.load()
self.assertTrue(yed.yaml_dict.has_key('foo'))
self.assertTrue(yed.yaml_dict['foo'], 'bar')
+ def test_array_insert(self):
+ '''Testing a create with content '''
+ yed = Yedit("yedit_test.yml")
+ yed.put('b.c.d[0]', 'inject')
+ self.assertTrue(yed.get('b.c.d[0]') == 'inject')
+
+ def test_array_insert_first_index(self):
+ '''Testing a create with content '''
+ yed = Yedit("yedit_test.yml")
+ yed.put('b.c.d[0]', 'inject')
+ self.assertTrue(yed.get('b.c.d[1]') == 'f')
+
+ def test_array_insert_second_index(self):
+ '''Testing a create with content '''
+ yed = Yedit("yedit_test.yml")
+ yed.put('b.c.d[0]', 'inject')
+ self.assertTrue(yed.get('b.c.d[2]') == 'g')
+
+ def test_dict_array_dict_access(self):
+ '''Testing a create with content'''
+ yed = Yedit("yedit_test.yml")
+ yed.put('b.c.d[0]', [{'x': {'y': 'inject'}}])
+ self.assertTrue(yed.get('b.c.d[0].[0].x.y') == 'inject')
+
+ def test_dict_array_dict_replace(self):
+ '''Testing multilevel delete'''
+ yed = Yedit("yedit_test.yml")
+ yed.put('b.c.d[0]', [{'x': {'y': 'inject'}}])
+ yed.put('b.c.d[0].[0].x.y', 'testing')
+ self.assertTrue(yed.yaml_dict.has_key('b'))
+ self.assertTrue(yed.yaml_dict['b'].has_key('c'))
+ self.assertTrue(yed.yaml_dict['b']['c'].has_key('d'))
+ self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'], list))
+ self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0], list))
+ self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0][0], dict))
+ self.assertTrue(yed.yaml_dict['b']['c']['d'][0][0]['x'].has_key('y'))
+ self.assertTrue(yed.yaml_dict['b']['c']['d'][0][0]['x']['y'], 'testing')
+
+ def test_dict_array_dict_remove(self):
+ '''Testing multilevel delete'''
+ yed = Yedit("yedit_test.yml")
+ yed.put('b.c.d[0]', [{'x': {'y': 'inject'}}])
+ yed.delete('b.c.d[0].[0].x.y')
+ self.assertTrue(yed.yaml_dict.has_key('b'))
+ self.assertTrue(yed.yaml_dict['b'].has_key('c'))
+ self.assertTrue(yed.yaml_dict['b']['c'].has_key('d'))
+ self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'], list))
+ self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0], list))
+ self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0][0], dict))
+ self.assertFalse(yed.yaml_dict['b']['c']['d'][0][0]['x'].has_key('y'))
+
def tearDown(self):
'''TearDown method'''
os.unlink(YeditTest.filename)