diff --git a/src/dsp_tools/commands/xmlupload/check_consistency_with_ontology.py b/src/dsp_tools/commands/xmlupload/check_consistency_with_ontology.py index f19925b9c..36f9cf6ad 100644 --- a/src/dsp_tools/commands/xmlupload/check_consistency_with_ontology.py +++ b/src/dsp_tools/commands/xmlupload/check_consistency_with_ontology.py @@ -5,7 +5,10 @@ from lxml import etree from regex import Pattern -from dsp_tools.commands.xmlupload.models.ontology_diagnose_models import InvalidOntologyElements, OntoCheckInformation +from dsp_tools.commands.xmlupload.models.ontology_lookup_models import ProjectOntosInformation +from dsp_tools.commands.xmlupload.models.ontology_problem_models import ( + InvalidOntologyElementsInData, +) from dsp_tools.commands.xmlupload.ontology_client import OntologyClient from dsp_tools.models.exceptions import UserError @@ -14,7 +17,7 @@ genericPrefixedOntology: Pattern[str] = regex.compile(r"^[\w\-]+:\w+$") -def do_xml_consistency_check(onto_client: OntologyClient, root: etree._Element) -> None: +def do_xml_consistency_check_with_ontology(onto_client: OntologyClient, root: etree._Element) -> None: """ This function takes an OntologyClient and the root of an XML. It retrieves the ontologies from the server. @@ -28,21 +31,24 @@ def do_xml_consistency_check(onto_client: OntologyClient, root: etree._Element) Raises: UserError: if there are any invalid properties or classes """ - onto_check_info = OntoCheckInformation( - default_ontology_prefix=onto_client.default_ontology, onto_lookup=onto_client.get_all_ontologies_from_server() + onto_check_info = ProjectOntosInformation( + default_ontology_prefix=onto_client.default_ontology, + onto_lookup=onto_client.get_all_ontologies_from_server(), ) - classes, properties = _get_all_classes_and_properties(root) - _find_problems_in_classes_and_properties(classes, properties, onto_check_info) + classes_in_data, properties_in_data = _get_all_classes_and_properties_from_data(root) + _find_if_all_classes_and_properties_exist_in_onto(classes_in_data, properties_in_data, onto_check_info) -def _find_problems_in_classes_and_properties( - classes: dict[str, list[str]], properties: dict[str, list[str]], onto_check_info: OntoCheckInformation +def _find_if_all_classes_and_properties_exist_in_onto( + classes_in_data: dict[str, list[str]], + properties_in_data: dict[str, list[str]], + onto_check_info: ProjectOntosInformation, ) -> None: - class_problems = _diagnose_all_classes(classes, onto_check_info) - property_problems = _diagnose_all_properties(properties, onto_check_info) + class_problems = _check_if_all_class_types_exist(classes_in_data, onto_check_info) + property_problems = _check_if_all_properties_exist(properties_in_data, onto_check_info) if not class_problems and not property_problems: return None - problems = InvalidOntologyElements( + problems = InvalidOntologyElementsInData( classes=class_problems, properties=property_problems, ontos_on_server=list(onto_check_info.onto_lookup.keys()) ) msg, df = problems.execute_problem_protocol() @@ -56,15 +62,17 @@ def _find_problems_in_classes_and_properties( raise UserError(msg) -def _get_all_classes_and_properties(root: etree._Element) -> tuple[dict[str, list[str]], dict[str, list[str]]]: - cls_dict = _get_all_class_types_and_ids(root) +def _get_all_classes_and_properties_from_data( + root: etree._Element, +) -> tuple[dict[str, list[str]], dict[str, list[str]]]: + cls_dict = _get_all_class_types_and_ids_from_data(root) prop_dict: dict[str, list[str]] = {} for resource in root.iterchildren(tag="resource"): prop_dict = _get_all_property_names_and_resource_ids_one_resource(resource, prop_dict) return cls_dict, prop_dict -def _get_all_class_types_and_ids(root: etree._Element) -> dict[str, list[str]]: +def _get_all_class_types_and_ids_from_data(root: etree._Element) -> dict[str, list[str]]: cls_dict: dict[str, list[str]] = {} for resource in root.iterchildren(tag="resource"): restype = resource.attrib["restype"] @@ -88,18 +96,18 @@ def _get_all_property_names_and_resource_ids_one_resource( return prop_dict -def _diagnose_all_classes( - classes: dict[str, list[str]], onto_check_info: OntoCheckInformation +def _check_if_all_class_types_exist( + classes: dict[str, list[str]], onto_check_info: ProjectOntosInformation ) -> list[tuple[str, list[str], str]]: problem_list = [] for cls_type, ids in classes.items(): - if problem := _diagnose_class(cls_type, onto_check_info): + if problem := _check_if_one_class_type_exists(cls_type, onto_check_info): problem_list.append((cls_type, ids, problem)) return problem_list -def _diagnose_class(cls_type: str, onto_check_info: OntoCheckInformation) -> str | None: - prefix, cls_ = _get_prefix_and_prop_or_cls_identifier(cls_type, onto_check_info.default_ontology_prefix) +def _check_if_one_class_type_exists(cls_type: str, onto_check_info: ProjectOntosInformation) -> str | None: + prefix, cls_ = _get_separate_prefix_and_iri_from_onto_prop_or_cls(cls_type, onto_check_info.default_ontology_prefix) if not prefix: return "Property name does not follow a known ontology pattern" if onto := onto_check_info.onto_lookup.get(prefix): @@ -108,18 +116,20 @@ def _diagnose_class(cls_type: str, onto_check_info: OntoCheckInformation) -> str return "Unknown ontology prefix" -def _diagnose_all_properties( - properties: dict[str, list[str]], onto_check_info: OntoCheckInformation +def _check_if_all_properties_exist( + properties: dict[str, list[str]], onto_check_info: ProjectOntosInformation ) -> list[tuple[str, list[str], str]]: problem_list = [] for prop_name, ids in properties.items(): - if problem := _diagnose_property(prop_name, onto_check_info): + if problem := _check_if_one_property_exists(prop_name, onto_check_info): problem_list.append((prop_name, ids, problem)) return problem_list -def _diagnose_property(prop_name: str, onto_check_info: OntoCheckInformation) -> str | None: - prefix, prop = _get_prefix_and_prop_or_cls_identifier(prop_name, onto_check_info.default_ontology_prefix) +def _check_if_one_property_exists(prop_name: str, onto_check_info: ProjectOntosInformation) -> str | None: + prefix, prop = _get_separate_prefix_and_iri_from_onto_prop_or_cls( + prop_name, onto_check_info.default_ontology_prefix + ) if not prefix: return "Property name does not follow a known ontology pattern" if onto := onto_check_info.onto_lookup.get(prefix): @@ -128,7 +138,7 @@ def _diagnose_property(prop_name: str, onto_check_info: OntoCheckInformation) -> return "Unknown ontology prefix" -def _get_prefix_and_prop_or_cls_identifier( +def _get_separate_prefix_and_iri_from_onto_prop_or_cls( prop_or_cls: str, default_ontology_prefix: str ) -> tuple[str, ...] | tuple[None, None]: if defaultOntologyColon.match(prop_or_cls): diff --git a/src/dsp_tools/commands/xmlupload/models/ontology_lookup_models.py b/src/dsp_tools/commands/xmlupload/models/ontology_lookup_models.py new file mode 100644 index 000000000..0e76cd7e7 --- /dev/null +++ b/src/dsp_tools/commands/xmlupload/models/ontology_lookup_models.py @@ -0,0 +1,57 @@ +from dataclasses import dataclass, field +from typing import Any + + +@dataclass(frozen=True) +class OntoInfo: + """This class saves the properties and the classes from an ontology.""" + + classes: list[str] = field(default_factory=list) + properties: list[str] = field(default_factory=list) + + +@dataclass +class ProjectOntosInformation: + """This class saves information needed to check the consistency with the ontology.""" + + default_ontology_prefix: str + onto_lookup: dict[str, OntoInfo] + + +def extract_classes_properties_from_onto(onto_graph: list[dict[str, Any]]) -> OntoInfo: + """ + This function takes an ontology graph from the DSP-API. + It extracts the classes and properties. + And saves them in an instance of the class Ontology. + + Args: + onto_graph: graph from DSP-API + + Returns: + Ontology instance with the classes and properties + """ + classes = _get_all_cleaned_classes_from_graph(onto_graph) + properties = _get_all_cleaned_properties_from_graph(onto_graph) + return OntoInfo(classes, properties) + + +def _get_all_cleaned_classes_from_graph(onto_graph: list[dict[str, Any]]) -> list[str]: + classes = _get_all_classes_from_graph(onto_graph) + return _remove_prefixes(classes) + + +def _get_all_classes_from_graph(onto_graph: list[dict[str, Any]]) -> list[str]: + return [elem["@id"] for elem in onto_graph if elem.get("knora-api:isResourceClass")] + + +def _get_all_cleaned_properties_from_graph(onto_graph: list[dict[str, Any]]) -> list[str]: + props = _get_all_properties_from_graph(onto_graph) + return _remove_prefixes(props) + + +def _get_all_properties_from_graph(onto_graph: list[dict[str, Any]]) -> list[str]: + return [elem["@id"] for elem in onto_graph if not elem.get("knora-api:isResourceClass")] + + +def _remove_prefixes(ontology_elements: list[str]) -> list[str]: + return [x.split(":")[1] for x in ontology_elements] diff --git a/src/dsp_tools/commands/xmlupload/models/ontology_diagnose_models.py b/src/dsp_tools/commands/xmlupload/models/ontology_problem_models.py similarity index 82% rename from src/dsp_tools/commands/xmlupload/models/ontology_diagnose_models.py rename to src/dsp_tools/commands/xmlupload/models/ontology_problem_models.py index 252e27601..0cdc369f4 100644 --- a/src/dsp_tools/commands/xmlupload/models/ontology_diagnose_models.py +++ b/src/dsp_tools/commands/xmlupload/models/ontology_problem_models.py @@ -1,32 +1,17 @@ import itertools -from dataclasses import dataclass, field +from dataclasses import dataclass import pandas as pd separator = "\n " list_separator = "\n - " -grand_separator = "\n----------------------------\n" +medium_separator = "\n----------------------------\n" +grand_separator = "\n\n---------------------------------------\n\n" maximum_prints = 50 @dataclass(frozen=True) -class OntoInfo: - """This class saves the properties and the classes from an ontology.""" - - classes: list[str] = field(default_factory=list) - properties: list[str] = field(default_factory=list) - - -@dataclass -class OntoCheckInformation: - """This class saves information needed to check the consistency with the ontology.""" - - default_ontology_prefix: str - onto_lookup: dict[str, OntoInfo] - - -@dataclass(frozen=True) -class InvalidOntologyElements: +class InvalidOntologyElementsInData: """This class saves and prints out the information regarding ontology classes and properties that are in the XML but not the ontology.""" @@ -42,15 +27,14 @@ def execute_problem_protocol(self) -> tuple[str, pd.DataFrame | None]: Returns: the error message and a dataframe with the errors if they exceed 50 or None """ - extra_separator = "\n\n---------------------------------------\n\n" msg = ( f"\nSome property and/or class type(s) used in the XML are unknown.\n" f"The ontologies for your project on the server are:{list_separator}" - f"{list_separator.join(self.ontos_on_server)}{extra_separator}" + f"{list_separator.join(self.ontos_on_server)}{grand_separator}" ) cls_msg = self._compose_problem_string_for_cls() if cls_msg: - msg += cls_msg + extra_separator + msg += cls_msg + grand_separator prop_msg = self._compose_problem_string_for_props() if prop_msg: msg += prop_msg @@ -108,7 +92,7 @@ def _format_cls(cls_tup: tuple[str, list[str], str]) -> str: problems = [_format_cls(x) for x in self.classes] - return "The following resource(s) have an invalid resource type:\n\n" + grand_separator.join(problems) + return "The following resource(s) have an invalid resource type:\n\n" + medium_separator.join(problems) else: return None @@ -126,6 +110,6 @@ def _format_prop(prop_tup: tuple[str, list[str], str]) -> str: ) problems = [_format_prop(x) for x in self.properties] - return "The following resource(s) have invalid property type(s):\n\n" + grand_separator.join(problems) + return "The following resource(s) have invalid property type(s):\n\n" + medium_separator.join(problems) else: return None diff --git a/src/dsp_tools/commands/xmlupload/ontology_client.py b/src/dsp_tools/commands/xmlupload/ontology_client.py index ae076b1c7..09a8ff67d 100644 --- a/src/dsp_tools/commands/xmlupload/ontology_client.py +++ b/src/dsp_tools/commands/xmlupload/ontology_client.py @@ -2,7 +2,7 @@ from pathlib import Path from typing import Any, Protocol -from dsp_tools.commands.xmlupload.models.ontology_diagnose_models import OntoInfo +from dsp_tools.commands.xmlupload.models.ontology_lookup_models import OntoInfo, extract_classes_properties_from_onto from dsp_tools.models.exceptions import BaseError, UserError from dsp_tools.utils.connection import Connection from dsp_tools.utils.create_logger import get_logger @@ -21,7 +21,10 @@ class OntologyClient(Protocol): ontology_names: list[str] = field(default_factory=list) def get_all_ontologies_from_server(self) -> dict[str, OntoInfo]: - """Get all the ontologies for a project and the knora-api ontology from the server.""" + """Get all the ontologies for a project from the server.""" + + def get_knora_api_ontology_from_server(self) -> list[dict[str, Any]]: + """Get the knora-api ontology from the server.""" @dataclass @@ -42,12 +45,14 @@ def get_all_ontologies_from_server(self) -> dict[str, OntoInfo]: a dictionary with the ontology name as key and the ontology as value. """ ontologies = self._get_all_ontology_jsons_from_server() - return {onto_name: deserialize_ontology(onto_graph) for onto_name, onto_graph in ontologies.items()} + return { + onto_name: extract_classes_properties_from_onto(onto_graph) for onto_name, onto_graph in ontologies.items() + } def _get_all_ontology_jsons_from_server(self) -> dict[str, list[dict[str, Any]]]: self._get_ontology_names_from_server() project_ontos = {onto: self._get_ontology_from_server(onto) for onto in self.ontology_names} - project_ontos["knora-api"] = self._get_knora_api_ontology_from_server() + project_ontos["knora-api"] = self.get_knora_api_ontology_from_server() return project_ontos def _get_ontology_names_from_server(self) -> None: @@ -77,7 +82,16 @@ def _get_ontology_from_server(self, ontology_name: str) -> list[dict[str, Any]]: raise BaseError(f"Unexpected response from server: {res}") from e return onto_graph - def _get_knora_api_ontology_from_server(self) -> list[dict[str, Any]]: + def get_knora_api_ontology_from_server(self) -> list[dict[str, Any]]: + """ + This function returns the knora-api ontology from the server. + + Returns: + knora-api ontology in json format + + Raises: + BaseError: if an unexpected response from the server occurred + """ url = "/ontology/knora-api/v2#" try: res = self.con.get(url) @@ -88,42 +102,3 @@ def _get_knora_api_ontology_from_server(self) -> list[dict[str, Any]]: except KeyError as e: raise BaseError(f"Unexpected response from server when retrieving knora-api ontology: {res}") from e return onto_graph - - -def deserialize_ontology(onto_graph: list[dict[str, Any]]) -> OntoInfo: - """ - This function takes an ontology graph from the DSP-API. - It extracts the classes and properties. - And saves them in an instance of the class Ontology. - - Args: - onto_graph: graph from DSP-API - - Returns: - Ontology instance with the classes and properties - """ - classes = _get_all_cleaned_classes_from_graph(onto_graph) - properties = _get_all_cleaned_properties_from_graph(onto_graph) - return OntoInfo(classes, properties) - - -def _get_all_cleaned_classes_from_graph(onto_graph: list[dict[str, Any]]) -> list[str]: - classes = _get_all_classes_from_graph(onto_graph) - return _remove_prefixes(classes) - - -def _get_all_classes_from_graph(onto_graph: list[dict[str, Any]]) -> list[str]: - return [elem["@id"] for elem in onto_graph if elem.get("knora-api:isResourceClass")] - - -def _get_all_cleaned_properties_from_graph(onto_graph: list[dict[str, Any]]) -> list[str]: - props = _get_all_properties_from_graph(onto_graph) - return _remove_prefixes(props) - - -def _get_all_properties_from_graph(onto_graph: list[dict[str, Any]]) -> list[str]: - return [elem["@id"] for elem in onto_graph if not elem.get("knora-api:isResourceClass")] - - -def _remove_prefixes(ontology_elements: list[str]) -> list[str]: - return [x.split(":")[1] for x in ontology_elements] diff --git a/src/dsp_tools/commands/xmlupload/xmlupload.py b/src/dsp_tools/commands/xmlupload/xmlupload.py index fbe1d7079..6c524a7c9 100644 --- a/src/dsp_tools/commands/xmlupload/xmlupload.py +++ b/src/dsp_tools/commands/xmlupload/xmlupload.py @@ -10,7 +10,7 @@ from lxml import etree -from dsp_tools.commands.xmlupload.check_consistency_with_ontology import do_xml_consistency_check +from dsp_tools.commands.xmlupload.check_consistency_with_ontology import do_xml_consistency_check_with_ontology from dsp_tools.commands.xmlupload.iri_resolver import IriResolver from dsp_tools.commands.xmlupload.list_client import ListClient, ListClientLive from dsp_tools.commands.xmlupload.models.permission import Permissions @@ -94,7 +94,7 @@ def xmlupload( default_ontology=default_ontology, save_location=config.diagnostics.save_location, ) - do_xml_consistency_check(onto_client=ontology_client, root=root) + do_xml_consistency_check_with_ontology(onto_client=ontology_client, root=root) resources, permissions_lookup, stash = _prepare_upload( root=root, @@ -104,11 +104,7 @@ def xmlupload( ) project_client: ProjectClient = ProjectClientLive(con, config.shortcode) - if default_ontology not in project_client.get_ontology_name_dict(): - raise UserError( - f"The default ontology '{default_ontology}' " - "specified in the XML file is not part of the project on the DSP server." - ) + list_client: ListClient = ListClientLive(con, project_client.get_project_iri()) iri_resolver, failed_uploads = _upload( diff --git a/test/unittests/commands/xmlupload/test_check_consistency_with_ontology_high_level.py b/test/unittests/commands/xmlupload/test_check_consistency_with_ontology_high_level.py index 320f183c4..f0b8f7fa6 100644 --- a/test/unittests/commands/xmlupload/test_check_consistency_with_ontology_high_level.py +++ b/test/unittests/commands/xmlupload/test_check_consistency_with_ontology_high_level.py @@ -7,7 +7,7 @@ import pytest from lxml import etree -from dsp_tools.commands.xmlupload.check_consistency_with_ontology import do_xml_consistency_check +from dsp_tools.commands.xmlupload.check_consistency_with_ontology import do_xml_consistency_check_with_ontology from dsp_tools.commands.xmlupload.ontology_client import OntologyClientLive from dsp_tools.models.exceptions import BaseError, UserError @@ -69,7 +69,7 @@ def test_error_on_nonexistent_shortcode() -> None: save_location=Path("bar"), ) with pytest.raises(UserError, match="A project with shortcode 9999 could not be found on the DSP server"): - do_xml_consistency_check(ontology_client, root) + do_xml_consistency_check_with_ontology(ontology_client, root) def test_error_on_nonexistent_onto_name() -> None: @@ -99,7 +99,7 @@ def test_error_on_nonexistent_onto_name() -> None: "---------------------------------------\n\n" ) with pytest.raises(UserError, match=expected): - do_xml_consistency_check(ontology_client, root) + do_xml_consistency_check_with_ontology(ontology_client, root) if __name__ == "__main__": diff --git a/test/unittests/commands/xmlupload/test_check_consistency_with_ontology.py b/test/unittests/commands/xmlupload/test_check_consistency_with_ontology_low_level.py similarity index 69% rename from test/unittests/commands/xmlupload/test_check_consistency_with_ontology.py rename to test/unittests/commands/xmlupload/test_check_consistency_with_ontology_low_level.py index 45b61b387..e9152b4f6 100644 --- a/test/unittests/commands/xmlupload/test_check_consistency_with_ontology.py +++ b/test/unittests/commands/xmlupload/test_check_consistency_with_ontology_low_level.py @@ -3,178 +3,83 @@ from pytest_unordered import unordered from dsp_tools.commands.xmlupload.check_consistency_with_ontology import ( - _diagnose_all_classes, - _diagnose_all_properties, - _diagnose_class, - _diagnose_property, - _find_problems_in_classes_and_properties, - _get_all_class_types_and_ids, - _get_all_classes_and_properties, + _check_if_all_class_types_exist, + _check_if_all_properties_exist, + _check_if_one_class_type_exists, + _check_if_one_property_exists, + _find_if_all_classes_and_properties_exist_in_onto, + _get_all_class_types_and_ids_from_data, + _get_all_classes_and_properties_from_data, _get_all_property_names_and_resource_ids_one_resource, - _get_prefix_and_prop_or_cls_identifier, + _get_separate_prefix_and_iri_from_onto_prop_or_cls, ) -from dsp_tools.commands.xmlupload.models.ontology_diagnose_models import OntoCheckInformation, OntoInfo +from dsp_tools.commands.xmlupload.models.ontology_lookup_models import OntoInfo, ProjectOntosInformation from dsp_tools.models.exceptions import UserError -def test_get_all_classes_and_properties() -> None: - test_ele = etree.fromstring( - """ - - - resB - - - - - - - resB - - - resA - - - """ - ) - expected_classes = {":TestThing1": ["resA"], ":TestThing2": ["resB", "resC"]} - expected_properties = { - ":hasResource1": ["resA"], - ":hasResource2": ["resC"], - ":hasResource3": ["resC"], - } - res_classes, res_properties = _get_all_classes_and_properties(test_ele) - assert res_classes.keys() == expected_classes.keys() - for k, v in res_classes.items(): - assert unordered(v) == expected_classes[k] - assert res_properties.keys() == expected_properties.keys() - for k, v in res_properties.items(): - assert unordered(v) == expected_properties[k] - - -def test_get_all_class_types_and_ids() -> None: - test_ele = etree.fromstring( - """ - - - - """ - ) - expected_classes = {":TestThing1": ["resA"], ":TestThing2": ["resB", "resC"]} - res_classes = _get_all_class_types_and_ids(test_ele) - assert res_classes.keys() == expected_classes.keys() - for k, v in res_classes.items(): - assert unordered(v) == expected_classes[k] - - -def test_get_all_property_names_and_resource_ids_one_resouce() -> None: - test_ele = etree.fromstring( - """ - - resB - - - resA - - """ - ) - expected = {"a": ["a"], ":hasResource2": ["resC"], ":hasResource3": ["resC"]} - res_dic = _get_all_property_names_and_resource_ids_one_resource(test_ele, {"a": ["a"]}) - assert res_dic.keys() == expected.keys() - for k, v in res_dic.items(): - assert unordered(v) == expected[k] - - -def test_find_problems_in_classes_and_properties_all_good() -> None: - onto_check_info = OntoCheckInformation( - default_ontology_prefix="test", - onto_lookup={ - "test": OntoInfo(classes=["classA", "classB"], properties=["propA", "propB"]), - "knora-api": OntoInfo(classes=["knoraClassA"], properties=["knoraPropA"]), - }, - ) - classes = {"knoraClassA": ["idA"]} - properties = {"knora-api:knoraPropA": ["idA"]} - _find_problems_in_classes_and_properties(classes, properties, onto_check_info) - - -def test_find_problems_in_classes_and_properties_problem() -> None: - onto_check_info = OntoCheckInformation( - default_ontology_prefix="test", - onto_lookup={ - "test": OntoInfo(classes=["classA", "classB"], properties=["propA", "propB"]), - "knora-api": OntoInfo(classes=["knoraClassA"], properties=["knoraPropA"]), - }, - ) - classes = {"knora": ["idA"]} - properties = {"knora-api:knoraPropA": ["idA"]} - with pytest.raises(UserError): - _find_problems_in_classes_and_properties(classes, properties, onto_check_info) - - -class TestDiagnoseClass: +class TestCheckClassType: def test_no_knora_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=["classA", "classB"], properties=[]), "knora-api": OntoInfo(classes=["knoraClassA"], properties=[]), }, ) - assert not _diagnose_class("knoraClassA", onto_check_info) + assert not _check_if_one_class_type_exists("knoraClassA", onto_check_info) def test_knora_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=["classA", "classB"], properties=[]), "knora-api": OntoInfo(classes=["knoraClassA"], properties=[]), }, ) - assert not _diagnose_class("knora-api:knoraClassA", onto_check_info) + assert not _check_if_one_class_type_exists("knora-api:knoraClassA", onto_check_info) def test_no_default_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=["classA", "classB"], properties=[]), "knora-api": OntoInfo(classes=["knoraClassA"], properties=[]), }, ) - assert not _diagnose_class(":classA", onto_check_info) + assert not _check_if_one_class_type_exists(":classA", onto_check_info) def test_default_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=["classA", "classB"], properties=[]), "knora-api": OntoInfo(classes=["knoraClassA"], properties=[]), }, ) - assert not _diagnose_class("test:classB", onto_check_info) + assert not _check_if_one_class_type_exists("test:classB", onto_check_info) def test_unknown_class(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=["classA", "classB"], properties=[]), "knora-api": OntoInfo(classes=["knoraClassA"], properties=[]), }, ) - assert _diagnose_class("test:classC", onto_check_info) == "Invalid Class Type" + assert _check_if_one_class_type_exists("test:classC", onto_check_info) == "Invalid Class Type" def test_unknown_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=["classA", "classB"], properties=[]), "knora-api": OntoInfo(classes=["knoraClassA"], properties=[]), }, ) - assert _diagnose_class("other:classC", onto_check_info) == "Unknown ontology prefix" + assert _check_if_one_class_type_exists("other:classC", onto_check_info) == "Unknown ontology prefix" def test_diagnose_all_classes_no_problems(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=["classA", "classB"], properties=[]), @@ -182,10 +87,10 @@ def test_diagnose_all_classes_no_problems(self) -> None: }, ) test_classes = {"knora-api:knoraClassA": ["idA"], ":classB": ["idB"]} - assert not _diagnose_all_classes(test_classes, onto_check_info) + assert not _check_if_all_class_types_exist(test_classes, onto_check_info) def test_diagnose_all_classes_problems(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=["classA", "classB"], properties=[]), @@ -193,72 +98,74 @@ def test_diagnose_all_classes_problems(self) -> None: }, ) test_classes = {"knoraClassA": ["idA"], ":classD": ["idD"]} - assert _diagnose_all_classes(test_classes, onto_check_info) == [(":classD", ["idD"], "Invalid Class Type")] + assert _check_if_all_class_types_exist(test_classes, onto_check_info) == [ + (":classD", ["idD"], "Invalid Class Type") + ] -class TestDiagnoseProperties: +class TestCheckProperties: def test_no_knora_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=[], properties=["propA", "propB"]), "knora-api": OntoInfo(classes=[], properties=["knoraPropA"]), }, ) - assert not _diagnose_property("knoraPropA", onto_check_info) + assert not _check_if_one_property_exists("knoraPropA", onto_check_info) def test_knora_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=[], properties=["propA", "propB"]), "knora-api": OntoInfo(classes=[], properties=["knoraPropA"]), }, ) - assert not _diagnose_property("knora-api:knoraPropA", onto_check_info) + assert not _check_if_one_property_exists("knora-api:knoraPropA", onto_check_info) def test_no_default_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=[], properties=["propA", "propB"]), "knora-api": OntoInfo(classes=[], properties=["knoraPropA"]), }, ) - assert not _diagnose_property(":propA", onto_check_info) + assert not _check_if_one_property_exists(":propA", onto_check_info) def test_default_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=[], properties=["propA", "propB"]), "knora-api": OntoInfo(classes=[], properties=["knoraPropA"]), }, ) - assert not _diagnose_property("test:propB", onto_check_info) + assert not _check_if_one_property_exists("test:propB", onto_check_info) def test_unknown_prefix(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=[], properties=["propA", "propB"]), "knora-api": OntoInfo(classes=[], properties=["knoraPropA"]), }, ) - assert _diagnose_property("other:propB", onto_check_info) == "Unknown ontology prefix" + assert _check_if_one_property_exists("other:propB", onto_check_info) == "Unknown ontology prefix" def test_unknown_property(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=[], properties=["propA", "propB"]), "knora-api": OntoInfo(classes=[], properties=["knoraPropA"]), }, ) - assert _diagnose_property("test:propC", onto_check_info) == "Invalid Property" + assert _check_if_one_property_exists("test:propC", onto_check_info) == "Invalid Property" def test_diagnose_all_properties_problems(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=[], properties=["propA", "propB"]), @@ -267,10 +174,10 @@ def test_diagnose_all_properties_problems(self) -> None: ) test_properties = {"test:propB": ["idB"], "other:propB": ["idB"], "test:propD": ["idD"]} expected = [("other:propB", ["idB"], "Unknown ontology prefix"), ("test:propD", ["idD"], "Invalid Property")] - assert unordered(_diagnose_all_properties(test_properties, onto_check_info)) == expected + assert unordered(_check_if_all_properties_exist(test_properties, onto_check_info)) == expected def test_diagnose_all_properties_no_problems(self) -> None: - onto_check_info = OntoCheckInformation( + onto_check_info = ProjectOntosInformation( default_ontology_prefix="test", onto_lookup={ "test": OntoInfo(classes=[], properties=["propA", "propB"]), @@ -278,15 +185,113 @@ def test_diagnose_all_properties_no_problems(self) -> None: }, ) test_properties = {"test:propB": ["idB"], "knoraPropA": ["idA"]} - assert not unordered(_diagnose_all_properties(test_properties, onto_check_info)) + assert not unordered(_check_if_all_properties_exist(test_properties, onto_check_info)) + + +def test_find_if_all_classes_and_properties_exist_in_onto() -> None: + onto_check_info = ProjectOntosInformation( + default_ontology_prefix="test", + onto_lookup={ + "test": OntoInfo(classes=["classA", "classB"], properties=["propA", "propB"]), + "knora-api": OntoInfo(classes=["knoraClassA"], properties=["knoraPropA"]), + }, + ) + classes = {"knoraClassA": ["idA"]} + properties = {"knora-api:knoraPropA": ["idA"]} + _find_if_all_classes_and_properties_exist_in_onto(classes, properties, onto_check_info) + + +def test_find_if_all_classes_and_properties_exist_in_onto_problem() -> None: + onto_check_info = ProjectOntosInformation( + default_ontology_prefix="test", + onto_lookup={ + "test": OntoInfo(classes=["classA", "classB"], properties=["propA", "propB"]), + "knora-api": OntoInfo(classes=["knoraClassA"], properties=["knoraPropA"]), + }, + ) + classes = {"knora": ["idA"]} + properties = {"knora-api:knoraPropA": ["idA"]} + with pytest.raises(UserError): + _find_if_all_classes_and_properties_exist_in_onto(classes, properties, onto_check_info) def test_get_prefix_and_prop_cls_identifier() -> None: - assert _get_prefix_and_prop_or_cls_identifier(":propA", "test") == ("test", "propA") - assert _get_prefix_and_prop_or_cls_identifier("knora-api:knoraPropA", "test") == ("knora-api", "knoraPropA") - assert _get_prefix_and_prop_or_cls_identifier("knoraPropB", "test") == ("knora-api", "knoraPropB") - assert _get_prefix_and_prop_or_cls_identifier("test:propA", "test") == ("test", "propA") + assert _get_separate_prefix_and_iri_from_onto_prop_or_cls(":propA", "test") == ("test", "propA") + assert _get_separate_prefix_and_iri_from_onto_prop_or_cls("knora-api:knoraPropA", "test") == ( + "knora-api", + "knoraPropA", + ) + assert _get_separate_prefix_and_iri_from_onto_prop_or_cls("knoraPropB", "test") == ("knora-api", "knoraPropB") + assert _get_separate_prefix_and_iri_from_onto_prop_or_cls("test:propA", "test") == ("test", "propA") def test_get_prefix_and_prop_cls_identifier_error() -> None: - assert _get_prefix_and_prop_or_cls_identifier("123654/", "test") == (None, None) + assert _get_separate_prefix_and_iri_from_onto_prop_or_cls("123654/", "test") == (None, None) + + +def test_get_all_class_types_and_ids_from_data() -> None: + test_ele = etree.fromstring( + """ + + + + """ + ) + expected_classes = {":TestThing1": ["resA"], ":TestThing2": ["resB", "resC"]} + res_classes = _get_all_class_types_and_ids_from_data(test_ele) + assert res_classes.keys() == expected_classes.keys() + for k, v in res_classes.items(): + assert unordered(v) == expected_classes[k] + + +def test_get_all_property_names_and_resource_ids_one_resource() -> None: + test_ele = etree.fromstring( + """ + + resB + + + resA + + """ + ) + expected = {"a": ["a"], ":hasResource2": ["resC"], ":hasResource3": ["resC"]} + res_dic = _get_all_property_names_and_resource_ids_one_resource(test_ele, {"a": ["a"]}) + assert res_dic.keys() == expected.keys() + for k, v in res_dic.items(): + assert unordered(v) == expected[k] + + +def test_get_all_classes_and_properties_from_data() -> None: + test_ele = etree.fromstring( + """ + + + resB + + + + + + + resB + + + resA + + + """ + ) + expected_classes = {":TestThing1": ["resA"], ":TestThing2": ["resB", "resC"]} + expected_properties = { + ":hasResource1": ["resA"], + ":hasResource2": ["resC"], + ":hasResource3": ["resC"], + } + res_classes, res_properties = _get_all_classes_and_properties_from_data(test_ele) + assert res_classes.keys() == expected_classes.keys() + for k, v in res_classes.items(): + assert unordered(v) == expected_classes[k] + assert res_properties.keys() == expected_properties.keys() + for k, v in res_properties.items(): + assert unordered(v) == expected_properties[k] diff --git a/test/unittests/commands/xmlupload/test_ontology_client.py b/test/unittests/commands/xmlupload/test_ontology_client.py index cfbb9fe4b..01df52114 100644 --- a/test/unittests/commands/xmlupload/test_ontology_client.py +++ b/test/unittests/commands/xmlupload/test_ontology_client.py @@ -7,10 +7,6 @@ from dsp_tools.commands.xmlupload.ontology_client import ( OntologyClientLive, - _get_all_classes_from_graph, - _get_all_properties_from_graph, - _remove_prefixes, - deserialize_ontology, ) @@ -22,151 +18,6 @@ def get(self, route: str, headers: dict[str, str] | None = None) -> dict[Any, An return self.get_response -class TestGetAllClassesFromGraph: - @staticmethod - def test_single_class() -> None: - test_graph = [ - { - "knora-api:isResourceClass": True, - "rdfs:label": "Sequenz einer Audio-Ressource", - "knora-api:canBeInstantiated": True, - "rdfs:subClassOf": [], - "@type": "owl:Class", - "@id": "testonto:AudioSequence", - }, - ] - res_cls = _get_all_classes_from_graph(test_graph) - assert res_cls == ["testonto:AudioSequence"] - - @staticmethod - def test_property() -> None: - test_graph = [ - { - "rdfs:label": "URI", - "rdfs:subPropertyOf": {}, - "knora-api:isEditable": True, - "knora-api:isResourceProperty": True, - "@type": "owl:ObjectProperty", - "salsah-gui:guiAttribute": [], - "knora-api:objectType": {}, - "salsah-gui:guiElement": {}, - "@id": "testonto:hasUri", - }, - ] - res_cls = _get_all_classes_from_graph(test_graph) - assert not res_cls - - @staticmethod - def test_from_graph_resources_and_properties() -> None: - test_graph = [ - { - "knora-api:isResourceClass": True, - "rdfs:label": "Sequenz einer Audio-Ressource", - "knora-api:canBeInstantiated": True, - "rdfs:subClassOf": [], - "@type": "owl:Class", - "@id": "testonto:AudioSequence", - }, - { - "rdfs:label": "URI", - "rdfs:subPropertyOf": {}, - "knora-api:isEditable": True, - "knora-api:isResourceProperty": True, - "@type": "owl:ObjectProperty", - "salsah-gui:guiAttribute": [], - "knora-api:objectType": {}, - "salsah-gui:guiElement": {}, - "@id": "testonto:hasUri", - }, - ] - res_cls = _get_all_classes_from_graph(test_graph) - assert res_cls == ["testonto:AudioSequence"] - - -def test_get_all_properties_from_graph_haslinkto() -> None: - test_graph = [ - { - "rdfs:label": "hasResource", - "rdfs:subPropertyOf": {}, - "knora-api:isEditable": True, - "knora-api:isResourceProperty": True, - "knora-api:isLinkProperty": True, - "@type": "owl:ObjectProperty", - "knora-api:objectType": {}, - "salsah-gui:guiElement": {}, - "@id": "testonto:hasResource", - }, - { - "knora-api:isLinkValueProperty": True, - "rdfs:label": "hasResource", - "rdfs:subPropertyOf": {}, - "knora-api:isEditable": True, - "knora-api:isResourceProperty": True, - "@type": "owl:ObjectProperty", - "knora-api:objectType": {}, - "salsah-gui:guiElement": {}, - "@id": "testonto:hasResourceValue", - }, - ] - res_prop = _get_all_properties_from_graph(test_graph) - assert res_prop == ["testonto:hasResource", "testonto:hasResourceValue"] - - -def test_get_all_properties_from_graph_resources_and_properties() -> None: - test_graph = [ - { - "knora-api:isResourceClass": True, - "rdfs:label": "Sequenz einer Audio-Ressource", - "knora-api:canBeInstantiated": True, - "rdfs:subClassOf": [], - "@type": "owl:Class", - "@id": "testonto:AudioSequence", - }, - { - "rdfs:label": "URI", - "rdfs:subPropertyOf": {}, - "knora-api:isEditable": True, - "knora-api:isResourceProperty": True, - "@type": "owl:ObjectProperty", - "salsah-gui:guiAttribute": [], - "knora-api:objectType": {}, - "salsah-gui:guiElement": {}, - "@id": "testonto:hasUri", - }, - ] - res_prop = _get_all_properties_from_graph(test_graph) - assert res_prop == ["testonto:hasUri"] - - -def test_deserialize_ontology() -> None: - test_graph = [ - { - "knora-api:isResourceClass": True, - "rdfs:label": "Annotation", - "knora-api:canBeInstantiated": True, - "rdfs:subClassOf": [], - "rdfs:comment": "A generic class for representing annotations", - "@type": "owl:Class", - "@id": "knora-api:Annotation", - }, - { - "rdfs:label": "has Link to", - "rdfs:subPropertyOf": {}, - "knora-api:isEditable": True, - "knora-api:isResourceProperty": True, - "@type": "owl:ObjectProperty", - "knora-api:objectType": {}, - "@id": "knora-api:hasLinkTo", - "knora-api:subjectType": {}, - "knora-api:isLinkProperty": True, - "rdfs:comment": "Represents a direct connection between two resources", - }, - ] - res_onto = deserialize_ontology(test_graph) - assert res_onto.classes == ["Annotation"] - assert res_onto.properties == ["hasLinkTo"] - - def test_get_ontology_names_from_server() -> None: response = { "project": { @@ -227,17 +78,5 @@ def test_get_knora_api_from_server() -> None: } con = ConnectionMock(response) onto_client = OntologyClientLive(con, "", "", Path("")) - res_graph = onto_client._get_knora_api_ontology_from_server() + res_graph = onto_client.get_knora_api_ontology_from_server() assert unordered(res_graph) == [{"resource_class": ["Information"]}, {"property": ["Information"]}] - - -def test_remove_prefixes_knora_classes() -> None: - test_elements = ["knora-api:Annotation", "knora-api:ArchiveFileValue", "knora-api:ArchiveRepresentation"] - res = _remove_prefixes(test_elements) - assert unordered(res) == ["Annotation", "ArchiveFileValue", "ArchiveRepresentation"] - - -def test_remove_prefixes_knora_properties() -> None: - test_elements = ["knora-api:attachedToUser", "knora-api:deletedBy"] - res = _remove_prefixes(test_elements) - assert unordered(res) == ["attachedToUser", "deletedBy"] diff --git a/test/unittests/commands/xmlupload/test_ontology_lookup_models.py b/test/unittests/commands/xmlupload/test_ontology_lookup_models.py new file mode 100644 index 000000000..89c54f247 --- /dev/null +++ b/test/unittests/commands/xmlupload/test_ontology_lookup_models.py @@ -0,0 +1,165 @@ +from pytest_unordered import unordered + +from dsp_tools.commands.xmlupload.models.ontology_lookup_models import ( + _get_all_classes_from_graph, + _get_all_properties_from_graph, + _remove_prefixes, + extract_classes_properties_from_onto, +) + + +class TestGetAllClassesFromGraph: + @staticmethod + def test_single_class() -> None: + test_graph = [ + { + "knora-api:isResourceClass": True, + "rdfs:label": "Sequenz einer Audio-Ressource", + "knora-api:canBeInstantiated": True, + "rdfs:subClassOf": [], + "@type": "owl:Class", + "@id": "testonto:AudioSequence", + }, + ] + res_cls = _get_all_classes_from_graph(test_graph) + assert res_cls == ["testonto:AudioSequence"] + + @staticmethod + def test_property() -> None: + test_graph = [ + { + "rdfs:label": "URI", + "rdfs:subPropertyOf": {}, + "knora-api:isEditable": True, + "knora-api:isResourceProperty": True, + "@type": "owl:ObjectProperty", + "salsah-gui:guiAttribute": [], + "knora-api:objectType": {}, + "salsah-gui:guiElement": {}, + "@id": "testonto:hasUri", + }, + ] + res_cls = _get_all_classes_from_graph(test_graph) + assert not res_cls + + @staticmethod + def test_from_graph_resources_and_properties() -> None: + test_graph = [ + { + "knora-api:isResourceClass": True, + "rdfs:label": "Sequenz einer Audio-Ressource", + "knora-api:canBeInstantiated": True, + "rdfs:subClassOf": [], + "@type": "owl:Class", + "@id": "testonto:AudioSequence", + }, + { + "rdfs:label": "URI", + "rdfs:subPropertyOf": {}, + "knora-api:isEditable": True, + "knora-api:isResourceProperty": True, + "@type": "owl:ObjectProperty", + "salsah-gui:guiAttribute": [], + "knora-api:objectType": {}, + "salsah-gui:guiElement": {}, + "@id": "testonto:hasUri", + }, + ] + res_cls = _get_all_classes_from_graph(test_graph) + assert res_cls == ["testonto:AudioSequence"] + + +def test_get_all_properties_from_graph_haslinkto() -> None: + test_graph = [ + { + "rdfs:label": "hasResource", + "rdfs:subPropertyOf": {}, + "knora-api:isEditable": True, + "knora-api:isResourceProperty": True, + "knora-api:isLinkProperty": True, + "@type": "owl:ObjectProperty", + "knora-api:objectType": {}, + "salsah-gui:guiElement": {}, + "@id": "testonto:hasResource", + }, + { + "knora-api:isLinkValueProperty": True, + "rdfs:label": "hasResource", + "rdfs:subPropertyOf": {}, + "knora-api:isEditable": True, + "knora-api:isResourceProperty": True, + "@type": "owl:ObjectProperty", + "knora-api:objectType": {}, + "salsah-gui:guiElement": {}, + "@id": "testonto:hasResourceValue", + }, + ] + res_prop = _get_all_properties_from_graph(test_graph) + assert res_prop == ["testonto:hasResource", "testonto:hasResourceValue"] + + +def test_get_all_properties_from_graph_resources_and_properties() -> None: + test_graph = [ + { + "knora-api:isResourceClass": True, + "rdfs:label": "Sequenz einer Audio-Ressource", + "knora-api:canBeInstantiated": True, + "rdfs:subClassOf": [], + "@type": "owl:Class", + "@id": "testonto:AudioSequence", + }, + { + "rdfs:label": "URI", + "rdfs:subPropertyOf": {}, + "knora-api:isEditable": True, + "knora-api:isResourceProperty": True, + "@type": "owl:ObjectProperty", + "salsah-gui:guiAttribute": [], + "knora-api:objectType": {}, + "salsah-gui:guiElement": {}, + "@id": "testonto:hasUri", + }, + ] + res_prop = _get_all_properties_from_graph(test_graph) + assert res_prop == ["testonto:hasUri"] + + +def test_deserialize_ontology() -> None: + test_graph = [ + { + "knora-api:isResourceClass": True, + "rdfs:label": "Annotation", + "knora-api:canBeInstantiated": True, + "rdfs:subClassOf": [], + "rdfs:comment": "A generic class for representing annotations", + "@type": "owl:Class", + "@id": "knora-api:Annotation", + }, + { + "rdfs:label": "has Link to", + "rdfs:subPropertyOf": {}, + "knora-api:isEditable": True, + "knora-api:isResourceProperty": True, + "@type": "owl:ObjectProperty", + "knora-api:objectType": {}, + "@id": "knora-api:hasLinkTo", + "knora-api:subjectType": {}, + "knora-api:isLinkProperty": True, + "rdfs:comment": "Represents a direct connection between two resources", + }, + ] + res_onto = extract_classes_properties_from_onto(test_graph) + assert res_onto.classes == ["Annotation"] + assert res_onto.properties == ["hasLinkTo"] + + +def test_remove_prefixes_knora_classes() -> None: + test_elements = ["knora-api:Annotation", "knora-api:ArchiveFileValue", "knora-api:ArchiveRepresentation"] + res = _remove_prefixes(test_elements) + assert unordered(res) == ["Annotation", "ArchiveFileValue", "ArchiveRepresentation"] + + +def test_remove_prefixes_knora_properties() -> None: + test_elements = ["knora-api:attachedToUser", "knora-api:deletedBy"] + res = _remove_prefixes(test_elements) + assert unordered(res) == ["attachedToUser", "deletedBy"] diff --git a/test/unittests/commands/xmlupload/test_ontology_diagnose_models.py b/test/unittests/commands/xmlupload/test_ontology_problem_models.py similarity index 84% rename from test/unittests/commands/xmlupload/test_ontology_diagnose_models.py rename to test/unittests/commands/xmlupload/test_ontology_problem_models.py index 10f12bb37..359e78ab6 100644 --- a/test/unittests/commands/xmlupload/test_ontology_diagnose_models.py +++ b/test/unittests/commands/xmlupload/test_ontology_problem_models.py @@ -1,11 +1,11 @@ import pandas as pd from pandas.testing import assert_frame_equal -from dsp_tools.commands.xmlupload.models.ontology_diagnose_models import InvalidOntologyElements +from dsp_tools.commands.xmlupload.models.ontology_problem_models import InvalidOntologyElementsInData def test_print_problem_string_cls() -> None: - onto = InvalidOntologyElements([("clsA", ["idA"], "wrong")], [], ontos_on_server=["test"]) + onto = InvalidOntologyElementsInData([("clsA", ["idA"], "wrong")], [], ontos_on_server=["test"]) msg = onto._compose_problem_string_for_cls() assert msg == ( "The following resource(s) have an invalid resource type:\n\n" @@ -17,12 +17,12 @@ def test_print_problem_string_cls() -> None: def test_print_problem_string_no_cls() -> None: - onto = InvalidOntologyElements([], [], []) + onto = InvalidOntologyElementsInData([], [], []) assert not onto._compose_problem_string_for_cls() def test_print_problem_string_prop() -> None: - onto = InvalidOntologyElements([], [("propA", ["idA"], "wrong")], ["test"]) + onto = InvalidOntologyElementsInData([], [("propA", ["idA"], "wrong")], ["test"]) msg = onto._compose_problem_string_for_props() assert msg == ( "The following resource(s) have invalid property type(s):\n\n" @@ -34,12 +34,12 @@ def test_print_problem_string_prop() -> None: def test_print_problem_string_no_prop() -> None: - onto = InvalidOntologyElements([], [], []) + onto = InvalidOntologyElementsInData([], [], []) assert not onto._compose_problem_string_for_props() def test_execute_problem_protocol() -> None: - onto = InvalidOntologyElements( + onto = InvalidOntologyElementsInData( [("clsA", ["idA"], "wrong")], [("propA", ["idA"], "wrong"), ("propB", ["idB", "idC"], "wrong")], ["test1", "test2"], @@ -74,7 +74,7 @@ def test_execute_problem_protocol() -> None: def test_get_problems_as_df() -> None: - onto = InvalidOntologyElements( + onto = InvalidOntologyElementsInData( [("clsA", ["idA"], "wrongA")], [("propB", ["idB"], "wrongB"), ("propC", ["idC1", "idC2"], "wrongC")], ["test"] ) expected_df = pd.DataFrame(