diff --git a/backend/tests/settings/test_alerts.py b/backend/tests/settings/test_alerts.py index 2d97aeca3..92ec26160 100644 --- a/backend/tests/settings/test_alerts.py +++ b/backend/tests/settings/test_alerts.py @@ -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, @@ -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 diff --git a/backend/tests/users/test_users.py b/backend/tests/users/test_users.py index a4f7e09d3..f622e241b 100644 --- a/backend/tests/users/test_users.py +++ b/backend/tests/users/test_users.py @@ -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" + )