Skip to content

Commit 779326c

Browse files
committed
Add test for authentication endpoint
1 parent 33eed41 commit 779326c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def fake_ui_url():
1919
@fixture
2020
def mocked_api(
2121
fake_api_url,
22+
fake_user_json,
2223
fake_info_json,
2324
fake_block_info_json,
2425
fake_samples_json,
@@ -29,6 +30,9 @@ def mocked_api(
2930
fake_api = respx_mock.get("/", name="api")
3031
fake_api.return_value = Response(200, content="<!doctype html></html>")
3132

33+
fake_authentication = respx_mock.get("/get-current-user", name="current_user")
34+
fake_authentication.return_value = Response(200, json=fake_user_json)
35+
3236
fake_info_api = respx_mock.get("/info", name="info")
3337
fake_info_api.return_value = Response(200, json=fake_info_json)
3438

@@ -247,6 +251,35 @@ def fake_block_info_json():
247251
)
248252

249253

254+
@fixture
255+
def fake_user_json():
256+
"""Returns a mocked JSON response from the /get-current-user endpoint."""
257+
258+
return json.loads(
259+
"""
260+
{
261+
"account_status": "active",
262+
"contact_email": null,
263+
"display_name": "Jane Doe",
264+
"identities": [
265+
{
266+
"display_name": "Jane Doe",
267+
"identifier": "1111111",
268+
"identity_type": "github",
269+
"name": "jane-doe",
270+
"verified": true
271+
}
272+
],
273+
"immutable_id": "6574f788aabb227db8d1b14e",
274+
"last_modified": null,
275+
"managers": null,
276+
"relationships": null,
277+
"role": "user",
278+
"type": "people"
279+
}"""
280+
)
281+
282+
250283
@fixture(scope="session")
251284
def fake_api_key():
252285
"""Returns a fake API key."""

tests/test_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def test_sample_list(mocked_api, fake_api_url):
2323
assert mocked_api["info"].called
2424
assert mocked_api["info-blocks"].called
2525

26+
client.authenticate()
27+
assert mocked_api["current_user"].called
28+
2629
samples = client.get_items(display=True)
2730
assert mocked_api["samples"].called
2831
assert len(samples)

0 commit comments

Comments
 (0)