pyPreservica 2.8.0__tar.gz → 2.8.2__tar.gz
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.
- {pypreservica-2.8.0 → pypreservica-2.8.2}/PKG-INFO +1 -1
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/__init__.py +2 -2
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/mdformsAPI.py +171 -109
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica.egg-info/PKG-INFO +1 -1
- {pypreservica-2.8.0 → pypreservica-2.8.2}/setup.py +1 -1
- pypreservica-2.8.2/tests/test_groups.py +97 -0
- pypreservica-2.8.0/tests/test_groups.py +0 -8
- {pypreservica-2.8.0 → pypreservica-2.8.2}/LICENSE.txt +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/README.md +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/adminAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/authorityAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/common.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/contentAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/entityAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/monitorAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/opex.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/parAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/retentionAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/uploadAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/webHooksAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica/workflowAPI.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica.egg-info/SOURCES.txt +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica.egg-info/dependency_links.txt +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica.egg-info/requires.txt +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/pyPreservica.egg-info/top_level.txt +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/setup.cfg +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_authority_records.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_bitstream.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_children.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_content_api.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_crawl_fs.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_delete.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_download.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_entity.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_export_opex.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_identifier.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_ingest.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_integrity_check.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_metadata.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_par.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_replace.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_retention.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_schema.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_security.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_thumbnail.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_upload.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_users.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_workflow.py +0 -0
- {pypreservica-2.8.0 → pypreservica-2.8.2}/tests/test_xml_metadata.py +0 -0
|
@@ -18,11 +18,11 @@ from .adminAPI import AdminAPI
|
|
|
18
18
|
from .monitorAPI import MonitorAPI, MonitorCategory, MonitorStatus, MessageStatus
|
|
19
19
|
from .webHooksAPI import WebHooksAPI, TriggerType, WebHookHandler
|
|
20
20
|
from .authorityAPI import AuthorityAPI, Table
|
|
21
|
-
from .mdformsAPI import MetadataGroupsAPI,
|
|
21
|
+
from .mdformsAPI import MetadataGroupsAPI, Group, GroupField, GroupFieldType
|
|
22
22
|
|
|
23
23
|
__author__ = "James Carr (drjamescarr@gmail.com)"
|
|
24
24
|
|
|
25
25
|
# Version of the pyPreservica package
|
|
26
|
-
__version__ = "2.8.
|
|
26
|
+
__version__ = "2.8.2"
|
|
27
27
|
|
|
28
28
|
__license__ = "Apache License Version 2.0"
|
|
@@ -8,9 +8,8 @@ author: James Carr
|
|
|
8
8
|
licence: Apache License 2.0
|
|
9
9
|
|
|
10
10
|
"""
|
|
11
|
-
import json
|
|
12
11
|
import xml.etree.ElementTree
|
|
13
|
-
from typing import Callable, List
|
|
12
|
+
from typing import Callable, List, Union, Generator
|
|
14
13
|
|
|
15
14
|
from pyPreservica.common import *
|
|
16
15
|
|
|
@@ -60,13 +59,77 @@ class Group:
|
|
|
60
59
|
name: str
|
|
61
60
|
description: str
|
|
62
61
|
schemaUri: str
|
|
63
|
-
fields: List[GroupField]
|
|
62
|
+
fields: List[GroupField]
|
|
63
|
+
|
|
64
|
+
def __init__(self, name: str, description: str):
|
|
65
|
+
self.name = name
|
|
66
|
+
self.description = description
|
|
67
|
+
self.fields = []
|
|
64
68
|
|
|
65
69
|
def __str__(self):
|
|
66
70
|
return (f"Group ID: {self.group_id}\n" + f"Group Name: {self.name}\n" +
|
|
67
71
|
f"Group Description: {self.description}\n" + f"Group Schema URI: {self.schemaUri}")
|
|
68
72
|
|
|
69
73
|
|
|
74
|
+
def _object_from_json_(json_doc: dict) -> Group:
|
|
75
|
+
"""
|
|
76
|
+
Create a JSON dict object from a Group object
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
group: Group = Group(name=json_doc['name'], description=json_doc['description'])
|
|
80
|
+
group.fields = []
|
|
81
|
+
if 'id' in json_doc:
|
|
82
|
+
group.group_id = json_doc['id']
|
|
83
|
+
if 'schemaUri' in json_doc:
|
|
84
|
+
group.schemaUri = json_doc['schemaUri']
|
|
85
|
+
|
|
86
|
+
if 'fields' in json_doc:
|
|
87
|
+
for field in json_doc['fields']:
|
|
88
|
+
gf: GroupField = GroupField(field['id'], field['name'], GroupFieldType(str(field['type'])))
|
|
89
|
+
if 'minOccurs' in field:
|
|
90
|
+
gf.minOccurs = int(field['minOccurs'])
|
|
91
|
+
if 'maxOccurs' in field:
|
|
92
|
+
gf.maxOccurs = int(field['maxOccurs'])
|
|
93
|
+
if 'visible' in field:
|
|
94
|
+
gf.visible = bool(field['visible'])
|
|
95
|
+
if 'editable' in field:
|
|
96
|
+
gf.editable = bool(field['editable'])
|
|
97
|
+
if 'values' in field:
|
|
98
|
+
for v in field['values']:
|
|
99
|
+
gf.values.append(str(v))
|
|
100
|
+
if 'defaultValue' in field:
|
|
101
|
+
gf.default = str(field['defaultValue'])
|
|
102
|
+
if 'indexed' in field:
|
|
103
|
+
gf.indexed = bool(field['indexed'])
|
|
104
|
+
|
|
105
|
+
group.fields.append(gf)
|
|
106
|
+
|
|
107
|
+
return group
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _json_from_object_(group: Group) -> dict:
|
|
111
|
+
"""
|
|
112
|
+
Create a JSON dict object from a Group object
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
fields = []
|
|
116
|
+
for field in group.fields:
|
|
117
|
+
f = {"id": field.field_id, "name": field.name, "type": str(field.field_type.value)}
|
|
118
|
+
f["minOccurs"] = str(field.minOccurs)
|
|
119
|
+
f["maxOccurs"] = str(field.maxOccurs)
|
|
120
|
+
f["visible"] = str(field.visible)
|
|
121
|
+
f["editable"] = str(field.editable)
|
|
122
|
+
if (field.values is not None) and (len(field.values) > 0):
|
|
123
|
+
f["values"] = [item for item in field.values]
|
|
124
|
+
f["defaultValue"] = str(field.default)
|
|
125
|
+
f["indexed"] = str(field.indexed)
|
|
126
|
+
fields.append(f)
|
|
127
|
+
|
|
128
|
+
json_doc = {"name": group.name, "description": group.description, "fields": fields}
|
|
129
|
+
|
|
130
|
+
return json_doc
|
|
131
|
+
|
|
132
|
+
|
|
70
133
|
class MetadataGroupsAPI(AuthenticatedAPI):
|
|
71
134
|
def __init__(self, username: str = None, password: str = None, tenant: str = None, server: str = None,
|
|
72
135
|
use_shared_secret: bool = False, two_fa_secret_key: str = None,
|
|
@@ -100,7 +163,7 @@ class MetadataGroupsAPI(AuthenticatedAPI):
|
|
|
100
163
|
:param group_id: Group ID
|
|
101
164
|
:type group_id: str
|
|
102
165
|
|
|
103
|
-
:return:
|
|
166
|
+
:return:
|
|
104
167
|
:rtype: None
|
|
105
168
|
|
|
106
169
|
"""
|
|
@@ -118,7 +181,46 @@ class MetadataGroupsAPI(AuthenticatedAPI):
|
|
|
118
181
|
logger.error(exception)
|
|
119
182
|
raise exception
|
|
120
183
|
|
|
121
|
-
def
|
|
184
|
+
def add_fields(self, group_id: str, new_fields: List[GroupField]) -> dict:
|
|
185
|
+
"""
|
|
186
|
+
Add new metadata fields to an existing Group
|
|
187
|
+
|
|
188
|
+
The new fields are appended to the end of the group
|
|
189
|
+
|
|
190
|
+
:param group_id: The group ID of the group to update
|
|
191
|
+
:type group_id: str
|
|
192
|
+
|
|
193
|
+
:param new_fields: The list of new fields to add to the group
|
|
194
|
+
:type new_fields: List[GroupField]
|
|
195
|
+
|
|
196
|
+
:return: The updated Metadata Group as a JSON dict
|
|
197
|
+
:rtype: dict
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
this_group: Group = self.group(group_id)
|
|
203
|
+
|
|
204
|
+
for field in new_fields:
|
|
205
|
+
this_group.fields.append(field)
|
|
206
|
+
|
|
207
|
+
doc = _json_from_object_(this_group)
|
|
208
|
+
|
|
209
|
+
headers = {HEADER_TOKEN: self.token, 'Content-Type': 'application/json;charset=UTF-8'}
|
|
210
|
+
url = f'{self.protocol}://{self.server}/api/metadata/groups/{group_id}'
|
|
211
|
+
with self.session.put(url, headers=headers, json=doc) as request:
|
|
212
|
+
if request.status_code == requests.codes.unauthorized:
|
|
213
|
+
self.token = self.__token__()
|
|
214
|
+
return self.add_fields(group_id, new_fields)
|
|
215
|
+
elif request.status_code == requests.codes.created:
|
|
216
|
+
return json.loads(str(request.content.decode('utf-8')))
|
|
217
|
+
else:
|
|
218
|
+
exception = HTTPException(None, request.status_code, request.url, "add_fields",
|
|
219
|
+
request.content.decode('utf-8'))
|
|
220
|
+
logger.error(exception)
|
|
221
|
+
raise exception
|
|
222
|
+
|
|
223
|
+
def add_group(self, group_name: str, group_description: str, fields: List[GroupField]) -> dict:
|
|
122
224
|
"""
|
|
123
225
|
Create a new Metadata Group GroupFields
|
|
124
226
|
|
|
@@ -131,79 +233,69 @@ class MetadataGroupsAPI(AuthenticatedAPI):
|
|
|
131
233
|
:param fields: The list of fields
|
|
132
234
|
:type fields: List[GroupField]
|
|
133
235
|
|
|
134
|
-
:return: JSON
|
|
135
|
-
:rtype:
|
|
236
|
+
:return: The new metadata Group as a JSON dict
|
|
237
|
+
:rtype: dict
|
|
136
238
|
|
|
137
239
|
"""
|
|
138
240
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
fields_str = f"""{{
|
|
148
|
-
"id" : "{field.field_id}",
|
|
149
|
-
"name": "{field.name}",
|
|
150
|
-
"type": "{field.field_type.value}",
|
|
151
|
-
"minOccurs": "{field.minOccurs}",
|
|
152
|
-
"maxOccurs": "{field.maxOccurs}",
|
|
153
|
-
"visible": "{field.visible}", {values}
|
|
154
|
-
"editable": "{field.editable}",
|
|
155
|
-
"defaultValue": "{field.default}",
|
|
156
|
-
"indexed": "{field.indexed}"
|
|
157
|
-
}}"""
|
|
158
|
-
|
|
159
|
-
fields_str_list.append(fields_str)
|
|
160
|
-
|
|
161
|
-
json_doc = f"""{{
|
|
162
|
-
"name" : "{group_name}",
|
|
163
|
-
"description" : "{group_description}",
|
|
164
|
-
"fields" : [ {",".join(fields_str_list)} ]
|
|
165
|
-
}}"""
|
|
166
|
-
|
|
167
|
-
print(json_doc)
|
|
168
|
-
|
|
169
|
-
json_response = self.add_group_json(json_doc)
|
|
170
|
-
group_id = json_response['id']
|
|
171
|
-
return self.group(group_id)
|
|
172
|
-
|
|
173
|
-
def add_group_json(self, json_document: str) -> str:
|
|
241
|
+
group: Group = Group(group_name, group_description)
|
|
242
|
+
group.fields = fields
|
|
243
|
+
|
|
244
|
+
json_document: dict = _json_from_object_(group)
|
|
245
|
+
json_response: dict = self.add_group_json(json_document)
|
|
246
|
+
return json_response
|
|
247
|
+
|
|
248
|
+
def add_group_json(self, json_object: Union[dict, str]) -> dict:
|
|
174
249
|
"""
|
|
175
|
-
|
|
250
|
+
Create a new Metadata Group using a JSON dictionary object or document
|
|
176
251
|
|
|
177
|
-
|
|
178
|
-
|
|
252
|
+
:param json_object: JSON dictionary or string
|
|
253
|
+
:type json_object: dict
|
|
179
254
|
|
|
180
|
-
|
|
181
|
-
|
|
255
|
+
:return: JSON document
|
|
256
|
+
:rtype: dict
|
|
182
257
|
|
|
183
|
-
|
|
258
|
+
"""
|
|
184
259
|
headers = {HEADER_TOKEN: self.token, 'Content-Type': 'application/json;charset=UTF-8'}
|
|
185
260
|
url = f'{self.protocol}://{self.server}/api/metadata/groups/'
|
|
186
|
-
with self.session.post(url, headers=headers, data=json_document) as request:
|
|
187
|
-
if request.status_code == requests.codes.unauthorized:
|
|
188
|
-
self.token = self.__token__()
|
|
189
|
-
return self.add_group_json(json_document)
|
|
190
|
-
elif request.status_code == requests.codes.created:
|
|
191
|
-
return json.loads(str(request.content.decode('utf-8')))
|
|
192
|
-
else:
|
|
193
|
-
exception = HTTPException(None, request.status_code, request.url, "add_group_json",
|
|
194
|
-
request.content.decode('utf-8'))
|
|
195
|
-
logger.error(exception)
|
|
196
|
-
raise exception
|
|
197
261
|
|
|
198
|
-
|
|
262
|
+
if isinstance(json_object, dict):
|
|
263
|
+
with self.session.post(url, headers=headers, json=json_object) as request:
|
|
264
|
+
if request.status_code == requests.codes.unauthorized:
|
|
265
|
+
self.token = self.__token__()
|
|
266
|
+
return self.add_group_json(json_object)
|
|
267
|
+
elif request.status_code == requests.codes.created:
|
|
268
|
+
return json.loads(str(request.content.decode('utf-8')))
|
|
269
|
+
else:
|
|
270
|
+
exception = HTTPException(None, request.status_code, request.url, "add_group_json",
|
|
271
|
+
request.content.decode('utf-8'))
|
|
272
|
+
logger.error(exception)
|
|
273
|
+
raise exception
|
|
274
|
+
|
|
275
|
+
elif isinstance(json_object, str):
|
|
276
|
+
with self.session.post(url, headers=headers, data=json_object) as request:
|
|
277
|
+
if request.status_code == requests.codes.unauthorized:
|
|
278
|
+
self.token = self.__token__()
|
|
279
|
+
return self.add_group_json(json_object)
|
|
280
|
+
elif request.status_code == requests.codes.created:
|
|
281
|
+
return json.loads(str(request.content.decode('utf-8')))
|
|
282
|
+
else:
|
|
283
|
+
exception = HTTPException(None, request.status_code, request.url, "add_group_json",
|
|
284
|
+
request.content.decode('utf-8'))
|
|
285
|
+
logger.error(exception)
|
|
286
|
+
raise exception
|
|
287
|
+
else:
|
|
288
|
+
raise RuntimeError("Argument must be a JSON dictionary or a JSON str")
|
|
289
|
+
|
|
290
|
+
def group_json(self, group_id: str) -> dict:
|
|
199
291
|
"""
|
|
200
|
-
Return a Group as a JSON
|
|
292
|
+
Return a Group as a JSON object
|
|
201
293
|
|
|
202
294
|
:param group_id: The Group id
|
|
203
295
|
:type group_id: str
|
|
204
296
|
|
|
205
297
|
:return: JSON document
|
|
206
|
-
:rtype:
|
|
298
|
+
:rtype: dict
|
|
207
299
|
|
|
208
300
|
"""
|
|
209
301
|
headers = {HEADER_TOKEN: self.token, 'Content-Type': 'application/json;charset=UTF-8'}
|
|
@@ -213,7 +305,7 @@ class MetadataGroupsAPI(AuthenticatedAPI):
|
|
|
213
305
|
self.token = self.__token__()
|
|
214
306
|
return self.group_json(group_id)
|
|
215
307
|
elif request.status_code == requests.codes.ok:
|
|
216
|
-
return str(request.content.decode('utf-8'))
|
|
308
|
+
return json.loads(str(request.content.decode('utf-8')))
|
|
217
309
|
else:
|
|
218
310
|
exception = HTTPException(None, request.status_code, request.url, "group_json",
|
|
219
311
|
request.content.decode('utf-8'))
|
|
@@ -222,47 +314,24 @@ class MetadataGroupsAPI(AuthenticatedAPI):
|
|
|
222
314
|
|
|
223
315
|
def group(self, group_id: str) -> Group:
|
|
224
316
|
"""
|
|
225
|
-
Return a Group object by its
|
|
317
|
+
Return a Group object by its ID
|
|
226
318
|
|
|
227
319
|
:param group_id: The Group id
|
|
228
320
|
:type group_id: str
|
|
229
321
|
|
|
230
|
-
:return:
|
|
322
|
+
:return: The metadata Group Object
|
|
231
323
|
:rtype: Group
|
|
232
324
|
|
|
233
325
|
"""
|
|
234
|
-
json_group = json.loads(self.group_json(group_id))
|
|
235
|
-
group: Group = Group()
|
|
236
|
-
group.group_id = json_group['id']
|
|
237
|
-
group.name = json_group['name']
|
|
238
|
-
group.description = json_group['description']
|
|
239
|
-
group.schemaUri = json_group['schemaUri']
|
|
240
|
-
|
|
241
|
-
for f in json_group['fields']:
|
|
242
|
-
gf: GroupField = GroupField(f['id'], f['name'])
|
|
243
|
-
if 'type' in f:
|
|
244
|
-
gf.field_type = f['type']
|
|
245
|
-
if 'visible' in f:
|
|
246
|
-
gf.visible = f['visible']
|
|
247
|
-
if 'editable' in f:
|
|
248
|
-
gf.editable = f['editable']
|
|
249
|
-
if 'indexed' in f:
|
|
250
|
-
gf.indexed = f['indexed']
|
|
251
|
-
if 'maxOccurs' in f:
|
|
252
|
-
gf.maxOccurs = f['maxOccurs']
|
|
253
|
-
if 'minOccurs' in f:
|
|
254
|
-
gf.minOccurs = f['minOccurs']
|
|
255
|
-
if 'values' in f:
|
|
256
|
-
gf.values = f['values']
|
|
257
|
-
group.fields.append(gf)
|
|
258
|
-
return group
|
|
259
326
|
|
|
260
|
-
|
|
327
|
+
return _object_from_json_(self.group_json(group_id))
|
|
328
|
+
|
|
329
|
+
def groups_json(self) -> List[dict]:
|
|
261
330
|
"""
|
|
262
|
-
Return all the
|
|
331
|
+
Return all the metadata Groups in the tenancy as a list of JSON dict objects
|
|
263
332
|
|
|
264
|
-
:return: JSON
|
|
265
|
-
:rtype:
|
|
333
|
+
:return: List of JSON dictionary object
|
|
334
|
+
:rtype: List[dict]
|
|
266
335
|
|
|
267
336
|
"""
|
|
268
337
|
|
|
@@ -273,28 +342,21 @@ class MetadataGroupsAPI(AuthenticatedAPI):
|
|
|
273
342
|
self.token = self.__token__()
|
|
274
343
|
return self.groups_json()
|
|
275
344
|
elif request.status_code == requests.codes.ok:
|
|
276
|
-
return str(request.content.decode('utf-8'))
|
|
345
|
+
return json.loads(str(request.content.decode('utf-8')))['groups']
|
|
277
346
|
else:
|
|
278
347
|
exception = HTTPException(None, request.status_code, request.url, "groups_json",
|
|
279
348
|
request.content.decode('utf-8'))
|
|
280
349
|
logger.error(exception)
|
|
281
350
|
raise exception
|
|
282
351
|
|
|
283
|
-
def groups(self) ->
|
|
352
|
+
def groups(self) -> Generator[Group, None, None]:
|
|
284
353
|
"""
|
|
285
|
-
Return all the
|
|
354
|
+
Return all the metadata Groups in the tenancy as Group Objects
|
|
286
355
|
|
|
287
|
-
:return:
|
|
288
|
-
:rtype:
|
|
356
|
+
:return: Generator of Group Objects
|
|
357
|
+
:rtype: Group
|
|
289
358
|
|
|
290
359
|
"""
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
group: Group = Group()
|
|
295
|
-
group.group_id = g['id']
|
|
296
|
-
group.name = g['name']
|
|
297
|
-
group.description = g['description']
|
|
298
|
-
group.schemaUri = g['schemaUri']
|
|
299
|
-
return_groups.append(group)
|
|
300
|
-
return return_groups
|
|
360
|
+
|
|
361
|
+
for group in self.groups_json():
|
|
362
|
+
yield _object_from_json_(group)
|
|
@@ -21,7 +21,7 @@ if sys.argv[-1] == 'publish':
|
|
|
21
21
|
# This call to setup() does all the work
|
|
22
22
|
setup(
|
|
23
23
|
name=PKG,
|
|
24
|
-
version="2.8.
|
|
24
|
+
version="2.8.2",
|
|
25
25
|
description="Python library for the Preservica API",
|
|
26
26
|
long_description=README,
|
|
27
27
|
long_description_content_type="text/markdown",
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pyPreservica import *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_cam_get_all_groups_as_objects():
|
|
6
|
+
client = MetadataGroupsAPI()
|
|
7
|
+
assert len(list(client.groups())) > 0
|
|
8
|
+
for g in client.groups():
|
|
9
|
+
assert isinstance(g, Group)
|
|
10
|
+
assert g.group_id is not None
|
|
11
|
+
assert g.name is not None
|
|
12
|
+
assert g.schemaUri is not None
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_cam_get_all_groups_as_JSON():
|
|
16
|
+
client = MetadataGroupsAPI()
|
|
17
|
+
for g in client.groups_json():
|
|
18
|
+
if g['name'] == "digiteek":
|
|
19
|
+
assert g['schemaUri'] == 'http://www.preservica.com/metadata/group/digiteek'
|
|
20
|
+
if g['name'] == 'McD Metadata':
|
|
21
|
+
assert g['schemaUri'] == 'http://www.preservica.com/metadata/group/mcd_metadata'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_can_get_group():
|
|
25
|
+
client = MetadataGroupsAPI()
|
|
26
|
+
for g in client.groups():
|
|
27
|
+
if g.name == "digiteek":
|
|
28
|
+
full_group: Group = client.group(g.group_id)
|
|
29
|
+
assert full_group.name == "digiteek"
|
|
30
|
+
assert full_group.description == "digiteek"
|
|
31
|
+
assert len(full_group.fields) == 19
|
|
32
|
+
break
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_can_add_group_by_object():
|
|
36
|
+
client = MetadataGroupsAPI()
|
|
37
|
+
group1: Group = Group("my_group_name1", "my_group_description1")
|
|
38
|
+
group1.fields.append(GroupField(field_id="attribute_1", name="Attribute 1x", field_type=GroupFieldType.STRING))
|
|
39
|
+
group1.fields.append(GroupField(field_id="attribute_2", name="Attribute 2x", field_type=GroupFieldType.NUMBER))
|
|
40
|
+
group1.fields.append(GroupField(field_id="attribute_3", name="Attribute 3x", field_type=GroupFieldType.DATE))
|
|
41
|
+
|
|
42
|
+
g1: dict = client.add_group(group1.name, group1.description, group1.fields)
|
|
43
|
+
|
|
44
|
+
assert g1['name'] == group1.name
|
|
45
|
+
assert g1['description'] == group1.description
|
|
46
|
+
|
|
47
|
+
assert len(g1['fields']) == 3
|
|
48
|
+
|
|
49
|
+
group1: Group = client.group(g1['id'])
|
|
50
|
+
|
|
51
|
+
client.delete_group(group1.group_id)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_can_add_new_fields_to_group():
|
|
55
|
+
client = MetadataGroupsAPI()
|
|
56
|
+
|
|
57
|
+
group2: Group = Group("test_group_1", "test_group_1_description")
|
|
58
|
+
|
|
59
|
+
assert len(group2.fields) == 0
|
|
60
|
+
|
|
61
|
+
group2.fields.append(GroupField(field_id="attribute_11", name="Attribute 11", field_type=GroupFieldType.STRING))
|
|
62
|
+
group2.fields.append(GroupField(field_id="attribute_22", name="Attribute 22", field_type=GroupFieldType.NUMBER))
|
|
63
|
+
group2.fields.append(GroupField(field_id="attribute_33", name="Attribute 33", field_type=GroupFieldType.DATE))
|
|
64
|
+
|
|
65
|
+
assert len(group2.fields) == 3
|
|
66
|
+
|
|
67
|
+
g2: dict = client.add_group(group2.name, group2.description, group2.fields)
|
|
68
|
+
|
|
69
|
+
assert g2['name'] == group2.name
|
|
70
|
+
assert g2['description'] == group2.description
|
|
71
|
+
|
|
72
|
+
assert len(g2['fields']) == 3
|
|
73
|
+
|
|
74
|
+
group_id = g2['id']
|
|
75
|
+
|
|
76
|
+
group3: Group = client.group(group_id)
|
|
77
|
+
|
|
78
|
+
assert g2['name'] == group3.name
|
|
79
|
+
assert g2['description'] == group3.description
|
|
80
|
+
|
|
81
|
+
new_fields = []
|
|
82
|
+
|
|
83
|
+
new_fields.append(GroupField(field_id="attribute_4", name="Attribute 4", field_type=GroupFieldType.LONG_STRING))
|
|
84
|
+
new_fields.append(GroupField(field_id="attribute_5", name="Attribute 5", field_type=GroupFieldType.NUMBER))
|
|
85
|
+
|
|
86
|
+
client.add_fields(group_id, new_fields)
|
|
87
|
+
|
|
88
|
+
group4: Group = client.group(group_id)
|
|
89
|
+
|
|
90
|
+
assert len(group4.fields) == 5
|
|
91
|
+
|
|
92
|
+
client.delete_group(group_id)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_can_get_group_by_URI():
|
|
96
|
+
client = MetadataGroupsAPI()
|
|
97
|
+
uri = "http://www.preservica.com/metadata/group/mcd_metadata"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|