示例#1
0
 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)
示例#2
0
 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'])
示例#3
0
 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))
示例#4
0
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"})
示例#5
0
 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))
示例#6
0
def mapping(map_file, json_data, root_path="/"):
    return process_mapping(json_data,
                           debug(demjson.decode_file(map_file), "mapper:"),
                           root_path)
示例#7
0
def test_object():
    MAP_STRUCTURE = {"name": {"path": "/title"}}

    result = deep_mapper.process_mapping(DATA1, MAP_STRUCTURE, "/")
    assert_that(result).contains_entry({'name': 'hello'})