Skip to content

Commit

Permalink
Add userinfo endpoint for api v2 (#138)
Browse files Browse the repository at this point in the history
* 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 <eirini.koutsaniti@cscs.ch>
Co-authored-by: Eirini Koutsaniti <ekoutsaniti@gmail.com>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent 3525518 commit 45d8734
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ jobs:
pip install .[test]
- name: type check with mypy
run: |
mypy .
mypy firecrest
13 changes: 13 additions & 0 deletions firecrest/v2/_async/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions firecrest/v2/_sync/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions tests/v2/responses/userinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"status_code": 200,
"response": {
"user": {
"id": "1000",
"name": "fireuser"
},
"group": {
"id": "100",
"name": "users"
},
"groups": [
{
"id": "100",
"name": "users"
}
]
}
}
7 changes: 7 additions & 0 deletions tests/v2/test_status_v2_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 6 additions & 0 deletions tests/v2/test_status_v2_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 45d8734

Please sign in to comment.