Skip to content

Commit 90fdaa5

Browse files
committed
tests: test_full_migration: Update and complete test cases
1 parent 11643a5 commit 90fdaa5

File tree

2 files changed

+151
-9
lines changed

2 files changed

+151
-9
lines changed

tests/cds-rdm/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
)
2424
from invenio_access.models import ActionRoles
2525
from invenio_access.permissions import superuser_access, system_identity
26+
27+
# from invenio_accounts import testutils
2628
from invenio_accounts.models import Role
2729
from invenio_administration.permissions import administration_access_action
2830
from invenio_app import factory as app_factory

tests/cds-rdm/test_full_migration.py

Lines changed: 149 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# 2788738 -> user with orcid
1+
# 2788738 -> user with orcid # TODO
22
# 2684743 -> many fields
33
# 2889522 -> multiple file versions
44
# 2051872 -> multiple version with custom fields
55
# 2207587 -> multiple custom fields
6-
# 2783103 -> file missing # TODO
7-
# 2783104 -> file restricted # TODO
8-
# 2046076 -> irregular experiment field value # TODO
9-
# 1597985 -> contains ALEPH identifier # TODO
10-
# 2041388 -> custom affiliation # TODO
11-
# 2779426 -> clump of keywords # TODO
12-
# 2294138 -> author with inspire id # TODO
6+
# 2783103 -> file missing
7+
# 2783104 -> file restricted
8+
# 2046076 -> irregular experiment field value
9+
# 1597985 -> contains ALEPH identifier
10+
# 2041388 -> custom affiliation
11+
# 2779426 -> clump of keywords
12+
# 2294138 -> author with inspire id
1313
import json
1414
from pathlib import Path
1515

@@ -24,6 +24,7 @@
2424

2525

2626
def suite_multi_field(record):
27+
"""2684743."""
2728
dict_rec = record.to_dict()
2829
assert dict_rec["created"] == "2019-07-29T00:00:00+00:00"
2930
assert dict_rec["versions"]["index"] == 1
@@ -122,8 +123,9 @@ def suite_multi_field(record):
122123

123124

124125
def orcid_id(record):
125-
dict_rec = record.to_dict()
126+
"""2788738."""
126127
# TODO pre-create user with orcid
128+
dict_rec = record.to_dict()
127129
assert dict_rec["metadata"]["creators"] == [
128130
{
129131
"person_or_org": {
@@ -138,11 +140,13 @@ def orcid_id(record):
138140

139141

140142
def multiple_versions(record, record_state):
143+
"""2889522."""
141144
dict_rec = record.to_dict()
142145
assert dict_rec["versions"]["index"] == 2
143146

144147

145148
def multiple_versions_with_cs(record):
149+
"""2051872."""
146150
dict_rec = record.to_dict()
147151
assert dict_rec["versions"]["index"] == 2
148152
assert dict_rec["custom_fields"] == {
@@ -151,6 +155,126 @@ def multiple_versions_with_cs(record):
151155
}
152156

153157

158+
def multiple_custom_fields(record):
159+
"""2207587."""
160+
dict_rec = record.to_dict()
161+
assert "custom_fields" in dict_rec
162+
assert dict_rec["custom_fields"] == {
163+
"cern:accelerators": [
164+
{"id": "CERN AD", "title": {"en": "CERN AD"}},
165+
{"id": "CERN AD", "title": {"en": "CERN AD"}},
166+
],
167+
}
168+
169+
170+
def file_missing(record):
171+
"""2783103."""
172+
dict_rec = record.to_dict()
173+
assert "files" in dict_rec
174+
assert dict_rec["files"]["enabled"] == False
175+
assert dict_rec["files"]["count"] == 0
176+
assert "media_files" in dict_rec
177+
assert dict_rec["media_files"]["enabled"] == False
178+
assert dict_rec["media_files"]["count"] == 0
179+
180+
181+
def file_restricted(record):
182+
"""2783104."""
183+
dict_rec = record.to_dict()
184+
assert "access" in dict_rec
185+
assert dict_rec["access"]["record"] == "public"
186+
assert dict_rec["access"]["files"] == "restricted"
187+
assert "files" in dict_rec
188+
assert dict_rec["files"]["enabled"] == True
189+
assert dict_rec["files"]["count"] == 1
190+
191+
192+
def irregular_exp_field(record):
193+
"""2046076."""
194+
dict_rec = record.to_dict()
195+
assert "custom_fields" in dict_rec
196+
assert dict_rec["custom_fields"] == {
197+
"cern:accelerators": [
198+
{"id": "CERN AD", "title": {"en": "CERN AD"}},
199+
],
200+
}
201+
assert "subjects" in dict_rec["metadata"]
202+
assert dict_rec["metadata"]["subjects"] == [
203+
{
204+
"id": "Computing and Computers",
205+
"subject": "Computing and Computers",
206+
"scheme": "CERN",
207+
},
208+
{"subject": "COMPASS"},
209+
{"subject": "DAQ"},
210+
{"subject": "FPGA"},
211+
{"subject": "GUI"},
212+
{"subject": "COMPASS NA58"},
213+
]
214+
215+
216+
def custom_affiliation(record):
217+
"""2041388."""
218+
dict_rec = record.to_dict()
219+
for creator in dict_rec["metadata"]["creators"]:
220+
assert "affiliations" in creator
221+
for affiliation in creator["affiliations"]:
222+
assert "ror" != affiliation.get("scheme", None)
223+
224+
225+
def contains_aleph(record):
226+
"""1597985."""
227+
dict_rec = record.to_dict()
228+
assert "identifiers" in dict_rec["metadata"]
229+
assert dict_rec["metadata"]["identifiers"] == [
230+
{"identifier": "CERN-STUDENTS-Note-2013-181", "scheme": "cds_ref"},
231+
{"identifier": "000733613CER", "scheme": "aleph"},
232+
]
233+
234+
235+
def contains_keywords(record):
236+
"""2779426."""
237+
dict_rec = record.to_dict()
238+
assert "subjects" in dict_rec["metadata"]
239+
assert dict_rec["metadata"]["subjects"] == [
240+
{
241+
"id": "Detectors and Experimental Techniques",
242+
"subject": "Detectors and Experimental Techniques",
243+
"scheme": "CERN",
244+
},
245+
{
246+
"subject": "Gaseous detectors, Drift tubes, CSC, MSGC, Microdot chambers, Micromegas, Micropattern, GEM, TPC, RPC, TGC, RICH, electron avalanche, Garfield++, Magboltz"
247+
},
248+
]
249+
250+
251+
def author_with_inspire(record):
252+
"""2294138."""
253+
dict_rec = record.to_dict()
254+
assert "contributors" in dict_rec["metadata"]
255+
assert dict_rec["metadata"]["contributors"] == [
256+
{
257+
"person_or_org": {
258+
"type": "personal",
259+
"name": "Glatzer, Julian",
260+
"given_name": "Julian",
261+
"family_name": "Glatzer",
262+
"identifiers": [
263+
{"identifier": "INSPIRE-00013837", "scheme": "inspire"},
264+
{"identifier": "2073275", "scheme": "lcds"},
265+
],
266+
},
267+
"role": {
268+
"id": "other",
269+
"title": {"en": "Other"},
270+
},
271+
"affiliations": [
272+
{"name": "Universitat Autonoma de Barcelona ES"},
273+
],
274+
},
275+
]
276+
277+
154278
def test_full_migration_stream(
155279
test_app,
156280
minimal_restricted_record,
@@ -211,3 +335,19 @@ def test_full_migration_stream(
211335
multiple_versions(loaded_rec, record)
212336
if record["legacy_recid"] == "2051872":
213337
multiple_versions_with_cs(loaded_rec)
338+
if record["legacy_recid"] == "2207587":
339+
multiple_custom_fields(loaded_rec)
340+
if record["legacy_recid"] == "2783103":
341+
file_missing(loaded_rec)
342+
if record["legacy_recid"] == "2783104":
343+
file_restricted(loaded_rec)
344+
if record["legacy_recid"] == "2046076":
345+
irregular_exp_field(loaded_rec)
346+
if record["legacy_recid"] == "2041388":
347+
custom_affiliation(loaded_rec)
348+
if record["legacy_recid"] == "1597985":
349+
contains_aleph(loaded_rec)
350+
if record["legacy_recid"] == "2779426":
351+
contains_keywords(loaded_rec)
352+
if record["legacy_recid"] == "2294138":
353+
author_with_inspire(loaded_rec)

0 commit comments

Comments
 (0)