def transfer_data(self, data, map_options, map_root_path): ''' method helper that provide filling Django model with objects that was ejected from data through map_options & map_root_path ''' mapped_data = process_mapping(data, map_options, map_root_path) if map_options else data for item in mapped_data: self.model.objects.create(**item)
def test_only_exist_keys(self): MAP_STRUCTURE = { 'name': { 'path': '/title' }, } result = deep_mapper.process_mapping(DATA, MAP_STRUCTURE, '/root') self.assertTrue(isinstance(result, list)) self.assertTrue(len(result) == len(DATA['root'])) self.assertTrue(result[0]['name'] == DATA['root'][0]['title'])
def test_with_various_empty_keys(self): MAP_STRUCTURE = { 'name': { 'path': '/title' }, 'image': { 'path': '/media/ico' }, } result = deep_mapper.process_mapping(DATA, MAP_STRUCTURE, '/root') self.assertTrue(isinstance(result, list))
def test_arry_mapping(): MAP_STRUCTURE = { "methods": { "path": "/mds", "sub_mapping": { "title": { "path": "/name" } } } } result = deep_mapper.process_mapping(DATA, MAP_STRUCTURE, "/") assert_that(result).contains_key('methods') assert_that(result["methods"][0]).contains_entry({"title": "alan"})
def test_postprocess(self): MAP_STRUCTURE = { 'name': { 'path': '/title' }, 'count': { 'path': '/counter', 'postprocess': int }, 'image': { 'path': '/media/ico' }, } result = deep_mapper.process_mapping(DATA, MAP_STRUCTURE, '/root') self.assertTrue(isinstance(result, list))
def mapping(map_file, json_data, root_path="/"): return process_mapping(json_data, debug(demjson.decode_file(map_file), "mapper:"), root_path)
def test_object(): MAP_STRUCTURE = {"name": {"path": "/title"}} result = deep_mapper.process_mapping(DATA1, MAP_STRUCTURE, "/") assert_that(result).contains_entry({'name': 'hello'})