oldaplib 0.3.30__py3-none-any.whl → 0.4.1__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 +62 -11
- oldaplib/ontologies/admin.trig +12 -51
- oldaplib/ontologies/gaga.trigs +23 -0
- oldaplib/ontologies/oldap.trig +138 -62
- oldaplib/src/connection.py +39 -34
- oldaplib/src/enums/adminpermissions.py +1 -1
- oldaplib/src/enums/datapermissions.py +24 -4
- oldaplib/src/enums/{permissionsetattr.py → roleattr.py} +2 -3
- oldaplib/src/enums/userattr.py +3 -2
- oldaplib/src/helpers/observable_dict.py +1 -0
- oldaplib/src/in_project.py +0 -1
- oldaplib/src/objectfactory.py +349 -104
- oldaplib/src/propertyclass.py +1 -1
- oldaplib/src/{permissionset.py → role.py} +90 -112
- oldaplib/src/user.py +183 -97
- oldaplib/src/userdataclass.py +67 -38
- oldaplib/src/version.py +1 -1
- oldaplib/test/test_datamodel.py +5 -2
- oldaplib/test/test_in_project.py +21 -20
- oldaplib/test/test_objectfactory.py +100 -34
- oldaplib/test/test_resourceclass.py +3 -3
- oldaplib/test/test_role.py +407 -0
- oldaplib/test/test_user.py +159 -98
- oldaplib/testdata/instances_test.trig +48 -26
- {oldaplib-0.3.30.dist-info → oldaplib-0.4.1.dist-info}/METADATA +1 -1
- {oldaplib-0.3.30.dist-info → oldaplib-0.4.1.dist-info}/RECORD +27 -26
- oldaplib/test/test_permissionset.py +0 -443
- {oldaplib-0.3.30.dist-info → oldaplib-0.4.1.dist-info}/WHEEL +0 -0
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import unittest
|
|
3
|
-
from copy import deepcopy
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
from pprint import pprint
|
|
6
|
-
from time import sleep
|
|
7
|
-
|
|
8
|
-
from oldaplib.src.cachesingleton import CacheSingleton, CacheSingletonRedis
|
|
9
|
-
from oldaplib.src.datamodel import DataModel
|
|
10
|
-
from oldaplib.src.dtypes.namespaceiri import NamespaceIRI
|
|
11
|
-
from oldaplib.src.enums.permissionsetattr import PermissionSetAttr
|
|
12
|
-
from oldaplib.src.enums.xsd_datatypes import XsdDatatypes
|
|
13
|
-
from oldaplib.src.hasproperty import HasProperty
|
|
14
|
-
from oldaplib.src.helpers.serializer import serializer
|
|
15
|
-
from oldaplib.src.objectfactory import ResourceInstanceFactory
|
|
16
|
-
from oldaplib.src.permissionset import PermissionSet
|
|
17
|
-
from oldaplib.src.connection import Connection
|
|
18
|
-
from oldaplib.src.enums.language import Language
|
|
19
|
-
from oldaplib.src.enums.datapermissions import DataPermission
|
|
20
|
-
from oldaplib.src.helpers.context import Context
|
|
21
|
-
from oldaplib.src.helpers.langstring import LangString
|
|
22
|
-
from oldaplib.src.helpers.oldaperror import OldapErrorInconsistency, OldapErrorNotFound, OldapErrorNoPermission, \
|
|
23
|
-
OldapErrorAlreadyExists, OldapErrorImmutable, OldapErrorInUse
|
|
24
|
-
from oldaplib.src.project import Project
|
|
25
|
-
from oldaplib.src.propertyclass import PropertyClass
|
|
26
|
-
from oldaplib.src.resourceclass import ResourceClass
|
|
27
|
-
from oldaplib.src.xsd.iri import Iri
|
|
28
|
-
from oldaplib.src.xsd.xsd_integer import Xsd_integer
|
|
29
|
-
from oldaplib.src.xsd.xsd_qname import Xsd_QName
|
|
30
|
-
from oldaplib.src.xsd.xsd_string import Xsd_string
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def find_project_root(current_path):
|
|
34
|
-
# Climb up the directory hierarchy and check for a marker file
|
|
35
|
-
path = Path(current_path).absolute()
|
|
36
|
-
while not (path / 'pyproject.toml').exists():
|
|
37
|
-
if path.parent == path:
|
|
38
|
-
# Root of the filesystem, file not found
|
|
39
|
-
raise RuntimeError('Project root not found')
|
|
40
|
-
path = path.parent
|
|
41
|
-
return path
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
class TestPermissionSet(unittest.TestCase):
|
|
45
|
-
_connection: Connection
|
|
46
|
-
_unpriv: Connection
|
|
47
|
-
|
|
48
|
-
@classmethod
|
|
49
|
-
def setUpClass(cls):
|
|
50
|
-
cache = CacheSingletonRedis()
|
|
51
|
-
cache.clear()
|
|
52
|
-
super().setUpClass()
|
|
53
|
-
cls._project_root = find_project_root(__file__)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
cls._context = Context(name="DEFAULT")
|
|
57
|
-
cls._context['test'] = NamespaceIRI("http://testing.org/datatypes#")
|
|
58
|
-
cls._context.use('test')
|
|
59
|
-
|
|
60
|
-
cls._connection = Connection(userId="rosenth",
|
|
61
|
-
credentials="RioGrande",
|
|
62
|
-
context_name="DEFAULT")
|
|
63
|
-
cls._unpriv = Connection(userId="fornaro",
|
|
64
|
-
credentials="RioGrande",
|
|
65
|
-
context_name="DEFAULT")
|
|
66
|
-
|
|
67
|
-
cls._connection.clear_graph(Xsd_QName('oldap:admin'))
|
|
68
|
-
file = cls._project_root / 'oldaplib' / 'ontologies' / 'admin.trig'
|
|
69
|
-
cls._connection.upload_turtle(file)
|
|
70
|
-
|
|
71
|
-
file = cls._project_root / 'oldaplib' / 'ontologies' / 'admin-testing.trig'
|
|
72
|
-
cls._connection.upload_turtle(file)
|
|
73
|
-
|
|
74
|
-
cls._connection.clear_graph(Xsd_QName('test:test'))
|
|
75
|
-
cls._connection.clear_graph(Xsd_QName('test:onto'))
|
|
76
|
-
cls._connection.clear_graph(Xsd_QName('test:shacl'))
|
|
77
|
-
cls._connection.clear_graph(Xsd_QName('test:lists'))
|
|
78
|
-
cls._connection.clear_graph(Xsd_QName('test:data'))
|
|
79
|
-
file = cls._project_root / 'oldaplib' / 'testdata' / 'connection_test.trig'
|
|
80
|
-
cls._connection.upload_turtle(file)
|
|
81
|
-
|
|
82
|
-
cls._project = Project.read(cls._connection, "test")
|
|
83
|
-
LangString.defaultLanguage = Language.EN
|
|
84
|
-
|
|
85
|
-
@classmethod
|
|
86
|
-
def tearDownClass(cls):
|
|
87
|
-
#cls._connection.clear_graph(Xsd_QName('oldap:admin'))
|
|
88
|
-
#cls._connection.upload_turtle("oldap/ontologies/admin.trig")
|
|
89
|
-
#sleep(1) # upload may take a while...
|
|
90
|
-
pass
|
|
91
|
-
|
|
92
|
-
def test_construct_permissionset(self):
|
|
93
|
-
ps = PermissionSet(con=self._connection,
|
|
94
|
-
permissionSetId="test1_ps",
|
|
95
|
-
label=LangString("testPerm@en", "test@Perm@de"),
|
|
96
|
-
comment=LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"),
|
|
97
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
98
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
99
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE)
|
|
100
|
-
self.assertEqual(ps.label, LangString("testPerm@en", "test@Perm@de"))
|
|
101
|
-
self.assertEqual(ps.comment, LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"))
|
|
102
|
-
self.assertEqual(ps.definedByProject, Iri('oldap:SystemProject'))
|
|
103
|
-
|
|
104
|
-
def test_deepcopy_permissionset(self):
|
|
105
|
-
ps = PermissionSet(con=self._connection,
|
|
106
|
-
permissionSetId="test1_ps",
|
|
107
|
-
label=LangString("testPerm@en", "test@Perm@de"),
|
|
108
|
-
comment=LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"),
|
|
109
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
110
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
111
|
-
ps1 = deepcopy(ps)
|
|
112
|
-
self.assertEqual(ps.permissionSetId, ps1.permissionSetId)
|
|
113
|
-
self.assertFalse(ps.permissionSetId is ps1.permissionSetId)
|
|
114
|
-
|
|
115
|
-
self.assertEqual(ps.label, ps1.label)
|
|
116
|
-
self.assertFalse(ps.label is ps1.label)
|
|
117
|
-
|
|
118
|
-
self.assertEqual(ps.comment, ps1.comment)
|
|
119
|
-
self.assertFalse(ps.comment is ps1.comment)
|
|
120
|
-
|
|
121
|
-
self.assertEqual(ps.givesPermission, ps1.givesPermission)
|
|
122
|
-
|
|
123
|
-
self.assertEqual(ps.definedByProject, ps1.definedByProject)
|
|
124
|
-
self.assertFalse(ps.definedByProject is ps1.definedByProject)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def test_create_permissionset(self):
|
|
128
|
-
ps = PermissionSet(con=self._connection,
|
|
129
|
-
permissionSetId="test3_ps",
|
|
130
|
-
label=LangString("\";SELECT * { password ?p ?o . }@en", "test@Perm@de"),
|
|
131
|
-
comment=LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"),
|
|
132
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
133
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
134
|
-
ps.create()
|
|
135
|
-
self.assertIsNotNone(ps.created)
|
|
136
|
-
self.assertIsNotNone(ps.creator)
|
|
137
|
-
self.assertIsNotNone(ps.modified)
|
|
138
|
-
self.assertIsNotNone(ps.contributor)
|
|
139
|
-
del ps
|
|
140
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId="test3_ps", definedByProject=Iri('oldap:SystemProject'), ignore_cache=True)
|
|
141
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE)
|
|
142
|
-
self.assertEqual(ps.label, LangString("\";SELECT * { password ?p ?o . }@en", "test@Perm@de"))
|
|
143
|
-
self.assertEqual(ps.comment, LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"))
|
|
144
|
-
self.assertEqual(ps.definedByProject, Iri('oldap:SystemProject'))
|
|
145
|
-
|
|
146
|
-
ps.delete() # cleanup
|
|
147
|
-
|
|
148
|
-
def test_create_permset_with_shortname(self):
|
|
149
|
-
ps = PermissionSet(con=self._connection,
|
|
150
|
-
permissionSetId="test4_ps",
|
|
151
|
-
label=LangString("test4@en", "test4@Perm@de"),
|
|
152
|
-
comment=LangString("Testing a PermissionSet 4@en", "Test eines PermissionSet 4@Perm@de"),
|
|
153
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
154
|
-
definedByProject='britnet')
|
|
155
|
-
ps.create()
|
|
156
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId="test4_ps", definedByProject=Iri('http://www.salsah.org/version/2.0/SwissBritNet'), ignore_cache=True)
|
|
157
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE)
|
|
158
|
-
self.assertEqual(ps.label, LangString("test4@en", "test4@Perm@de"))
|
|
159
|
-
|
|
160
|
-
ps.delete() # cleanup
|
|
161
|
-
|
|
162
|
-
def test_create_prmission_set_without_label(self):
|
|
163
|
-
ps = PermissionSet(con=self._connection,
|
|
164
|
-
permissionSetId="test5_ps",
|
|
165
|
-
label=LangString(),
|
|
166
|
-
comment=LangString("Testing a PermissionSet 4@en", "Test eines PermissionSet 4@Perm@de"),
|
|
167
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
168
|
-
definedByProject='britnet')
|
|
169
|
-
ps.create()
|
|
170
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE)
|
|
171
|
-
|
|
172
|
-
ps.read(con=self._connection, permissionSetId="test5_ps", definedByProject='britnet')
|
|
173
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE)
|
|
174
|
-
ps.delete()
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
# @unittest.skip('Work in progress')
|
|
178
|
-
def test_read_permission_A(self):
|
|
179
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId='GenericView', definedByProject='oldap:SystemProject', ignore_cache=True)
|
|
180
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_VIEW) # add assertion here
|
|
181
|
-
self.assertEqual(ps.label, LangString("GenericView@en", "GenericView@de", "GenericView@fr", "GenericView@it"))
|
|
182
|
-
self.assertEqual(ps.definedByProject, Iri('oldap:SystemProject'))
|
|
183
|
-
|
|
184
|
-
def test_read_permission_B(self):
|
|
185
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId='HyperHamletMember', definedByProject='oldap:HyperHamlet', ignore_cache=True)
|
|
186
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE) # add assertion here
|
|
187
|
-
self.assertEqual(ps.label, LangString("HyHaUpdate@en", "HyHaUpdate@de", "HyHaUpdate@fr", "HyHaUpdate@it"))
|
|
188
|
-
self.assertEqual(ps.definedByProject, Iri('oldap:HyperHamlet'))
|
|
189
|
-
|
|
190
|
-
def test_read_permission_with_cache(self):
|
|
191
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId='HyperHamletMember', definedByProject='oldap:HyperHamlet', ignore_cache=True)
|
|
192
|
-
ps2 = PermissionSet.read(con=self._connection, permissionSetId='HyperHamletMember', definedByProject='oldap:HyperHamlet')
|
|
193
|
-
self.assertEqual(ps2.givesPermission, DataPermission.DATA_UPDATE)
|
|
194
|
-
self.assertEqual(ps.givesPermission, ps2.givesPermission)
|
|
195
|
-
|
|
196
|
-
self.assertEqual(ps2.label, LangString("HyHaUpdate@en", "HyHaUpdate@de", "HyHaUpdate@fr", "HyHaUpdate@it"))
|
|
197
|
-
self.assertEqual(ps.label, ps2.label)
|
|
198
|
-
self.assertFalse(ps.label is ps2.label)
|
|
199
|
-
|
|
200
|
-
self.assertEqual(ps2.definedByProject, Iri('oldap:HyperHamlet'))
|
|
201
|
-
self.assertEqual(ps.definedByProject, ps2.definedByProject)
|
|
202
|
-
self.assertFalse(ps.definedByProject is ps2.definedByProject)
|
|
203
|
-
|
|
204
|
-
def test_read_permission_with_iri(self):
|
|
205
|
-
ps = PermissionSet.read(con=self._connection, qname=Xsd_QName('hyha:HyperHamletMember'), ignore_cache=True)
|
|
206
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE) # add assertion here
|
|
207
|
-
self.assertEqual(ps.label, LangString("HyHaUpdate@en", "HyHaUpdate@de", "HyHaUpdate@fr", "HyHaUpdate@it"))
|
|
208
|
-
self.assertEqual(ps.definedByProject, Iri('oldap:HyperHamlet'))
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
def test_create_permission(self):
|
|
212
|
-
ps = PermissionSet(con=self._connection,
|
|
213
|
-
permissionSetId="testPerm",
|
|
214
|
-
label=LangString("testPerm@en", "test@Perm@de"),
|
|
215
|
-
comment=LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"),
|
|
216
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
217
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
218
|
-
ps.create()
|
|
219
|
-
self.assertIsNotNone(ps.created)
|
|
220
|
-
self.assertIsNotNone(ps.creator)
|
|
221
|
-
self.assertIsNotNone(ps.modified)
|
|
222
|
-
self.assertIsNotNone(ps.contributor)
|
|
223
|
-
del ps
|
|
224
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId="testPerm", definedByProject='oldap:SystemProject', ignore_cache=True)
|
|
225
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE)
|
|
226
|
-
self.assertEqual(ps.label, LangString("testPerm@en", "test@Perm@de"))
|
|
227
|
-
self.assertEqual(ps.comment, LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"))
|
|
228
|
-
self.assertEqual(ps.definedByProject, Iri('oldap:SystemProject'))
|
|
229
|
-
|
|
230
|
-
ps.delete() # cleanup
|
|
231
|
-
|
|
232
|
-
def test_create_permission_strange_label(self):
|
|
233
|
-
ps = PermissionSet(con=self._connection,
|
|
234
|
-
permissionSetId="gagaPerm",
|
|
235
|
-
label=LangString("\";SELECT * { password ?p ?o . }@en", "test@Perm@de"),
|
|
236
|
-
comment=LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"),
|
|
237
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
238
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
239
|
-
ps.create()
|
|
240
|
-
self.assertIsNotNone(ps.created)
|
|
241
|
-
self.assertIsNotNone(ps.creator)
|
|
242
|
-
self.assertIsNotNone(ps.modified)
|
|
243
|
-
self.assertIsNotNone(ps.contributor)
|
|
244
|
-
del ps
|
|
245
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId="gagaPerm", definedByProject='oldap:SystemProject', ignore_cache=True)
|
|
246
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE)
|
|
247
|
-
self.assertEqual(ps.label, LangString("\";SELECT * { password ?p ?o . }@en", "test@Perm@de"))
|
|
248
|
-
self.assertEqual(ps.comment, LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"))
|
|
249
|
-
self.assertEqual(ps.definedByProject, Iri('oldap:SystemProject'))
|
|
250
|
-
|
|
251
|
-
ps.delete()
|
|
252
|
-
|
|
253
|
-
def test_create_permission_no_label(self):
|
|
254
|
-
ps = PermissionSet(con=self._connection,
|
|
255
|
-
permissionSetId="gagaPerm2",
|
|
256
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
257
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
258
|
-
ps.create()
|
|
259
|
-
del ps
|
|
260
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId="gagaPerm2", definedByProject='oldap:SystemProject', ignore_cache=True)
|
|
261
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_UPDATE)
|
|
262
|
-
self.assertIsNone(ps.label)
|
|
263
|
-
self.assertIsNone(ps.comment)
|
|
264
|
-
self.assertEqual(ps.definedByProject, Iri('oldap:SystemProject'))
|
|
265
|
-
|
|
266
|
-
ps.delete()
|
|
267
|
-
|
|
268
|
-
def test_create_permission_duplicate(self):
|
|
269
|
-
ps = PermissionSet(con=self._connection,
|
|
270
|
-
permissionSetId="testPerm2",
|
|
271
|
-
label=LangString("testPerm@en", "test@Perm@de"),
|
|
272
|
-
comment=LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"),
|
|
273
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
274
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
275
|
-
ps.create()
|
|
276
|
-
ps = PermissionSet(con=self._connection,
|
|
277
|
-
permissionSetId="testPerm2",
|
|
278
|
-
label=LangString("testPerm33@en", "test@Perm33@de"),
|
|
279
|
-
comment=LangString("Testing a PermissionSet33@en", "Test eines PermissionSet33@Perm@de"),
|
|
280
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
281
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
282
|
-
with self.assertRaises(OldapErrorAlreadyExists) as ex:
|
|
283
|
-
ps.create()
|
|
284
|
-
|
|
285
|
-
ps.read(con=self._connection, permissionSetId="testPerm2", definedByProject=Iri('oldap:SystemProject'))
|
|
286
|
-
|
|
287
|
-
ps.delete()
|
|
288
|
-
|
|
289
|
-
def test_create_permission_unauthorized(self):
|
|
290
|
-
ps = PermissionSet(con=self._unpriv,
|
|
291
|
-
permissionSetId="testPermUnauth",
|
|
292
|
-
label=LangString("testPermUnauth@en", "test@PermUnauth@de"),
|
|
293
|
-
comment=LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"),
|
|
294
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
295
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
296
|
-
with self.assertRaises(OldapErrorNoPermission):
|
|
297
|
-
ps.create()
|
|
298
|
-
|
|
299
|
-
def test_create_permission_unauthorized(self):
|
|
300
|
-
ps = PermissionSet(con=self._unpriv,
|
|
301
|
-
label=LangString("testPermUnauth2@en", "test@PermUnauth2@de"),
|
|
302
|
-
comment=LangString("Testing a PermissionSet@en", "Test eines PermissionSet@Perm@de"),
|
|
303
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
304
|
-
definedByProject=Iri('oldap:HyperHamlet'))
|
|
305
|
-
with self.assertRaises(OldapErrorNoPermission):
|
|
306
|
-
ps.create()
|
|
307
|
-
|
|
308
|
-
# TODO: More testing!!!
|
|
309
|
-
def test_search_permission_sets(self):
|
|
310
|
-
iris = PermissionSet.search(self._connection, label="GenericView")
|
|
311
|
-
self.assertEqual(len(iris), 1)
|
|
312
|
-
self.assertTrue(Xsd_QName('oldap:GenericView') in iris)
|
|
313
|
-
|
|
314
|
-
iris = PermissionSet.search(self._connection, label=Xsd_string("GenericView@de"))
|
|
315
|
-
self.assertEqual(len(iris), 1)
|
|
316
|
-
self.assertTrue(Xsd_QName('oldap:GenericView') in iris)
|
|
317
|
-
|
|
318
|
-
iris = PermissionSet.search(self._connection, definedByProject=Iri("oldap:HyperHamlet"))
|
|
319
|
-
self.assertEqual(len(iris), 1)
|
|
320
|
-
self.assertEqual(Xsd_QName('hyha:HyperHamletMember'), iris[0])
|
|
321
|
-
|
|
322
|
-
iris = PermissionSet.search(self._connection, givesPermission=DataPermission.DATA_RESTRICTED)
|
|
323
|
-
#self.assertEqual(len(iris), 1)
|
|
324
|
-
self.assertEqual([Xsd_QName('oldap:GenericRestricted')], iris)
|
|
325
|
-
|
|
326
|
-
iris = PermissionSet.search(self._connection)
|
|
327
|
-
self.assertEqual({Xsd_QName("oldap:GenericRestricted"),
|
|
328
|
-
Xsd_QName("oldap:GenericView"),
|
|
329
|
-
Xsd_QName("hyha:HyperHamletMember"),
|
|
330
|
-
Xsd_QName("oldap:GenericExtend"),
|
|
331
|
-
Xsd_QName("oldap:GenericUpdate")}, set(iris))
|
|
332
|
-
|
|
333
|
-
def test_update_permission_set(self):
|
|
334
|
-
ps = PermissionSet(con=self._connection,
|
|
335
|
-
permissionSetId="testUpdatePerm",
|
|
336
|
-
label=LangString("testUpdatePerm@en", "testVerändernPerm@de"),
|
|
337
|
-
comment=LangString("Testing update of PermissionSet@en", "Test einer Veränderung eines PermissionSet@Perm@de"),
|
|
338
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
339
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
340
|
-
ps.create()
|
|
341
|
-
|
|
342
|
-
psId = ps.permissionSetId
|
|
343
|
-
del ps
|
|
344
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId=psId, definedByProject=Iri('oldap:SystemProject'), ignore_cache=True)
|
|
345
|
-
ps.label[Language.FR] = "testeModificationPerm"
|
|
346
|
-
ps.givesPermission = DataPermission.DATA_VIEW
|
|
347
|
-
ps.update()
|
|
348
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId=psId, definedByProject=Iri('oldap:SystemProject'))
|
|
349
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_VIEW)
|
|
350
|
-
self.assertEqual(ps.givesPermission, DataPermission.DATA_VIEW)
|
|
351
|
-
self.assertEqual(ps.label, LangString("testUpdatePerm@en", "testVerändernPerm@de", "testeModificationPerm@fr"))
|
|
352
|
-
del ps.comment
|
|
353
|
-
ps.update()
|
|
354
|
-
self.assertIsNone(ps.comment)
|
|
355
|
-
self.assertIsNone(ps.get(PermissionSetAttr.COMMENT))
|
|
356
|
-
|
|
357
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId=psId, definedByProject=Iri('oldap:SystemProject'), ignore_cache=True)
|
|
358
|
-
ps.comment = LangString("gagagaga@en")
|
|
359
|
-
with self.assertRaises(OldapErrorImmutable):
|
|
360
|
-
ps[PermissionSetAttr.DEFINED_BY_PROJECT] = Iri('oldap:HyperHamlet')
|
|
361
|
-
|
|
362
|
-
ps = PermissionSet.read(con=self._unpriv, permissionSetId=psId, definedByProject=Iri('oldap:SystemProject'), ignore_cache=True)
|
|
363
|
-
ps.comment = LangString("gagagaga@fr")
|
|
364
|
-
with self.assertRaises(OldapErrorNoPermission):
|
|
365
|
-
ps.update()
|
|
366
|
-
|
|
367
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId=psId, definedByProject=Iri('oldap:SystemProject'), ignore_cache=True)
|
|
368
|
-
ps.delete()
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
def test_update_permissionset_B(self):
|
|
372
|
-
ps = PermissionSet(con=self._connection,
|
|
373
|
-
permissionSetId="testUpdatePermB",
|
|
374
|
-
label=LangString("testUpdatePerm@en", "testVerändernPerm@de"),
|
|
375
|
-
comment=LangString("Testing update of PermissionSet@en", "Test einer Veränderung eines PermissionSet@Perm@de"),
|
|
376
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
377
|
-
definedByProject=Iri('oldap:SystemProject'))
|
|
378
|
-
ps.create()
|
|
379
|
-
psId = ps.permissionSetId
|
|
380
|
-
del ps
|
|
381
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId=psId, definedByProject=Iri('oldap:SystemProject'), ignore_cache=True)
|
|
382
|
-
|
|
383
|
-
ps.label[Language.IT] = "TEST_ADD_DEL"
|
|
384
|
-
del ps.label[Language.EN]
|
|
385
|
-
ps.update()
|
|
386
|
-
|
|
387
|
-
def test_delete_permission_set(self):
|
|
388
|
-
ps = PermissionSet(con=self._connection,
|
|
389
|
-
permissionSetId="testDeletePerm",
|
|
390
|
-
label=LangString("testDeletePerm@en", "testDeletePerm@de"),
|
|
391
|
-
comment=LangString("Testing deleting a PermissionSet@en", "Test einer Löschung eines PermissionSet@Perm@de"),
|
|
392
|
-
givesPermission=DataPermission.DATA_UPDATE,
|
|
393
|
-
definedByProject=Iri('oldap:HyperHamlet'))
|
|
394
|
-
ps.create()
|
|
395
|
-
del ps
|
|
396
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId="testDeletePerm", definedByProject=Iri('oldap:HyperHamlet'), ignore_cache=True)
|
|
397
|
-
ps.delete()
|
|
398
|
-
|
|
399
|
-
with self.assertRaises(OldapErrorNotFound) as ex:
|
|
400
|
-
project = ps.read(con=self._connection, permissionSetId="testDeletePerm", definedByProject=Iri('oldap:HyperHamlet'), ignore_cache=True)
|
|
401
|
-
|
|
402
|
-
def test_delete_permission_set_in_use(self):
|
|
403
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId="GenericView", definedByProject=Iri('oldap:SystemProject'), ignore_cache=True)
|
|
404
|
-
with self.assertRaises(OldapErrorInUse):
|
|
405
|
-
ps.delete()
|
|
406
|
-
|
|
407
|
-
def test_delete_permission_set_user_with_data(self):
|
|
408
|
-
dm = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
409
|
-
dm_name = self._project.projectShortName
|
|
410
|
-
|
|
411
|
-
irgendwas = PropertyClass(con=self._connection,
|
|
412
|
-
project=self._project,
|
|
413
|
-
property_class_iri=Xsd_QName(f'{dm_name}:irgendwas'),
|
|
414
|
-
datatype=XsdDatatypes.string,
|
|
415
|
-
name=LangString(["AnyString@en", "Irgendwas@de"]))
|
|
416
|
-
|
|
417
|
-
#
|
|
418
|
-
# Now we create a simple data model
|
|
419
|
-
#
|
|
420
|
-
resobj = ResourceClass(con=self._connection,
|
|
421
|
-
project=self._project,
|
|
422
|
-
owlclass_iri=Xsd_QName(f'{dm_name}:DummyClass'),
|
|
423
|
-
label=LangString(["Dummy@en", "Dummy@de"]),
|
|
424
|
-
hasproperties=[
|
|
425
|
-
HasProperty(con=self._connection, project=self._project, prop=irgendwas, maxCount=Xsd_integer(1),
|
|
426
|
-
minCount=Xsd_integer(1), order=1)])
|
|
427
|
-
dm[Xsd_QName(f'{dm_name}:resobj')] = resobj
|
|
428
|
-
dm.update()
|
|
429
|
-
dm = DataModel.read(self._connection, self._project, ignore_cache=True)
|
|
430
|
-
|
|
431
|
-
factory = ResourceInstanceFactory(con=self._connection, project=self._project)
|
|
432
|
-
DummyClass = factory.createObjectInstance('DummyClass')
|
|
433
|
-
r = DummyClass(irgendwas="Dies ist irgend ein String", grantsPermission=Xsd_QName('oldap:GenericUpdate'))
|
|
434
|
-
r.create()
|
|
435
|
-
|
|
436
|
-
ps = PermissionSet.read(con=self._connection, permissionSetId="GenericUpdate", definedByProject=Iri('oldap:SystemProject'), ignore_cache=True)
|
|
437
|
-
with self.assertRaises(OldapErrorInUse):
|
|
438
|
-
ps.delete()
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if __name__ == '__main__':
|
|
443
|
-
unittest.main()
|
|
File without changes
|