Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 6e3ad99

Browse files
committed
fix get accepted licences
1 parent 92d63a1 commit 6e3ad99

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

cads_api_client/api_client.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ def estimate_costs(self, collection_id: str, **request: Any) -> dict[str, Any]:
205205
"""
206206
return self.get_process(collection_id).estimate_costs(**request)
207207

208+
def get_accepted_licences(
209+
self,
210+
scope: Literal["all", "dataset", "portal"] | None = None,
211+
) -> list[dict[str, Any]]:
212+
"""Retrieve acccepted licences.
213+
214+
Parameters
215+
----------
216+
scope: str | None
217+
Licence scope. Options: ``"all", "dataset", "portal"``.
218+
219+
Returns
220+
-------
221+
list[dict[str, Any]]
222+
List of dictionaries with license information.
223+
"""
224+
params = {k: v for k, v in zip(["scope"], [scope]) if v is not None}
225+
licences: list[dict[str, Any]]
226+
licences = self._profile_api.accepted_licences(**params).get("licences", [])
227+
return licences
228+
208229
def get_collection(self, collection_id: str) -> cads_api_client.Collection:
209230
"""Retrieve a catalogue collection.
210231
@@ -424,16 +445,3 @@ def submit_and_wait_on_results(
424445
cads_api_client.Results
425446
"""
426447
return self._retrieve_api.submit(collection_id, **request).make_results()
427-
428-
@property
429-
def accepted_licences(self) -> list[dict[str, Any]]:
430-
"""Accepted licences.
431-
432-
Returns
433-
-------
434-
list[dict[str, Any]]
435-
List of dictionaries with license information.
436-
"""
437-
licences: list[dict[str, Any]]
438-
licences = self._profile_api.accepted_licences.get("licences", [])
439-
return licences

cads_api_client/profile.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ def accept_licence(self, licence_id: str, revision: int) -> dict[str, Any]:
5050
url = f"{self.url}/account/licences/{licence_id}"
5151
return self._get_api_response("put", url, json={"revision": revision}).json
5252

53-
@property
54-
def accepted_licences(self) -> dict[str, Any]:
53+
def accepted_licences(self, **params: Any) -> dict[str, Any]:
5554
url = f"{self.url}/account/licences"
56-
return self._get_api_response("get", url).json
55+
return self._get_api_response("get", url, params=params).json
5756

5857
def check_authentication(self) -> dict[str, Any]:
5958
url = f"{self.url}/account/verification/pat"

tests/integration_test_50_profile.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1+
from typing import Literal
2+
13
import pytest
24
from requests import HTTPError
35

46
from cads_api_client import ApiClient, config
57

68

7-
def test_api_client_accept_licence() -> None:
9+
@pytest.mark.parametrize("scope", [None, "all", "dataset", "portal"])
10+
def test_api_client_accept_licence(
11+
scope: Literal["all", "dataset", "portal"] | None,
12+
) -> None:
813
try:
914
# Can not use anonymous user
1015
config.get_config("key")
1116
except Exception:
1217
pytest.skip("The API key is missing")
1318

1419
client = ApiClient(maximum_tries=0)
15-
licence = client.get_licences()[0]
20+
licence = client.get_licences(scope=scope)[0]
1621
licence_id = licence["id"]
1722
licence_revision = licence["revision"]
1823

@@ -22,7 +27,7 @@ def test_api_client_accept_licence() -> None:
2227

2328
assert any(
2429
licence["id"] == licence_id and licence["revision"] == licence_revision
25-
for licence in client.accepted_licences
30+
for licence in client.get_accepted_licences(scope=scope)
2631
)
2732

2833

0 commit comments

Comments
 (0)