-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_ontology_client.py
81 lines (70 loc) · 2.84 KB
/
test_ontology_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from dataclasses import dataclass
from test.unittests.commands.xmlupload.connection_mock import ConnectionMockBase
from typing import Any
from pytest_unordered import unordered
from dsp_tools.commands.xmlupload.ontology_client import (
OntologyClientLive,
)
@dataclass
class ConnectionMock(ConnectionMockBase):
get_response: dict[Any, Any]
def get(self, route: str, headers: dict[str, str] | None = None) -> dict[Any, Any]: # noqa: ARG002 (unused-method-argument)
return self.get_response
def test_get_ontology_names_from_server() -> None:
response = {
"project": {
"description": [],
"id": "http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF",
"keywords": [],
"logo": None,
"longname": "Bernoulli-Euler Online",
"ontologies": [
"http://api.dasch.swiss/ontology/0801/biblio/v2",
"http://api.dasch.swiss/ontology/0801/newton/v2",
"http://api.dasch.swiss/ontology/0801/leibniz/v2",
"http://api.dasch.swiss/ontology/0801/beol/v2",
],
"selfjoin": False,
"shortcode": "0801",
"shortname": "beol",
"status": True,
}
}
con = ConnectionMock(response)
onto_client = OntologyClientLive(con, "0801", "beol")
onto_client._get_ontology_names_from_server()
assert unordered(onto_client.ontology_names) == ["biblio", "newton", "leibniz", "beol"]
def test_get_ontology_from_server() -> None:
response = {
"knora-api:lastModificationDate": {},
"rdfs:label": "The BEOL ontology",
"@graph": [
{"resource_class": ["Information"]},
{"property": ["Information"]},
],
"knora-api:attachedToProject": {},
"@type": "owl:Ontology",
"@id": "http://api.dasch.swiss/ontology/0801/beol/v2",
"@context": {},
}
con = ConnectionMock(response)
onto_client = OntologyClientLive(con, "0801", "beol")
res_graph = onto_client._get_ontology_from_server("beol")
assert unordered(res_graph) == [{"resource_class": ["Information"]}, {"property": ["Information"]}]
def test_get_knora_api_from_server() -> None:
response = {
"rdfs:label": "The knora-api ontology in the complex schema",
"@graph": [
{"resource_class": ["Information"]},
{"property": ["Information"]},
],
"knora-api:attachedToProject": {},
"knora-api:isBuiltIn": True,
"@type": "owl:Ontology",
"@id": "http://api.knora.org/ontology/knora-api/v2",
"@context": {},
}
con = ConnectionMock(response)
onto_client = OntologyClientLive(con, "", "")
res_graph = onto_client.get_knora_api_ontology_from_server()
assert unordered(res_graph) == [{"resource_class": ["Information"]}, {"property": ["Information"]}]