From fcf8e6f1af68797e4a54efb22a47095fc4e3bedf Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 31 Mar 2016 16:29:20 -0400 Subject: Yedit enhancements --- test/env-setup | 2 +- test/units/yedit_test.py | 68 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/env-setup b/test/env-setup index b05df0f9e..7456a641b 100644 --- a/test/env-setup +++ b/test/env-setup @@ -2,7 +2,7 @@ CUR_PATH=$(pwd) -PREFIX_PYTHONPATH=$CUR_PATH/inventory/:$CUR_PATH/roles/lib_yaml_editor/build/src +PREFIX_PYTHONPATH=$CUR_PATH/inventory/:$CUR_PATH/roles/lib_yaml_editor/library export PYTHONPATH=$PREFIX_PYTHONPATH:$PYTHONPATH 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) -- cgit v1.2.3