Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add some more tests to increase coverage #2022

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
)
Loading