From 349534c9c989bb7f9267bfc9e44b03f4642b057e Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Mon, 11 Mar 2024 12:01:00 +0100 Subject: [PATCH] fix(utils): make rdfimport parent model check more loose The check was designed to check the type of the passed object is a sublcass of the superclass, but we usually pass a class and not an instance, so lets also check the class itself. --- apis_core/utils/rdf.py | 2 +- apis_core/utils/test_rdf.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apis_core/utils/rdf.py b/apis_core/utils/rdf.py index 1b4b270b2..141745ef8 100644 --- a/apis_core/utils/rdf.py +++ b/apis_core/utils/rdf.py @@ -20,7 +20,7 @@ def definition_matches_model(definition: str, model: object) -> bool: module, cls = definition.get("superclass").rsplit(".", 1) module = importlib.import_module(module) parent = getattr(module, cls) - if issubclass(type(model), parent): + if issubclass(type(model), parent) or issubclass(model, parent): return True except Exception as e: logger.error("superclass %s led to: %s", definition.get("superclass"), e) diff --git a/apis_core/utils/test_rdf.py b/apis_core/utils/test_rdf.py index 580825abe..8b3056aa2 100644 --- a/apis_core/utils/test_rdf.py +++ b/apis_core/utils/test_rdf.py @@ -31,11 +31,9 @@ class Meta: class RdfTest(TestCase): def test_get_definition_from_dict_place_from_geonames(self): achensee = { - "kind": "https://www.geonames.org/ontology#P.PPL", "lat": "47.5", "long": "11.7", - "name": "Achensee", - "parent": "https://sws.geonames.org/2782113/", + "label": "Achensee", } # https://www.geonames.org/2783029/achensee.html uri = str(testdata / "achensee.rdf") @@ -55,7 +53,8 @@ def test_get_definition_from_dict_place_from_dnb(self): def test_get_definition_from_dict_person_from_dnb(self): pierre = { - "name": "Ramus,Pierre", + "forename": "Pierre", + "surname": "Ramus", "profession": "https://d-nb.info/gnd/4053309-8", "date_of_birth": "1882-04-15", "date_of_death": "1942",