diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5f2dbcf..b7397f7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -92,6 +92,7 @@ repos: hooks: - id: typos args: [--force-exclude] + exclude: tests/conftest - repo: https://github.com/FHPythonUtils/LicenseCheck/ rev: b2b50f4d40c95b15478279a7a00553a1dc2925ef # frozen: 2024.2 diff --git a/tests/cassettes/repository.yaml b/tests/cassettes/repository.yaml index af87948..55ed435 100644 --- a/tests/cassettes/repository.yaml +++ b/tests/cassettes/repository.yaml @@ -1,91 +1,4 @@ interactions: -- request: - body: '' - headers: - accept: - - text/xml; charset=utf-8 - accept-encoding: - - gzip, deflate - connection: - - keep-alive - host: - - www.re3data.org - user-agent: - - python-re3data/0.1.0 - method: GET - uri: https://www.re3data.org/api/beta/repository/r3d100010468 - response: - body: - string: !!binary | - H4sIAAAAAAAAA+UaXW/bOPK9wP4Hnh8Ou0D0YcdJ21zrvZzjbgOkSeC0i8O9FIw0tnmRRC1JxXH/ - 0f6O/WM3Q1GWbMtJ2jh36O1DEIvzyeHMcEjOm5/v0oTdgtJCZm87XT/sMMgiGYts+rZTmIn3qvPz - 4MWbv3iegv2YG+5LNWVX0QxSziZSMTMDdgI6UiI3yIPJCRuDBq6iGTtBfPzKpRZGKgHaZ7+WoljP - 7+0hXQTpNSjWC7t9n8VSHHVDv7ff7QUozQ/DQ89D4Wo/PnLSGaqb6SMceduZGZMfBcF8PvcbugXa - 6hb0vF7HYd9psYI937eIvTDsBv/8cFZOxhOZNjyLAKm0OCq5nMmIG2uZB4Uxh1GOrCAhNHDfv+Jv - /07HncELxtzEnHkWNLQcXFKfxpAZMRGgBgjphqh02D989SbYjtfkUzE/5ymwhGfTgk/hbQeyaWfw - L8hkLCtOTcxWFp/GZwOapMZZfrGkdnbr9ITWRt5Q8N3x6VjPuEIn+1wt+sFB2A8aAH++6MN0ss79 - gWk2wOPx6cnR1XD8OQz73d7rJzLKkrvP3YNXh93+oxjFj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tTVw4shxoPCMJYr/qlEDHQU/oj3gZbaRrqL8VcjIenJ065FtmQ - zaifKb6s+zVq27YBa9LfCk416Qee4YGK3nLwgFDSbUIa76BgOHlP9SBUeUkr0J7Z1geXj7DDYWdA - 3WNDYYB9cFiu7cy9oLbwu1dgZXlXOsdR5PPIL27oMs0+h+mgIvG0o9EBfeKCgFfD7lFiLZTaDfIs - tqJlpAvq6t7pv2UeK9eLtsp9vEUUWlXdaNeVxoRmkcQMUDa1fJzJVMsMj+0FluW67CwcukDB830M - dz5zlFj8a3acGJSFiZuV/8oeBffSpplIczwQMer7oCdVYkLvwTN7OZDaHhyXo1gVjpr92D3ww67f - w6PpT6vSRHYLmZB1L9NiSe+z6nqDXagcg44uC6WK677IBZtKwzg17oBHU7aqzjk1OHnXCj/QBvhV - dj+tCj69T7BrlyJOCS8y9BdkK8zMzbTSK08KXfVLkZyqiYsvG3s82/Sk6iuT5nWKjws44nrBCrtp - lC/XkAqPF0aSbaOl61I7V56ANTcuqmvuKrOP1axuQJIZZb6q800zXaBgVO4ENfqHvLN3OKXAPcwP - aKIEFoFNiMGQOqrGMAmWhq+RnReANxFJQnIq1fzqTF46YTOLGrVotOIcet39KoVWkBo7Qbt8sn0/ - g7rrp0RvgF5U4dBs/qxGbEfn4D9yCaEjmSsAAA== - headers: - Cache-Control: - - no-cache, private - Connection: - - Keep-Alive - Content-Encoding: - - gzip - Content-Length: - - '2536' - Content-Type: - - text/xml; charset=UTF-8 - Date: - - Tue, 21 May 2024 13:55:12 GMT - Keep-Alive: - - timeout=5, max=100 - Link: - - /api/beta/repositories; rel="index" - Server: - - Apache/2.4.41 (Ubuntu) - Vary: - - Accept-Encoding - status: - code: 200 - message: OK - request: body: '' headers: diff --git a/tests/conftest.py b/tests/conftest.py index 0aef041..93653b5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -60,3 +60,187 @@ def mock_repository_list_route(respx_mock: MockRouter) -> Route: return respx_mock.get("https://www.re3data.org/api/beta/repositories").mock( return_value=httpx.Response(httpx.codes.OK, text=REPOSITORY_LIST_XML) ) + + +REPOSITORY_GET_XML: str = """ + + + + r3d100010468 + Zenodo + https://zenodo.org/ + FAIRsharing_doi:10.25504/FAIRsharing.wy4egf + RRID:SCR_004129 + RRID:nlx_158614 + ZENODO builds and operates a simple and innovative service that + enables researchers, scientists, EU projects and institutions to share and showcase + multidisciplinary research results (data and publications) that are not part of the existing + institutional or subject-based repositories of the research communities. + ZENODO enables researchers, scientists, EU projects and institutions to: + easily share the long tail of small research results in a wide variety of formats including + text, spreadsheets, audio, video, and images across all fields of science. + display their research results and get credited by making the research results citable and + integrate them into existing reporting lines to funding agencies like the European Commission. + easily access and reuse shared research results. + https://zenodo.org/contact + info@zenodo.org + other + 2.916.709 results + 2013-05-08 + + eng + 1 Humanities and Social Sciences + 2 Life Sciences + 3 Natural Sciences + 4 Engineering Sciences + https://about.zenodo.org/ + Archived data + Audiovisual data + Images + Networkbased data + Plain text + Raw data + Scientific and statistical data formats + Source code + Standard office documents + Structured graphics + Structured text + other + dataProvider + FAIR + multidisciplinary + + European Commission, Horizon 2020 + EEC + funding + non-profit + + https://research-and-innovation.ec.europa.eu/funding/funding-opportunities/funding-programmes-and-open-calls/horizon-2020_en + 2014 + 2020 + https://research-and-innovation.ec.europa.eu/contact-us_en + + + European Commission, Research & Innovation, Seventh Framework Programm - FP7 + FP7 + EEC + funding + non-profit + https://commission.europa.eu/research-and-innovation_en + + + https://research-and-innovation.ec.europa.eu/contact-us_en + + + European Organization for Nuclear Research + CERN + Centre Européen pour la Recherche Nucléaire + EEC + funding + general + technical + non-profit + https://home.cern/ + ROR:01ggx4157 + + + https://about.zenodo.org/contact/ + + + OpenAIRE + Open Access Infrastructure for Research in Europa + EEC + funding + general + non-profit + https://www.openaire.eu/ + ROR:019kf3481 + RRID:SCR_013740 + + + https://www.openaire.eu/contact-us + + + Policies + https://about.zenodo.org/policies/ + + + Terms of use + https://about.zenodo.org/terms/ + + + open + + + CC0 + https://creativecommons.org/publicdomain/zero/1.0/ + + + closed + + + embargoed + + + open + + + restricted + registration + + + CC + https://creativecommons.org/ + + + CC0 + https://creativecommons.org/publicdomain/zero/1.0/ + + + other + https://about.zenodo.org/policies/ + + + restricted + registration + + + Policies + https://about.zenodo.org/policies/ + + + other + + yes + https://zenodo.org/oai2d + https://developers.zenodo.org/ + DOI + https://about.zenodo.org/ + ORCID + yes + no + + DataCite Metadata Schema + + http://www.dcc.ac.uk/resources/metadata-standards/datacite-metadata-schema + + + Dublin Core + http://www.dcc.ac.uk/resources/metadata-standards/dublin-core + + Zenodo is covered by Thomson Reuters Data Citation Index. Zenodo uses Altmetric metrics and provides impact information in the form of software citations (15.01.2019). Zenodo uses invenio repository software. OpenAIRE Orphan Record Repository got a make-over and was re-branded as ZENODO. Zenodo uses Invenio repository software. ZENODO was launched within the OpenAIREplus project as part of a European-wide research infrastructure. Easy upload and semi-automatic metadata completion by communication with existing online services such as DropBox for upload, Mendeley/ORCID/CrossRef/OpenAIRE for upload and pre-filling metadata. + 2013-06-13 + 2023-04-26 + + +""" + + +@pytest.fixture() +def mock_repository_get_route(respx_mock: MockRouter) -> Route: + return respx_mock.get("https://www.re3data.org/api/beta/repository/r3d100010468").mock( + return_value=httpx.Response(httpx.codes.OK, text=REPOSITORY_GET_XML) + ) diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py index cb49ea6..679832b 100644 --- a/tests/integration/test_cli.py +++ b/tests/integration/test_cli.py @@ -99,34 +99,28 @@ def test_repository_get_without_repository_id(mock_repository_list_route: Route) assert "Missing argument" in result.output -@pytest.mark.default_cassette("repository.yaml") -@pytest.mark.vcr() -def test_repository_get_with_repository_id_default_return_type(zenodo_id: str) -> None: +def test_repository_get_with_repository_id_default_return_type( + mock_repository_get_route: Route, zenodo_id: str +) -> None: result = runner.invoke(app, ["repository", "get", zenodo_id]) assert result.exit_code == 0 assert "" in result.output assert "r3d100010468" in result.output -@pytest.mark.default_cassette("repository.yaml") -@pytest.mark.vcr() -def test_repository_get_with_repository_id_xml(zenodo_id: str) -> None: +def test_repository_get_with_repository_id_xml(mock_repository_get_route: Route, zenodo_id: str) -> None: result = runner.invoke(app, ["repository", "get", zenodo_id, "--return-type", "xml"]) assert result.exit_code == 0 assert "" in result.output assert "r3d100010468" in result.output -@pytest.mark.default_cassette("repository.yaml") -@pytest.mark.vcr() -def test_repository_get_with_repository_id_response(zenodo_id: str) -> None: +def test_repository_get_with_repository_id_response(mock_repository_get_route: Route, zenodo_id: str) -> None: result = runner.invoke(app, ["repository", "get", zenodo_id, "--return-type", "response"]) assert result.exit_code == 0 assert "" in result.output -@pytest.mark.default_cassette("repository.yaml") -@pytest.mark.vcr() def test_repository_get_with_repository_id_invalid_return_type(zenodo_id: str) -> None: result = runner.invoke(app, ["repository", "get", zenodo_id, "--return-type", "json"]) assert result.exit_code == 2 diff --git a/tests/integration/test_client.py b/tests/integration/test_client.py index f0417d0..562f74e 100644 --- a/tests/integration/test_client.py +++ b/tests/integration/test_client.py @@ -23,7 +23,7 @@ def test_client_list_repositories_default_return_type(client: Client, mock_repos assert "" in response -def test_client_list_repositories_invalid_return_type(client: Client, mock_repository_list_route: Route) -> None: +def test_client_list_repositories_invalid_return_type(client: Client) -> None: with pytest.raises(ValueError, match="Invalid `return_type`"): client.repositories.list(return_type="json") @@ -42,9 +42,9 @@ def test_client_list_repositories_response(client: Client, mock_repository_list_ assert response.status_code == httpx.codes.OK -@pytest.mark.default_cassette("repository.yaml") -@pytest.mark.vcr() -def test_client_get_single_repository_default_return_type(client: Client, zenodo_id: str) -> None: +def test_client_get_single_repository_default_return_type( + client: Client, mock_repository_get_route: Route, zenodo_id: str +) -> None: response = client.repositories.get(zenodo_id) assert isinstance(response, str) assert '' in response @@ -52,9 +52,7 @@ def test_client_get_single_repository_default_return_type(client: Client, zenodo assert "r3d100010468" in response -@pytest.mark.default_cassette("repository.yaml") -@pytest.mark.vcr() -def test_client_get_single_repository_xml(client: Client, zenodo_id: str) -> None: +def test_client_get_single_repository_xml(client: Client, mock_repository_get_route: Route, zenodo_id: str) -> None: response = client.repositories.get(zenodo_id, return_type="xml") assert isinstance(response, str) assert '' in response @@ -62,9 +60,9 @@ def test_client_get_single_repository_xml(client: Client, zenodo_id: str) -> Non assert "r3d100010468" in response -@pytest.mark.default_cassette("repository.yaml") -@pytest.mark.vcr() -def test_client_get_single_repository_response(client: Client, zenodo_id: str) -> None: +def test_client_get_single_repository_response( + client: Client, mock_repository_get_route: Route, zenodo_id: str +) -> None: response = client.repositories.get(zenodo_id, return_type="response") assert isinstance(response, httpx.Response) assert response.status_code == httpx.codes.OK