def body(self, lib_object: JSON, body: Body) -> Body: body.short_name = self.utils.normalize_body_name(body.short_name) body.ags = lib_object.get("ags") if body.ags: body.ags = body.ags.replace(" ", "") if len(body.ags or "") > 8: # Special case for https://ris.krefeld.de/webservice/oparl/v1/body/1 if body.ags[8:] == "0" * len(body.ags[8:]): body.ags = body.ags[:8] else: raise RuntimeError( "The Amtliche Gemeindeschlüssel of {} is longer than 8 characters: '{}'".format( body, body.ags ) ) # We don't really need the location because we have our own outline # importing logic and don't need the city, but we import it for comprehensiveness location = self.retrieve(Location, lib_object.get("location"), body.oparl_id) if location and location.geometry: if location.geometry["type"] == "Point": body.center = location body.outline = None elif location.geometry["type"] == "Polygon": logger.warning("Overriding outline of Body with api version") body.center = None body.outline = location else: logger.warning( "Location object is of type {}, which is neither 'Point' nor 'Polygon'." "Skipping this location.".format(location.geometry["type"]) ) return body
def setUpClass(cls): super().setUpClass() cls.api_data = {} cls.loader = MockLoader() cls.loader.api_data = cls.api_data for file in os.listdir(cls.dummy_data): if not file.endswith(".json"): continue with open(os.path.join(cls.dummy_data, file)) as fp: data = json.load(fp) cls.api_data[data["id"]] = data for entry in externalize(data): if entry.data["id"] not in cls.api_data: cls.api_data[entry.data["id"]] = entry.data # Used by test_location_default_body body = Body() body.short_name = "München" cls.converter = JsonToDb(cls.loader, default_body=body) cls.converter.warn_missing = False cls.utils = Utils()