Skip to content

Commit

Permalink
test: Add some more tests to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
zusorio committed Nov 19, 2024
1 parent 3fbb0a1 commit 3e2382e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
19 changes: 18 additions & 1 deletion backend/tests/settings/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_get_alerts(client: TestClient, db: orm.Session, executor_name: str):
users_crud.create_user(
db, executor_name, executor_name, None, users_models.Role.USER
)
notices_crud.create_notice(
notice = notices_crud.create_notice(
db,
notices_models.CreateNoticeRequest(
level=notices_models.NoticeLevel.INFO,
Expand All @@ -35,6 +35,23 @@ def test_get_alerts(client: TestClient, db: orm.Session, executor_name: str):
"message": "test message",
}.items() <= response.json()[0].items()

single_response = client.get(f"/api/v1/notices/{notice.id}")
assert single_response.status_code == 200
assert {
"level": "info",
"title": "test title",
"message": "test message",
}.items() <= single_response.json().items()


def test_get_missing_alert(
client: TestClient, db: orm.Session, executor_name: str
):
response = client.get("/api/v1/notices/1")

assert response.status_code == 404
assert response.json()["detail"]["err_code"] == "ANNOUNCEMENT_NOT_FOUND"


def test_create_alert2(
client: TestClient, db: orm.Session, executor_name: str
Expand Down
28 changes: 28 additions & 0 deletions backend/tests/users/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,31 @@ def test_fail_update_own_user(
assert (
response.json()["detail"]["err_code"] == "CHANGES_NOT_ALLOWED_FOR_ROLE"
)


@pytest.mark.usefixtures("admin")
def test_get_users(
client: testclient.TestClient,
executor_name: str,
):
response = client.get("/api/v1/users")

assert response.status_code == 200
assert len(response.json()) >= 2
assert any(user["name"] == "admin" for user in response.json())
assert any(user["name"] == executor_name for user in response.json())


@pytest.mark.usefixtures("admin")
def test_fail_update_user_no_reason(
client: testclient.TestClient,
test_user: users_models.DatabaseUser,
):
response = client.patch(
f"/api/v1/users/{test_user.id}", json={"role": users_models.Role.ADMIN}
)

assert response.status_code == 403
assert (
response.json()["detail"]["err_code"] == "ROLE_UPDATE_REQUIRES_REASON"
)

0 comments on commit 3e2382e

Please sign in to comment.