Skip to content

Commit

Permalink
test(study-search): integration tests for studies counting and pagina…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
mabw-rte committed Feb 26, 2024
1 parent 36ea8ac commit 7cd9b97
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/integration/studies_blueprint/test_get_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,16 @@ def test_study_listing(
study_map = res.json()
assert not all_studies.intersection(study_map)
assert all(map(lambda x: pm(x) in [PublicMode.READ, PublicMode.FULL], study_map.values()))
# test pagination
res = client.get(
STUDIES_URL,
headers={"Authorization": f"Bearer {john_doe_access_token}"},
params={"pageNb": 1, "pageSize": 2},
)
if len(study_map) > 2:
assert res.status_code == LIST_STATUS_CODE, res.json()
page_studies = res.json()
assert len(page_studies) == min(2, len(study_map) - 2)

# test 1.b for an admin user
res = client.get(
Expand All @@ -463,6 +473,16 @@ def test_study_listing(
assert res.status_code == LIST_STATUS_CODE, res.json()
study_map = res.json()
assert not all_studies.difference(study_map)
# test pagination
res = client.get(
STUDIES_URL,
headers={"Authorization": f"Bearer {admin_access_token}"},
params={"pageNb": 1, "pageSize": 2},
)
if len(study_map) > 2:
assert res.status_code == LIST_STATUS_CODE, res.json()
page_studies = res.json()
assert len(page_studies) == min(2, len(study_map) - 2)

# test 1.c for a user with access to select studies
res = client.get(
Expand Down Expand Up @@ -620,6 +640,16 @@ def test_study_listing(
study_map = res.json()
assert not all_studies.difference(studies_version_850.union(studies_version_860)).intersection(study_map)
assert not studies_version_850.union(studies_version_860).difference(study_map)
# test pagination
res = client.get(
STUDIES_URL,
headers={"Authorization": f"Bearer {admin_access_token}"},
params={"versions": "850,860", "pageNb": 1, "pageSize": 2},
)
if len(study_map) > 2:
assert res.status_code == LIST_STATUS_CODE, res.json()
page_studies = res.json()
assert len(page_studies) == min(2, len(study_map) - 2)

# tests (7) for users filtering
# test 7.a to get studies for one user: James Bond
Expand Down Expand Up @@ -1344,6 +1374,17 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_
study_map = res.json()
assert not expected_studies.difference(set(study_map))
assert not all_studies.difference(expected_studies).intersection(set(study_map))
# test pagination
if len(expected_studies) > 2:
res = client.get(
STUDIES_URL,
headers={"Authorization": f"Bearer {users_tokens['user_1']}"},
params={"groups": ",".join(request_groups_ids), "pageNb": 1, "pageSize": 2}
if request_groups_ids
else {"pageNb": 1, "pageSize": 2},
)
assert res.status_code == LIST_STATUS_CODE, res.json()
assert len(res.json()) == min(2, len(expected_studies) - 2)

# user_2 access
requests_params_expected_studies = [
Expand Down Expand Up @@ -1475,3 +1516,21 @@ def test_get_studies__invalid_parameters(
assert res.status_code == INVALID_PARAMS_STATUS_CODE, res.json()
description = res.json()["description"]
assert re.search(r"could not be parsed to a boolean", description), f"{description=}"


def test_studies_counting(client: TestClient, admin_access_token: str, user_access_token: str) -> None:
# test admin studies count
res = client.get(STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"})
assert res.status_code == 200, res.json()
expected_studies_count = len(res.json())
res = client.get(STUDIES_URL + "/count", headers={"Authorization": f"Bearer {admin_access_token}"})
assert res.status_code == 200, res.json()
assert res.json() == expected_studies_count

# test user studies count
res = client.get(STUDIES_URL, headers={"Authorization": f"Bearer {user_access_token}"})
assert res.status_code == 200, res.json()
expected_studies_count = len(res.json())
res = client.get(STUDIES_URL + "/count", headers={"Authorization": f"Bearer {user_access_token}"})
assert res.status_code == 200, res.json()
assert res.json() == expected_studies_count

0 comments on commit 7cd9b97

Please sign in to comment.