diff --git a/README.md b/README.md index d48f044..ea67f9c 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,15 @@ CADS API Python client The `ApiClient` needs the `url` to the API root and a valid API `key` to access protected resources. 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 the anonymous user -`00112233-4455-6677-c899-aabbccddeeff`. This is used in anonymous tests and +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 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", "00112233-4455-6677-c899-aabbccddeeff") +>>> cads_api_key = os.getenv("CADS_API_KEY", "00000000-0000-4000-a000-000000000000") >>> import cads_api_client >>> client = cads_api_client.ApiClient(cads_api_key) @@ -21,7 +21,6 @@ Draft Python API: >>> collection.end_datetime() datetime.datetime(2022, 7, 20, 23, 0) >>> remote = client.retrieve( -... accepted_licences=[{"id": "licence-to-use-copernicus-products", "revision": 12}], ... collection_id="reanalysis-era5-pressure-levels", ... product_type="reanalysis", ... variable="temperature", @@ -33,7 +32,6 @@ datetime.datetime(2022, 7, 20, 23, 0) ... target="tmp1-era5.grib", ... ) # blocks >>> remote = collection.submit( -... accepted_licences=[{"id": "licence-to-use-copernicus-products", "revision": 12}], ... variable="temperature", ... product_type="reanalysis", ... year="2021", diff --git a/cads_api_client/api_client.py b/cads_api_client/api_client.py index ba02d8a..c15fd96 100644 --- a/cads_api_client/api_client.py +++ b/cads_api_client/api_client.py @@ -1,5 +1,5 @@ import functools -from typing import Any, Dict, List, Optional +from typing import Any, Dict, Optional import attrs import requests @@ -58,14 +58,12 @@ def retrieve( collection_id: str, target: Optional[str] = None, retry_options: Dict[str, Any] = {}, - accepted_licences: List[Dict[str, Any]] = [], **request: Any, ) -> str: collection = self.collection(collection_id) return collection.retrieve( target, retry_options=retry_options, - accepted_licences=accepted_licences, **request, ) diff --git a/cads_api_client/catalogue.py b/cads_api_client/catalogue.py index 33f3550..894f733 100644 --- a/cads_api_client/catalogue.py +++ b/cads_api_client/catalogue.py @@ -42,23 +42,18 @@ def retrieve_process(self) -> processing.Process: "get", url, headers=self.headers, session=self.session ) - def submit( - self, accepted_licences: List[Dict[str, Any]] = [], **request: Any - ) -> processing.Remote: + def submit(self, **request: Any) -> processing.Remote: retrieve_process = self.retrieve_process() - status_info = retrieve_process.execute( - inputs=request, accepted_licences=accepted_licences, session=self.session - ) + status_info = retrieve_process.execute(inputs=request, session=self.session) return status_info.make_remote() def retrieve( self, target: Optional[str] = None, retry_options: Dict[str, Any] = {}, - accepted_licences: List[Dict[str, Any]] = [], **request: Any, ) -> str: - remote = self.submit(accepted_licences=accepted_licences, **request) + remote = self.submit(**request) return remote.download(target, retry_options=retry_options) diff --git a/cads_api_client/processing.py b/cads_api_client/processing.py index 131b3fd..ce51b39 100644 --- a/cads_api_client/processing.py +++ b/cads_api_client/processing.py @@ -114,13 +114,12 @@ def id(self) -> str: def execute( self, inputs: Dict[str, Any], - accepted_licences: List[Dict[str, Any]] = [], retry_options: Dict[str, Any] = {}, **kwargs: Any, ) -> StatusInfo: assert "json" not in kwargs url = f"{self.response.request.url}/execute" - json = {"inputs": inputs, "acceptedLicences": accepted_licences} + json = {"inputs": inputs} return StatusInfo.from_request( "post", url, diff --git a/tests/conftest.py b/tests/conftest.py index b06aa84..e60f11a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,8 +13,13 @@ def api_root_url() -> str: @pytest.fixture def api_key() -> str: - # default to anonymous access for tests - return os.getenv("CADS_API_KEY") or "00112233-4455-6677-c899-aabbccddeeff" + # default to test user 1 + return os.getenv("CADS_API_KEY") or "00000000-0000-4000-a000-000000000000" + + +@pytest.fixture +def api_key_anon() -> str: + return "00112233-4455-6677-c899-aabbccddeeff" @pytest.fixture diff --git a/tests/integration_test_20_processing.py b/tests/integration_test_20_processing.py index cd0d2c0..e408927 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: str, request_year: str + api_root_url: str, api_key_anon: str, request_year: str ) -> None: collection_id = "test-adaptor-mars" - 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 e347e48..88828f1 100644 --- a/tests/integration_test_30_remote.py +++ b/tests/integration_test_30_remote.py @@ -1,5 +1,3 @@ -from typing import Any - import py from cads_api_client import catalogue, processing @@ -54,16 +52,12 @@ def test_collection_retrieve_with_url_cds_adaptor( ) -> None: collection_id = "test-adaptor-url" headers = {"PRIVATE-TOKEN": api_key} - accepted_licences: list[dict[str, Any]] = [ - {"id": "licence-to-use-copernicus-products", "revision": 12} - ] cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmpdir.join("wfde1.zip")) res = dataset.retrieve( - accepted_licences=accepted_licences, variable="grid_point_altitude", reference_dataset="cru", version="2.1", @@ -77,7 +71,6 @@ def test_collection_retrieve_with_url_cds_adaptor( target = str(tmpdir.join("wfde2.zip")) res = dataset.retrieve( - accepted_licences=accepted_licences, variable="grid_point_altitude", reference_dataset="cru", version="2.1", @@ -94,16 +87,12 @@ def test_collection_retrieve_with_direct_mars_cds_adaptor( ) -> None: collection_id = "test-adaptor-direct-mars" headers = {"PRIVATE-TOKEN": api_key} - accepted_licences: list[dict[str, Any]] = [ - {"id": "licence-to-use-copernicus-products", "revision": 12} - ] cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmpdir.join("era5-complete.grib")) res = dataset.retrieve( - accepted_licences=accepted_licences, levelist=1, dataset="reanalysis", time="00:00:00", @@ -126,16 +115,12 @@ def test_collection_retrieve_with_mars_cds_adaptor( ) -> None: collection_id = "test-adaptor-mars" headers = {"PRIVATE-TOKEN": api_key} - accepted_licences: list[dict[str, Any]] = [ - {"id": "licence-to-use-copernicus-products", "revision": 12} - ] cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmpdir.join("era5.grib")) res = dataset.retrieve( - accepted_licences=accepted_licences, product_type="reanalysis", variable="2m_temperature", year=request_year, @@ -155,16 +140,12 @@ def test_collection_retrieve_with_legacy_cds_adaptor( ) -> None: collection_id = "test-adaptor-legacy" headers = {"PRIVATE-TOKEN": api_key} - accepted_licences: list[dict[str, Any]] = [ - {"id": "licence-to-use-copernicus-products", "revision": 12} - ] cat = catalogue.Catalogue(f"{api_root_url}/catalogue", headers=headers) dataset = cat.collection(collection_id) target = str(tmpdir.join("era5.grib")) res = dataset.retrieve( - accepted_licences=accepted_licences, product_type="reanalysis", variable="temperature", year=request_year, diff --git a/tests/test_10_processing.py b/tests/test_10_processing.py index 4200894..ce6a7e2 100644 --- a/tests/test_10_processing.py +++ b/tests/test_10_processing.py @@ -257,7 +257,6 @@ def responses_add() -> None: json_params_matcher( { "inputs": {"variable": "temperature", "year": "2022"}, - "acceptedLicences": [], } ) ],