Skip to content

Commit

Permalink
legacy: fix alternate identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Sep 17, 2023
1 parent d4411dc commit 4e99f80
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 43 deletions.
23 changes: 9 additions & 14 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions site/tests/legacy/deposits/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def test_data():
return dict(
metadata=dict(
access_right="embargoed",
# TODO uncomment when communities are implemented
# communities=[{"identifier": "c1"}],
communities=[{"identifier": "c1"}],
conference_acronym="Some acronym",
conference_dates="Some dates",
conference_place="Some place",
Expand All @@ -41,7 +40,7 @@ def test_data():
grants=[
dict(id="10.13039/501100001665::755021"),
],
# TODO changed previous string ("Some isbn") to a valid isbn
# NOTE: changed previous string ("Some isbn") to a valid isbn
imprint_isbn="978-3-16-148410-0",
imprint_place="Some place",
# TODO changed previous string ("Some publisher") to "Zenodo" which is the hardcoded publisher for now.
Expand Down Expand Up @@ -74,13 +73,11 @@ def test_data():
scheme="doi",
resource_type="dataset",
),
# TODO commented since scheme ads not supported in rdm
# dict(
# identifier="2011ApJS..192...18K",
# relation="isAlternateIdentifier",
# scheme="ads",
# resource_type="publication-article",
# ),
dict(
identifier="2011ApJS..192...18K",
relation="isAlternateIdentifier",
scheme="ads",
),
],
thesis_supervisors=[
dict(name="Doe, John", affiliation="Atlantis"),
Expand Down Expand Up @@ -122,8 +119,7 @@ def expected_record_metadata():
"""Return expected rdm draft metadata."""
return dict(
access_right="embargoed",
# TODO uncomment when communities are implemented
# communities=[{"identifier": "c1"}],
communities=[{"identifier": "c1"}],
conference_acronym="Some acronym",
conference_dates="Some dates",
conference_place="Some place",
Expand Down Expand Up @@ -177,6 +173,11 @@ def expected_record_metadata():
scheme="doi",
resource_type="dataset",
),
dict(
identifier="2011ApJS..192...18K",
relation="isAlternateIdentifier",
scheme="ads",
),
],
thesis_university="Some thesis_university",
contributors=[
Expand Down
14 changes: 7 additions & 7 deletions site/tests/legacy/deposits/test_rest_api_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_input_output(
client = client_with_login

# Create
res = client.post(deposit_url, data=json.dumps(test_data), headers=headers)
res = client.post(deposit_url, json=test_data, headers=headers)
assert res.status_code == 201
links = res.json["links"]

Expand All @@ -66,13 +66,13 @@ def test_input_output(
}
)

ignored_keys = set()

# doi is returned as a top level key (and not inside metadata)
ignored_keys.add("doi")

differences = list(
dictdiffer.diff(data["metadata"], expected_record_metadata, ignore=ignored_keys)
dictdiffer.diff(
data["metadata"],
expected_record_metadata,
# doi is returned as a top level key (and not inside metadata)
ignore={"doi"},
)
)

assert not differences
15 changes: 6 additions & 9 deletions site/zenodo_rdm/legacy/deserializers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ class Meta:

unknown = EXCLUDE

# TODO add later
# if not data:
# raise ValidationError("Empty metadata is not accepted")

@pre_load
def split_identifiers(self, data, **kwargs):
"""Splits alternate and related identifiers."""
Expand All @@ -133,7 +129,7 @@ def split_identifiers(self, data, **kwargs):
alternate_identifiers = []
related_identifiers = []
for identifier in input_identifiers:
if identifier.get("relation", "") == "isAlternateIdentifier":
if identifier.get("relation") == "isAlternateIdentifier":
alternate_identifiers.append(identifier)
else:
related_identifiers.append(identifier)
Expand Down Expand Up @@ -162,7 +158,10 @@ def split_identifiers(self, data, **kwargs):
references = fields.Method(deserialize="load_references")
language = fields.Method(deserialize="load_language")
related_identifiers = fields.Method(deserialize="load_related_identifiers")
identifiers = fields.Method(deserialize="load_alternate_identifiers")
identifiers = fields.Method(
deserialize="load_alternate_identifiers",
data_key="alternate_identifiers",
)

@post_load(pass_original=True)
def load_upload_type(self, result, original, **kwargs):
Expand Down Expand Up @@ -434,9 +433,7 @@ def load_alternate_identifiers(self, obj):

for legacy_identifier in obj:
rdm_identifier = identifier_schema.load(
{
"identifier": legacy_identifier["identifier"],
}
{"identifier": legacy_identifier["identifier"]}
)

alternate_identifiers.append(rdm_identifier)
Expand Down
1 change: 1 addition & 0 deletions site/zenodo_rdm/legacy/serializers/schemas/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def to_camel_case(string, split_char=" "):
"requires": "requires",
"isobsoletedby": "isObsoletedBy",
"obsoletes": "obsoletes",
"isalternateidentifier": "isAlternateIdentifier",
}


Expand Down
3 changes: 2 additions & 1 deletion site/zenodo_rdm/legacy/serializers/schemas/legacyjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def hook_alternate_identifiers(self, data, **kwargs):
related_identifiers = data.get("related_identifiers", [])
for identifier in alternate_identifiers:
related_identifier = {
"relation_type": {"id": "isAlternateIdentifier"},
"relation_type": {"id": "isalternateidentifier"},
"identifier": identifier["identifier"],
"scheme": identifier["scheme"],
}
related_identifiers.append(related_identifier)
if related_identifiers:
Expand Down

0 comments on commit 4e99f80

Please sign in to comment.