write unit test for defaults.merge

This commit is contained in:
Ahmed AbouZaid 2017-12-06 12:24:06 +01:00
parent fcd2767c54
commit 6af5cd844f

View File

@ -37,3 +37,82 @@ class DefaultsTestCase(TestCase, LoaderModuleMockMixin):
MagicMock(return_value={'users': {'root': [0]}})):
self.assertEqual(defaults.get('core:users:root'),
{'users': {'root': [0]}})
def test_merge_with_list_merging(self):
'''
Test deep merging of dicts with merge_lists enabled.
'''
src_dict = {
'string_key': 'string_val_src',
'list_key': [
'list_val_src',
],
'dict_key': {
'dict_key_src': 'dict_val_src',
}
}
dest_dict = {
'string_key': 'string_val_dest',
'list_key': [
'list_val_dest',
],
'dict_key': {
'dict_key_dest': 'dict_val_dest',
}
}
merged_dict = {
'string_key': 'string_val_src',
'list_key': [
'list_val_dest',
'list_val_src'
],
'dict_key': {
'dict_key_dest': 'dict_val_dest',
'dict_key_src': 'dict_val_src'
}
}
defaults.merge(dest_dict, src_dict, merge_lists=True)
self.assertEqual(dest_dict, merged_dict)
def test_merge_without_list_merging(self):
'''
Test deep merging of dicts with merge_lists disabled.
'''
src_dict = {
'string_key': 'string_val_src',
'list_key': [
'list_val_src',
],
'dict_key': {
'dict_key_src': 'dict_val_src',
}
}
dest_dict = {
'string_key': 'string_val_dest',
'list_key': [
'list_val_dest',
],
'dict_key': {
'dict_key_dest': 'dict_val_dest',
}
}
merged_dict = {
'string_key': 'string_val_src',
'list_key': [
'list_val_src'
],
'dict_key': {
'dict_key_dest': 'dict_val_dest',
'dict_key_src': 'dict_val_src'
}
}
defaults.merge(dest_dict, src_dict, merge_lists=False)
self.assertEqual(dest_dict, merged_dict)