-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openaire: migrated openaire backend.
- Loading branch information
1 parent
c350874
commit 6639000
Showing
13 changed files
with
793 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 CERN. | ||
# | ||
# Zenodo-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""OpenAIRE tests.""" | ||
|
||
|
||
from zenodo_rdm.openaire.proxies import current_openaire | ||
|
||
|
||
def test_openaire_type(app): | ||
"""Test OpenAIRE type.""" | ||
|
||
state = current_openaire.state | ||
assert set(state.inverse_openaire_community_map.keys()) == set(["c1", "c2", "c3"]) | ||
|
||
assert set(state.inverse_openaire_community_map["c1"]) == set(["foo", "bar"]) | ||
assert set(state.inverse_openaire_community_map["c2"]) == set(["foo"]) | ||
assert set(state.inverse_openaire_community_map["c3"]) == set(["bar"]) | ||
|
||
assert set(state.openaire_communities.keys()) == set(["foo", "bar"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 CERN. | ||
# | ||
# Invenio-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Test for OpenAIRE helpers.""" | ||
|
||
from copy import deepcopy | ||
|
||
import pytest | ||
|
||
from zenodo_rdm.openaire.utils import ( | ||
OA_DATASET, | ||
OA_OTHER, | ||
OA_PUBLICATION, | ||
OA_SOFTWARE, | ||
openaire_id, | ||
openaire_link, | ||
openaire_type, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def minimal_open_record(minimal_record): | ||
"""Minimal record with open access.""" | ||
r = deepcopy(minimal_record) | ||
|
||
# Test only open records | ||
r["access"] = {"record": "public", "files": "public"} | ||
return r | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"resource_type,expected", | ||
[ | ||
("image-photo", OA_DATASET), | ||
("other", OA_OTHER), | ||
("publication-book", OA_PUBLICATION), | ||
("publication", OA_PUBLICATION), | ||
], | ||
) | ||
def test_openaire_type_serialization( | ||
running_app, minimal_open_record, resource_type, expected | ||
): | ||
"""Test OpenAIRE type. | ||
It uses only open records. | ||
""" | ||
r = deepcopy(minimal_open_record) | ||
|
||
r["metadata"]["resource_type"] = {"id": resource_type} | ||
|
||
assert openaire_type(r) == expected | ||
|
||
|
||
def test_embardoged_publication_serialization(running_app, minimal_record): | ||
"""Test OpenAIRE serialization for an embargoed (restricted) publication.""" | ||
r = deepcopy(minimal_record) | ||
|
||
r["metadata"]["resource_type"] = {"id": "publication"} | ||
|
||
# Non-open publications | ||
r["access_right"] = { | ||
"files": "restricted", | ||
"record": "restricted", | ||
"embargo": {"active": True}, | ||
} | ||
assert openaire_type(r) is None | ||
|
||
|
||
def test_funded_publication_serialization(running_app, minimal_record): | ||
"""Test a publication that is funded (e.g. has grants).""" | ||
r = deepcopy(minimal_record) | ||
|
||
r["metadata"]["resource_type"] = {"id": "publication"} | ||
|
||
# with grants | ||
r["metadata"]["funding"] = [{"funder": {"id": "someid"}, "award": {"id": "someid"}}] | ||
assert openaire_type(r) == OA_PUBLICATION | ||
|
||
# in ecfunded community | ||
del r["metadata"]["funding"] | ||
r["parent"] = {"communities": {"ids": ["ecfunded"]}} | ||
assert openaire_type(r) == OA_PUBLICATION | ||
r["parent"] = {"communities": {"ids": ["zenodo"]}} | ||
assert openaire_type(r) is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"resource_type,expected", | ||
[ | ||
("software", "od______2659::47287d1800c112499a117ca17aa1909d"), | ||
("other", "od______2659::47287d1800c112499a117ca17aa1909d"), | ||
("dataset", "od______2659::204007f516ddcf0a452c2f22d48695ca"), | ||
("publication", "od______2659::47287d1800c112499a117ca17aa1909d"), | ||
], | ||
) | ||
def test_openaire_id(running_app, minimal_open_record, resource_type, expected): | ||
"""Test OpenAIRE ID.""" | ||
r = deepcopy(minimal_open_record) | ||
r["pids"] = { | ||
"doi": {"identifier": "10.5281/zenodo.123"}, | ||
"oai": {"identifier": "oai:zenodo.org:123"}, | ||
} | ||
r["metadata"]["resource_type"] = {"id": resource_type} | ||
assert openaire_id(r) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"resource_type,oatype", | ||
[ | ||
("software", OA_SOFTWARE), | ||
("image-photo", OA_DATASET), | ||
("other", OA_OTHER), | ||
("dataset", OA_DATASET), | ||
("publication", OA_PUBLICATION), | ||
], | ||
) | ||
def test_openaire_link(running_app, minimal_open_record, resource_type, oatype): | ||
"""Test OpenAIRE ID.""" | ||
r = deepcopy(minimal_open_record) | ||
|
||
doi = "10.5281/zenodo.123" | ||
r["pids"] = { | ||
"doi": {"identifier": doi}, | ||
"oai": {"identifier": "oai:zenodo.org:123"}, | ||
} | ||
r["metadata"]["resource_type"] = {"id": resource_type} | ||
assert openaire_link(r) == f"https://explore.openaire.eu/search/{oatype}?pid={doi}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 CERN. | ||
# | ||
# Zenodo-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Tests for openaire serializer.""" | ||
|
||
import pytest | ||
from zenodo_rdm.openaire.serializers import OpenAIREV1Serializer | ||
from invenio_rdm_records.proxies import current_rdm_records_service as records_service | ||
from invenio_access.permissions import system_identity | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def openaire_serializer(): | ||
yield OpenAIREV1Serializer() | ||
|
||
|
||
def test_record_serializer(running_app, minimal_record, openaire_serializer): | ||
serializer = openaire_serializer | ||
|
||
# Disable files, we don't care about files for this test. | ||
minimal_record["files"]["enabled"] = False | ||
|
||
# We use system identity since we just want a record to be serialized, we don't care about permissions. | ||
draft = records_service.create(system_identity, minimal_record) | ||
record = records_service.publish(id_=draft.id, identity=system_identity) | ||
|
||
serialized_record = serializer.dump_obj(record) | ||
assert serialized_record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 CERN. | ||
# | ||
# Zendo-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""OpenAire related configs.""" | ||
|
||
# OpenAIRE API configs | ||
OPENAIRE_API_USERNAME = "" | ||
"""OpenAIRE API authentication - username.""" | ||
|
||
OPENAIRE_API_PASSWORD = "" | ||
"""OpenAIRE API authentication - password.""" | ||
|
||
OPENAIRE_API_URL = "http://dev.openaire.research-infrastructures.eu/is/mvc/api/results" | ||
"""OpenAIRE API endpoint.""" | ||
|
||
# Beta configs | ||
OPENAIRE_API_URL_BETA = None | ||
|
||
# Other configs | ||
OPENAIRE_COMMUNITIES = {} | ||
"""OpenAIRE communities resource subtypes configuration.""" | ||
|
||
OPENAIRE_PORTAL_URL = "https://explore.openaire.eu" | ||
"""OpenAIRE portal url.""" | ||
|
||
OPENAIRE_DIRECT_INDEXING_ENABLED = False | ||
"""Enable sending published records for direct indexing at OpenAIRE.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 CERN. | ||
# | ||
# Zenodo-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""OpenAIRE errors.""" | ||
|
||
|
||
class OpenAIRERequestError(Exception): | ||
"""Error for failed requests on the OpenAIRE API.""" |
Oops, something went wrong.