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

Commit

Permalink
test: Adds missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm committed Nov 8, 2023
1 parent 1c36b81 commit 02cb0da
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/tests/endpoints/test_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,74 @@ async def test_delete_repo(
assert response.json() is None


@pytest.mark.parametrize(
("user_idx", "repo_id", "status_code", "status_detail", "expected_idx"),
[
(None, 12345, 401, "Not authenticated", None),
(0, 0, 422, None, None),
(0, 100, 404, "Table Repository has no corresponding entry.", None),
(0, 12345, 200, None, 0),
(0, 123456, 200, None, 1),
(1, 12345, 422, "Expected `github_token` to check access.", None),
(1, 123456, 200, None, 1),
],
)
@pytest.mark.asyncio()
async def test_enable_repo(
async_client: AsyncClient,
repo_session: AsyncSession,
user_idx: Union[int, None],
repo_id: int,
status_code: int,
status_detail: Union[str, None],
expected_idx: Union[int, None],
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(USER_TABLE[user_idx]["id"], USER_TABLE[user_idx]["scope"].split())

response = await async_client.put(f"/repos/{repo_id}/enable", json={}, headers=auth)
assert response.status_code == status_code, print(response.__dict__)
if isinstance(status_detail, str):
assert response.json()["detail"] == status_detail
if response.status_code // 100 == 2:
assert response.json() == {**REPO_TABLE[expected_idx], "is_active": True}


@pytest.mark.parametrize(
("user_idx", "repo_id", "status_code", "status_detail", "expected_idx"),
[
(None, 12345, 401, "Not authenticated", None),
(0, 0, 422, None, None),
(0, 100, 404, "Table Repository has no corresponding entry.", None),
(0, 12345, 200, None, 0),
(0, 123456, 200, None, 1),
(1, 12345, 422, "Expected `github_token` to check access.", None),
(1, 123456, 200, None, 1),
],
)
@pytest.mark.asyncio()
async def test_disable_repo(
async_client: AsyncClient,
repo_session: AsyncSession,
user_idx: Union[int, None],
repo_id: int,
status_code: int,
status_detail: Union[str, None],
expected_idx: Union[int, None],
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(USER_TABLE[user_idx]["id"], USER_TABLE[user_idx]["scope"].split())

response = await async_client.put(f"/repos/{repo_id}/disable", json={}, headers=auth)
assert response.status_code == status_code, print(response.__dict__)
if isinstance(status_detail, str):
assert response.json()["detail"] == status_detail
if response.status_code // 100 == 2:
assert response.json() == {**REPO_TABLE[expected_idx], "is_active": False}


@pytest.mark.parametrize(
("user_idx", "repo_id", "status_code", "status_detail", "expected_response"),
[
Expand Down

0 comments on commit 02cb0da

Please sign in to comment.