-
Notifications
You must be signed in to change notification settings - Fork 3
/
model_test.py
327 lines (302 loc) · 11.1 KB
/
model_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 SciCat Project (https://github.com/SciCatProject/scitacean)
import uuid
import pytest
from dateutil.parser import parse as parse_date
from scitacean import PID, Client, DatasetType
from scitacean.model import DerivedDataset, RawDataset, Technique
from .common.backend import skip_if_not_backend
@pytest.fixture
def client(
request,
scicat_access,
scicat_backend,
):
skip_if_not_backend(request)
return Client.from_credentials(
url=scicat_access.url, **scicat_access.functional_credentials
)
def test_derived_dataset_default_values(client):
dset = DerivedDataset(
accessGroups=["access1"],
contactEmail="contact@email.com",
creationTime=parse_date("2000-01-01T01:01:01.000Z"),
inputDatasets=[PID(prefix="PID.SAMPLE.PREFIX", pid="abcd")],
investigator="inv@esti.gator",
owner="owner",
ownerGroup="ownerGroup",
sourceFolder="/source/folder",
usedSoftware=["software1"],
type=DatasetType.DERIVED,
)
pid = client.scicat.create_dataset_model(dset).pid
finalized = client.scicat.get_dataset_model(pid)
# Inputs
assert finalized.accessGroups == ["access1"]
assert finalized.contactEmail == "contact@email.com"
assert finalized.creationTime == parse_date("2000-01-01T01:01:01.000Z")
assert finalized.inputDatasets == [PID(prefix="PID.SAMPLE.PREFIX", pid="abcd")]
assert finalized.investigator == "inv@esti.gator"
assert finalized.owner == "owner"
assert finalized.ownerGroup == "ownerGroup"
assert finalized.sourceFolder == "/source/folder"
assert finalized.usedSoftware == ["software1"]
# Default values
assert finalized.createdAt # some non-empty str
assert finalized.createdBy # some non-empty str
assert finalized.classification # some non-empty str
assert finalized.datasetName # some non-empty str
assert finalized.history == []
assert finalized.isPublished is None
assert finalized.pid # some non-empty str
assert finalized.techniques == []
assert finalized.updatedAt # some non-empty str
assert finalized.version # some non-empty str
# Left empty
assert finalized.description is None is None
assert finalized.jobParameters is None
assert finalized.jobLogData is None
assert finalized.keywords is None
assert finalized.license is None
assert finalized.numberOfFiles is None
assert finalized.numberOfFilesArchived is None
assert finalized.orcidOfOwner is None
assert finalized.ownerEmail is None
assert finalized.packedSize is None
assert finalized.scientificMetadata is None
assert finalized.sharedWith is None
assert finalized.size is None
assert finalized.sourceFolderHost is None
assert finalized.validationStatus is None
def test_raw_dataset_default_values(client):
dset = RawDataset(
accessGroups=["access1"],
contactEmail="contact@email.com",
creationTime=parse_date("2000-01-01T01:01:01.000Z"),
owner="owner",
ownerGroup="ownerGroup",
principalInvestigator="inv@esti.gator",
sourceFolder="/source/folder",
type=DatasetType.RAW,
)
pid = client.scicat.create_dataset_model(dset).pid
finalized = client.scicat.get_dataset_model(pid)
# Inputs
assert finalized.accessGroups == ["access1"]
assert finalized.contactEmail == "contact@email.com"
assert finalized.creationTime == parse_date("2000-01-01T01:01:01.000Z")
assert finalized.owner == "owner"
assert finalized.ownerGroup == "ownerGroup"
assert finalized.principalInvestigator == "inv@esti.gator"
assert finalized.sourceFolder == "/source/folder"
# Default values
assert finalized.createdAt # some non-empty str
assert finalized.createdBy # some non-empty str
assert finalized.classification # some non-empty str
assert finalized.datasetName # some non-empty str
assert finalized.history == []
assert finalized.isPublished is None
assert finalized.pid # some non-empty str
assert finalized.techniques == []
assert finalized.updatedAt # some non-empty str
assert finalized.version # some non-empty str
# Left empty
assert finalized.creationLocation is None
assert finalized.dataFormat is None
assert finalized.description is None
assert finalized.endTime is None
assert finalized.instrumentId is None
assert finalized.keywords is None
assert finalized.license is None
assert finalized.numberOfFiles is None
assert finalized.numberOfFilesArchived is None
assert finalized.orcidOfOwner is None
assert finalized.ownerEmail is None
assert finalized.packedSize is None
assert finalized.proposalId is None
assert finalized.sampleId is None
assert finalized.scientificMetadata is None
assert finalized.sharedWith is None
assert finalized.size is None
assert finalized.sourceFolderHost is None
assert finalized.validationStatus is None
def test_derived_dataset_overwritten_values(client):
dset = DerivedDataset(
accessGroups=["access1"],
classification="classes",
contactEmail="contact@email.com",
createdAt=parse_date("2001-01-01T01:01:01.000Z"),
createdBy="creator",
creationTime=parse_date("2000-01-01T01:01:01.000Z"),
datasetName="datasetName",
description="description",
history=[
DerivedDataset(
accessGroups=["access1"],
contactEmail="contact@email.com",
creationTime=parse_date("2000-01-01T01:01:01.000Z"),
inputDatasets=[PID(prefix="PID.SAMPLE.PREFIX", pid="abcd")],
investigator="inv@esti.gator",
owner="owner",
ownerGroup="ownerGroup",
sourceFolder="/source/folder",
usedSoftware=["software1"],
type=DatasetType.DERIVED,
).dict()
],
inputDatasets=[PID(prefix="PID.SAMPLE.PREFIX", pid="abcd")],
investigator="inv@esti.gator",
isPublished=True,
jobParameters={"tiredness": "great"},
jobLogData="all-good",
keywords=["keyword1"],
license="the-license",
numberOfFiles=123,
numberOfFilesArchived=42,
orcidOfOwner="https://orcid.org/0000-0002-3761-3201",
owner="owner",
ownerEmail="owner@email.eu",
ownerGroup="ownerGroup",
packedSize=551,
pid=PID(pid=f"derived-id-{uuid.uuid4()}"),
scientificMetadata={"sci1": ["data1"]},
sharedWith=["shared1"],
size=6123,
sourceFolder="/source/folder",
sourceFolderHost="/host/source/folder",
techniques=[Technique(name="technique1", pid="technique1-id")],
type=DatasetType.DERIVED,
updatedAt=parse_date("2001-01-01T01:01:01.000Z"),
usedSoftware=["software1"],
validationStatus="not-validated",
version="9999.00.888",
)
pid = client.scicat.create_dataset_model(dset).pid
finalized = client.scicat.get_dataset_model(pid)
preserved_inputs = [
"accessGroups",
"classification",
"contactEmail",
"creationTime",
"datasetName",
"description",
"inputDatasets",
"investigator",
"isPublished",
"jobParameters",
"jobLogData",
"keywords",
"license",
"numberOfFiles",
"numberOfFilesArchived",
"orcidOfOwner",
"owner",
"ownerEmail",
"ownerGroup",
"packedSize",
"scientificMetadata",
"sharedWith",
"size",
"sourceFolder",
"sourceFolderHost",
"techniques",
"usedSoftware",
"validationStatus",
]
overwritten_inputs = ["createdAt", "createdBy", "updatedAt", "pid", "version"]
for key in preserved_inputs:
assert getattr(finalized, key) == getattr(dset, key)
for key in overwritten_inputs:
assert getattr(finalized, key) != getattr(dset, key)
assert finalized.history == [] # This is a new dataset, so the history is empty.
def test_raw_dataset_overwritten_values(client):
dset = RawDataset(
accessGroups=["access1"],
classification="classes",
contactEmail="contact@email.com",
createdAt=parse_date("2001-01-01T01:01:01.000Z"),
createdBy="creator",
creationLocation="the-realverse",
creationTime=parse_date("2000-01-01T01:01:01.000Z"),
dataFormat="data-format",
datasetName="datasetName",
description="description",
endTime=parse_date("2010-01-01T01:01:01.000Z"),
history=[
RawDataset(
accessGroups=["access1"],
contactEmail="contact@email.com",
creationTime=parse_date("2000-01-01T01:01:01.000Z"),
owner="owner",
ownerGroup="ownerGroup",
principalInvestigator="inv@esti.gator",
sourceFolder="/source/folder",
type=DatasetType.RAW,
).dict()
],
instrumentId="instrument-id",
isPublished=True,
keywords=["keyword1"],
license="the-license",
numberOfFiles=123,
numberOfFilesArchived=42,
orcidOfOwner="https://orcid.org/0000-0002-3761-3201",
owner="owner",
ownerEmail="owner@email.eu",
ownerGroup="ownerGroup",
packedSize=551,
pid=PID(pid=f"derived-id-{uuid.uuid4()}"),
principalInvestigator="inv@esti.gator",
proposalId="proposal-id",
sampleId="sample-id",
scientificMetadata={"sci1": ["data1"]},
sharedWith=["shared1"],
size=6123,
sourceFolder="/source/folder",
sourceFolderHost="/host/source/folder",
techniques=[Technique(name="technique1", pid="technique1-id")],
type=DatasetType.RAW,
updatedAt=parse_date("2001-01-01T01:01:01.000Z"),
validationStatus="not-validated",
version="9999.00.888",
)
pid = client.scicat.create_dataset_model(dset).pid
finalized = client.scicat.get_dataset_model(pid)
preserved_inputs = [
"accessGroups",
"classification",
"contactEmail",
"creationLocation",
"creationTime",
"dataFormat",
"datasetName",
"description",
"endTime",
"instrumentId",
"isPublished",
"keywords",
"license",
"numberOfFiles",
"numberOfFilesArchived",
"orcidOfOwner",
"owner",
"ownerEmail",
"ownerGroup",
"packedSize",
"principalInvestigator",
"proposalId",
"sampleId",
"scientificMetadata",
"sharedWith",
"size",
"sourceFolder",
"sourceFolderHost",
"techniques",
"validationStatus",
]
overwritten_inputs = ["createdAt", "createdBy", "updatedAt", "pid", "version"]
for key in preserved_inputs:
assert getattr(finalized, key) == getattr(dset, key)
for key in overwritten_inputs:
assert getattr(finalized, key) != getattr(dset, key)
assert finalized.history == [] # This is a new dataset, so the history is empty.