Exemplo n.º 1
0
 def wrap_pre_load(self, data, **kwargs):
     data = {
         item["zdm"]: item["szz"]
         for item in filter(lambda x: "szz" in x.keys(), data)
     }
     pairs = tuple(
         (field.metadata['load_key'], field.data_key or field_name)
         for field_name, field in self.fields.items()
         if 'load_key' in field.metadata)
     return replace_keys(data, pairs)
Exemplo n.º 2
0
    def wrap_post_dump(self, data, **kwargs):
        pairs = tuple(
            (field.data_key or field_name, field.metadata['dump_key'])
            for field_name, field in self.fields.items()
            if 'dump_key' in field.metadata)
        data = replace_keys(data, pairs)

        parse_fields = ["xjzt", "zczt", "sfzx"]
        data["alsfj"] = data.pop("makeup_as_60") + data.pop("rebuild_as_60")
        for field in parse_fields:
            if data[field] == -1:
                data.pop(field)

        parse_fields = ["qsXnxq", "zzXnxq"]
        for field in parse_fields:
            if data[field] is None:
                data[field] = ''
        return data
Exemplo n.º 3
0
def test_replace_keys(base_dict, pairs, expected):
    test_dict = base_dict.copy()
    rtn_dict = replace_keys(test_dict, pairs)
    assert test_dict == rtn_dict == expected