From 45d8734c1595fa2ef7bd32f4365429fa1f1084b2 Mon Sep 17 00:00:00 2001 From: rsarm Date: Tue, 10 Dec 2024 10:30:51 +0100 Subject: [PATCH] Add userinfo endpoint for api v2 (#138) * Run unittests for all PRs, not only the ones to main (#131) * add user info endpoint async * add user info endpoint sync * add unit tests * fix json format * Fix types --------- Co-authored-by: Eirini Koutsaniti Co-authored-by: Eirini Koutsaniti --- .github/workflows/testing.yml | 2 +- firecrest/v2/_async/Client.py | 13 +++++++++++++ firecrest/v2/_sync/Client.py | 13 +++++++++++++ tests/v2/responses/userinfo.json | 19 +++++++++++++++++++ tests/v2/test_status_v2_async.py | 7 +++++++ tests/v2/test_status_v2_sync.py | 6 ++++++ 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/v2/responses/userinfo.json diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 3a2e651..4ac549b 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -65,4 +65,4 @@ jobs: pip install .[test] - name: type check with mypy run: | - mypy . + mypy firecrest diff --git a/firecrest/v2/_async/Client.py b/firecrest/v2/_async/Client.py index debd0d2..dc27992 100644 --- a/firecrest/v2/_async/Client.py +++ b/firecrest/v2/_async/Client.py @@ -291,6 +291,19 @@ async def partitions( ) return self._check_response(resp, 200)["partitions"] + async def userinfo( + self, + system_name: str + ) -> dict: + """Returns user and groups information. + + :calls: GET `/status/{system_name}/userinfo` + """ + resp = await self._get_request( + endpoint=f"/status/{system_name}/userinfo" + ) + return self._check_response(resp, 200) + async def list_files( self, system_name: str, diff --git a/firecrest/v2/_sync/Client.py b/firecrest/v2/_sync/Client.py index 9b7f7a4..389552c 100644 --- a/firecrest/v2/_sync/Client.py +++ b/firecrest/v2/_sync/Client.py @@ -291,6 +291,19 @@ def partitions( ) return self._check_response(resp, 200)["partitions"] + def userinfo( + self, + system_name: str + ) -> dict: + """Returns user and groups information. + + :calls: GET `/status/{system_name}/userinfo` + """ + resp = self._get_request( + endpoint=f"/status/{system_name}/userinfo" + ) + return self._check_response(resp, 200) + def list_files( self, system_name: str, diff --git a/tests/v2/responses/userinfo.json b/tests/v2/responses/userinfo.json new file mode 100644 index 0000000..e0656a3 --- /dev/null +++ b/tests/v2/responses/userinfo.json @@ -0,0 +1,19 @@ +{ + "status_code": 200, + "response": { + "user": { + "id": "1000", + "name": "fireuser" + }, + "group": { + "id": "100", + "name": "users" + }, + "groups": [ + { + "id": "100", + "name": "users" + } + ] + } +} diff --git a/tests/v2/test_status_v2_async.py b/tests/v2/test_status_v2_async.py index bf9dc88..d3c1951 100644 --- a/tests/v2/test_status_v2_async.py +++ b/tests/v2/test_status_v2_async.py @@ -92,3 +92,10 @@ async def test_reservations(valid_client): data = read_json_file("v2/responses/reservations.json") resp = await valid_client.reservations("cluster") assert resp == data["response"]["reservations"] + + +@pytest.mark.asyncio +async def test_userinfo(valid_client): + data = read_json_file("v2/responses/userinfo.json") + resp = await valid_client.userinfo("cluster") + assert resp == data["response"] diff --git a/tests/v2/test_status_v2_sync.py b/tests/v2/test_status_v2_sync.py index f416dea..4936daf 100644 --- a/tests/v2/test_status_v2_sync.py +++ b/tests/v2/test_status_v2_sync.py @@ -88,3 +88,9 @@ def test_reservations(valid_client): data = read_json_file("v2/responses/reservations.json") resp = valid_client.reservations("cluster") assert resp == data["response"]["reservations"] + + +def test_userinfo(valid_client): + data = read_json_file("v2/responses/userinfo.json") + resp = valid_client.userinfo("cluster") + assert resp == data["response"]