Beispiel #1
0
 def test_add(self):
     result = DictionaryBuilder(inherit={'meta': {'old_attr': "value"}}, add=["meta.attr=something="])
     self.assertEqual("something=", result['meta']['attr'])
     self.assertEqual("value", result['meta']['old_attr'])
Beispiel #2
0
 def test_get_modified_dict_exclude_meta_fields(self):
     expected_result = {'items': ["1","2","3","4","5","6"]}
     result = DictionaryBuilder(inherit={'items': ["1", "2", "3", "4", "5"], '_id': "12345", '_created': "7876768768"}, append=["items=6"], exclude_meta=True)
     self.assertDictEqual(result.data, expected_result)
Beispiel #3
0
 def test_append_target_is_none(self):
     result = DictionaryBuilder(inherit={'meta': {'attr': None}}, append=["meta.attr=modified"])
     self.assertEqual(result['meta']['attr'], ["modified"])
Beispiel #4
0
 def test_get_modified_dict(self):
     expected_result = {'items': ["1","2","3","4","5","6"]}
     result = DictionaryBuilder(inherit={'items': ["1", "2", "3", "4", "5"]}, append=["items=6"])
     self.assertDictEqual(result.data, expected_result)
Beispiel #5
0
 def test_append_nested(self):
     result = DictionaryBuilder(inherit={'meta': {'key': 'value'}}, append=["meta.attr.new=list_item"])
     self.assertEqual(result['meta']['attr']['new'], ["list_item"])
     self.assertEqual(result['meta']['key'], "value")
Beispiel #6
0
 def test_append_target_is_not_list(self):
     with self.assertRaises(Exception):
         DictionaryBuilder(inherit={'meta': {'attr': "orig"}}, append=["meta.attr=modified"])
Beispiel #7
0
 def test_delete_parent_does_not_exist_works(self):
     DictionaryBuilder(inherit={'meta': {'attr': "orig"}}, delete=["meta_does_not_exist"])
Beispiel #8
0
 def test_append(self):
     result = DictionaryBuilder(inherit={'meta': {'attr': ["orig"]}}, append=["meta.attr=modified"])
     self.assertEqual(result['meta']['attr'], ["orig", "modified"])
Beispiel #9
0
 def test_delete(self):
     result = DictionaryBuilder(inherit={'meta': {'attr': "orig"}}, delete=["meta.attr"])
     self.assertNotIn('attr', result['meta'])
Beispiel #10
0
 def test_delete_parent(self):
     result = DictionaryBuilder(inherit={'meta': {'attr': "orig"}, 'feta': "foobar"}, delete=["meta"])
     self.assertNotIn("meta", result.data.keys())
Beispiel #11
0
 def test_add_can_not_overwrite_list_value_with_dictionary(self):
     with self.assertRaises(RuntimeError):
         DictionaryBuilder(inherit={'meta': ["item"]}, add=["meta.attr=new"])
Beispiel #12
0
 def test_add_can_not_overwrite_string_value_with_dictionary(self):
     with self.assertRaises(RuntimeError):
         DictionaryBuilder(inherit={'meta': {'old_attr': "value"}}, add=["meta.old_attr.new_type.new=something"])
Beispiel #13
0
 def test_add_already_existing_value_can_be_overwritten(self):
     result = DictionaryBuilder(inherit={'meta': {'old_attr': "value"}}, add=["meta.old_attr=something"])
     self.assertEqual("something", result['meta']['old_attr'])
Beispiel #14
0
 def test_add_nested(self):
     result = DictionaryBuilder(inherit={'meta': {'key': 'value'}}, add=["meta.parent.child=something"])
     self.assertEqual("something", result['meta']['parent']['child'])
     self.assertEqual("value", result['meta']['key'])
Beispiel #15
0
 def test_add_nested_none_can_be_overwritten(self):
     result = DictionaryBuilder(inherit={'meta': None}, add=["meta.parent.child=something"])
     self.assertEqual("something", result['meta']['parent']['child'])