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

Commit

Permalink
Merge pull request #42 from ecmwf-projects/fix-accept-licence
Browse files Browse the repository at this point in the history
fix accept licence
  • Loading branch information
malmans2 authored Mar 18, 2024
2 parents be352a1 + 16c5ddc commit 16e019e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cads_api_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ def licences(self) -> Dict[str, Any]:
def accepted_licences(self) -> Dict[str, Any]:
return self.profile_api.accepted_licences()

def accept_licence(self, licence_id: str) -> Dict[str, Any]:
return self.profile_api.accept_licence(licence_id)
def accept_licence(self, licence_id: str, revision: int) -> Dict[str, Any]:
return self.profile_api.accept_licence(licence_id, revision=revision)
6 changes: 4 additions & 2 deletions cads_api_client/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ def profile(self) -> Dict[str, Any]:
response = processing.ApiResponse.from_request("get", url, headers=self.headers)
return response.json

def accept_licence(self, licence_id: str) -> Dict[str, Any]:
def accept_licence(self, licence_id: str, revision: int) -> Dict[str, Any]:
url = f"{self.url}/account/licences/{licence_id}"
response = processing.ApiResponse.from_request("put", url, headers=self.headers)
response = processing.ApiResponse.from_request(
"put", url, headers=self.headers, json={"revision": revision}
)
return response.json

def accepted_licences(self) -> Dict[str, Any]:
Expand Down
25 changes: 25 additions & 0 deletions tests/integration_test_40_api_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest

from cads_api_client import ApiClient


@pytest.fixture
def api_client(api_root_url: str, api_key: str) -> ApiClient:
return ApiClient(url=api_root_url, key=api_key)


def test_accept_licence(api_client: ApiClient) -> None:
licence = api_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)
assert expected == actual

assert any(
[
licence["id"] == licence_id and licence["revision"] == licence_revision
for licence in api_client.accepted_licences["licences"]
]
)

0 comments on commit 16e019e

Please sign in to comment.