Coverage for tests\test_post_api_projects_constraints_approve.py: 100.00%
75 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-22 23:23 +0100
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-22 23:23 +0100
1# -*- coding: utf-8 -*-
3"""
4* Name: interactive-clustering-gui/tests/test_post_api_projects_constraints_approve.py
5* Description: Unittests for `app` module on the `POST /api/projects/{project_id}/constraints/approve` route.
6* Author: Erwan Schild
7* Created: 22/02/2022
8* Licence: CeCILL (https://cecill.info/licences.fr.html)
9"""
11# ==============================================================================
12# IMPORT PYTHON DEPENDENCIES
13# ==============================================================================
15import pytest
17from tests.dummies_utils import create_dummy_projects
19# ==============================================================================
20# test_ko_not_found
21# ==============================================================================
24@pytest.mark.asyncio()
25async def test_ko_not_found(async_client):
26 """
27 Test the `POST /api/projects/{project_id}/constraints/approve` route with not existing project.
29 Arguments:
30 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
31 """
32 # Assert HTTP client is created.
33 assert async_client
35 # Assert route `POST /api/projects/{project_id}/constraints/approve` works.
36 response_post = await async_client.post(url="/api/projects/UNKNOWN_PROJECT/constraints/approve")
37 assert response_post.status_code == 404
38 assert response_post.json() == {
39 "detail": "The project with id 'UNKNOWN_PROJECT' doesn't exist.",
40 }
43# ==============================================================================
44# test_ko_bad_state_1
45# ==============================================================================
48@pytest.mark.asyncio()
49async def test_ko_bad_state_1(async_client, tmp_path):
50 """
51 Test the `POST /api/projects/{project_id}/constraints/approve` route with bad state.
53 Arguments:
54 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
55 tmp_path: The temporary path given for this test, declared in `conftest.py`.
56 """
57 # Assert HTTP client is created.
58 assert async_client
60 # Create dummy projects.
61 create_dummy_projects(
62 tmp_path=tmp_path,
63 list_of_dummy_project_ids=[
64 "0a_INITIALIZATION_WITHOUT_MODELIZATION",
65 ],
66 )
68 # Assert route `POST /api/projects/{project_id}/constraints/approve` works.
69 response_post = await async_client.post(
70 url="/api/projects/0a_INITIALIZATION_WITHOUT_MODELIZATION/constraints/approve"
71 )
72 assert response_post.status_code == 403
73 assert response_post.json() == {
74 "detail": "The project with id '0a_INITIALIZATION_WITHOUT_MODELIZATION' doesn't allow constraints approbation during this state (state='INITIALIZATION_WITHOUT_MODELIZATION').",
75 }
77 # Assert route `GET /api/projects/{project_id}/status` is still the same.
78 response_get = await async_client.get(url="/api/projects/0a_INITIALIZATION_WITHOUT_MODELIZATION/status")
79 assert response_get.status_code == 200
80 assert response_get.json()["status"]["iteration_id"] == 0
81 assert response_get.json()["status"]["state"] == "INITIALIZATION_WITHOUT_MODELIZATION"
84# ==============================================================================
85# test_ko_bad_state_2
86# ==============================================================================
89@pytest.mark.asyncio()
90async def test_ko_bad_state_2(async_client, tmp_path):
91 """
92 Test the `POST /api/projects/{project_id}/constraints/approve` route with bad state.
94 Arguments:
95 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
96 tmp_path: The temporary path given for this test, declared in `conftest.py`.
97 """
98 # Assert HTTP client is created.
99 assert async_client
101 # Create dummy projects.
102 create_dummy_projects(
103 tmp_path=tmp_path,
104 list_of_dummy_project_ids=[
105 "1b_SAMPLING_PENDING",
106 ],
107 )
109 # Assert route `POST /api/projects/{project_id}/constraints/approve` works.
110 response_post = await async_client.post(url="/api/projects/1b_SAMPLING_PENDING/constraints/approve")
111 assert response_post.status_code == 403
112 assert response_post.json() == {
113 "detail": "The project with id '1b_SAMPLING_PENDING' doesn't allow constraints approbation during this state (state='SAMPLING_PENDING').",
114 }
116 # Assert route `GET /api/projects/{project_id}/status` is still the same.
117 response_get = await async_client.get(url="/api/projects/1b_SAMPLING_PENDING/status")
118 assert response_get.status_code == 200
119 assert response_get.json()["status"]["iteration_id"] == 1
120 assert response_get.json()["status"]["state"] == "SAMPLING_PENDING"
123# ==============================================================================
124# test_ko_bad_state_3
125# ==============================================================================
128@pytest.mark.asyncio()
129async def test_ko_bad_state_3(async_client, tmp_path):
130 """
131 Test the `POST /api/projects/{project_id}/constraints/approve` route with bad state.
133 Arguments:
134 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
135 tmp_path: The temporary path given for this test, declared in `conftest.py`.
136 """
137 # Assert HTTP client is created.
138 assert async_client
140 # Create dummy projects.
141 create_dummy_projects(
142 tmp_path=tmp_path,
143 list_of_dummy_project_ids=[
144 "1o_CLUSTERING_WORKING",
145 ],
146 )
148 # Assert route `POST /api/projects/{project_id}/constraints/approve` works.
149 response_post = await async_client.post(url="/api/projects/1o_CLUSTERING_WORKING/constraints/approve")
150 assert response_post.status_code == 403
151 assert response_post.json() == {
152 "detail": "The project with id '1o_CLUSTERING_WORKING' doesn't allow constraints approbation during this state (state='CLUSTERING_WORKING').",
153 }
155 # Assert route `GET /api/projects/{project_id}/status` is still the same.
156 response_get = await async_client.get(url="/api/projects/1o_CLUSTERING_WORKING/status")
157 assert response_get.status_code == 200
158 assert response_get.json()["status"]["iteration_id"] == 1
159 assert response_get.json()["status"]["state"] == "CLUSTERING_WORKING"
162# ==============================================================================
163# test_ko_bad_state_4
164# ==============================================================================
167@pytest.mark.asyncio()
168async def test_ko_bad_state_4(async_client, tmp_path):
169 """
170 Test the `POST /api/projects/{project_id}/constraints/approve` route with bad state.
172 Arguments:
173 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
174 tmp_path: The temporary path given for this test, declared in `conftest.py`.
175 """
176 # Assert HTTP client is created.
177 assert async_client
179 # Create dummy projects.
180 create_dummy_projects(
181 tmp_path=tmp_path,
182 list_of_dummy_project_ids=[
183 "1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS",
184 ],
185 )
187 # Assert route `POST /api/projects/{project_id}/constraints/approve` works.
188 response_post = await async_client.post(
189 url="/api/projects/1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/constraints/approve"
190 )
191 assert response_post.status_code == 403
192 assert response_post.json() == {
193 "detail": "The project with id '1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS' doesn't allow constraints approbation during this state (state='ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS').",
194 }
196 # Assert route `GET /api/projects/{project_id}/status` is still the same.
197 response_get = await async_client.get(
198 url="/api/projects/1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/status"
199 )
200 assert response_get.status_code == 200
201 assert response_get.json()["status"]["iteration_id"] == 1
202 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS"
205# ==============================================================================
206# test_ok_1
207# ==============================================================================
210@pytest.mark.asyncio()
211async def test_ok_1(async_client, tmp_path):
212 """
213 Test the `POST /api/projects/{project_id}/constraints/approve` route with good state.
215 Arguments:
216 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
217 tmp_path: The temporary path given for this test, declared in `conftest.py`.
218 """
219 # Assert HTTP client is created.
220 assert async_client
222 # Create dummy projects.
223 create_dummy_projects(
224 tmp_path=tmp_path,
225 list_of_dummy_project_ids=[
226 "1d_ANNOTATION_WITH_UPTODATE_MODELIZATION",
227 ],
228 )
230 # Assert route `POST /api/projects/{project_id}/constraints/approve` works.
231 response_post = await async_client.post(
232 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints/approve"
233 )
234 assert response_post.status_code == 201
235 assert response_post.json() == {
236 "project_id": "1d_ANNOTATION_WITH_UPTODATE_MODELIZATION",
237 "detail": "In project with id '1d_ANNOTATION_WITH_UPTODATE_MODELIZATION', the constraints have been approved.",
238 }
240 # Assert route `GET /api/projects/{project_id}/status` is still the same.
241 response_get = await async_client.get(url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status")
242 assert response_get.status_code == 200
243 assert response_get.json()["status"]["iteration_id"] == 1
244 assert response_get.json()["status"]["state"] == "CLUSTERING_TODO"
247# ==============================================================================
248# test_ok_2
249# ==============================================================================
252@pytest.mark.asyncio()
253async def test_ok_2(async_client, tmp_path):
254 """
255 Test the `POST /api/projects/{project_id}/constraints/approve` route with good state.
257 Arguments:
258 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
259 tmp_path: The temporary path given for this test, declared in `conftest.py`.
260 """
261 # Assert HTTP client is created.
262 assert async_client
264 # Create dummy projects.
265 create_dummy_projects(
266 tmp_path=tmp_path,
267 list_of_dummy_project_ids=[
268 "1l_ANNOTATION_WITH_UPTODATE_MODELIZATION",
269 ],
270 )
272 # Assert route `POST /api/projects/{project_id}/constraints/approve` works.
273 response_post = await async_client.post(
274 url="/api/projects/1l_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints/approve"
275 )
276 assert response_post.status_code == 201
277 assert response_post.json() == {
278 "project_id": "1l_ANNOTATION_WITH_UPTODATE_MODELIZATION",
279 "detail": "In project with id '1l_ANNOTATION_WITH_UPTODATE_MODELIZATION', the constraints have been approved.",
280 }
282 # Assert route `GET /api/projects/{project_id}/status` is still the same.
283 response_get = await async_client.get(url="/api/projects/1l_ANNOTATION_WITH_UPTODATE_MODELIZATION/status")
284 assert response_get.status_code == 200
285 assert response_get.json()["status"]["iteration_id"] == 1
286 assert response_get.json()["status"]["state"] == "CLUSTERING_TODO"