def test_merge_replace_array(self): old_dict_list = {'list1': [0, 1, 2, 3, 4]} new_dict_list = {'list1': [0, 1]} results = dict_merger.merge(old_dict_list, new_dict_list, update_dict_operation='replace') self.assertDictEqual(results, old_dict_list)
def test_merge_remove_key(self): old_dict = {'key1': 'value1'} new_dict = {'key2': 'value2'} results = dict_merger.merge(old_dict, new_dict, update_dict_operation='remove') self.assertDictEqual(results, old_dict)
def update(self, **kwargs): original_data = self._get_original_data(**kwargs) merged_data = dict_merger.merge(original_data, kwargs['data'], **kwargs) updated_data = schema_mapper.map_to_schema(merged_data, self.model_schema_file, self.model_schema) self.table.put_item(Item=updated_data, ConditionExpression=Attr( self.model_version_key).eq(original_data[self.model_version_key])) super().publish('update', updated_data) return updated_data
def update(self, **kwargs): exists = self.__get_existing(**kwargs) if not exists: self.__raise_error('NOT_EXISTS', **kwargs) kwargs['data'] = dict_merger.merge(exists, kwargs['data'], **kwargs) update = self.__create_update_query(kwargs['data']) self.__execute(update['query'], update['params'], **kwargs) super().publish('update', kwargs['data']) return kwargs['data']
def test_merge(self): old_dict = {'key1': 'value1'} new_dict = {'key2': 'value2'} results = dict_merger.merge(old_dict, new_dict) self.assertDictEqual(results, {'key1': 'value1', 'key2': 'value2'})