diff --git a/Pipfile.lock b/Pipfile.lock index 10b94093..d02c9a1d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -955,7 +955,7 @@ "sha256:404d4fd47725e760c5caee1126736d8242d0ac7bac79b643277517f7be073ee7", "sha256:e5d524a3ea09fe64674e1ebbc19cc8b76c5c3342fffd4e41f3c0e3ca350eaa3a" ], - "markers": "python_version >= '3.7'", + "index": "pypi", "version": "==12.0.0b2.dev29" }, "invenio-assets": { @@ -1088,6 +1088,7 @@ "sha256:353c4aba5ddb334ee45b801a2bc0b22e73e363163a776f0b3360d850dc3013ff", "sha256:8c01c4dcc5604b996d30bf69dc35948536639943f5cb3d0da5240105ea08b533" ], + "index": "pypi", "version": "==1.3.2" }, "invenio-mail": { @@ -1163,11 +1164,11 @@ }, "invenio-rdm-records": { "hashes": [ - "sha256:2e4e7461c5e2108288a63af141d61b0885ec333dbb988494203dfcecab366da9", - "sha256:dba0acf272c3731b8ff0089b4dbc133c301107dc8d98c8f98ab0bb10805ee01b" + "sha256:a92acc88758375fa43604c43f243d0feedba760dca622ecb7a2682adf01f38fe", + "sha256:eaacc03472519c504f9e04667301ab6e47db38b330a57f4b6f6c425a05081ba1" ], "markers": "python_version >= '3.7'", - "version": "==4.23.1" + "version": "==4.23.2" }, "invenio-records": { "hashes": [ @@ -1302,7 +1303,6 @@ "sha256:45a2c3a529296870a97b7de34eda4a31bee16bc7bf954e07d39abe49caf8f887" ], "index": "pypi", - "markers": "python_version >= '3.9'", "version": "==8.15.0" }, "isbnlib": { @@ -1380,7 +1380,6 @@ "sha256:a870ad254da1a8ca84b6a2905cac29d265f805acc57af304784962a2aa6508f6" ], "index": "pypi", - "markers": "python_version >= '3.7'", "version": "==4.17.3" }, "jupyter-client": { @@ -2671,7 +2670,7 @@ "sha256:8d36afa7616d8ab714608411b4a3b13e58f463aee519024578e062e141dce20f", "sha256:8f135f6502756bde6b2a9b28989df5fbe87c9970cecaa69041edcce7f0589b14" ], - "markers": "python_version >= '3.6'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", "version": "==1.26.16" }, "uwsgi": { @@ -2777,11 +2776,11 @@ "version": "==0.12.0" }, "zenodo-legacy": { - "editable": "True", + "editable": true, "path": "./legacy" }, "zenodo-rdm": { - "editable": "True", + "editable": true, "path": "./site" }, "zipp": { @@ -3103,7 +3102,6 @@ "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6" ], "index": "pypi", - "markers": "python_full_version >= '3.8.0'", "version": "==5.12.0" }, "itsdangerous": { @@ -3281,7 +3279,6 @@ "sha256:1d339b004f764d6cd0f06e690f6dd748df3d62e6fe1a692d6a5500ac2c5b75a5" ], "index": "pypi", - "markers": "python_version >= '2.7'", "version": "==0.3.12" }, "pytest-cov": { @@ -3306,7 +3303,6 @@ "sha256:a2eb2535b7d45f98c4f43e1bc82ed485541703b470eee52771645bb8fd970df9" ], "index": "pypi", - "markers": "python_version >= '3.7'", "version": "==2.1.4" }, "pytest-isort": { @@ -3367,7 +3363,6 @@ "sha256:9a5160e1ea90688d5963ba09a2dcd8bdd526620edbb65c328728f1b2228d5ab5" ], "index": "pypi", - "markers": "python_version >= '3.9'", "version": "==7.2.6" }, "sphinxcontrib-applehelp": { @@ -3447,7 +3442,7 @@ "sha256:8d36afa7616d8ab714608411b4a3b13e58f463aee519024578e062e141dce20f", "sha256:8f135f6502756bde6b2a9b28989df5fbe87c9970cecaa69041edcce7f0589b14" ], - "markers": "python_version >= '3.6'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", "version": "==1.26.16" }, "werkzeug": { diff --git a/site/tests/legacy/deposits/conftest.py b/site/tests/legacy/deposits/conftest.py index ed234da4..7d402b6b 100644 --- a/site/tests/legacy/deposits/conftest.py +++ b/site/tests/legacy/deposits/conftest.py @@ -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", @@ -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. @@ -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"), @@ -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", @@ -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=[ diff --git a/site/tests/legacy/deposits/test_rest_api_metadata.py b/site/tests/legacy/deposits/test_rest_api_metadata.py index 51f2083b..6fff3c0c 100644 --- a/site/tests/legacy/deposits/test_rest_api_metadata.py +++ b/site/tests/legacy/deposits/test_rest_api_metadata.py @@ -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"] @@ -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 diff --git a/site/zenodo_rdm/legacy/deserializers/metadata.py b/site/zenodo_rdm/legacy/deserializers/metadata.py index eb1fd7df..44b6544e 100644 --- a/site/zenodo_rdm/legacy/deserializers/metadata.py +++ b/site/zenodo_rdm/legacy/deserializers/metadata.py @@ -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.""" @@ -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) @@ -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): @@ -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) diff --git a/site/zenodo_rdm/legacy/serializers/schemas/common.py b/site/zenodo_rdm/legacy/serializers/schemas/common.py index adc898d6..db060910 100644 --- a/site/zenodo_rdm/legacy/serializers/schemas/common.py +++ b/site/zenodo_rdm/legacy/serializers/schemas/common.py @@ -55,6 +55,7 @@ def to_camel_case(string, split_char=" "): "requires": "requires", "isobsoletedby": "isObsoletedBy", "obsoletes": "obsoletes", + "isalternateidentifier": "isAlternateIdentifier", } diff --git a/site/zenodo_rdm/legacy/serializers/schemas/legacyjson.py b/site/zenodo_rdm/legacy/serializers/schemas/legacyjson.py index 149fe417..eb8de57b 100644 --- a/site/zenodo_rdm/legacy/serializers/schemas/legacyjson.py +++ b/site/zenodo_rdm/legacy/serializers/schemas/legacyjson.py @@ -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: