From 81af1bbbc429115b9d011dbb7af84a1255681252 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Mon, 22 Jul 2024 17:14:20 +0200 Subject: [PATCH 1/7] introduce test user 2 api key for missing licences integration test --- tests/conftest.py | 5 +++++ tests/integration_test_20_processing.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5ce7bdd..ef5e309 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,6 +35,11 @@ def api_key(api_root_url: str) -> str: return key +@pytest.fixture +def api_key_test_user_2() -> str: + return "00000000-0000-3000-abcd-000000000001" + + @pytest.fixture def api_key_anon() -> str: return "00112233-4455-6677-c899-aabbccddeeff" diff --git a/tests/integration_test_20_processing.py b/tests/integration_test_20_processing.py index e408927..c7d5364 100644 --- a/tests/integration_test_20_processing.py +++ b/tests/integration_test_20_processing.py @@ -49,10 +49,10 @@ def test_validate_constraints(api_root_url: str) -> None: def test_collection_missing_licence( - api_root_url: str, api_key_anon: str, request_year: str + api_root_url: str, api_key_test_user_2: str, request_year: str ) -> None: collection_id = "test-adaptor-mars" - headers = {"PRIVATE-TOKEN": api_key_anon} + headers = {"PRIVATE-TOKEN": api_key_test_user_2} proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) process = proc.process(collection_id) From bdb3798379e9ab52113ed626e2361794b2fc2a75 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 24 Jul 2024 10:21:13 +0200 Subject: [PATCH 2/7] fix integration-test --- tests/integration_test_20_processing.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/integration_test_20_processing.py b/tests/integration_test_20_processing.py index c7d5364..940d3df 100644 --- a/tests/integration_test_20_processing.py +++ b/tests/integration_test_20_processing.py @@ -49,24 +49,16 @@ def test_validate_constraints(api_root_url: str) -> None: def test_collection_missing_licence( - api_root_url: str, api_key_test_user_2: str, request_year: str + api_root_url: str, api_key_test_user_2: str ) -> None: - collection_id = "test-adaptor-mars" + collection_id = "satellite-total-column-water-vapour-land-ocean" headers = {"PRIVATE-TOKEN": api_key_test_user_2} proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) process = proc.process(collection_id) with pytest.raises(RuntimeError, match="403 Client Error"): _ = process.execute( - inputs=dict( - product_type="reanalysis", - variable="temperature", - year=request_year, - month="01", - day="01", - time="00:00", - level="1000", - ), + inputs={}, ) From a508dd3c223e2e7c97cea15dec9507bfdb772384 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 24 Jul 2024 11:37:17 +0200 Subject: [PATCH 3/7] add test for anonymous user --- tests/integration_test_20_processing.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/integration_test_20_processing.py b/tests/integration_test_20_processing.py index 940d3df..5d44be1 100644 --- a/tests/integration_test_20_processing.py +++ b/tests/integration_test_20_processing.py @@ -62,6 +62,15 @@ def test_collection_missing_licence( ) +def test_collection_anonymous_user(api_root_url: str, api_key_anon: str) -> None: + collection_id = "test-adaptor-mars" + headers = {"PRIVATE-TOKEN": api_key_anon} + proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) + process = proc.process(collection_id) + response = process.execute(inputs={}) + assert "message" in response.json + + def test_jobs_list(api_root_url: str, api_key: str, request_year: str) -> None: collection_id = "test-adaptor-dummy" headers = {"PRIVATE-TOKEN": api_key} From f19a9a011a11c05f0a56d993d7d2773940635cf6 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 24 Jul 2024 14:43:42 +0200 Subject: [PATCH 4/7] change test dataset --- tests/integration_test_20_processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_test_20_processing.py b/tests/integration_test_20_processing.py index 5d44be1..96301a9 100644 --- a/tests/integration_test_20_processing.py +++ b/tests/integration_test_20_processing.py @@ -51,7 +51,7 @@ def test_validate_constraints(api_root_url: str) -> None: def test_collection_missing_licence( api_root_url: str, api_key_test_user_2: str ) -> None: - collection_id = "satellite-total-column-water-vapour-land-ocean" + collection_id = "test-adaptor-observation-repository-gnss" headers = {"PRIVATE-TOKEN": api_key_test_user_2} proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) process = proc.process(collection_id) From c1d2218f7061818e1f8ecb4859eff19e2a616b52 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Thu, 25 Jul 2024 10:57:49 +0200 Subject: [PATCH 5/7] update integration tests --- tests/conftest.py | 30 +++++-------------- tests/integration_test_20_processing.py | 12 ++++---- tests/integration_test_30_remote.py | 26 ++++++++-------- .../integration_test_50_legacy_api_client.py | 12 ++++---- 4 files changed, 32 insertions(+), 48 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ef5e309..bcd2a5c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,6 @@ from typing import TYPE_CHECKING, Any import pytest -import requests if TYPE_CHECKING: from cads_api_client import ApiClient @@ -18,31 +17,16 @@ def api_root_url() -> str: @pytest.fixture -def api_key(api_root_url: str) -> str: - if key := os.getenv("CADS_API_KEY"): - return key - - # default to test user 1 - key = "00000000-0000-4000-a000-000000000000" - - # Accept all licences - result = requests.get(f"{api_root_url}/catalogue/v1/vocabularies/licences") - requests.patch( - f"{api_root_url}/profiles/v1/account/licences", - json=result.json(), - headers={"PRIVATE-TOKEN": key}, - ) +def api_key_test() -> str: + key = os.getenv("CADS_TEST_KEY") + if key is None: + pytest.skip("CADS_TEST_KEY is not defined") return key -@pytest.fixture -def api_key_test_user_2() -> str: - return "00000000-0000-3000-abcd-000000000001" - - @pytest.fixture def api_key_anon() -> str: - return "00112233-4455-6677-c899-aabbccddeeff" + return os.getenv("CADS_ANON_KEY", "00112233-4455-6677-c899-aabbccddeeff") @pytest.fixture @@ -62,7 +46,7 @@ def temp_environ() -> Any: @pytest.fixture -def api_client(api_root_url: str, api_key: str) -> ApiClient: +def api_client(api_root_url: str, api_key_test: str) -> ApiClient: from cads_api_client import ApiClient - return ApiClient(url=api_root_url, key=api_key) + return ApiClient(url=api_root_url, key=api_key_test) diff --git a/tests/integration_test_20_processing.py b/tests/integration_test_20_processing.py index 96301a9..67b339e 100644 --- a/tests/integration_test_20_processing.py +++ b/tests/integration_test_20_processing.py @@ -49,17 +49,15 @@ def test_validate_constraints(api_root_url: str) -> None: def test_collection_missing_licence( - api_root_url: str, api_key_test_user_2: str + api_root_url: str, api_key_test: str, request_year: str ) -> None: collection_id = "test-adaptor-observation-repository-gnss" - headers = {"PRIVATE-TOKEN": api_key_test_user_2} + headers = {"PRIVATE-TOKEN": api_key_test} proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) process = proc.process(collection_id) with pytest.raises(RuntimeError, match="403 Client Error"): - _ = process.execute( - inputs={}, - ) + _ = process.execute(inputs={}) def test_collection_anonymous_user(api_root_url: str, api_key_anon: str) -> None: @@ -71,9 +69,9 @@ def test_collection_anonymous_user(api_root_url: str, api_key_anon: str) -> None assert "message" in response.json -def test_jobs_list(api_root_url: str, api_key: str, request_year: str) -> None: +def test_jobs_list(api_root_url: str, api_key_anon: str, request_year: str) -> None: collection_id = "test-adaptor-dummy" - headers = {"PRIVATE-TOKEN": api_key} + headers = {"PRIVATE-TOKEN": api_key_anon} proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) process = proc.process(collection_id) diff --git a/tests/integration_test_30_remote.py b/tests/integration_test_30_remote.py index fe56059..3f887bd 100644 --- a/tests/integration_test_30_remote.py +++ b/tests/integration_test_30_remote.py @@ -14,9 +14,11 @@ def test_from_collection_to_process(api_root_url: str) -> None: assert isinstance(res, processing.Process) -def test_collection_submit(api_root_url: str, api_key: str, request_year: str) -> None: +def test_collection_submit( + api_root_url: str, api_key_anon: str, request_year: str +) -> None: collection_id = "test-adaptor-dummy" - headers = {"PRIVATE-TOKEN": api_key} + headers = {"PRIVATE-TOKEN": api_key_anon} cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) @@ -30,10 +32,10 @@ def test_collection_submit(api_root_url: str, api_key: str, request_year: str) - def test_collection_retrieve_with_dummy_adaptor( - api_root_url: str, api_key: str, request_year: str, tmpdir: py.path.local + api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local ) -> None: collection_id = "test-adaptor-dummy" - headers = {"PRIVATE-TOKEN": api_key} + headers = {"PRIVATE-TOKEN": api_key_anon} cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) @@ -49,10 +51,10 @@ def test_collection_retrieve_with_dummy_adaptor( def test_collection_retrieve_with_url_cds_adaptor( - api_root_url: str, api_key: str, request_year: str, tmpdir: py.path.local + api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local ) -> None: collection_id = "test-adaptor-url" - headers = {"PRIVATE-TOKEN": api_key} + headers = {"PRIVATE-TOKEN": api_key_anon} cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) @@ -84,10 +86,10 @@ def test_collection_retrieve_with_url_cds_adaptor( def test_collection_retrieve_with_direct_mars_cds_adaptor( - api_root_url: str, api_key: str, request_year: str, tmpdir: py.path.local + api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local ) -> None: collection_id = "test-adaptor-direct-mars" - headers = {"PRIVATE-TOKEN": api_key} + headers = {"PRIVATE-TOKEN": api_key_anon} cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) @@ -112,10 +114,10 @@ def test_collection_retrieve_with_direct_mars_cds_adaptor( def test_collection_retrieve_with_mars_cds_adaptor( - api_root_url: str, api_key: str, request_year: str, tmpdir: py.path.local + api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local ) -> None: collection_id = "test-adaptor-mars" - headers = {"PRIVATE-TOKEN": api_key} + headers = {"PRIVATE-TOKEN": api_key_anon} cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) @@ -138,10 +140,10 @@ def test_collection_retrieve_with_mars_cds_adaptor( @pytest.mark.skip(reason="discontinued adaptor") def test_collection_retrieve_with_legacy_cds_adaptor( - api_root_url: str, api_key: str, request_year: str, tmpdir: py.path.local + api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local ) -> None: collection_id = "test-adaptor-legacy" - headers = {"PRIVATE-TOKEN": api_key} + headers = {"PRIVATE-TOKEN": api_key_anon} cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) diff --git a/tests/integration_test_50_legacy_api_client.py b/tests/integration_test_50_legacy_api_client.py index 81d4477..e56c9e1 100644 --- a/tests/integration_test_50_legacy_api_client.py +++ b/tests/integration_test_50_legacy_api_client.py @@ -5,8 +5,8 @@ from cads_api_client import legacy_api_client -def test_retrieve(tmp_path: pathlib.Path, api_root_url: str, api_key: str) -> None: - client = legacy_api_client.LegacyApiClient(url=api_root_url, key=api_key) +def test_retrieve(tmp_path: pathlib.Path, api_root_url: str, api_key_anon: str) -> None: + client = legacy_api_client.LegacyApiClient(url=api_root_url, key=api_key_anon) collection_id = "test-adaptor-dummy" request = {"size": 1} @@ -25,10 +25,10 @@ def test_retrieve(tmp_path: pathlib.Path, api_root_url: str, api_key: str) -> No @pytest.mark.parametrize("quiet", [True, False]) def test_quiet( - caplog: pytest.LogCaptureFixture, api_root_url: str, api_key: str, quiet: bool + caplog: pytest.LogCaptureFixture, api_root_url: str, api_key_anon: str, quiet: bool ) -> None: client = legacy_api_client.LegacyApiClient( - url=api_root_url, key=api_key, quiet=quiet + url=api_root_url, key=api_key_anon, quiet=quiet ) client.retrieve("test-adaptor-dummy", {}) records = [record for record in caplog.records if record.levelname == "INFO"] @@ -37,8 +37,8 @@ def test_quiet( @pytest.mark.parametrize("debug", [True, False]) def test_debug( - caplog: pytest.LogCaptureFixture, api_root_url: str, api_key: str, debug: bool + caplog: pytest.LogCaptureFixture, api_root_url: str, api_key_anon: str, debug: bool ) -> None: - legacy_api_client.LegacyApiClient(url=api_root_url, key=api_key, debug=debug) + legacy_api_client.LegacyApiClient(url=api_root_url, key=api_key_anon, debug=debug) records = [record for record in caplog.records if record.levelname == "DEBUG"] assert records if debug else not records From 392eead4885e4d7227e69a8489bf3fb3a5036d99 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Thu, 1 Aug 2024 08:51:18 +0200 Subject: [PATCH 6/7] cleanup tests --- README.md | 4 +- notebooks/cads_api_client_test.ipynb | 13 +- notebooks/cads_api_constraints_test.ipynb | 40 +---- ...ads_api_filters_and_pagination_tests.ipynb | 24 +-- notebooks/cads_api_licences_tests.ipynb | 15 +- tests/conftest.py | 36 +--- tests/integration_test_10_catalogue.py | 12 +- tests/integration_test_20_processing.py | 44 ++--- tests/integration_test_30_remote.py | 61 ++++--- tests/integration_test_40_api_client.py | 14 +- .../integration_test_50_legacy_api_client.py | 18 +- tests/integration_test_60_features.py | 13 +- tests/integration_test_70_real_datasets.py | 166 ------------------ tests/test_10_config.py | 7 +- 14 files changed, 94 insertions(+), 373 deletions(-) delete mode 100644 tests/integration_test_70_real_datasets.py diff --git a/README.md b/README.md index 0d0a200..324b4df 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,14 @@ The `ApiClient` needs the `url` to the API root and a valid API `key` to access You can also set the `CADS_API_URL` and `CADS_API_KEY` environment variables. It is possible (but not recommended) to use the API key of one of the test users, -`00000000-0000-4000-a000-000000000000`. This is used in anonymous tests and +`00112233-4455-6677-c899-aabbccddeeff`. This is used in anonymous tests and it is designed to be the least performant option to access the system. Draft Python API: ```python >>> import os ->>> cads_api_key = os.getenv("CADS_API_KEY", "00000000-0000-4000-a000-000000000000") +>>> cads_api_key = os.getenv("CADS_API_KEY", "00112233-4455-6677-c899-aabbccddeeff") >>> import cads_api_client >>> client = cads_api_client.ApiClient(cads_api_key) diff --git a/notebooks/cads_api_client_test.ipynb b/notebooks/cads_api_client_test.ipynb index 4c021ae..3ee6243 100644 --- a/notebooks/cads_api_client_test.ipynb +++ b/notebooks/cads_api_client_test.ipynb @@ -21,17 +21,6 @@ "import cads_api_client" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "10798c3d", - "metadata": {}, - "outputs": [], - "source": [ - "api_url = os.getenv(\"CADS_API_ROOT_URL\", \"http://cds2-dev.copernicus-climate.eu/api\")\n", - "api_url" - ] - }, { "cell_type": "markdown", "id": "622e6c14", @@ -51,7 +40,7 @@ "metadata": {}, "outputs": [], "source": [ - "client = cads_api_client.ApiClient(url=api_url, key=\"00112233-4455-6677-c899-aabbccddeeff\")\n", + "client = cads_api_client.ApiClient(key=\"00112233-4455-6677-c899-aabbccddeeff\")\n", "client" ] }, diff --git a/notebooks/cads_api_constraints_test.ipynb b/notebooks/cads_api_constraints_test.ipynb index 6cf9fd7..76798d3 100644 --- a/notebooks/cads_api_constraints_test.ipynb +++ b/notebooks/cads_api_constraints_test.ipynb @@ -33,28 +33,6 @@ "import cads_processing_api_service" ] }, - { - "cell_type": "code", - "execution_count": 3, - "id": "b76bb911", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'http://cds2-dev.copernicus-climate.eu/api'" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "api_url = os.getenv(\"CADS_API_URL\", \"http://cds2-dev.copernicus-climate.eu/api\")\n", - "api_url" - ] - }, { "cell_type": "markdown", "id": "4336b457", @@ -65,24 +43,12 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "4916eb9b", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "ApiClient(key='00112233-4455-6677-c899-aabbccddeeff', url='http://cds2-dev.copernicus-climate.eu/api')" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "client = cads_api_client.ApiClient(url=api_url, key=\"00112233-4455-6677-c899-aabbccddeeff\")\n", - "client" + "client = cads_api_client.ApiClient(key=\"00112233-4455-6677-c899-aabbccddeeff\")" ] }, { diff --git a/notebooks/cads_api_filters_and_pagination_tests.ipynb b/notebooks/cads_api_filters_and_pagination_tests.ipynb index d64d613..009ee23 100644 --- a/notebooks/cads_api_filters_and_pagination_tests.ipynb +++ b/notebooks/cads_api_filters_and_pagination_tests.ipynb @@ -29,28 +29,6 @@ "## Client instantiation" ] }, - { - "cell_type": "code", - "execution_count": 2, - "id": "a873e0ad", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'http://cds2-dev.copernicus-climate.eu/api'" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "api_url = os.getenv(\"CADS_API_ROOT_URL\", \"http://cds2-dev.copernicus-climate.eu/api\")\n", - "api_url" - ] - }, { "cell_type": "code", "execution_count": 3, @@ -58,7 +36,7 @@ "metadata": {}, "outputs": [], "source": [ - "client = cads_api_client.ApiClient(url=api_url, key=\"00112233-4455-6677-c899-aabbccddeeff\")" + "client = cads_api_client.ApiClient(key=\"00112233-4455-6677-c899-aabbccddeeff\")" ] }, { diff --git a/notebooks/cads_api_licences_tests.ipynb b/notebooks/cads_api_licences_tests.ipynb index 8440232..5b8d3b0 100644 --- a/notebooks/cads_api_licences_tests.ipynb +++ b/notebooks/cads_api_licences_tests.ipynb @@ -40,19 +40,6 @@ "## Client instantiation" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "a873e0ad", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "api_url = os.getenv(\"CADS_API_ROOT_URL\", \"http://cds2-dev.copernicus-climate.eu/api\")\n", - "api_url" - ] - }, { "cell_type": "code", "execution_count": null, @@ -60,7 +47,7 @@ "metadata": {}, "outputs": [], "source": [ - "client = cads_api_client.ApiClient(url=api_url, key=\"00000000-0000-4000-a000-000000000000\")\n", + "client = cads_api_client.ApiClient()\n", "client" ] }, diff --git a/tests/conftest.py b/tests/conftest.py index bcd2a5c..d4ba101 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,7 @@ from __future__ import annotations import os -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING import pytest @@ -10,43 +10,19 @@ @pytest.fixture -def api_root_url() -> str: +def api_url() -> str: from cads_api_client import config return config.get_config("url") @pytest.fixture -def api_key_test() -> str: - key = os.getenv("CADS_TEST_KEY") - if key is None: - pytest.skip("CADS_TEST_KEY is not defined") - return key +def api_anon_key() -> str: + return os.getenv("CADS_API_ANON_KEY", "00112233-4455-6677-c899-aabbccddeeff") @pytest.fixture -def api_key_anon() -> str: - return os.getenv("CADS_ANON_KEY", "00112233-4455-6677-c899-aabbccddeeff") - - -@pytest.fixture -def request_year() -> str: - return os.environ.get("CADS_TEST_YEAR", "2016") - - -@pytest.fixture() -def temp_environ() -> Any: - """Create a modifiable environment that affect only the test scope.""" - old_environ = dict(os.environ) - - yield os.environ - - os.environ.clear() - os.environ.update(old_environ) - - -@pytest.fixture -def api_client(api_root_url: str, api_key_test: str) -> ApiClient: +def api_anon_client(api_url: str, api_anon_key: str) -> ApiClient: from cads_api_client import ApiClient - return ApiClient(url=api_root_url, key=api_key_test) + return ApiClient(url=api_url, key=api_anon_key) diff --git a/tests/integration_test_10_catalogue.py b/tests/integration_test_10_catalogue.py index 3d578fb..01b8a15 100644 --- a/tests/integration_test_10_catalogue.py +++ b/tests/integration_test_10_catalogue.py @@ -1,8 +1,8 @@ from cads_api_client import catalogue -def test_collections(api_root_url: str) -> None: - cat = catalogue.Catalogue(f"{api_root_url}/catalogue") +def test_collections(api_url: str) -> None: + cat = catalogue.Catalogue(f"{api_url}/catalogue") res: catalogue.Collections | None = cat.collections() @@ -22,8 +22,8 @@ def test_collections(api_root_url: str) -> None: assert expected_collection_id in collection_ids -def test_collections_limit(api_root_url: str) -> None: - cat = catalogue.Catalogue(f"{api_root_url}/catalogue") +def test_collections_limit(api_url: str) -> None: + cat = catalogue.Catalogue(f"{api_url}/catalogue") collections = cat.collections(params={"limit": 1}) res = collections.next() @@ -32,9 +32,9 @@ def test_collections_limit(api_root_url: str) -> None: assert res.response.status_code == 200 -def test_collection(api_root_url: str) -> None: +def test_collection(api_url: str) -> None: collection_id = "test-adaptor-mars" - cat = catalogue.Catalogue(f"{api_root_url}/catalogue") + cat = catalogue.Catalogue(f"{api_url}/catalogue") res = cat.collection(collection_id) diff --git a/tests/integration_test_20_processing.py b/tests/integration_test_20_processing.py index 67b339e..b19ed08 100644 --- a/tests/integration_test_20_processing.py +++ b/tests/integration_test_20_processing.py @@ -3,8 +3,8 @@ from cads_api_client import processing -def test_processes(api_root_url: str) -> None: - proc = processing.Processing(f"{api_root_url}/retrieve") +def test_processes(api_url: str) -> None: + proc = processing.Processing(f"{api_url}/retrieve") res = proc.processes() @@ -17,8 +17,8 @@ def test_processes(api_root_url: str) -> None: assert len(res.process_ids()) == 10 -def test_processes_limit(api_root_url: str) -> None: - proc = processing.Processing(f"{api_root_url}/retrieve") +def test_processes_limit(api_url: str) -> None: + proc = processing.Processing(f"{api_url}/retrieve") processes = proc.processes(params={"limit": 1}) res = processes.next() @@ -27,9 +27,9 @@ def test_processes_limit(api_root_url: str) -> None: assert res.response.status_code == 200 -def test_process(api_root_url: str) -> None: +def test_process(api_url: str) -> None: process_id = "test-adaptor-dummy" - proc = processing.Processing(f"{api_root_url}/retrieve") + proc = processing.Processing(f"{api_url}/retrieve") res = proc.process(process_id) @@ -39,40 +39,28 @@ def test_process(api_root_url: str) -> None: assert isinstance(res.json["links"], list) -def test_validate_constraints(api_root_url: str) -> None: +def test_validate_constraints(api_url: str) -> None: process_id = "test-adaptor-mars" - proc = processing.Processing(f"{api_root_url}/retrieve") + proc = processing.Processing(f"{api_url}/retrieve") process = proc.process(process_id) res = process.valid_values({}) assert set(["product_type", "variable", "year", "month", "time"]) <= set(res) -def test_collection_missing_licence( - api_root_url: str, api_key_test: str, request_year: str -) -> None: - collection_id = "test-adaptor-observation-repository-gnss" - headers = {"PRIVATE-TOKEN": api_key_test} - proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) - process = proc.process(collection_id) - - with pytest.raises(RuntimeError, match="403 Client Error"): - _ = process.execute(inputs={}) - - -def test_collection_anonymous_user(api_root_url: str, api_key_anon: str) -> None: +def test_collection_anonymous_user(api_url: str, api_anon_key: str) -> None: collection_id = "test-adaptor-mars" - headers = {"PRIVATE-TOKEN": api_key_anon} - proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) + headers = {"PRIVATE-TOKEN": api_anon_key} + proc = processing.Processing(f"{api_url}/retrieve", headers=headers) process = proc.process(collection_id) response = process.execute(inputs={}) assert "message" in response.json -def test_jobs_list(api_root_url: str, api_key_anon: str, request_year: str) -> None: +def test_jobs_list(api_url: str, api_anon_key: str) -> None: collection_id = "test-adaptor-dummy" - headers = {"PRIVATE-TOKEN": api_key_anon} - proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) + headers = {"PRIVATE-TOKEN": api_anon_key} + proc = processing.Processing(f"{api_url}/retrieve", headers=headers) process = proc.process(collection_id) _ = process.execute(inputs={}) @@ -91,9 +79,9 @@ def test_jobs_list(api_root_url: str, api_key_anon: str, request_year: str) -> N assert len(res["jobs"]) == 1 -def test_validate_constraints_error(api_root_url: str) -> None: +def test_validate_constraints_error(api_url: str) -> None: process_id = "test-adaptor-mars" - proc = processing.Processing(f"{api_root_url}/retrieve") + proc = processing.Processing(f"{api_url}/retrieve") process = proc.process(process_id) with pytest.raises(RuntimeError, match="422 Client Error"): process.valid_values({"invalid_param": 1}) diff --git a/tests/integration_test_30_remote.py b/tests/integration_test_30_remote.py index 3f887bd..8dab856 100644 --- a/tests/integration_test_30_remote.py +++ b/tests/integration_test_30_remote.py @@ -1,12 +1,13 @@ -import py +import pathlib + import pytest from cads_api_client import catalogue, processing -def test_from_collection_to_process(api_root_url: str) -> None: +def test_from_collection_to_process(api_url: str) -> None: collection_id = "test-adaptor-dummy" - cat = catalogue.Catalogue(f"{api_root_url}/catalogue") + cat = catalogue.Catalogue(f"{api_url}/catalogue") dataset = cat.collection(collection_id) res = dataset.retrieve_process() @@ -14,13 +15,11 @@ def test_from_collection_to_process(api_root_url: str) -> None: assert isinstance(res, processing.Process) -def test_collection_submit( - api_root_url: str, api_key_anon: str, request_year: str -) -> None: +def test_collection_submit(api_url: str, api_anon_key: str) -> None: collection_id = "test-adaptor-dummy" - headers = {"PRIVATE-TOKEN": api_key_anon} + headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) res = dataset.submit() @@ -32,14 +31,14 @@ def test_collection_submit( def test_collection_retrieve_with_dummy_adaptor( - api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local + api_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-dummy" - headers = {"PRIVATE-TOKEN": api_key_anon} + headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) - target = str(tmpdir.join("dummy.txt")) + target = str(tmp_path / "dummy.txt") res = dataset.retrieve( target=target, @@ -51,14 +50,14 @@ def test_collection_retrieve_with_dummy_adaptor( def test_collection_retrieve_with_url_cds_adaptor( - api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local + api_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-url" - headers = {"PRIVATE-TOKEN": api_key_anon} + headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) - target = str(tmpdir.join("wfde1.zip")) + target = str(tmp_path / "wfde1.zip") res = dataset.retrieve( variable="grid_point_altitude", @@ -71,7 +70,7 @@ def test_collection_retrieve_with_url_cds_adaptor( assert isinstance(res, str) assert res.endswith(target) - target = str(tmpdir.join("wfde2.zip")) + target = str(tmp_path / "wfde2.zip") res = dataset.retrieve( variable="grid_point_altitude", @@ -86,14 +85,14 @@ def test_collection_retrieve_with_url_cds_adaptor( def test_collection_retrieve_with_direct_mars_cds_adaptor( - api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local + api_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-direct-mars" - headers = {"PRIVATE-TOKEN": api_key_anon} + headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) - target = str(tmpdir.join("era5-complete.grib")) + target = str(tmp_path / "era5-complete.grib") res = dataset.retrieve( levelist="1", @@ -114,19 +113,19 @@ def test_collection_retrieve_with_direct_mars_cds_adaptor( def test_collection_retrieve_with_mars_cds_adaptor( - api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local + api_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-mars" - headers = {"PRIVATE-TOKEN": api_key_anon} + headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) - target = str(tmpdir.join("era5.grib")) + target = str(tmp_path / "era5.grib") res = dataset.retrieve( product_type="reanalysis", variable="2m_temperature", - year=request_year, + year="2016", month="01", day="02", time="00:00", @@ -140,19 +139,19 @@ def test_collection_retrieve_with_mars_cds_adaptor( @pytest.mark.skip(reason="discontinued adaptor") def test_collection_retrieve_with_legacy_cds_adaptor( - api_root_url: str, api_key_anon: str, request_year: str, tmpdir: py.path.local + api_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-legacy" - headers = {"PRIVATE-TOKEN": api_key_anon} + headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) - target = str(tmpdir.join("era5.grib")) + target = str(tmp_path / "era5.grib") res = dataset.retrieve( product_type="reanalysis", variable="temperature", - year=request_year, + year="2016", month="01", day="02", time="00:00", diff --git a/tests/integration_test_40_api_client.py b/tests/integration_test_40_api_client.py index be98fed..0d70e31 100644 --- a/tests/integration_test_40_api_client.py +++ b/tests/integration_test_40_api_client.py @@ -1,18 +1,18 @@ from cads_api_client import ApiClient -def test_accept_licence(api_client: ApiClient) -> None: - licence = api_client.licences["licences"][0] +def test_accept_licence() -> None: + client = ApiClient() + + licence = client.licences["licences"][0] licence_id = licence["id"] licence_revision = licence["revision"] expected = {"id": licence_id, "revision": licence_revision} - actual = api_client.accept_licence(licence_id, licence_revision) + actual = client.accept_licence(licence_id, licence_revision) assert expected == actual assert any( - [ - licence["id"] == licence_id and licence["revision"] == licence_revision - for licence in api_client.accepted_licences["licences"] - ] + licence["id"] == licence_id and licence["revision"] == licence_revision + for licence in client.accepted_licences["licences"] ) diff --git a/tests/integration_test_50_legacy_api_client.py b/tests/integration_test_50_legacy_api_client.py index e56c9e1..850ace9 100644 --- a/tests/integration_test_50_legacy_api_client.py +++ b/tests/integration_test_50_legacy_api_client.py @@ -5,8 +5,8 @@ from cads_api_client import legacy_api_client -def test_retrieve(tmp_path: pathlib.Path, api_root_url: str, api_key_anon: str) -> None: - client = legacy_api_client.LegacyApiClient(url=api_root_url, key=api_key_anon) +def test_retrieve(tmp_path: pathlib.Path, api_url: str, api_anon_key: str) -> None: + client = legacy_api_client.LegacyApiClient(url=api_url, key=api_anon_key) collection_id = "test-adaptor-dummy" request = {"size": 1} @@ -25,10 +25,13 @@ def test_retrieve(tmp_path: pathlib.Path, api_root_url: str, api_key_anon: str) @pytest.mark.parametrize("quiet", [True, False]) def test_quiet( - caplog: pytest.LogCaptureFixture, api_root_url: str, api_key_anon: str, quiet: bool + caplog: pytest.LogCaptureFixture, + api_url: str, + api_anon_key: str, + quiet: bool, ) -> None: client = legacy_api_client.LegacyApiClient( - url=api_root_url, key=api_key_anon, quiet=quiet + url=api_url, key=api_anon_key, quiet=quiet ) client.retrieve("test-adaptor-dummy", {}) records = [record for record in caplog.records if record.levelname == "INFO"] @@ -37,8 +40,11 @@ def test_quiet( @pytest.mark.parametrize("debug", [True, False]) def test_debug( - caplog: pytest.LogCaptureFixture, api_root_url: str, api_key_anon: str, debug: bool + caplog: pytest.LogCaptureFixture, + api_url: str, + api_anon_key: str, + debug: bool, ) -> None: - legacy_api_client.LegacyApiClient(url=api_root_url, key=api_key_anon, debug=debug) + legacy_api_client.LegacyApiClient(url=api_url, key=api_anon_key, debug=debug) records = [record for record in caplog.records if record.levelname == "DEBUG"] assert records if debug else not records diff --git a/tests/integration_test_60_features.py b/tests/integration_test_60_features.py index dcd767a..f6b7a07 100644 --- a/tests/integration_test_60_features.py +++ b/tests/integration_test_60_features.py @@ -8,8 +8,8 @@ def test_features_url_cds_adaptor_area_selection( - api_client: ApiClient, tmp_path: Path, + api_anon_client: ApiClient, ) -> None: collection_id = "test-adaptor-url" request: dict[str, Any] = { @@ -19,12 +19,12 @@ def test_features_url_cds_adaptor_area_selection( "retry_options": {"maximum_tries": 0}, } - result_bigger = api_client.retrieve( + result_bigger = api_anon_client.retrieve( collection_id, **request, target=str(tmp_path / "bigger.zip"), ) - result_smaller = api_client.retrieve( + result_smaller = api_anon_client.retrieve( collection_id, **request, target=str(tmp_path / "smaller.zip"), @@ -41,10 +41,9 @@ def test_features_url_cds_adaptor_area_selection( ], ) def test_features_mars_cds_adaptor_format( - api_client: ApiClient, + api_anon_client: ApiClient, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, - request_year: str, format: str, expected_extension: str, ) -> None: @@ -54,7 +53,7 @@ def test_features_mars_cds_adaptor_format( request: dict[str, Any] = { "product_type": "reanalysis", "variable": "2m_temperature", - "year": request_year, + "year": "2016", "month": "01", "day": "02", "time": "00:00", @@ -62,7 +61,7 @@ def test_features_mars_cds_adaptor_format( "retry_options": {"maximum_tries": 0}, } - result = api_client.retrieve( + result = api_anon_client.retrieve( collection_id, **request, format=format, diff --git a/tests/integration_test_70_real_datasets.py b/tests/integration_test_70_real_datasets.py deleted file mode 100644 index 0af3626..0000000 --- a/tests/integration_test_70_real_datasets.py +++ /dev/null @@ -1,166 +0,0 @@ -"""TODO: Move these tests to a dedicated repository.""" - -import datetime -import os -from pathlib import Path -from typing import Any - -import pytest - -from cads_api_client import ApiClient - -XFAIL_REASON = "temporary E2E tests" - - -@pytest.mark.xfail(reason=XFAIL_REASON) -@pytest.mark.parametrize( - "collection_id,request_params", - [ - ( - "insitu-observations-woudc-ozone-total-column-and-profiles", - { - "variable": ["air_temperature"], - "observation_type": "vertical_profile", - }, - ), - ( - "insitu-observations-igra-baseline-network", - { - "variable": ["air_temperature"], - "archive": ["global_radiosonde_archive"], - }, - ), - ( - "insitu-observations-gnss", - { - "network_type": "igs_r3", - "variable": [ - "precipitable_water_column", - "precipitable_water_column_total_uncertainty", - ], - }, - ), - ( - "insitu-observations-gruan-reference-network", - { - "variable": ["air_temperature"], - }, - ), - ( - "insitu-observations-near-surface-temperature-us-climate-reference-network", - { - "time_aggregation": "daily", - "variable": [ - "maximum_air_temperature", - "maximum_air_temperature_negative_total_uncertainty", - "maximum_air_temperature_positive_total_uncertainty", - ], - }, - ), - ], -) -def test_real_datasets_observations( - api_client: ApiClient, - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - collection_id: str, - request_params: dict[str, Any], -) -> None: - monkeypatch.chdir(tmp_path) - - common_params: dict[str, Any] = { - "year": "2014", - "month": "01", - "day": "01", - "format": "netCDF", - "retry_options": {"maximum_tries": 0}, - "target": None, - } - - result = api_client.retrieve( - collection_id, - **common_params, - **request_params, - ) - - _, extension = os.path.splitext(result) - assert extension == ".nc" - assert os.path.getsize(result) - - -@pytest.mark.xfail(reason=XFAIL_REASON) -@pytest.mark.parametrize( - "collection_id,request_params", - [ - ( - "reanalysis-era5-single-levels", - { - "variable": "2m_temperature", - "product_type": "reanalysis", - "year": "2020", - "month": "01", - "day": "01", - "time": "00:00", - }, - ), - ( - "seasonal-original-single-levels", - { - "originating_centre": "ukmo", - "system": "12", - "variable": ["2m_dewpoint_temperature"], - "year": ["2015"], - "month": ["02"], - "day": ["09"], - "leadtime_hour": ["390"], - }, - ), - ( - "cams-global-atmospheric-composition-forecasts", - { - "variable": [ - "total_column_dimethyl_sulfide", - "total_column_glyoxal", - ], - "date": "2024-01-02", - "time": "00:00", - "leadtime_hour": "0", - "type": "forecast", - }, - ), - ], -) -@pytest.mark.parametrize( - "data_format,expected_extension", - [ - ("grib", ".grib"), - ("netcdf", ".nc"), - ], -) -def test_real_datasets_format( - api_client: ApiClient, - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - collection_id: str, - request_params: dict[str, Any], - data_format: str, - expected_extension: str, -) -> None: - monkeypatch.chdir(tmp_path) - - common_params: dict[str, Any] = { - "data_format": data_format, - "_timestamp": datetime.datetime.now().isoformat(), - "retry_options": {"maximum_tries": 0}, - "target": None, - } - - result = api_client.retrieve( - collection_id, - **common_params, - **request_params, - ) - - _, actual_extension = os.path.splitext(result) - assert actual_extension == expected_extension - assert os.path.getsize(result) diff --git a/tests/test_10_config.py b/tests/test_10_config.py index 1a7397d..efcbc9b 100644 --- a/tests/test_10_config.py +++ b/tests/test_10_config.py @@ -1,5 +1,4 @@ import json -from typing import Any import py import pytest @@ -42,7 +41,7 @@ def test_get_config_from_configuration_file(tmpdir: py.path) -> None: def test_get_config_from_environment_variables( - tmpdir: py.path, temp_environ: Any + tmpdir: py.path, monkeypatch: pytest.MonkeyPatch ) -> None: expected_config = {"url": "dummy-url", "key": "dummy-key"} file_config = {"url": "wrong-url", "key": "wrong-key"} @@ -50,8 +49,8 @@ def test_get_config_from_environment_variables( config_file = tmpdir.join(".cads-api-client.json") config_file.write(json.dumps(file_config)) - temp_environ["CADS_API_URL"] = expected_config["url"] - temp_environ["CADS_API_KEY"] = expected_config["key"] + monkeypatch.setenv("CADS_API_URL", expected_config["url"]) + monkeypatch.setenv("CADS_API_KEY", expected_config["key"]) res = config.get_config("url", str(config_file), config={}) From ed33427cd59400a845a5701c45584659d3f86a5c Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Thu, 1 Aug 2024 09:23:11 +0200 Subject: [PATCH 7/7] restore api_root_url --- tests/conftest.py | 6 ++-- tests/integration_test_10_catalogue.py | 12 ++++---- tests/integration_test_20_processing.py | 28 +++++++++---------- tests/integration_test_30_remote.py | 28 +++++++++---------- .../integration_test_50_legacy_api_client.py | 12 ++++---- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d4ba101..e8addf8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,7 @@ @pytest.fixture -def api_url() -> str: +def api_root_url() -> str: from cads_api_client import config return config.get_config("url") @@ -22,7 +22,7 @@ def api_anon_key() -> str: @pytest.fixture -def api_anon_client(api_url: str, api_anon_key: str) -> ApiClient: +def api_anon_client(api_root_url: str, api_anon_key: str) -> ApiClient: from cads_api_client import ApiClient - return ApiClient(url=api_url, key=api_anon_key) + return ApiClient(url=api_root_url, key=api_anon_key) diff --git a/tests/integration_test_10_catalogue.py b/tests/integration_test_10_catalogue.py index 01b8a15..3d578fb 100644 --- a/tests/integration_test_10_catalogue.py +++ b/tests/integration_test_10_catalogue.py @@ -1,8 +1,8 @@ from cads_api_client import catalogue -def test_collections(api_url: str) -> None: - cat = catalogue.Catalogue(f"{api_url}/catalogue") +def test_collections(api_root_url: str) -> None: + cat = catalogue.Catalogue(f"{api_root_url}/catalogue") res: catalogue.Collections | None = cat.collections() @@ -22,8 +22,8 @@ def test_collections(api_url: str) -> None: assert expected_collection_id in collection_ids -def test_collections_limit(api_url: str) -> None: - cat = catalogue.Catalogue(f"{api_url}/catalogue") +def test_collections_limit(api_root_url: str) -> None: + cat = catalogue.Catalogue(f"{api_root_url}/catalogue") collections = cat.collections(params={"limit": 1}) res = collections.next() @@ -32,9 +32,9 @@ def test_collections_limit(api_url: str) -> None: assert res.response.status_code == 200 -def test_collection(api_url: str) -> None: +def test_collection(api_root_url: str) -> None: collection_id = "test-adaptor-mars" - cat = catalogue.Catalogue(f"{api_url}/catalogue") + cat = catalogue.Catalogue(f"{api_root_url}/catalogue") res = cat.collection(collection_id) diff --git a/tests/integration_test_20_processing.py b/tests/integration_test_20_processing.py index b19ed08..f015a01 100644 --- a/tests/integration_test_20_processing.py +++ b/tests/integration_test_20_processing.py @@ -3,8 +3,8 @@ from cads_api_client import processing -def test_processes(api_url: str) -> None: - proc = processing.Processing(f"{api_url}/retrieve") +def test_processes(api_root_url: str) -> None: + proc = processing.Processing(f"{api_root_url}/retrieve") res = proc.processes() @@ -17,8 +17,8 @@ def test_processes(api_url: str) -> None: assert len(res.process_ids()) == 10 -def test_processes_limit(api_url: str) -> None: - proc = processing.Processing(f"{api_url}/retrieve") +def test_processes_limit(api_root_url: str) -> None: + proc = processing.Processing(f"{api_root_url}/retrieve") processes = proc.processes(params={"limit": 1}) res = processes.next() @@ -27,9 +27,9 @@ def test_processes_limit(api_url: str) -> None: assert res.response.status_code == 200 -def test_process(api_url: str) -> None: +def test_process(api_root_url: str) -> None: process_id = "test-adaptor-dummy" - proc = processing.Processing(f"{api_url}/retrieve") + proc = processing.Processing(f"{api_root_url}/retrieve") res = proc.process(process_id) @@ -39,28 +39,28 @@ def test_process(api_url: str) -> None: assert isinstance(res.json["links"], list) -def test_validate_constraints(api_url: str) -> None: +def test_validate_constraints(api_root_url: str) -> None: process_id = "test-adaptor-mars" - proc = processing.Processing(f"{api_url}/retrieve") + proc = processing.Processing(f"{api_root_url}/retrieve") process = proc.process(process_id) res = process.valid_values({}) assert set(["product_type", "variable", "year", "month", "time"]) <= set(res) -def test_collection_anonymous_user(api_url: str, api_anon_key: str) -> None: +def test_collection_anonymous_user(api_root_url: str, api_anon_key: str) -> None: collection_id = "test-adaptor-mars" headers = {"PRIVATE-TOKEN": api_anon_key} - proc = processing.Processing(f"{api_url}/retrieve", headers=headers) + proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) process = proc.process(collection_id) response = process.execute(inputs={}) assert "message" in response.json -def test_jobs_list(api_url: str, api_anon_key: str) -> None: +def test_jobs_list(api_root_url: str, api_anon_key: str) -> None: collection_id = "test-adaptor-dummy" headers = {"PRIVATE-TOKEN": api_anon_key} - proc = processing.Processing(f"{api_url}/retrieve", headers=headers) + proc = processing.Processing(f"{api_root_url}/retrieve", headers=headers) process = proc.process(collection_id) _ = process.execute(inputs={}) @@ -79,9 +79,9 @@ def test_jobs_list(api_url: str, api_anon_key: str) -> None: assert len(res["jobs"]) == 1 -def test_validate_constraints_error(api_url: str) -> None: +def test_validate_constraints_error(api_root_url: str) -> None: process_id = "test-adaptor-mars" - proc = processing.Processing(f"{api_url}/retrieve") + proc = processing.Processing(f"{api_root_url}/retrieve") process = proc.process(process_id) with pytest.raises(RuntimeError, match="422 Client Error"): process.valid_values({"invalid_param": 1}) diff --git a/tests/integration_test_30_remote.py b/tests/integration_test_30_remote.py index 8dab856..9e50bfb 100644 --- a/tests/integration_test_30_remote.py +++ b/tests/integration_test_30_remote.py @@ -5,9 +5,9 @@ from cads_api_client import catalogue, processing -def test_from_collection_to_process(api_url: str) -> None: +def test_from_collection_to_process(api_root_url: str) -> None: collection_id = "test-adaptor-dummy" - cat = catalogue.Catalogue(f"{api_url}/catalogue") + cat = catalogue.Catalogue(f"{api_root_url}/catalogue") dataset = cat.collection(collection_id) res = dataset.retrieve_process() @@ -15,11 +15,11 @@ def test_from_collection_to_process(api_url: str) -> None: assert isinstance(res, processing.Process) -def test_collection_submit(api_url: str, api_anon_key: str) -> None: +def test_collection_submit(api_root_url: str, api_anon_key: str) -> None: collection_id = "test-adaptor-dummy" headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) res = dataset.submit() @@ -31,12 +31,12 @@ def test_collection_submit(api_url: str, api_anon_key: str) -> None: def test_collection_retrieve_with_dummy_adaptor( - api_url: str, api_anon_key: str, tmp_path: pathlib.Path + api_root_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-dummy" headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmp_path / "dummy.txt") @@ -50,12 +50,12 @@ def test_collection_retrieve_with_dummy_adaptor( def test_collection_retrieve_with_url_cds_adaptor( - api_url: str, api_anon_key: str, tmp_path: pathlib.Path + api_root_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-url" headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmp_path / "wfde1.zip") @@ -85,12 +85,12 @@ def test_collection_retrieve_with_url_cds_adaptor( def test_collection_retrieve_with_direct_mars_cds_adaptor( - api_url: str, api_anon_key: str, tmp_path: pathlib.Path + api_root_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-direct-mars" headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmp_path / "era5-complete.grib") @@ -113,12 +113,12 @@ def test_collection_retrieve_with_direct_mars_cds_adaptor( def test_collection_retrieve_with_mars_cds_adaptor( - api_url: str, api_anon_key: str, tmp_path: pathlib.Path + api_root_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-mars" headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmp_path / "era5.grib") @@ -139,12 +139,12 @@ def test_collection_retrieve_with_mars_cds_adaptor( @pytest.mark.skip(reason="discontinued adaptor") def test_collection_retrieve_with_legacy_cds_adaptor( - api_url: str, api_anon_key: str, tmp_path: pathlib.Path + api_root_url: str, api_anon_key: str, tmp_path: pathlib.Path ) -> None: collection_id = "test-adaptor-legacy" headers = {"PRIVATE-TOKEN": api_anon_key} - cat = catalogue.Catalogue(f"{api_url}/catalogue", headers=headers) + cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmp_path / "era5.grib") diff --git a/tests/integration_test_50_legacy_api_client.py b/tests/integration_test_50_legacy_api_client.py index 850ace9..f089d50 100644 --- a/tests/integration_test_50_legacy_api_client.py +++ b/tests/integration_test_50_legacy_api_client.py @@ -5,8 +5,8 @@ from cads_api_client import legacy_api_client -def test_retrieve(tmp_path: pathlib.Path, api_url: str, api_anon_key: str) -> None: - client = legacy_api_client.LegacyApiClient(url=api_url, key=api_anon_key) +def test_retrieve(tmp_path: pathlib.Path, api_root_url: str, api_anon_key: str) -> None: + client = legacy_api_client.LegacyApiClient(url=api_root_url, key=api_anon_key) collection_id = "test-adaptor-dummy" request = {"size": 1} @@ -26,12 +26,12 @@ def test_retrieve(tmp_path: pathlib.Path, api_url: str, api_anon_key: str) -> No @pytest.mark.parametrize("quiet", [True, False]) def test_quiet( caplog: pytest.LogCaptureFixture, - api_url: str, + api_root_url: str, api_anon_key: str, quiet: bool, ) -> None: client = legacy_api_client.LegacyApiClient( - url=api_url, key=api_anon_key, quiet=quiet + url=api_root_url, key=api_anon_key, quiet=quiet ) client.retrieve("test-adaptor-dummy", {}) records = [record for record in caplog.records if record.levelname == "INFO"] @@ -41,10 +41,10 @@ def test_quiet( @pytest.mark.parametrize("debug", [True, False]) def test_debug( caplog: pytest.LogCaptureFixture, - api_url: str, + api_root_url: str, api_anon_key: str, debug: bool, ) -> None: - legacy_api_client.LegacyApiClient(url=api_url, key=api_anon_key, debug=debug) + legacy_api_client.LegacyApiClient(url=api_root_url, key=api_anon_key, debug=debug) records = [record for record in caplog.records if record.levelname == "DEBUG"] assert records if debug else not records