oldaplib 0.3.27__py3-none-any.whl → 0.3.29__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/shared.trig +122 -1
- oldaplib/src/connection.py +43 -71
- oldaplib/src/datamodel.py +49 -47
- oldaplib/src/helpers/context.py +3 -1
- oldaplib/src/objectfactory.py +145 -20
- oldaplib/src/oldaplist.py +2 -0
- oldaplib/src/oldaplist_helpers.py +1 -1
- oldaplib/src/permissionset.py +26 -10
- oldaplib/src/project.py +36 -20
- oldaplib/src/user.py +74 -26
- oldaplib/src/version.py +1 -1
- oldaplib/src/xsd/xsd_anyuri.py +4 -4
- oldaplib/test/XXX_test_fasnacht.py +17 -0
- oldaplib/test/test_connection.py +0 -1
- oldaplib/test/test_context.py +4 -2
- oldaplib/test/test_datamodel.py +2 -5
- oldaplib/test/test_externalontologies.py +0 -1
- oldaplib/test/test_hasproperty.py +0 -1
- oldaplib/test/test_objectfactory.py +62 -6
- oldaplib/test/test_oldaplist.py +1 -1
- oldaplib/test/test_oldaplist_helpers.py +1 -1
- oldaplib/test/test_oldaplistnode.py +0 -1
- oldaplib/test/test_permissionset.py +2 -1
- oldaplib/test/test_project.py +0 -1
- oldaplib/test/test_propertyclass.py +0 -1
- oldaplib/test/test_resourceclass.py +1 -1
- oldaplib/test/test_user.py +0 -1
- oldaplib/test/test_xsd_datatypes.py +1 -1
- oldaplib/testdata/instances_test.trig +14 -0
- {oldaplib-0.3.27.dist-info → oldaplib-0.3.29.dist-info}/METADATA +1 -1
- {oldaplib-0.3.27.dist-info → oldaplib-0.3.29.dist-info}/RECORD +32 -32
- oldaplib/apps/load_list.py +0 -45
- {oldaplib-0.3.27.dist-info → oldaplib-0.3.29.dist-info}/WHEEL +0 -0
|
@@ -150,7 +150,7 @@ def dump_list_to(con: IConnection,
|
|
|
150
150
|
make_dict(node, listdict[str(listnode.oldapListNodeId)]['nodes'])
|
|
151
151
|
|
|
152
152
|
#
|
|
153
|
-
# We need to get the OldapList IRI for
|
|
153
|
+
# We need to get the OldapList IRI for asking the cache...
|
|
154
154
|
#
|
|
155
155
|
if not isinstance(project, Project):
|
|
156
156
|
project = Project.read(con, project)
|
oldaplib/src/permissionset.py
CHANGED
|
@@ -190,6 +190,21 @@ class PermissionSet(Model):
|
|
|
190
190
|
def qname(self) -> Xsd_QName:
|
|
191
191
|
return self.__permset_iri
|
|
192
192
|
|
|
193
|
+
def trig_to_str(self, created: Xsd_dateTime, modified: Xsd_dateTime, indent: int = 0, indent_inc: int = 4):
|
|
194
|
+
blank = ''
|
|
195
|
+
sparql = ''
|
|
196
|
+
sparql += f'{blank:{indent * indent_inc}} {self.__permset_iri.toRdf} a oldap:PermissionSet'
|
|
197
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:creator {self._con.userIri.toRdf}'
|
|
198
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:created {created.toRdf}'
|
|
199
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:contributor {self._con.userIri.toRdf}'
|
|
200
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:modified {modified.toRdf}'
|
|
201
|
+
for attr, value in self._attributes.items():
|
|
202
|
+
if attr.value.prefix == 'virtual' or not value:
|
|
203
|
+
continue
|
|
204
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}{attr.value.toRdf} {value.toRdf}'
|
|
205
|
+
return sparql
|
|
206
|
+
|
|
207
|
+
|
|
193
208
|
def create(self, indent: int = 0, indent_inc: int = 4) -> None:
|
|
194
209
|
"""
|
|
195
210
|
Creates and stores a permission set in the triple store.
|
|
@@ -236,15 +251,16 @@ class PermissionSet(Model):
|
|
|
236
251
|
sparql += f'{blank:{indent * indent_inc}}INSERT DATA {{\n'
|
|
237
252
|
sparql += f'{blank:{(indent + 1) * indent_inc}}GRAPH oldap:admin {{\n'
|
|
238
253
|
|
|
239
|
-
sparql +=
|
|
240
|
-
sparql += f'
|
|
241
|
-
sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:
|
|
242
|
-
sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:
|
|
243
|
-
sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
254
|
+
sparql += self.trig_to_str(created=timestamp, modified=timestamp, indent=indent + 2, indent_inc=indent_inc)
|
|
255
|
+
# sparql += f'{blank:{(indent + 2) * indent_inc}} {self.__permset_iri.toRdf} a oldap:PermissionSet'
|
|
256
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:creator {self._con.userIri.toRdf}'
|
|
257
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:created {timestamp.toRdf}'
|
|
258
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:contributor {self._con.userIri.toRdf}'
|
|
259
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:modified {timestamp.toRdf}'
|
|
260
|
+
# for attr, value in self._attributes.items():
|
|
261
|
+
# if attr.value.prefix == 'virtual' or not value:
|
|
262
|
+
# continue
|
|
263
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}{attr.value.toRdf} {value.toRdf}'
|
|
248
264
|
sparql += f'\n{blank:{(indent + 1) * indent_inc}}}}\n'
|
|
249
265
|
sparql += f'{blank:{indent * indent_inc}}}}\n'
|
|
250
266
|
|
|
@@ -307,6 +323,7 @@ class PermissionSet(Model):
|
|
|
307
323
|
:raises OldapErrorInconsistency: Raised if the permission set contains inconsistencies
|
|
308
324
|
in its data during retrieval.
|
|
309
325
|
"""
|
|
326
|
+
context = Context(name=con.context_name)
|
|
310
327
|
if qname:
|
|
311
328
|
permset_iri = Xsd_QName(qname, validate=True)
|
|
312
329
|
elif permissionSetId and definedByProject:
|
|
@@ -325,7 +342,6 @@ class PermissionSet(Model):
|
|
|
325
342
|
if tmp is not None:
|
|
326
343
|
tmp.update_notifier()
|
|
327
344
|
return tmp
|
|
328
|
-
context = Context(name=con.context_name)
|
|
329
345
|
sparql = context.sparql_context
|
|
330
346
|
sparql += f"""
|
|
331
347
|
SELECT ?permset ?p ?o
|
oldaplib/src/project.py
CHANGED
|
@@ -426,6 +426,21 @@ class Project(Model):
|
|
|
426
426
|
projects.append(ProjectSearchResult(r['project'], r['shortname']))
|
|
427
427
|
return projects
|
|
428
428
|
|
|
429
|
+
|
|
430
|
+
def trig_to_str(self, created: Xsd_dateTime, modified: Xsd_dateTime,indent: int = 0, indent_inc: int = 4):
|
|
431
|
+
blank = ''
|
|
432
|
+
sparql = ''
|
|
433
|
+
sparql += f'\n{blank:{indent * indent_inc}}{self.projectIri.toRdf} a oldap:Project'
|
|
434
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:creator {self._con.userIri.toRdf}'
|
|
435
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:created {created.toRdf}'
|
|
436
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:contributor {self._con.userIri.toRdf}'
|
|
437
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:modified {modified.toRdf}'
|
|
438
|
+
for attr, value in self._attributes.items():
|
|
439
|
+
if not value:
|
|
440
|
+
continue
|
|
441
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}{attr.value.toRdf} {value.toRdf}'
|
|
442
|
+
return sparql
|
|
443
|
+
|
|
429
444
|
def create(self, indent: int = 0, indent_inc: int = 4) -> None:
|
|
430
445
|
"""
|
|
431
446
|
Creates a new project in the triple store. The function starts by
|
|
@@ -459,11 +474,14 @@ class Project(Model):
|
|
|
459
474
|
raise OldapErrorNoPermission(message)
|
|
460
475
|
|
|
461
476
|
timestamp = Xsd_dateTime.now()
|
|
462
|
-
indent: int = 0
|
|
463
|
-
indent_inc: int = 4
|
|
477
|
+
#indent: int = 0
|
|
478
|
+
#indent_inc: int = 4
|
|
464
479
|
|
|
465
480
|
context = Context(name=self._con.context_name)
|
|
466
481
|
|
|
482
|
+
#
|
|
483
|
+
# SPARQL to check if project with the given projectShortName already exists
|
|
484
|
+
#
|
|
467
485
|
sparql0 = context.sparql_context
|
|
468
486
|
sparql0 += f"""
|
|
469
487
|
ASK {{
|
|
@@ -475,15 +493,9 @@ class Project(Model):
|
|
|
475
493
|
}}
|
|
476
494
|
"""
|
|
477
495
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
FROM oldap:admin
|
|
482
|
-
WHERE {{
|
|
483
|
-
?project a oldap:Project .
|
|
484
|
-
FILTER(?project = {self.projectIri.toRdf})
|
|
485
|
-
}}
|
|
486
|
-
"""
|
|
496
|
+
#
|
|
497
|
+
# SPARQL to check if the given namespaceIri is already used by another project
|
|
498
|
+
#
|
|
487
499
|
sparql1a = context.sparql_context
|
|
488
500
|
sparql1a += f"""
|
|
489
501
|
ASK {{
|
|
@@ -493,6 +505,9 @@ class Project(Model):
|
|
|
493
505
|
}}
|
|
494
506
|
"""
|
|
495
507
|
|
|
508
|
+
#
|
|
509
|
+
# SPARQL to check if project with the given projectIri already exists
|
|
510
|
+
#
|
|
496
511
|
sparql1b = context.sparql_context
|
|
497
512
|
sparql1b += f"""
|
|
498
513
|
ASK {{
|
|
@@ -506,15 +521,16 @@ class Project(Model):
|
|
|
506
521
|
sparql2 = context.sparql_context
|
|
507
522
|
sparql2 += f'{blank:{indent * indent_inc}}INSERT DATA {{'
|
|
508
523
|
sparql2 += f'\n{blank:{(indent + 1) * indent_inc}}GRAPH oldap:admin {{'
|
|
509
|
-
sparql2 +=
|
|
510
|
-
sparql2 += f'
|
|
511
|
-
sparql2 += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:
|
|
512
|
-
sparql2 += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:
|
|
513
|
-
sparql2 += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
524
|
+
sparql2 += self.trig_to_str(created=timestamp, modified=timestamp, indent=indent + 2, indent_inc=indent_inc)
|
|
525
|
+
# sparql2 += f'\n{blank:{(indent + 2) * indent_inc}}{self.projectIri.toRdf} a oldap:Project'
|
|
526
|
+
# sparql2 += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:creator {self._con.userIri.toRdf}'
|
|
527
|
+
# sparql2 += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:created {timestamp.toRdf}'
|
|
528
|
+
# sparql2 += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:contributor {self._con.userIri.toRdf}'
|
|
529
|
+
# sparql2 += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:modified {timestamp.toRdf}'
|
|
530
|
+
# for attr, value in self._attributes.items():
|
|
531
|
+
# if not value:
|
|
532
|
+
# continue
|
|
533
|
+
# sparql2 += f' ;\n{blank:{(indent + 3) * indent_inc}}{attr.value.toRdf} {value.toRdf}'
|
|
518
534
|
sparql2 += f' .\n{blank:{(indent + 1) * indent_inc}}}}\n'
|
|
519
535
|
sparql2 += f'{blank:{indent * indent_inc}}}}\n'
|
|
520
536
|
|
oldaplib/src/user.py
CHANGED
|
@@ -363,7 +363,43 @@ class User(Model):
|
|
|
363
363
|
self._changeset[UserAttr.IN_PROJECT] = AttributeChange(self._attributes[UserAttr.IN_PROJECT], Action.MODIFY)
|
|
364
364
|
self._attributes[UserAttr.IN_PROJECT][project].remove(permission)
|
|
365
365
|
|
|
366
|
-
def
|
|
366
|
+
def trig_to_str(self,
|
|
367
|
+
creator: Iri,
|
|
368
|
+
created: Xsd_dateTime,
|
|
369
|
+
contributor: Iri,
|
|
370
|
+
modified: Xsd_dateTime,
|
|
371
|
+
indent: int = 0, indent_inc: int = 4):
|
|
372
|
+
blank = ''
|
|
373
|
+
sparql = ''
|
|
374
|
+
sparql += f'{blank:{indent * indent_inc}}{self.userIri.toRdf} a oldap:User'
|
|
375
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:creator {creator.toRdf}'
|
|
376
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:created {created.toRdf}'
|
|
377
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:contributor {contributor.toRdf}'
|
|
378
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:modified {modified.toRdf}'
|
|
379
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}oldap:userId {self.userId.toRdf}'
|
|
380
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}schema:familyName {self.familyName.toRdf}'
|
|
381
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}schema:givenName {self.givenName.toRdf}'
|
|
382
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}schema:email {self.email.toRdf}'
|
|
383
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}oldap:credentials {self.credentials.toRdf}'
|
|
384
|
+
activeval = "true" if self.isActive else "false"
|
|
385
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}oldap:isActive {activeval}'
|
|
386
|
+
star = ''
|
|
387
|
+
if self.inProject:
|
|
388
|
+
project = [p.toRdf for p in self.inProject.keys()]
|
|
389
|
+
rdfstr = ", ".join(project)
|
|
390
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}oldap:inProject {rdfstr}'
|
|
391
|
+
for p in self.inProject.keys():
|
|
392
|
+
for admin_p in self.inProject[p]: # TODO: May be use .get() instead of [] !!!!!!!!!!!!!!!!!!!!!!!!!
|
|
393
|
+
star += f'{blank:{indent * indent_inc}}<<{self.userIri.toRdf} oldap:inProject {p.toRdf}>> oldap:hasAdminPermission {admin_p.value} .\n'
|
|
394
|
+
if self.hasPermissions:
|
|
395
|
+
rdfstr = ", ".join([str(x) for x in self.hasPermissions])
|
|
396
|
+
sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}oldap:hasPermissions {rdfstr}'
|
|
397
|
+
sparql += " .\n\n"
|
|
398
|
+
sparql += star
|
|
399
|
+
return sparql
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def create(self, indent: int = 0, indent_inc: int = 4, keep_dates: bool = False) -> None:
|
|
367
403
|
"""
|
|
368
404
|
Creates a user in the triple store with the provided details. Before proceeding with the
|
|
369
405
|
creation, it verifies the uniqueness of the `userId` and `userIri`. The user is created
|
|
@@ -444,31 +480,43 @@ class User(Model):
|
|
|
444
480
|
sparql += f'{blank:{indent * indent_inc}}INSERT DATA {{\n'
|
|
445
481
|
sparql += f'{blank:{(indent + 1) * indent_inc}}GRAPH oldap:admin {{\n'
|
|
446
482
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
sparql +=
|
|
471
|
-
|
|
483
|
+
if keep_dates:
|
|
484
|
+
sparql += self.trig_to_str(creator=self.creator,
|
|
485
|
+
created=self.created,
|
|
486
|
+
contributor=self.contributor,
|
|
487
|
+
modified=self.modified,
|
|
488
|
+
indent=indent + 2, indent_inc=indent_inc)
|
|
489
|
+
else:
|
|
490
|
+
sparql += self.trig_to_str(creator=self._con.userIri,
|
|
491
|
+
created=timestamp,
|
|
492
|
+
contributor=self._con.userIri,
|
|
493
|
+
modified=timestamp,
|
|
494
|
+
indent=indent + 2, indent_inc=indent_inc)
|
|
495
|
+
# sparql += f'{blank:{(indent + 2) * indent_inc}}{self.userIri.toRdf} a oldap:User'
|
|
496
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:creator {self._con.userIri.toRdf}'
|
|
497
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:created {timestamp.toRdf}'
|
|
498
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:contributor {self._con.userIri.toRdf}'
|
|
499
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:modified {timestamp.toRdf}'
|
|
500
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}oldap:userId {self.userId.toRdf}'
|
|
501
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}schema:familyName {self.familyName.toRdf}'
|
|
502
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}schema:givenName {self.givenName.toRdf}'
|
|
503
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}schema:email {self.email.toRdf}'
|
|
504
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}oldap:credentials {self.credentials.toRdf}'
|
|
505
|
+
# activeval = "true" if self.isActive else "false"
|
|
506
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}oldap:isActive {activeval}'
|
|
507
|
+
# star = ''
|
|
508
|
+
# if self.inProject:
|
|
509
|
+
# project = [p.toRdf for p in self.inProject.keys()]
|
|
510
|
+
# rdfstr = ", ".join(project)
|
|
511
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}oldap:inProject {rdfstr}'
|
|
512
|
+
# for p in self.inProject.keys():
|
|
513
|
+
# for admin_p in self.inProject[p]: # TODO: May be use .get() instead of [] !!!!!!!!!!!!!!!!!!!!!!!!!
|
|
514
|
+
# star += f'{blank:{(indent + 2) * indent_inc}}<<{self.userIri.toRdf} oldap:inProject {p.toRdf}>> oldap:hasAdminPermission {admin_p.value} .\n'
|
|
515
|
+
# if self.hasPermissions:
|
|
516
|
+
# rdfstr = ", ".join([str(x) for x in self.hasPermissions])
|
|
517
|
+
# sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}oldap:hasPermissions {rdfstr}'
|
|
518
|
+
# sparql += " .\n\n"
|
|
519
|
+
# sparql += star
|
|
472
520
|
sparql += f'{blank:{(indent + 1) * indent_inc}}}}\n'
|
|
473
521
|
sparql += f'{blank:{indent * indent_inc}}}}\n'
|
|
474
522
|
|
oldaplib/src/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.3.
|
|
1
|
+
__version__ = "0.3.29"
|
oldaplib/src/xsd/xsd_anyuri.py
CHANGED
|
@@ -69,15 +69,15 @@ class Xsd_anyURI(Xsd):
|
|
|
69
69
|
raise OldapErrorValue(f'Invalid URN format for "{value}".')
|
|
70
70
|
elif value.startswith("http"):
|
|
71
71
|
if not re.match(self._uri_pattern, str(value)):
|
|
72
|
-
raise OldapErrorValue(f'Invalid string "{value}" for xsd:anyURI.')
|
|
72
|
+
raise OldapErrorValue(f'Invalid string "{value}" for xsd:anyURI (regexp).')
|
|
73
73
|
if validate:
|
|
74
74
|
if not XsdValidator.validate(XsdDatatypes.anyURI, str(value)):
|
|
75
|
-
raise OldapErrorValue(f'Invalid string "{value}" for anyURI')
|
|
75
|
+
raise OldapErrorValue(f'Invalid string "{value}" for xsd:anyURI (validator)')
|
|
76
76
|
else:
|
|
77
77
|
if not url(str(value)):
|
|
78
|
-
raise OldapErrorValue(f'Invalid string "{value}" for xsd:anyURI.')
|
|
78
|
+
raise OldapErrorValue(f'Invalid string "{value}" for xsd:anyURI (url()).')
|
|
79
79
|
else:
|
|
80
|
-
raise OldapErrorValue(f'Invalid string "{value}" for anyURI')
|
|
80
|
+
raise OldapErrorValue(f'Invalid string "{value}" for anyURI (no urn:/http:)')
|
|
81
81
|
self._value = str(value)
|
|
82
82
|
self._append_allowed = self._value[-1] == '/' or self._value[-1] == '#'
|
|
83
83
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from oldaplib.src.connection import Connection
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
from oldaplib.src.datamodel import DataModel
|
|
5
|
+
from oldaplib.src.project import Project
|
|
6
|
+
|
|
7
|
+
class TestDataModel(unittest.TestCase):
|
|
8
|
+
|
|
9
|
+
# @unittest.skip('Work in progress')
|
|
10
|
+
def test_fasnacht(self):
|
|
11
|
+
connection = Connection(userId="rosenth",
|
|
12
|
+
credentials="RioGrande",
|
|
13
|
+
context_name="DEFAULT")
|
|
14
|
+
|
|
15
|
+
project = Project.read(connection, "fasnacht")
|
|
16
|
+
dm = DataModel.read(connection, project, ignore_cache=False)
|
|
17
|
+
pass
|
oldaplib/test/test_connection.py
CHANGED
|
@@ -52,7 +52,6 @@ class TestBasicConnection(unittest.TestCase):
|
|
|
52
52
|
cls._connection.clear_graph(Xsd_QName('test:onto'))
|
|
53
53
|
file = project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
54
54
|
cls._connection.upload_turtle(file)
|
|
55
|
-
sleep(1) # upload may take a while...
|
|
56
55
|
|
|
57
56
|
@classmethod
|
|
58
57
|
def tearDownClass(cls):
|
oldaplib/test/test_context.py
CHANGED
|
@@ -55,14 +55,14 @@ class TestContext(unittest.TestCase):
|
|
|
55
55
|
self.assertIsNone(qn)
|
|
56
56
|
with self.assertRaises(OldapError) as ex:
|
|
57
57
|
qn = context.iri2qname('waseliwas/soll')
|
|
58
|
-
self.assertEqual(str(ex.exception), 'Invalid string "waseliwas/soll" for anyURI')
|
|
58
|
+
self.assertEqual(str(ex.exception), 'Invalid string "waseliwas/soll" for anyURI (no urn:/http:)')
|
|
59
59
|
|
|
60
60
|
def test_context_qname2iri(self):
|
|
61
61
|
context = Context(name='qname2iri')
|
|
62
62
|
self.assertEqual(context.qname2iri(Xsd_QName('skos:gaga')), 'http://www.w3.org/2004/02/skos/core#gaga')
|
|
63
63
|
with self.assertRaises(OldapError) as ex:
|
|
64
64
|
qn = context.iri2qname('gaga')
|
|
65
|
-
self.assertEqual(str(ex.exception), 'Invalid string "gaga" for anyURI')
|
|
65
|
+
self.assertEqual(str(ex.exception), 'Invalid string "gaga" for anyURI (no urn:/http:)')
|
|
66
66
|
self.assertIsNone(context.iri2qname('abc:def'))
|
|
67
67
|
t = Xsd_QName('xml:integer')
|
|
68
68
|
self.assertEqual(context.qname2iri(t), 'http://www.w3.org/XML/1998/namespace#integer')
|
|
@@ -79,6 +79,7 @@ PREFIX sh: <http://www.w3.org/ns/shacl#>
|
|
|
79
79
|
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
|
|
80
80
|
PREFIX schema: <http://schema.org/>
|
|
81
81
|
PREFIX dcterms: <http://purl.org/dc/terms/>
|
|
82
|
+
PREFIX dcmitype: <http://purl.org/dc/dcmitype/>
|
|
82
83
|
PREFIX oldap: <http://oldap.org/base#>
|
|
83
84
|
PREFIX shared: <http://oldap.org/shared#>
|
|
84
85
|
PREFIX test: <http://www.test.org/gaga#>
|
|
@@ -97,6 +98,7 @@ PREFIX test: <http://www.test.org/gaga#>
|
|
|
97
98
|
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
|
|
98
99
|
@prefix schema: <http://schema.org/> .
|
|
99
100
|
@prefix dcterms: <http://purl.org/dc/terms/> .
|
|
101
|
+
@prefix dcmitype: <http://purl.org/dc/dcmitype/> .
|
|
100
102
|
@prefix oldap: <http://oldap.org/base#> .
|
|
101
103
|
@prefix shared: <http://oldap.org/shared#> .
|
|
102
104
|
@prefix test: <http://www.test.org/gaga#> .
|
oldaplib/test/test_datamodel.py
CHANGED
|
@@ -102,9 +102,6 @@ class TestDataModel(unittest.TestCase):
|
|
|
102
102
|
file = project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
103
103
|
cls._connection.upload_turtle(file)
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
sleep(1) # upload may take a while...
|
|
107
|
-
|
|
108
105
|
cls._project = Project.read(cls._connection, "test", ignore_cache=True)
|
|
109
106
|
cls._dmproject = Project.read(cls._connection, "dmtest", ignore_cache=True)
|
|
110
107
|
cls._dmprojectA = Project.read(cls._connection, "dmtestA", ignore_cache=True)
|
|
@@ -390,6 +387,7 @@ class TestDataModel(unittest.TestCase):
|
|
|
390
387
|
|
|
391
388
|
def test_datamodel_read_shared(self):
|
|
392
389
|
model = DataModel.read(self._connection, self._sharedproject, ignore_cache=True)
|
|
390
|
+
pass
|
|
393
391
|
|
|
394
392
|
def test_datamodel_read_system(self):
|
|
395
393
|
model = DataModel.read(self._connection, self._sysproject, ignore_cache=True)
|
|
@@ -1114,8 +1112,6 @@ class TestDataModel(unittest.TestCase):
|
|
|
1114
1112
|
file = project_root / 'oldaplib' / 'testdata' / 'objectfactory_test.trig'
|
|
1115
1113
|
self._connection.upload_turtle(file)
|
|
1116
1114
|
|
|
1117
|
-
sleep(1) # upload may take a while...
|
|
1118
|
-
|
|
1119
1115
|
cache = CacheSingletonRedis()
|
|
1120
1116
|
cache.clear()
|
|
1121
1117
|
dm1 = DataModel.read(self._connection, self._project, ignore_cache=False)
|
|
@@ -1123,3 +1119,4 @@ class TestDataModel(unittest.TestCase):
|
|
|
1123
1119
|
dm2 = DataModel.read(self._connection, self._project, ignore_cache=False)
|
|
1124
1120
|
|
|
1125
1121
|
pass
|
|
1122
|
+
|
|
@@ -51,7 +51,6 @@ class TestexternalOntologies(unittest.TestCase):
|
|
|
51
51
|
cls._connection.upload_turtle(file)
|
|
52
52
|
file = project_root / 'oldaplib' / 'ontologies' / 'admin-testing.trig'
|
|
53
53
|
cls._connection.upload_turtle(file)
|
|
54
|
-
sleep(1) # upload may take a while...
|
|
55
54
|
|
|
56
55
|
project = Project(con=cls._connection,
|
|
57
56
|
projectIri=Iri("http://extonto.test.org/test"),
|
|
@@ -52,7 +52,6 @@ class TestHasProperty(unittest.TestCase):
|
|
|
52
52
|
|
|
53
53
|
file = project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
54
54
|
cls._connection.upload_turtle(file)
|
|
55
|
-
sleep(1) # upload may take a while...
|
|
56
55
|
cls._project = Project.read(cls._connection, "test")
|
|
57
56
|
|
|
58
57
|
@classmethod
|
|
@@ -5,6 +5,7 @@ import unittest
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from pprint import pprint
|
|
7
7
|
from time import sleep
|
|
8
|
+
import jwt
|
|
8
9
|
|
|
9
10
|
from oldaplib.src.cachesingleton import CacheSingletonRedis
|
|
10
11
|
from oldaplib.src.datamodel import DataModel
|
|
@@ -108,8 +109,6 @@ class TestObjectFactory(unittest.TestCase):
|
|
|
108
109
|
file = project_root / 'oldaplib' / 'testdata' / 'instances_test.trig'
|
|
109
110
|
cls._connection.upload_turtle(file)
|
|
110
111
|
|
|
111
|
-
sleep(1) # upload may take a while...
|
|
112
|
-
|
|
113
112
|
user = User.read(cls._connection, "rosenth")
|
|
114
113
|
user.hasPermissions.add(Iri('oldap:GenericUpdate')) # TODO: SHOULD WORK WITH Xsd_QName
|
|
115
114
|
user.update()
|
|
@@ -362,6 +361,7 @@ class TestObjectFactory(unittest.TestCase):
|
|
|
362
361
|
factory = ResourceInstanceFactory(con=self._connection, project='test')
|
|
363
362
|
MO = factory.createObjectInstance('shared:MediaObject')
|
|
364
363
|
mo = MO(originalName='Cat.tif',
|
|
364
|
+
type='dcmitype:StillImage',
|
|
365
365
|
originalMimeType='image/tiff',
|
|
366
366
|
serverUrl='http://iiif.oldap.org/iiif/3/',
|
|
367
367
|
imageId='cat.tif',
|
|
@@ -547,7 +547,7 @@ class TestObjectFactory(unittest.TestCase):
|
|
|
547
547
|
givenName="Max",
|
|
548
548
|
grantsPermission={Iri('oldap:GenericView'), Iri('oldap:GenericUpdate')})
|
|
549
549
|
p.create()
|
|
550
|
-
|
|
550
|
+
|
|
551
551
|
obj1 = Person.read(con=self._connection,
|
|
552
552
|
iri=p.iri)
|
|
553
553
|
with self.assertRaises(OldapErrorValue):
|
|
@@ -703,22 +703,78 @@ class TestObjectFactory(unittest.TestCase):
|
|
|
703
703
|
self.assertEqual(len(res), 8)
|
|
704
704
|
|
|
705
705
|
#@unittest.skip('Work in progress')
|
|
706
|
-
def
|
|
707
|
-
res = ResourceInstance.get_media_object_by_id(con=self._connection,mediaObjectId='x_34db.tif')
|
|
706
|
+
def test_read_media_object_by_id_A(self):
|
|
707
|
+
res = ResourceInstance.get_media_object_by_id(con=self._connection, mediaObjectId='x_34db.tif')
|
|
708
|
+
self.assertEqual(res['iri'], Iri("urn:uuid:1b8e3f42-6d7a-4c9b-a3f8-93c2e5d7b901"))
|
|
709
|
+
self.assertEqual(res['permval'], Xsd_integer(2))
|
|
710
|
+
self.assertEqual(res['shared:imageId'], Xsd_string('x_34db.tif'))
|
|
711
|
+
self.assertEqual(res['shared:originalName'], Xsd_string("testfile.tif"))
|
|
712
|
+
self.assertEqual(res['shared:originalMimeType'], Xsd_string("image/tiff"))
|
|
713
|
+
self.assertEqual(res['shared:serverUrl'], Xsd_string("https://iiif.oldap.org"))
|
|
714
|
+
self.assertEqual(res['shared:protocol'], Xsd_string("iiif"))
|
|
715
|
+
self.assertEqual(res['graph'], Xsd_QName("test:data"))
|
|
716
|
+
self.assertEqual(res['shared:path'], Xsd_string("test/subtest"))
|
|
717
|
+
tinfo = jwt.decode(jwt=res['token'], key=self._connection.jwtkey, algorithms="HS256")
|
|
718
|
+
self.assertEqual(tinfo['id'], 'x_34db.tif')
|
|
719
|
+
self.assertEqual(tinfo['path'], 'test/subtest')
|
|
720
|
+
self.assertEqual(tinfo['permval'], '2')
|
|
721
|
+
|
|
722
|
+
def test_read_media_object_by_id_B(self):
|
|
723
|
+
res = ResourceInstance.get_media_object_by_id(con=self._connection, mediaObjectId='x_42db.jpg')
|
|
724
|
+
self.assertEqual(res['iri'], Iri("urn:uuid:1b8e3f42-6d7a-4c9b-a3f8-93c2e5d7b999"))
|
|
725
|
+
self.assertEqual(res['permval'], Xsd_integer(2))
|
|
726
|
+
self.assertEqual(res['shared:imageId'], Xsd_string('x_42db.jpg'))
|
|
727
|
+
self.assertEqual(res['shared:originalName'], Xsd_string("testfile.jpg"))
|
|
728
|
+
self.assertEqual(res['shared:originalMimeType'], Xsd_string("image/jpeg"))
|
|
729
|
+
self.assertEqual(res['shared:serverUrl'], Xsd_string("https://iiif.oldap.org"))
|
|
730
|
+
self.assertEqual(res['shared:protocol'], Xsd_string("iiif"))
|
|
731
|
+
self.assertEqual(res['graph'], Xsd_QName("test:data"))
|
|
732
|
+
self.assertEqual(res['test:caption'], [Xsd_string("This is a non-real, non-existing image")])
|
|
733
|
+
self.assertEqual(res['shared:path'], Xsd_string("test/subtest"))
|
|
734
|
+
tinfo = jwt.decode(jwt=res['token'], key=self._connection.jwtkey, algorithms="HS256")
|
|
735
|
+
self.assertEqual(tinfo['id'], 'x_42db.jpg')
|
|
736
|
+
self.assertEqual(tinfo['path'], 'test/subtest')
|
|
737
|
+
self.assertEqual(tinfo['permval'], '2')
|
|
738
|
+
|
|
739
|
+
def test_read_media_object_by_iri_A(self):
|
|
740
|
+
res = ResourceInstance.get_media_object_by_iri(con=self._connection, mediaObjectIri='urn:uuid:1b8e3f42-6d7a-4c9b-a3f8-93c2e5d7b901')
|
|
708
741
|
self.assertEqual(res['iri'], Iri("urn:uuid:1b8e3f42-6d7a-4c9b-a3f8-93c2e5d7b901"))
|
|
742
|
+
self.assertEqual(res['permval'], Xsd_integer(2))
|
|
743
|
+
self.assertEqual(res['shared:imageId'], Xsd_string('x_34db.tif'))
|
|
709
744
|
self.assertEqual(res['shared:originalName'], Xsd_string("testfile.tif"))
|
|
710
745
|
self.assertEqual(res['shared:originalMimeType'], Xsd_string("image/tiff"))
|
|
711
746
|
self.assertEqual(res['shared:serverUrl'], Xsd_string("https://iiif.oldap.org"))
|
|
712
747
|
self.assertEqual(res['shared:protocol'], Xsd_string("iiif"))
|
|
713
748
|
self.assertEqual(res['graph'], Xsd_QName("test:data"))
|
|
714
749
|
self.assertEqual(res['shared:path'], Xsd_string("test/subtest"))
|
|
715
|
-
|
|
750
|
+
tinfo = jwt.decode(jwt=res['token'], key=self._connection.jwtkey, algorithms="HS256")
|
|
751
|
+
self.assertEqual(tinfo['id'], 'x_34db.tif')
|
|
752
|
+
self.assertEqual(tinfo['path'], 'test/subtest')
|
|
753
|
+
self.assertEqual(tinfo['permval'], '2')
|
|
754
|
+
|
|
755
|
+
def test_read_media_object_by_iri_B(self):
|
|
756
|
+
res = ResourceInstance.get_media_object_by_iri(con=self._connection, mediaObjectIri='urn:uuid:1b8e3f42-6d7a-4c9b-a3f8-93c2e5d7b999')
|
|
757
|
+
self.assertEqual(res['iri'], Iri("urn:uuid:1b8e3f42-6d7a-4c9b-a3f8-93c2e5d7b999"))
|
|
758
|
+
self.assertEqual(res['permval'], Xsd_integer(2))
|
|
759
|
+
self.assertEqual(res['shared:imageId'], Xsd_string('x_42db.jpg'))
|
|
760
|
+
self.assertEqual(res['shared:originalName'], Xsd_string("testfile.jpg"))
|
|
761
|
+
self.assertEqual(res['shared:originalMimeType'], Xsd_string("image/jpeg"))
|
|
762
|
+
self.assertEqual(res['shared:serverUrl'], Xsd_string("https://iiif.oldap.org"))
|
|
763
|
+
self.assertEqual(res['shared:protocol'], Xsd_string("iiif"))
|
|
764
|
+
self.assertEqual(res['graph'], Xsd_QName("test:data"))
|
|
765
|
+
self.assertEqual(res['test:caption'], [Xsd_string("This is a non-real, non-existing image")])
|
|
766
|
+
self.assertEqual(res['shared:path'], Xsd_string("test/subtest"))
|
|
767
|
+
tinfo = jwt.decode(jwt=res['token'], key=self._connection.jwtkey, algorithms="HS256")
|
|
768
|
+
self.assertEqual(tinfo['id'], 'x_42db.jpg')
|
|
769
|
+
self.assertEqual(tinfo['path'], 'test/subtest')
|
|
770
|
+
self.assertEqual(tinfo['permval'], '2')
|
|
716
771
|
|
|
717
772
|
def test_create_media_object(self):
|
|
718
773
|
dm = DataModel.read(con=self._connection, project='test')
|
|
719
774
|
factory = ResourceInstanceFactory(con=self._connection, project='test')
|
|
720
775
|
MLE = factory.createObjectInstance('test:MediaLibraryEntry')
|
|
721
776
|
mle = MLE(originalName='MyCarnivalImagetif',
|
|
777
|
+
type='dcmitype:StillImage',
|
|
722
778
|
originalMimeType='image/tiff',
|
|
723
779
|
imageId='x_34dbY4.tif',
|
|
724
780
|
serverUrl='http://iiif.oldap.org/iiif/3/',
|
oldaplib/test/test_oldaplist.py
CHANGED
|
@@ -80,7 +80,7 @@ class TestOldapList(unittest.TestCase):
|
|
|
80
80
|
|
|
81
81
|
file = cls._project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
82
82
|
cls._connection.upload_turtle(file)
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
cls._project = Project.read(cls._connection, "test")
|
|
85
85
|
LangString.defaultLanguage = Language.EN
|
|
86
86
|
|
|
@@ -66,7 +66,7 @@ class OldapListHelperTestCase(unittest.TestCase):
|
|
|
66
66
|
cls._connection.clear_graph(Xsd_QName('hyha:data'))
|
|
67
67
|
file = project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
68
68
|
cls._connection.upload_turtle(file)
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
cls._project = Project.read(cls._connection, "test")
|
|
71
71
|
LangString.defaultLanguage = Language.EN
|
|
72
72
|
|
|
@@ -84,7 +84,6 @@ class TestOldapListNode(unittest.TestCase):
|
|
|
84
84
|
|
|
85
85
|
file = cls._project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
86
86
|
cls._connection.upload_turtle(file)
|
|
87
|
-
sleep(1)
|
|
88
87
|
|
|
89
88
|
cls._project = Project.read(cls._connection, "test")
|
|
90
89
|
cls._dmproject = Project.read(cls._connection, "dmtest", ignore_cache=True)
|
|
@@ -78,7 +78,7 @@ class TestPermissionSet(unittest.TestCase):
|
|
|
78
78
|
cls._connection.clear_graph(Xsd_QName('test:data'))
|
|
79
79
|
file = cls._project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
80
80
|
cls._connection.upload_turtle(file)
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
cls._project = Project.read(cls._connection, "test")
|
|
83
83
|
LangString.defaultLanguage = Language.EN
|
|
84
84
|
|
|
@@ -347,6 +347,7 @@ class TestPermissionSet(unittest.TestCase):
|
|
|
347
347
|
ps.update()
|
|
348
348
|
ps = PermissionSet.read(con=self._connection, permissionSetId=psId, definedByProject=Iri('oldap:SystemProject'))
|
|
349
349
|
self.assertEqual(ps.givesPermission, DataPermission.DATA_VIEW)
|
|
350
|
+
self.assertEqual(ps.givesPermission, DataPermission.DATA_VIEW)
|
|
350
351
|
self.assertEqual(ps.label, LangString("testUpdatePerm@en", "testVerändernPerm@de", "testeModificationPerm@fr"))
|
|
351
352
|
del ps.comment
|
|
352
353
|
ps.update()
|
oldaplib/test/test_project.py
CHANGED
|
@@ -56,7 +56,6 @@ class Testproject(unittest.TestCase):
|
|
|
56
56
|
cls._connection.upload_turtle(file)
|
|
57
57
|
file = project_root / 'oldaplib' / 'ontologies' / 'admin-testing.trig'
|
|
58
58
|
cls._connection.upload_turtle(file)
|
|
59
|
-
sleep(1) # upload may take a while...
|
|
60
59
|
|
|
61
60
|
@classmethod
|
|
62
61
|
def tearDownClass(cls):
|
|
@@ -70,7 +70,6 @@ class TestPropertyClass(unittest.TestCase):
|
|
|
70
70
|
cls._connection.clear_graph(Xsd_QName('test:onto'))
|
|
71
71
|
file = project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
72
72
|
cls._connection.upload_turtle(file)
|
|
73
|
-
sleep(1) # upload may take a while...
|
|
74
73
|
cls._project = Project.read(cls._connection, "test")
|
|
75
74
|
cls._sysproject = Project.read(cls._connection, "oldap")
|
|
76
75
|
|
|
@@ -137,7 +137,7 @@ class TestResourceClass(unittest.TestCase):
|
|
|
137
137
|
|
|
138
138
|
file = project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
139
139
|
cls._connection.upload_turtle(file)
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
cls._project = Project.read(cls._connection, "test")
|
|
142
142
|
cls._sysproject = Project.read(cls._connection, "oldap", ignore_cache=True)
|
|
143
143
|
|
oldaplib/test/test_user.py
CHANGED
|
@@ -281,7 +281,7 @@ class TestXsdDatatypes(unittest.TestCase):
|
|
|
281
281
|
self.assertEqual(hash(val1), hash(val2))
|
|
282
282
|
with self.assertRaises(OldapErrorValue) as ex:
|
|
283
283
|
val = Xsd_anyURI('waseliwas', validate=True)
|
|
284
|
-
self.assertEqual(str(ex.exception), 'Invalid string "waseliwas" for anyURI')
|
|
284
|
+
self.assertEqual(str(ex.exception), 'Invalid string "waseliwas" for anyURI (no urn:/http:)')
|
|
285
285
|
|
|
286
286
|
def test_xsd_base64binary(self):
|
|
287
287
|
data = base64.b64encode(b'Waseliwas soll den das sein?')
|