oldaplib 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- oldaplib/ontologies/admin-testing.trig +2 -4
- oldaplib/ontologies/admin.trig +2 -4
- oldaplib/ontologies/oldap.trig +221 -131
- oldaplib/ontologies/shared.trig +0 -3
- oldaplib/src/datamodel.py +109 -17
- oldaplib/src/dtypes/namespaceiri.py +16 -1
- oldaplib/src/enums/externalontologyattr.py +22 -0
- oldaplib/src/enums/owlpropertytype.py +10 -0
- oldaplib/src/enums/projectattr.py +0 -1
- oldaplib/src/enums/propertyclassattr.py +3 -1
- oldaplib/src/externalontology.py +554 -0
- oldaplib/src/hasproperty.py +5 -0
- oldaplib/src/helpers/context.py +4 -4
- oldaplib/src/helpers/langstring.py +11 -2
- oldaplib/src/helpers/observable_dict.py +4 -1
- oldaplib/src/helpers/observable_set.py +135 -80
- oldaplib/src/helpers/query_processor.py +3 -0
- oldaplib/src/model.py +1 -1
- oldaplib/src/oldaplist.py +2 -2
- oldaplib/src/oldaplistnode.py +2 -2
- oldaplib/src/permissionset.py +3 -3
- oldaplib/src/project.py +47 -113
- oldaplib/src/propertyclass.py +64 -24
- oldaplib/src/resourceclass.py +8 -6
- oldaplib/src/version.py +1 -1
- oldaplib/src/xsd/iri.py +3 -0
- oldaplib/src/xsd/xsd_anyuri.py +5 -5
- oldaplib/src/xsd/xsd_qname.py +5 -2
- oldaplib/test/test_context.py +0 -4
- oldaplib/test/test_datamodel.py +50 -1
- oldaplib/test/test_dtypes.py +3 -2
- oldaplib/test/test_externalontologies.py +175 -0
- oldaplib/test/test_project.py +31 -76
- oldaplib/test/test_propertyclass.py +93 -6
- oldaplib/test/test_resourceclass.py +10 -10
- oldaplib/testdata/connection_test.trig +29 -12
- oldaplib/testdata/datamodel_test.trig +1 -1
- oldaplib/testdata/objectfactory_test.trig +2 -1
- {oldaplib-0.3.2.dist-info → oldaplib-0.3.4.dist-info}/METADATA +1 -1
- {oldaplib-0.3.2.dist-info → oldaplib-0.3.4.dist-info}/RECORD +41 -38
- {oldaplib-0.3.2.dist-info → oldaplib-0.3.4.dist-info}/WHEEL +0 -0
oldaplib/test/test_datamodel.py
CHANGED
|
@@ -9,6 +9,7 @@ from oldaplib.src.cachesingleton import CacheSingletonRedis
|
|
|
9
9
|
from oldaplib.src.connection import Connection
|
|
10
10
|
from oldaplib.src.datamodel import DataModel, PropertyClassChange, ResourceClassChange
|
|
11
11
|
from oldaplib.src.dtypes.languagein import LanguageIn
|
|
12
|
+
from oldaplib.src.externalontology import ExternalOntology
|
|
12
13
|
from oldaplib.src.helpers.context import Context
|
|
13
14
|
from oldaplib.src.enums.action import Action
|
|
14
15
|
from oldaplib.src.dtypes.namespaceiri import NamespaceIRI
|
|
@@ -371,7 +372,8 @@ class TestDataModel(unittest.TestCase):
|
|
|
371
372
|
model = DataModel.read(self._connection, self._sysproject, ignore_cache=True)
|
|
372
373
|
self.assertEqual(set(model.get_propclasses()), {
|
|
373
374
|
Xsd_QName("oldap:hasAdminPermission"),
|
|
374
|
-
Xsd_QName("oldap:statementProperty")
|
|
375
|
+
Xsd_QName("oldap:statementProperty"),
|
|
376
|
+
Xsd_QName("oldap:namespaceIri")
|
|
375
377
|
})
|
|
376
378
|
self.assertEqual(set(model.get_resclasses()), {
|
|
377
379
|
Xsd_QName("oldap:Project"),
|
|
@@ -389,6 +391,19 @@ class TestDataModel(unittest.TestCase):
|
|
|
389
391
|
def test_datamodel_read_shared(self):
|
|
390
392
|
model = DataModel.read(self._connection, self._sharedproject, ignore_cache=True)
|
|
391
393
|
|
|
394
|
+
def test_datamodel_read_system(self):
|
|
395
|
+
model = DataModel.read(self._connection, self._sysproject, ignore_cache=True)
|
|
396
|
+
|
|
397
|
+
def test_datamodel_read_test(self):
|
|
398
|
+
model = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
399
|
+
ontos = model.get_extontos()
|
|
400
|
+
crm = model[Xsd_QName('test:crm')]
|
|
401
|
+
self.assertEqual(crm.prefix, 'crm')
|
|
402
|
+
self.assertEqual(crm.namespaceIri, 'http://www.cidoc-crm.org/cidoc-crm/')
|
|
403
|
+
context = model.context
|
|
404
|
+
self.assertEqual(context['crm'], 'http://www.cidoc-crm.org/cidoc-crm/')
|
|
405
|
+
|
|
406
|
+
|
|
392
407
|
def test_datamodel_cache(self):
|
|
393
408
|
start = time()
|
|
394
409
|
model = DataModel.read(self._connection, self._sysproject, ignore_cache=True)
|
|
@@ -488,6 +503,7 @@ class TestDataModel(unittest.TestCase):
|
|
|
488
503
|
#
|
|
489
504
|
dm[Xsd_QName(f'{dm_name}:Book')][Xsd_QName(f'{dm_name}:authors')].prop.name[Language.FR] = "Ecrivain(s)"
|
|
490
505
|
|
|
506
|
+
|
|
491
507
|
#
|
|
492
508
|
# Add a new property as internal property
|
|
493
509
|
#
|
|
@@ -584,6 +600,39 @@ class TestDataModel(unittest.TestCase):
|
|
|
584
600
|
tmp = set([key for key, val in dm[Xsd_QName(f'{dm_name}:Book')].superclass.items()])
|
|
585
601
|
assert tmp == {'oldap:Thing', 'dcterms:Event'}
|
|
586
602
|
|
|
603
|
+
def test_datamodel_extonto_motify(self):
|
|
604
|
+
model = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
605
|
+
model[Xsd_QName('test:crm')].label['it'] = 'CIDOC-CRM (it)'
|
|
606
|
+
model.update()
|
|
607
|
+
model = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
608
|
+
|
|
609
|
+
crm = model[Xsd_QName('test:crm')]
|
|
610
|
+
self.assertEqual(crm.prefix, 'crm')
|
|
611
|
+
self.assertEqual(crm.namespaceIri, 'http://www.cidoc-crm.org/cidoc-crm/')
|
|
612
|
+
self.assertEqual(crm.label, LangString("CIDOC-CRM@en", "CIDOC-CRM@de", "CIDOC-CRM@fr", "CIDOC-CRM (it)@it"))
|
|
613
|
+
|
|
614
|
+
def test_datamodel_extonto_delete(self):
|
|
615
|
+
model = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
616
|
+
self.assertIsInstance(model.get(Xsd_QName('test:edm')), ExternalOntology)
|
|
617
|
+
del model[Xsd_QName('test:edm')]
|
|
618
|
+
model.update()
|
|
619
|
+
model = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
620
|
+
self.assertIsNone(model.get(Xsd_QName('test:edm')))
|
|
621
|
+
|
|
622
|
+
def test_datamodel_extonto_add(self):
|
|
623
|
+
model = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
624
|
+
eo = ExternalOntology(con=self._connection,
|
|
625
|
+
projectShortName=self._project.projectShortName,
|
|
626
|
+
prefix='testonto',
|
|
627
|
+
namespaceIri='http://www.example.org/ns/testonto#',
|
|
628
|
+
label=LangString("Test ontology@en", "Test ontology@de"))
|
|
629
|
+
model[Xsd_QName('test:testonto')] = eo
|
|
630
|
+
model.update()
|
|
631
|
+
model = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
632
|
+
self.assertIsInstance(model.get(Xsd_QName('test:testonto')), ExternalOntology)
|
|
633
|
+
|
|
634
|
+
context = model.context
|
|
635
|
+
self.assertEqual(context['testonto'], 'http://www.example.org/ns/testonto#')
|
|
587
636
|
|
|
588
637
|
def test_incremental_generation(self):
|
|
589
638
|
dm = DataModel(con=self._connection,
|
oldaplib/test/test_dtypes.py
CHANGED
|
@@ -13,6 +13,7 @@ from oldaplib.src.helpers.numeric import Numeric
|
|
|
13
13
|
from oldaplib.src.helpers.oldaperror import OldapErrorValue, OldapErrorType
|
|
14
14
|
from oldaplib.src.helpers.query_processor import QueryProcessor
|
|
15
15
|
from oldaplib.src.helpers.serializer import serializer
|
|
16
|
+
from oldaplib.src.xsd.iri import Iri
|
|
16
17
|
from oldaplib.src.xsd.xsd import Xsd
|
|
17
18
|
from oldaplib.src.xsd.xsd_anyuri import Xsd_anyURI
|
|
18
19
|
from oldaplib.src.xsd.xsd_float import Xsd_float
|
|
@@ -93,7 +94,7 @@ class MyTestCase(unittest.TestCase):
|
|
|
93
94
|
ns1 = NamespaceIRI('http://www.org/test/')
|
|
94
95
|
self.assertEqual(str(ns1), 'http://www.org/test/')
|
|
95
96
|
self.assertEqual(repr(ns1), 'NamespaceIRI("http://www.org/test/")')
|
|
96
|
-
self.assertEqual(ns1.toRdf, '
|
|
97
|
+
self.assertEqual(ns1.toRdf, '<http://www.org/test/>')
|
|
97
98
|
self.assertEqual(ns1 + "gaga", Xsd_anyURI("http://www.org/test/gaga"))
|
|
98
99
|
|
|
99
100
|
ns2 = NamespaceIRI('http://www.org/test#')
|
|
@@ -106,7 +107,7 @@ class MyTestCase(unittest.TestCase):
|
|
|
106
107
|
|
|
107
108
|
self.create_triple("NamespaceIRI", ns1)
|
|
108
109
|
valx = self.get_triple("NamespaceIRI")
|
|
109
|
-
self.assertIsInstance(valx,
|
|
110
|
+
self.assertIsInstance(valx, Iri)
|
|
110
111
|
if isinstance(valx, Xsd_anyURI):
|
|
111
112
|
self.assertEqual(ns1, NamespaceIRI(valx))
|
|
112
113
|
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from time import sleep
|
|
4
|
+
from tkinter.font import names
|
|
5
|
+
|
|
6
|
+
from oldaplib.src.connection import Connection
|
|
7
|
+
from oldaplib.src.datamodel import DataModel
|
|
8
|
+
from oldaplib.src.dtypes.namespaceiri import NamespaceIRI
|
|
9
|
+
from oldaplib.src.enums.language import Language
|
|
10
|
+
from oldaplib.src.externalontology import ExternalOntology
|
|
11
|
+
from oldaplib.src.helpers.context import Context
|
|
12
|
+
from oldaplib.src.helpers.langstring import LangString
|
|
13
|
+
from oldaplib.src.helpers.oldaperror import OldapErrorNotFound, OldapError, OldapErrorImmutable
|
|
14
|
+
from oldaplib.src.project import Project
|
|
15
|
+
from oldaplib.src.xsd.iri import Iri
|
|
16
|
+
from oldaplib.src.xsd.xsd_qname import Xsd_QName
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def find_project_root(current_path):
|
|
20
|
+
# Climb up the directory hierarchy and check for a marker file
|
|
21
|
+
path = Path(current_path).absolute()
|
|
22
|
+
while not (path / 'pyproject.toml').exists():
|
|
23
|
+
if path.parent == path:
|
|
24
|
+
# Root of the filesystem, file not found
|
|
25
|
+
raise RuntimeError('Project root not found')
|
|
26
|
+
path = path.parent
|
|
27
|
+
return path
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class TestexternalOntologies(unittest.TestCase):
|
|
31
|
+
|
|
32
|
+
_connection: Connection
|
|
33
|
+
_unpriv: Connection
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def setUpClass(cls):
|
|
37
|
+
super().setUpClass()
|
|
38
|
+
project_root = find_project_root(__file__)
|
|
39
|
+
cls._context = Context(name="DEFAULT")
|
|
40
|
+
|
|
41
|
+
cls._connection = Connection(userId="rosenth",
|
|
42
|
+
credentials="RioGrande",
|
|
43
|
+
context_name="DEFAULT")
|
|
44
|
+
cls._unpriv = Connection(userId="fornaro",
|
|
45
|
+
credentials="RioGrande",
|
|
46
|
+
context_name="DEFAULT")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
cls._connection.clear_graph(Xsd_QName('oldap:admin'))
|
|
50
|
+
file = project_root / 'oldaplib' / 'ontologies' / 'admin.trig'
|
|
51
|
+
cls._connection.upload_turtle(file)
|
|
52
|
+
file = project_root / 'oldaplib' / 'ontologies' / 'admin-testing.trig'
|
|
53
|
+
cls._connection.upload_turtle(file)
|
|
54
|
+
sleep(1) # upload may take a while...
|
|
55
|
+
|
|
56
|
+
project = Project(con=cls._connection,
|
|
57
|
+
projectIri=Iri("http://extonto.test.org/test"),
|
|
58
|
+
projectShortName="testext",
|
|
59
|
+
namespaceIri=NamespaceIRI("http://extonto.test.org/test/ns/"))
|
|
60
|
+
project.create()
|
|
61
|
+
|
|
62
|
+
dm = DataModel(con=cls._connection, project=project)
|
|
63
|
+
dm.create()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def tearDownClass(cls):
|
|
68
|
+
cls._connection.clear_graph(Xsd_QName('testext:shacl'))
|
|
69
|
+
cls._connection.clear_graph(Xsd_QName('testext:onto'))
|
|
70
|
+
#cls._connection.upload_turtle("oldaplib/ontologies/admin.trig")
|
|
71
|
+
#sleep(1) # upload may take a while...
|
|
72
|
+
pass
|
|
73
|
+
|
|
74
|
+
def test_create(self):
|
|
75
|
+
p = Project.read(con=self._connection, projectIri_SName="testext", ignore_cache=True)
|
|
76
|
+
dm = DataModel.read(con=self._connection, project="testext", ignore_cache=True)
|
|
77
|
+
|
|
78
|
+
eo1 = ExternalOntology(con=self._connection,
|
|
79
|
+
projectShortName="testext",
|
|
80
|
+
prefix="gagaA",
|
|
81
|
+
label=LangString("GAGA A ontology@en", "Gaga A Ontologie@de"),
|
|
82
|
+
namespaceIri=NamespaceIRI("http://gaga.org/ns/gagaA/"))
|
|
83
|
+
eo1.create()
|
|
84
|
+
del eo1
|
|
85
|
+
|
|
86
|
+
eo1 = ExternalOntology.read(con=self._connection, projectShortName="testext", prefix="gagaA", ignore_cache=True)
|
|
87
|
+
self.assertEqual(eo1.prefix, "gagaA")
|
|
88
|
+
self.assertEqual(eo1.label, LangString("GAGA A ontology@en", "Gaga A Ontologie@de"))
|
|
89
|
+
self.assertEqual(eo1.namespaceIri, NamespaceIRI("http://gaga.org/ns/gagaA/"))
|
|
90
|
+
|
|
91
|
+
ExternalOntology.delete_all(con=self._connection, projectShortName="testext")
|
|
92
|
+
pass
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_update(self):
|
|
96
|
+
p = Project.read(con=self._connection, projectIri_SName="testext", ignore_cache=True)
|
|
97
|
+
dm = DataModel.read(con=self._connection, project="testext", ignore_cache=True)
|
|
98
|
+
|
|
99
|
+
eo1 = ExternalOntology(con=self._connection,
|
|
100
|
+
projectShortName="testext",
|
|
101
|
+
prefix="gagaB",
|
|
102
|
+
label=LangString("GAGA B ontology@en", "Gaga B Ontologie@de"),
|
|
103
|
+
namespaceIri=NamespaceIRI("http://gaga.org/ns/gagaB/"))
|
|
104
|
+
eo1.create()
|
|
105
|
+
|
|
106
|
+
del eo1
|
|
107
|
+
eo1 = ExternalOntology.read(con=self._connection, projectShortName="testext", prefix="gagaB", ignore_cache=True)
|
|
108
|
+
eo1.prefix = "gugus"
|
|
109
|
+
eo1.comment = LangString("Gugus comment@en", "Gugus Kommentar@de")
|
|
110
|
+
del eo1.label[Language.DE]
|
|
111
|
+
eo1.label[Language.FR] = "GAGA B ontologie"
|
|
112
|
+
eo1.update()
|
|
113
|
+
|
|
114
|
+
del eo1
|
|
115
|
+
eo1 = ExternalOntology.read(con=self._connection, projectShortName="testext", prefix="gagaB", ignore_cache=True)
|
|
116
|
+
self.assertEqual(eo1.prefix, "gugus")
|
|
117
|
+
self.assertEqual(eo1.label, LangString("GAGA B ontology@en", "GAGA B ontologie@fr"))
|
|
118
|
+
self.assertEqual(eo1.comment, LangString("Gugus comment@en", "Gugus Kommentar@de"))
|
|
119
|
+
self.assertEqual(eo1.namespaceIri, NamespaceIRI("http://gaga.org/ns/gagaB/"))
|
|
120
|
+
|
|
121
|
+
with self.assertRaises(OldapErrorImmutable):
|
|
122
|
+
eo1.namespaceIri = NamespaceIRI("http://gaga.org/ns/gaga2/new/")
|
|
123
|
+
|
|
124
|
+
ExternalOntology.delete_all(con=self._connection, projectShortName="testext")
|
|
125
|
+
|
|
126
|
+
def test_search(self):
|
|
127
|
+
p = Project.read(con=self._connection, projectIri_SName="testext", ignore_cache=True)
|
|
128
|
+
dm = DataModel.read(con=self._connection, project="testext", ignore_cache=True)
|
|
129
|
+
|
|
130
|
+
eo1 = ExternalOntology(con=self._connection,
|
|
131
|
+
projectShortName="testext",
|
|
132
|
+
prefix="gagaC",
|
|
133
|
+
label=LangString("GAGA C ontology@en", "Gaga C Ontologie@de"),
|
|
134
|
+
namespaceIri=NamespaceIRI("http://gaga.org/ns/gagaC/"))
|
|
135
|
+
eo1.create()
|
|
136
|
+
|
|
137
|
+
eo2 = ExternalOntology(con=self._connection,
|
|
138
|
+
projectShortName="testext",
|
|
139
|
+
prefix="gagaD",
|
|
140
|
+
label=LangString("GAGA D ontology@en", "Gaga D Ontologie@de"),
|
|
141
|
+
namespaceIri=NamespaceIRI("http://gaga.org/ns/gagaD/"))
|
|
142
|
+
eo2.create()
|
|
143
|
+
|
|
144
|
+
res = ExternalOntology.search(con=self._connection, projectShortName="testext")
|
|
145
|
+
qnames = [x.extonto_qname for x in res]
|
|
146
|
+
self.assertEqual(set(qnames), {Xsd_QName('testext:gagaC'), Xsd_QName('testext:gagaD')})
|
|
147
|
+
|
|
148
|
+
ExternalOntology.delete_all(con=self._connection, projectShortName="testext")
|
|
149
|
+
|
|
150
|
+
def test_delete(self):
|
|
151
|
+
p = Project.read(con=self._connection, projectIri_SName="testext", ignore_cache=True)
|
|
152
|
+
dm = DataModel.read(con=self._connection, project="testext", ignore_cache=True)
|
|
153
|
+
|
|
154
|
+
eo1 = ExternalOntology(con=self._connection,
|
|
155
|
+
projectShortName="testext",
|
|
156
|
+
prefix="gagaE",
|
|
157
|
+
label=LangString("GAGA E ontology@en", "Gaga E Ontologie@de"),
|
|
158
|
+
namespaceIri=NamespaceIRI("http://gaga.org/ns/gagaE/"))
|
|
159
|
+
eo1.create()
|
|
160
|
+
|
|
161
|
+
eo2 = ExternalOntology(con=self._connection,
|
|
162
|
+
projectShortName="testext",
|
|
163
|
+
prefix="gagaF",
|
|
164
|
+
label=LangString("GAGA F ontology@en", "Gaga F Ontologie@de"),
|
|
165
|
+
namespaceIri=NamespaceIRI("http://gaga.org/ns/gagaF/"))
|
|
166
|
+
eo2.create()
|
|
167
|
+
res = ExternalOntology.search(con=self._connection, projectShortName="testext", prefix="gagaF")
|
|
168
|
+
self.assertEqual(len(res), 1)
|
|
169
|
+
res[0].delete()
|
|
170
|
+
|
|
171
|
+
ExternalOntology.delete_all(con=self._connection, projectShortName="testext")
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
oldaplib/test/test_project.py
CHANGED
|
@@ -16,7 +16,8 @@ from oldaplib.src.xsd.xsd_qname import Xsd_QName
|
|
|
16
16
|
from oldaplib.src.xsd.xsd_ncname import Xsd_NCName
|
|
17
17
|
from oldaplib.src.xsd.xsd_date import Xsd_date
|
|
18
18
|
from oldaplib.src.helpers.langstring import LangString
|
|
19
|
-
from oldaplib.src.helpers.oldaperror import OldapErrorNotFound, OldapErrorInconsistency, OldapErrorNoPermission
|
|
19
|
+
from oldaplib.src.helpers.oldaperror import OldapErrorNotFound, OldapErrorInconsistency, OldapErrorNoPermission, \
|
|
20
|
+
OldapErrorAlreadyExists
|
|
20
21
|
from oldaplib.src.project import Project, ProjectSearchResult
|
|
21
22
|
from oldaplib.src.helpers.serializer import serializer
|
|
22
23
|
|
|
@@ -90,6 +91,9 @@ class Testproject(unittest.TestCase):
|
|
|
90
91
|
self.assertEqual(project.projectEnd, project2.projectEnd)
|
|
91
92
|
|
|
92
93
|
|
|
94
|
+
def test_project_read_with_uses_ontologies(self):
|
|
95
|
+
project = Project.read(con=self._connection, projectIri_SName="hyha", ignore_cache=True)
|
|
96
|
+
|
|
93
97
|
# @unittest.skip('Work in progress')
|
|
94
98
|
def test_project_read(self):
|
|
95
99
|
project = Project.read(con=self._connection, projectIri_SName=Iri("oldap:SystemProject"), ignore_cache=True)
|
|
@@ -260,83 +264,33 @@ class Testproject(unittest.TestCase):
|
|
|
260
264
|
project = Project.read(con=self._connection, projectIri_SName="unittest6", ignore_cache=True)
|
|
261
265
|
project.delete()
|
|
262
266
|
|
|
263
|
-
def
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
project.create()
|
|
276
|
-
project = Project.read(con=self._connection, projectIri_SName="WithExternalOntologiesA", ignore_cache=True)
|
|
277
|
-
self.assertEqual(project.usesExternalOntology, {
|
|
278
|
-
Xsd_NCName("prefix1"): NamespaceIRI("http://prefix1.org/"),
|
|
279
|
-
Xsd_NCName("prefix2"): NamespaceIRI("http://prefix2.org/")
|
|
280
|
-
})
|
|
267
|
+
def test_duplicate_project_create(self):
|
|
268
|
+
project1 = Project(con=self._connection,
|
|
269
|
+
projectShortName="unittestXX",
|
|
270
|
+
namespaceIri=NamespaceIRI("http://unitest.org/project/unittestXX#"),
|
|
271
|
+
label=LangString(["unittestXX@en", "unittestXX@de"]))
|
|
272
|
+
project1.create()
|
|
273
|
+
project2 = Project(con=self._connection,
|
|
274
|
+
projectShortName="unittestXX",
|
|
275
|
+
namespaceIri=NamespaceIRI("http://unitest.org/project/unittestYY#"),
|
|
276
|
+
label=LangString(["unittestXX@en", "unittestXX@de"]))
|
|
277
|
+
with self.assertRaises(OldapErrorAlreadyExists) as ex:
|
|
278
|
+
project2.create()
|
|
281
279
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
projectStart=Xsd_date(2024, 3, 3),
|
|
289
|
-
projectEnd=Xsd_date(2027, 3, 2),
|
|
290
|
-
usesExternalOntology={
|
|
291
|
-
Xsd_NCName("prefix1"): NamespaceIRI("http://prefix1.org/"),
|
|
292
|
-
Xsd_NCName("prefix2"): NamespaceIRI("http://prefix2.org/")
|
|
293
|
-
})
|
|
294
|
-
project.create()
|
|
295
|
-
project = Project.read(con=self._connection, projectIri_SName="WithExternalOntologiesB", ignore_cache=True)
|
|
296
|
-
del project.usesExternalOntology
|
|
297
|
-
project.update()
|
|
298
|
-
project = Project.read(con=self._connection, projectIri_SName="WithExternalOntologiesB", ignore_cache=True)
|
|
299
|
-
self.assertIsNone(project.usesExternalOntology)
|
|
300
|
-
|
|
301
|
-
def test_project_create_with_external_ontologies_C(self):
|
|
302
|
-
project = Project(con=self._connection,
|
|
303
|
-
projectShortName="WithExternalOntologiesC",
|
|
304
|
-
label=LangString("External Ontologies"),
|
|
305
|
-
namespaceIri=NamespaceIRI("http://unitest.org/project/unittestXX#"),
|
|
306
|
-
comment=LangString(["For testingXX@en", "Für TestsXX@de"]),
|
|
307
|
-
projectStart=Xsd_date(2024, 3, 3),
|
|
308
|
-
projectEnd=Xsd_date(2027, 3, 2))
|
|
309
|
-
project.create()
|
|
310
|
-
project = Project.read(con=self._connection, projectIri_SName="WithExternalOntologiesC", ignore_cache=True)
|
|
311
|
-
project.usesExternalOntology = {Xsd_NCName('prefix') : NamespaceIRI('http://prefix.org/')}
|
|
312
|
-
project.update()
|
|
313
|
-
project = Project.read(con=self._connection, projectIri_SName="WithExternalOntologiesC", ignore_cache=True)
|
|
314
|
-
self.assertEqual(project.usesExternalOntology, {Xsd_NCName('prefix') : NamespaceIRI('http://prefix.org/')})
|
|
315
|
-
|
|
316
|
-
def test_project_create_with_external_ontologies_D(self):
|
|
317
|
-
project = Project(con=self._connection,
|
|
318
|
-
projectShortName="WithExternalOntologiesD",
|
|
319
|
-
label=LangString("External Ontologies"),
|
|
320
|
-
namespaceIri=NamespaceIRI("http://unitest.org/project/unittestXX#"),
|
|
321
|
-
comment=LangString(["For testingXX@en", "Für TestsXX@de"]),
|
|
322
|
-
projectStart=Xsd_date(2024, 3, 3),
|
|
323
|
-
projectEnd=Xsd_date(2027, 3, 2),
|
|
324
|
-
usesExternalOntology={
|
|
325
|
-
Xsd_NCName("prefix1"): NamespaceIRI("http://prefix1.org/"),
|
|
326
|
-
Xsd_NCName("prefix2"): NamespaceIRI("http://prefix2.org/")
|
|
327
|
-
})
|
|
328
|
-
project.create()
|
|
329
|
-
project = Project.read(con=self._connection, projectIri_SName="WithExternalOntologiesD", ignore_cache=True)
|
|
330
|
-
del project.usesExternalOntology['prefix1']
|
|
331
|
-
project.usesExternalOntology[Xsd_NCName('prefix2')] = NamespaceIRI("http://prefix2.org/CHANGED/")
|
|
332
|
-
project.usesExternalOntology[Xsd_NCName('prefix3')] = NamespaceIRI("http://prefix3.org/")
|
|
333
|
-
project.update()
|
|
334
|
-
project = Project.read(con=self._connection, projectIri_SName="WithExternalOntologiesD", ignore_cache=True)
|
|
335
|
-
self.assertEqual(project.usesExternalOntology, {
|
|
336
|
-
Xsd_NCName("prefix2"): NamespaceIRI("http://prefix2.org/CHANGED/"),
|
|
337
|
-
Xsd_NCName("prefix3"): NamespaceIRI("http://prefix3.org/")
|
|
338
|
-
})
|
|
280
|
+
project3 = Project(con=self._connection,
|
|
281
|
+
projectShortName="unittestYY",
|
|
282
|
+
namespaceIri=NamespaceIRI("http://unitest.org/project/unittestXX#"),
|
|
283
|
+
label=LangString(["unittestXX@en", "unittestXX@de"]))
|
|
284
|
+
with self.assertRaises(OldapErrorAlreadyExists) as ex:
|
|
285
|
+
project3.create()
|
|
339
286
|
|
|
287
|
+
project4 = Project(con=self._connection,
|
|
288
|
+
projectIri=project1.projectIri,
|
|
289
|
+
projectShortName="unittestZZ",
|
|
290
|
+
namespaceIri=NamespaceIRI("http://unitest.org/project/unittestZZ#"),
|
|
291
|
+
label=LangString(["unittestZZ@en", "unittestZZ@de"]))
|
|
292
|
+
with self.assertRaises(OldapErrorAlreadyExists) as ex:
|
|
293
|
+
project4.create()
|
|
340
294
|
|
|
341
295
|
def test_project_create_without_label_comment(self):
|
|
342
296
|
project = Project(con=self._connection,
|
|
@@ -352,6 +306,7 @@ class Testproject(unittest.TestCase):
|
|
|
352
306
|
project = Project.read(con=self._connection, projectIri_SName="emptyfieldsXX", ignore_cache=True)
|
|
353
307
|
project.delete()
|
|
354
308
|
|
|
309
|
+
|
|
355
310
|
def test_project_create_empty_fields(self):
|
|
356
311
|
project = Project(con=self._connection,
|
|
357
312
|
projectShortName="emptyfields1",
|
|
@@ -16,6 +16,7 @@ from oldaplib.src.enums.propertyclassattr import PropClassAttr
|
|
|
16
16
|
from oldaplib.src.enums.xsd_datatypes import XsdDatatypes
|
|
17
17
|
from oldaplib.src.helpers.context import Context
|
|
18
18
|
from oldaplib.src.helpers.langstring import LangString, LangStringChange
|
|
19
|
+
from oldaplib.src.helpers.observable_set import ObservableSet
|
|
19
20
|
from oldaplib.src.helpers.oldaperror import OldapErrorAlreadyExists, OldapErrorValue, OldapErrorNoPermission, \
|
|
20
21
|
OldapErrorInconsistency
|
|
21
22
|
from oldaplib.src.helpers.query_processor import QueryProcessor
|
|
@@ -70,6 +71,8 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
70
71
|
cls._connection.upload_turtle(file)
|
|
71
72
|
sleep(1) # upload may take a while...
|
|
72
73
|
cls._project = Project.read(cls._connection, "test")
|
|
74
|
+
cls._sysproject = Project.read(cls._connection, "oldap")
|
|
75
|
+
|
|
73
76
|
|
|
74
77
|
@classmethod
|
|
75
78
|
def tearDownClass(cls):
|
|
@@ -90,6 +93,7 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
90
93
|
self.assertEqual(p.get(PropClassAttr.DATATYPE), XsdDatatypes.string)
|
|
91
94
|
self.assertEqual(p.get(PropClassAttr.NAME), LangString(["Test property@en", "Testprädikat@de"]))
|
|
92
95
|
self.assertEqual(p.get(PropClassAttr.DESCRIPTION), LangString("A property for testing...@en", "Property für Tests@de"))
|
|
96
|
+
self.assertEqual(p.get(PropClassAttr.TYPE), {OwlPropertyType.OwlDataProperty})
|
|
93
97
|
|
|
94
98
|
def test_star_propertyclass_constructor(self):
|
|
95
99
|
p = PropertyClass(con=self._connection,
|
|
@@ -104,6 +108,7 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
104
108
|
self.assertEqual(p.get(PropClassAttr.DATATYPE), XsdDatatypes.string)
|
|
105
109
|
self.assertEqual(p.get(PropClassAttr.NAME), LangString(["Test property@en", "Testprädikat@de"]))
|
|
106
110
|
self.assertEqual(p.get(PropClassAttr.DESCRIPTION), LangString("A property for testing...@en", "Property für Tests@de"))
|
|
111
|
+
self.assertEqual(p[PropClassAttr.TYPE], {OwlPropertyType.StatementProperty, OwlPropertyType.OwlDataProperty})
|
|
107
112
|
|
|
108
113
|
def test_propertyclass_inset_datatypes(self):
|
|
109
114
|
p = PropertyClass(con=self._connection,
|
|
@@ -166,6 +171,7 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
166
171
|
project=self._project,
|
|
167
172
|
toClass=Xsd_QName('test:Person'))
|
|
168
173
|
self.assertEqual(p2.get(PropClassAttr.CLASS), Xsd_QName('test:Person'))
|
|
174
|
+
self.assertEqual(p2.get(PropClassAttr.TYPE), {OwlPropertyType.OwlObjectProperty})
|
|
169
175
|
|
|
170
176
|
def test_propertyclass_toclass_constructor_invalid_A(self):
|
|
171
177
|
with self.assertRaises(OldapErrorValue):
|
|
@@ -212,6 +218,24 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
212
218
|
self.assertEqual(p4a.get(PropClassAttr.LANGUAGE_IN), LanguageIn(Language.EN, Language.FR))
|
|
213
219
|
self.assertEqual(p4a.get(PropClassAttr.DATATYPE), XsdDatatypes.langString)
|
|
214
220
|
|
|
221
|
+
def test_propertyclass_owltype_constructor(self):
|
|
222
|
+
p4 = PropertyClass(con=self._connection,
|
|
223
|
+
project=self._project,
|
|
224
|
+
property_class_iri=Xsd_QName('test:testprop4c'),
|
|
225
|
+
type={OwlPropertyType.SymmetricProperty},
|
|
226
|
+
datatype=XsdDatatypes.string)
|
|
227
|
+
p4.create()
|
|
228
|
+
self.assertEqual(p4.get(PropClassAttr.TYPE), {OwlPropertyType.SymmetricProperty, OwlPropertyType.OwlDataProperty})
|
|
229
|
+
p4 = PropertyClass.read(con=self._connection,
|
|
230
|
+
project=self._project,
|
|
231
|
+
property_class_iri=Xsd_QName('test:testprop4c'),
|
|
232
|
+
ignore_cache=True)
|
|
233
|
+
self.assertEqual(p4.get(PropClassAttr.TYPE), {OwlPropertyType.SymmetricProperty, OwlPropertyType.OwlDataProperty})
|
|
234
|
+
|
|
235
|
+
p4.type.add(OwlPropertyType.TransitiveProperty)
|
|
236
|
+
p4.update()
|
|
237
|
+
self.assertEqual(p4.get(PropClassAttr.TYPE), {OwlPropertyType.SymmetricProperty, OwlPropertyType.TransitiveProperty, OwlPropertyType.OwlDataProperty})
|
|
238
|
+
|
|
215
239
|
def test_propertyclass_inconsistent_constructor(self):
|
|
216
240
|
with self.assertRaises(OldapErrorValue):
|
|
217
241
|
p5 = PropertyClass(con=self._connection,
|
|
@@ -238,6 +262,12 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
238
262
|
self.assertEqual(p6.get(PropClassAttr.DATATYPE), XsdDatatypes.langString)
|
|
239
263
|
|
|
240
264
|
|
|
265
|
+
def test_propertyclass_read_projectshape(self):
|
|
266
|
+
p = PropertyClass.read(con=self._connection,
|
|
267
|
+
project=self._sysproject,
|
|
268
|
+
property_class_iri=Xsd_QName('oldap:namespaceIri'),
|
|
269
|
+
ignore_cache=True)
|
|
270
|
+
|
|
241
271
|
# @unittest.skip('Work in progress')
|
|
242
272
|
def test_propertyclass_read_shacl(self):
|
|
243
273
|
p1 = PropertyClass.read(con=self._connection,
|
|
@@ -255,8 +285,8 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
255
285
|
self.assertEqual(p1.description, LangString("This is a test property@de"))
|
|
256
286
|
self.assertIsNone(p1.get(PropClassAttr.SUBPROPERTY_OF))
|
|
257
287
|
self.assertIsNone(p1.subPropertyOf)
|
|
258
|
-
self.assertEqual(p1.get(PropClassAttr.TYPE), OwlPropertyType.OwlDataProperty)
|
|
259
|
-
self.assertEqual(p1.type, OwlPropertyType.OwlDataProperty)
|
|
288
|
+
self.assertEqual(p1.get(PropClassAttr.TYPE), {OwlPropertyType.OwlDataProperty})
|
|
289
|
+
self.assertEqual(p1.type, {OwlPropertyType.OwlDataProperty})
|
|
260
290
|
self.assertEqual(p1.creator, Iri('https://orcid.org/0000-0003-1681-4036'))
|
|
261
291
|
self.assertEqual(p1.created, Xsd_dateTime("2023-11-04T12:00:00Z"))
|
|
262
292
|
|
|
@@ -268,7 +298,7 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
268
298
|
self.assertEqual(p2[PropClassAttr.NAME], LangString("Test"))
|
|
269
299
|
self.assertEqual(p2[PropClassAttr.DESCRIPTION], LangString("Property shape for testing purposes"))
|
|
270
300
|
self.assertEqual(p2[PropClassAttr.DATATYPE], XsdDatatypes.string)
|
|
271
|
-
self.assertEqual(p2[PropClassAttr.TYPE], OwlPropertyType.OwlDataProperty)
|
|
301
|
+
self.assertEqual(p2[PropClassAttr.TYPE], {OwlPropertyType.OwlDataProperty})
|
|
272
302
|
|
|
273
303
|
p3 = PropertyClass.read(con=self._connection,
|
|
274
304
|
project=self._project,
|
|
@@ -342,14 +372,20 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
342
372
|
def test_propertyclass_create_D(self):
|
|
343
373
|
pX = PropertyClass(
|
|
344
374
|
con=self._connection,
|
|
345
|
-
#graph=Xsd_NCName('test'),
|
|
346
375
|
project=self._project,
|
|
347
|
-
property_class_iri=Xsd_QName('test:
|
|
376
|
+
property_class_iri=Xsd_QName('test:testWriteABC'),
|
|
377
|
+
datatype=XsdDatatypes.int
|
|
378
|
+
)
|
|
379
|
+
pX.create()
|
|
380
|
+
pX = PropertyClass(
|
|
381
|
+
con=self._connection,
|
|
382
|
+
project=self._project,
|
|
383
|
+
property_class_iri=Xsd_QName('test:testWriteABC'),
|
|
348
384
|
datatype=XsdDatatypes.int
|
|
349
385
|
)
|
|
350
386
|
with self.assertRaises(OldapErrorAlreadyExists) as ex:
|
|
351
387
|
pX.create()
|
|
352
|
-
self.assertEqual(str(ex.exception), 'Property "test:
|
|
388
|
+
self.assertEqual(str(ex.exception), 'Property "test:testWriteABC" already exists.')
|
|
353
389
|
|
|
354
390
|
def test_propertyclass_create_E(self):
|
|
355
391
|
p = PropertyClass(
|
|
@@ -367,6 +403,19 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
367
403
|
self.assertTrue(p.statementProperty)
|
|
368
404
|
self.assertEqual(p.get(PropClassAttr.DATATYPE), XsdDatatypes.string)
|
|
369
405
|
|
|
406
|
+
def test_propertyclass_create_F(self):
|
|
407
|
+
p4 = PropertyClass(con=self._connection,
|
|
408
|
+
project=self._project,
|
|
409
|
+
property_class_iri=Xsd_QName('test:testpropF'),
|
|
410
|
+
type={OwlPropertyType.SymmetricProperty},
|
|
411
|
+
datatype=XsdDatatypes.string)
|
|
412
|
+
p4.create()
|
|
413
|
+
p4 = PropertyClass.read(con=self._connection,
|
|
414
|
+
project=self._project,
|
|
415
|
+
property_class_iri=Xsd_QName('test:testpropF'),
|
|
416
|
+
ignore_cache=True)
|
|
417
|
+
self.assertEqual(p4.get(PropClassAttr.TYPE), {OwlPropertyType.SymmetricProperty, OwlPropertyType.OwlDataProperty})
|
|
418
|
+
|
|
370
419
|
def test_propertyclass_create_nopermission(self):
|
|
371
420
|
p1 = PropertyClass(
|
|
372
421
|
con=self._unpriv,
|
|
@@ -763,6 +812,44 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
763
812
|
for r in res:
|
|
764
813
|
self.assertIn(r['comment'], [Xsd_string("description english@en"), Xsd_string("description français@fr")])
|
|
765
814
|
|
|
815
|
+
def test_propertyclass_update7(self):
|
|
816
|
+
p7 = PropertyClass(con=self._connection,
|
|
817
|
+
project=self._project,
|
|
818
|
+
property_class_iri=Xsd_QName('test:testprop7'),
|
|
819
|
+
type={OwlPropertyType.SymmetricProperty},
|
|
820
|
+
datatype=XsdDatatypes.string)
|
|
821
|
+
p7.create()
|
|
822
|
+
p7 = PropertyClass.read(con=self._connection,
|
|
823
|
+
project=self._project,
|
|
824
|
+
property_class_iri=Xsd_QName('test:testprop7'),
|
|
825
|
+
ignore_cache=True)
|
|
826
|
+
p7.type.add(OwlPropertyType.TransitiveProperty)
|
|
827
|
+
p7.update()
|
|
828
|
+
p7 = PropertyClass.read(con=self._connection,
|
|
829
|
+
project=self._project,
|
|
830
|
+
property_class_iri=Xsd_QName('test:testprop7'),
|
|
831
|
+
ignore_cache=True)
|
|
832
|
+
self.assertEqual(p7.get(PropClassAttr.TYPE), {OwlPropertyType.SymmetricProperty, OwlPropertyType.TransitiveProperty, OwlPropertyType.OwlDataProperty})
|
|
833
|
+
|
|
834
|
+
def test_propertyclass_update8(self):
|
|
835
|
+
p8 = PropertyClass(con=self._connection,
|
|
836
|
+
project=self._project,
|
|
837
|
+
property_class_iri=Xsd_QName('test:testprop8'),
|
|
838
|
+
type={OwlPropertyType.SymmetricProperty, OwlPropertyType.TransitiveProperty},
|
|
839
|
+
datatype=XsdDatatypes.string)
|
|
840
|
+
p8.create()
|
|
841
|
+
p8 = PropertyClass.read(con=self._connection,
|
|
842
|
+
project=self._project,
|
|
843
|
+
property_class_iri=Xsd_QName('test:testprop8'),
|
|
844
|
+
ignore_cache=True)
|
|
845
|
+
p8.type.remove(OwlPropertyType.TransitiveProperty)
|
|
846
|
+
p8.update()
|
|
847
|
+
p8 = PropertyClass.read(con=self._connection,
|
|
848
|
+
project=self._project,
|
|
849
|
+
property_class_iri=Xsd_QName('test:testprop8'),
|
|
850
|
+
ignore_cache=True)
|
|
851
|
+
self.assertEqual(p8.get(PropClassAttr.TYPE), {OwlPropertyType.SymmetricProperty, OwlPropertyType.OwlDataProperty})
|
|
852
|
+
|
|
766
853
|
# @unittest.skip('Work in progress')
|
|
767
854
|
def test_propertyclass_delete_attrs(self):
|
|
768
855
|
p1 = PropertyClass(
|