Coverage for tests\test_put_api_projects_constraints_review.py: 100.00%
76 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_put_api_projects_constraints_review.py
5* Description: Unittests for `app` module on the `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` 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_1
21# ==============================================================================
24@pytest.mark.asyncio()
25async def test_ko_not_found_1(async_client):
26 """
27 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` 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 `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` works.
36 response_put = await async_client.put(url="/api/projects/UNKNOWN_PROJECT/constraints/UNKNOWN_CONSTRAINT/review")
37 assert response_put.status_code == 404
38 assert response_put.json() == {
39 "detail": "The project with id 'UNKNOWN_PROJECT' doesn't exist.",
40 }
43# ==============================================================================
44# test_ko_not_found_2
45# ==============================================================================
48@pytest.mark.asyncio()
49async def test_ko_not_found_2(async_client, tmp_path):
50 """
51 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` route with not existing project.
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 "1a_SAMPLING_TODO",
65 ],
66 )
68 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` works.
69 response_put = await async_client.put(url="/api/projects/1a_SAMPLING_TODO/constraints/UNKNOWN_CONSTRAINT/review")
70 assert response_put.status_code == 404
71 assert response_put.json() == {
72 "detail": "In project with id '1a_SAMPLING_TODO', the constraint with id 'UNKNOWN_CONSTRAINT' to annotate doesn't exist.",
73 }
76# ==============================================================================
77# test_ok_good_state_default
78# ==============================================================================
81@pytest.mark.asyncio()
82async def test_ok_good_state_default(async_client, tmp_path):
83 """
84 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` route with good state.
86 Arguments:
87 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
88 tmp_path: The temporary path given for this test, declared in `conftest.py`.
89 """
90 # Assert HTTP client is created.
91 assert async_client
93 # Create dummy projects.
94 create_dummy_projects(
95 tmp_path=tmp_path,
96 list_of_dummy_project_ids=[
97 "1d_ANNOTATION_WITH_UPTODATE_MODELIZATION",
98 ],
99 )
101 # Get texts before test.
102 response_get_constraints_before = await async_client.get(
103 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints?without_hidden_constraints=false"
104 )
105 assert response_get_constraints_before.status_code == 200
106 assert response_get_constraints_before.json()["constraints"]["(0,4)"]["to_review"] is False
108 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` works.
109 response_put = await async_client.put(
110 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints/(0,4)/review"
111 )
112 assert response_put.status_code == 202
113 assert response_put.json() == {
114 "project_id": "1d_ANNOTATION_WITH_UPTODATE_MODELIZATION",
115 "constraint_id": "(0,4)",
116 "detail": "In project with id '1d_ANNOTATION_WITH_UPTODATE_MODELIZATION', the constraint with id '(0,4)' need a review.",
117 }
119 # Assert route `GET /api/projects/{project_id}/constraints` is updated.
120 response_get_constraints_after = await async_client.get(
121 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints?without_hidden_constraints=false"
122 )
123 assert response_get_constraints_after.status_code == 200
124 for constraint_id in response_get_constraints_before.json()["constraints"].keys():
125 if constraint_id != "(0,4)":
126 assert (
127 response_get_constraints_after.json()["constraints"][constraint_id]
128 == response_get_constraints_before.json()["constraints"][constraint_id]
129 )
130 assert response_get_constraints_after.json()["constraints"]["(0,4)"]["to_review"] is True
132 # Assert route `GET /api/projects/{project_id}/status` is updated.
133 response_get_status = await async_client.get(url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status")
134 assert response_get_status.status_code == 200
135 assert response_get_status.json()["status"]["iteration_id"] == 1
136 assert response_get_status.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION"
139# ==============================================================================
140# test_ok_good_state_review
141# ==============================================================================
144@pytest.mark.asyncio()
145async def test_ok_good_state_review(async_client, tmp_path):
146 """
147 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` route with good state.
149 Arguments:
150 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
151 tmp_path: The temporary path given for this test, declared in `conftest.py`.
152 """
153 # Assert HTTP client is created.
154 assert async_client
156 # Create dummy projects.
157 create_dummy_projects(
158 tmp_path=tmp_path,
159 list_of_dummy_project_ids=[
160 "1m_CLUSTERING_TODO",
161 ],
162 )
164 # Get texts before test.
165 response_get_constraints_before = await async_client.get(
166 url="/api/projects/1m_CLUSTERING_TODO/constraints?without_hidden_constraints=false"
167 )
168 assert response_get_constraints_before.status_code == 200
169 assert response_get_constraints_before.json()["constraints"]["(0,4)"]["to_review"] is False
171 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` works.
172 response_put = await async_client.put(
173 url="/api/projects/1m_CLUSTERING_TODO/constraints/(0,4)/review?to_review=true"
174 )
175 assert response_put.status_code == 202
176 assert response_put.json() == {
177 "project_id": "1m_CLUSTERING_TODO",
178 "constraint_id": "(0,4)",
179 "detail": "In project with id '1m_CLUSTERING_TODO', the constraint with id '(0,4)' need a review.",
180 }
182 # Assert route `GET /api/projects/{project_id}/constraints` is updated.
183 response_get_constraints_after = await async_client.get(
184 url="/api/projects/1m_CLUSTERING_TODO/constraints?without_hidden_constraints=false"
185 )
186 assert response_get_constraints_after.status_code == 200
187 for constraint_id in response_get_constraints_before.json()["constraints"].keys():
188 if constraint_id != "(0,4)":
189 assert (
190 response_get_constraints_after.json()["constraints"][constraint_id]
191 == response_get_constraints_before.json()["constraints"][constraint_id]
192 )
193 assert response_get_constraints_after.json()["constraints"]["(0,4)"]["to_review"] is True
195 # Assert route `GET /api/projects/{project_id}/status` is updated.
196 response_get_status = await async_client.get(url="/api/projects/1m_CLUSTERING_TODO/status")
197 assert response_get_status.status_code == 200
198 assert response_get_status.json()["status"]["iteration_id"] == 1
199 assert response_get_status.json()["status"]["state"] == "CLUSTERING_TODO"
202# ==============================================================================
203# test_ok_good_state_not_review
204# ==============================================================================
207@pytest.mark.asyncio()
208async def test_ok_good_state_not_review(async_client, tmp_path):
209 """
210 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` route with good state.
212 Arguments:
213 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
214 tmp_path: The temporary path given for this test, declared in `conftest.py`.
215 """
216 # Assert HTTP client is created.
217 assert async_client
219 # Create dummy projects.
220 create_dummy_projects(
221 tmp_path=tmp_path,
222 list_of_dummy_project_ids=[
223 "1p_ITERATION_END",
224 ],
225 )
227 # Get texts before test.
228 response_get_constraints_before = await async_client.get(
229 url="/api/projects/1p_ITERATION_END/constraints?without_hidden_constraints=false"
230 )
231 assert response_get_constraints_before.status_code == 200
232 assert response_get_constraints_before.json()["constraints"]["(4,6)"]["to_review"] is True
234 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/review` works.
235 response_put = await async_client.put(url="/api/projects/1p_ITERATION_END/constraints/(4,6)/review?to_review=false")
236 assert response_put.status_code == 202
237 assert response_put.json() == {
238 "project_id": "1p_ITERATION_END",
239 "constraint_id": "(4,6)",
240 "detail": "In project with id '1p_ITERATION_END', the constraint with id '(4,6)' has been reviewed.",
241 }
243 # Assert route `GET /api/projects/{project_id}/constraints` is updated.
244 response_get_constraints_after = await async_client.get(
245 url="/api/projects/1p_ITERATION_END/constraints?without_hidden_constraints=false"
246 )
247 assert response_get_constraints_after.status_code == 200
248 for constraint_id in response_get_constraints_before.json()["constraints"].keys():
249 if constraint_id != "(4,6)":
250 assert (
251 response_get_constraints_after.json()["constraints"][constraint_id]
252 == response_get_constraints_before.json()["constraints"][constraint_id]
253 )
254 assert response_get_constraints_after.json()["constraints"]["(4,6)"]["to_review"] is False
256 # Assert route `GET /api/projects/{project_id}/status` is updated.
257 response_get_status = await async_client.get(url="/api/projects/1p_ITERATION_END/status")
258 assert response_get_status.status_code == 200
259 assert response_get_status.json()["status"]["iteration_id"] == 1
260 assert response_get_status.json()["status"]["state"] == "ITERATION_END"