Coverage for src/tests/api/v1/portal/endpoints/test_applications.py: 100%
25 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
1"""Module for testing the portal applications endpoints."""
3import pytest
5from fastapi import status
6from fastapi.testclient import TestClient
9pytestmark = pytest.mark.api
12async def test_get_applications(client: TestClient, make_application_in_db):
13 """Test the get applications api."""
14 await make_application_in_db()
15 response = client.get("/api/v1/portal/applications")
16 assert response.status_code == status.HTTP_200_OK
18 json = response.json()
19 assert "meta" in json, "There should be a meta object in the response"
20 assert "data" in json, "There should be a data list in the response"
23async def test_get_application(client: TestClient, make_application_in_db):
24 """Test the get application api."""
25 application = await make_application_in_db()
26 response = client.get(f"/api/v1/portal/applications/{application.id}")
27 assert response.status_code == status.HTTP_200_OK
29 json = response.json()
30 assert "data" in json, "There should be data in the response"
33def test_get_application_not_found(client: TestClient):
34 """Test if the get api responds with 404 when no application is found."""
35 response = client.get("/api/v1/portal/applications/9999")
36 assert response.status_code == status.HTTP_404_NOT_FOUND
39async def test_update_application(secure_client: TestClient, make_application_in_db):
40 """Test PATCH /api/v1/portal/applications."""
41 application = await make_application_in_db()
42 payload = {
43 "data": {
44 "type": "applications",
45 "id": str(application.id),
46 "attributes": {
47 "title": "Test",
48 "name": "test",
49 "short_description": "An application used for testing",
50 "description": "",
51 "weight": 0,
52 "events": application.can_contain_events,
53 "pages": application.can_contain_pages,
54 "news": application.can_contain_news,
55 "remark": "Updated",
56 },
57 },
58 }
59 response = secure_client.patch(
60 f"/api/v1/portal/applications/{application.id}", json=payload
61 )
62 assert response.status_code == status.HTTP_200_OK, response.json()