Coverage for tests\test_get_gui_projects_settings.py: 100.00%
121 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_get_gui_projects_settings.py
5* Description: Unittests for `app` module on the `GET /gui/projects/{project_id}/settings` 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 html
17import pytest
19from tests.dummies_utils import create_dummy_projects
21# ==============================================================================
22# test_ko_not_found
23# ==============================================================================
26@pytest.mark.asyncio()
27async def test_ko_not_found(async_client):
28 """
29 Test the `GET /gui/projects/{project_id}/settings` route with not existing project.
31 Arguments:
32 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
33 """
34 # Assert HTTP client is created.
35 assert async_client
37 # Assert route `GET /gui/projects/{project_id}/settings` works.
38 response_get = await async_client.get(url="/gui/projects/UNKNOWN_PROJECT/settings")
39 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8"))
40 assert response_get.status_code == 404
41 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
42 assert "<!-- HEAD -->" in parsed_response_get
43 assert "<title>Interactive Clustering</title>" in parsed_response_get
44 assert "<!-- BODY -->" in parsed_response_get
45 assert "<!-- CONTAINER ERROR -->" in parsed_response_get
46 assert "Error: 404" in parsed_response_get
47 assert "The project with id 'UNKNOWN_PROJECT' doesn't exist." in parsed_response_get
50# ==============================================================================
51# test_ko_bad_iteration_id
52# ==============================================================================
55@pytest.mark.asyncio()
56async def test_ko_bad_iteration_id(async_client, tmp_path):
57 """
58 Test the `GET /gui/projects/{project_id}/settings` route with not existing iteration id.
60 Arguments:
61 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
62 tmp_path: The temporary path given for this test, declared in `conftest.py`.
63 """
64 # Assert HTTP client is created.
65 assert async_client
67 # Create dummy projects.
68 create_dummy_projects(
69 tmp_path=tmp_path,
70 list_of_dummy_project_ids=[
71 "0a_INITIALIZATION_WITHOUT_MODELIZATION",
72 ],
73 )
75 # Assert route `GET /gui/projects/{project_id}/settings` works.
76 response_get = await async_client.get(
77 url="/gui/projects/0a_INITIALIZATION_WITHOUT_MODELIZATION/settings?iteration_id=99"
78 )
79 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8"))
80 assert response_get.status_code == 404
81 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
82 assert "<!-- HEAD -->" in parsed_response_get
83 assert "<title>Interactive Clustering</title>" in parsed_response_get
84 assert "<!-- BODY -->" in parsed_response_get
85 assert "<!-- CONTAINER ERROR -->" in parsed_response_get
86 assert "Error: 404" in parsed_response_get
87 assert (
88 "The project with id '0a_INITIALIZATION_WITHOUT_MODELIZATION' has no iteration with id '99'."
89 in parsed_response_get
90 )
93# ==============================================================================
94# test_ko_bad_settings_name
95# ==============================================================================
98@pytest.mark.asyncio()
99async def test_ko_bad_settings_name(async_client, tmp_path):
100 """
101 Test the `GET /gui/projects/{project_id}/settings` route with bad settings name.
103 Arguments:
104 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
105 tmp_path: The temporary path given for this test, declared in `conftest.py`.
106 """
107 # Assert HTTP client is created.
108 assert async_client
110 # Create dummy projects.
111 create_dummy_projects(
112 tmp_path=tmp_path,
113 list_of_dummy_project_ids=[
114 "0a_INITIALIZATION_WITHOUT_MODELIZATION",
115 ],
116 )
118 # Assert route `GET /gui/projects/{project_id}/settings` works.
119 response_get = await async_client.get(
120 url="/gui/projects/0a_INITIALIZATION_WITHOUT_MODELIZATION/settings?settings_names=UNKNOWN_SETTINGS"
121 )
122 assert response_get.status_code == 422
125# ==============================================================================
126# test_ok_default
127# ==============================================================================
130@pytest.mark.asyncio()
131async def test_ok_default(async_client, tmp_path):
132 """
133 Test the `GET /gui/projects/{project_id}/settings` route.
135 Arguments:
136 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
137 tmp_path: The temporary path given for this test, declared in `conftest.py`.
138 """
139 # Assert HTTP client is created.
140 assert async_client
142 # Create dummy projects.
143 create_dummy_projects(
144 tmp_path=tmp_path,
145 list_of_dummy_project_ids=[
146 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION",
147 ],
148 )
150 # Assert route `GET /gui/projects/{project_id}/settings` works.
151 response_get = await async_client.get(url="/gui/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings")
152 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8"))
153 assert response_get.status_code == 200
154 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
155 assert "<!-- HEAD -->" in parsed_response_get
156 assert "<title>Interactive Clustering</title>" in parsed_response_get
157 assert "<!-- BODY -->" in parsed_response_get
158 assert "<!-- CONTAINER SETTINGS -->" in parsed_response_get
159 assert "<!-- CONTAINER SETTINGS - TITLE -->" in parsed_response_get
160 assert "Current iteration (2): Settings synthesis" in parsed_response_get
161 assert "<!-- CONTAINER SETTINGS - CONTENT -->" in parsed_response_get
162 assert "<!-- CONTAINER SETTINGS - SETTINGS -->" in parsed_response_get
163 assert "<!-- CARD PREPROCESSING -->" in parsed_response_get
164 assert "<!-- CARD VECTORIZATION -->" in parsed_response_get
165 assert "<!-- CARD SAMPLING -->" in parsed_response_get
166 assert "<!-- CARD CLUSTERING -->" in parsed_response_get
167 assert "<!-- CONTAINER SETTINGS - ACTIONS NAVIGATION -->" in parsed_response_get
170# ==============================================================================
171# test_ok_with_iteration_id_1
172# ==============================================================================
175@pytest.mark.asyncio()
176async def test_ok_with_iteration_id_1(async_client, tmp_path):
177 """
178 Test the `GET /gui/projects/{project_id}/settings` route.
180 Arguments:
181 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
182 tmp_path: The temporary path given for this test, declared in `conftest.py`.
183 """
184 # Assert HTTP client is created.
185 assert async_client
187 # Create dummy projects.
188 create_dummy_projects(
189 tmp_path=tmp_path,
190 list_of_dummy_project_ids=[
191 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION",
192 ],
193 )
195 # Assert route `GET /gui/projects/{project_id}/settings` works.
196 response_get = await async_client.get(
197 url="/gui/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings?iteration_id=2"
198 )
199 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8"))
200 assert response_get.status_code == 200
201 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
202 assert "<!-- HEAD -->" in parsed_response_get
203 assert "<title>Interactive Clustering</title>" in parsed_response_get
204 assert "<!-- BODY -->" in parsed_response_get
205 assert "<!-- CONTAINER SETTINGS -->" in parsed_response_get
206 assert "<!-- CONTAINER SETTINGS - TITLE -->" in parsed_response_get
207 assert "Current iteration (2): Settings synthesis" in parsed_response_get
208 assert "<!-- CONTAINER SETTINGS - CONTENT -->" in parsed_response_get
209 assert "<!-- CONTAINER SETTINGS - SETTINGS -->" in parsed_response_get
210 assert "<!-- CARD PREPROCESSING -->" in parsed_response_get
211 assert "<!-- CARD VECTORIZATION -->" in parsed_response_get
212 assert "<!-- CARD SAMPLING -->" in parsed_response_get
213 assert "<!-- CARD CLUSTERING -->" in parsed_response_get
214 assert "<!-- CONTAINER SETTINGS - ACTIONS NAVIGATION -->" in parsed_response_get
217# ==============================================================================
218# test_ok_with_iteration_id_2
219# ==============================================================================
222@pytest.mark.asyncio()
223async def test_ok_with_iteration_id_2(async_client, tmp_path):
224 """
225 Test the `GET /gui/projects/{project_id}/settings` route.
227 Arguments:
228 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
229 tmp_path: The temporary path given for this test, declared in `conftest.py`.
230 """
231 # Assert HTTP client is created.
232 assert async_client
234 # Create dummy projects.
235 create_dummy_projects(
236 tmp_path=tmp_path,
237 list_of_dummy_project_ids=[
238 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION",
239 ],
240 )
242 # Assert route `GET /gui/projects/{project_id}/settings` works.
243 response_get = await async_client.get(
244 url="/gui/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings?iteration_id=0"
245 )
246 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8"))
247 assert response_get.status_code == 200
248 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
249 assert "<!-- HEAD -->" in parsed_response_get
250 assert "<title>Interactive Clustering</title>" in parsed_response_get
251 assert "<!-- BODY -->" in parsed_response_get
252 assert "<!-- CONTAINER SETTINGS -->" in parsed_response_get
253 assert "<!-- CONTAINER SETTINGS - TITLE -->" in parsed_response_get
254 assert "Previous iteration (0): Settings synthesis" in parsed_response_get
255 assert "<!-- CONTAINER SETTINGS - CONTENT -->" in parsed_response_get
256 assert "<!-- CONTAINER SETTINGS - SETTINGS -->" in parsed_response_get
257 assert "<!-- CARD PREPROCESSING -->" in parsed_response_get
258 assert "<!-- CARD VECTORIZATION -->" in parsed_response_get
259 assert "<!-- CARD SAMPLING -->" not in parsed_response_get
260 assert "<!-- CARD CLUSTERING -->" in parsed_response_get
261 assert "<!-- CONTAINER SETTINGS - ACTIONS NAVIGATION -->" in parsed_response_get
264# ==============================================================================
265# test_ok_with_settings_name
266# ==============================================================================
269@pytest.mark.asyncio()
270async def test_ok_with_settings_name(async_client, tmp_path):
271 """
272 Test the `GET /gui/projects/{project_id}/settings` route.
274 Arguments:
275 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
276 tmp_path: The temporary path given for this test, declared in `conftest.py`.
277 """
278 # Assert HTTP client is created.
279 assert async_client
281 # Create dummy projects.
282 create_dummy_projects(
283 tmp_path=tmp_path,
284 list_of_dummy_project_ids=[
285 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION",
286 ],
287 )
289 # Assert route `GET /gui/projects/{project_id}/settings` works.
290 response_get = await async_client.get(
291 url="/gui/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings?settings_names=preprocessing&settings_names=vectorization"
292 )
293 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8"))
294 assert response_get.status_code == 200
295 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
296 assert "<!-- HEAD -->" in parsed_response_get
297 assert "<title>Interactive Clustering</title>" in parsed_response_get
298 assert "<!-- BODY -->" in parsed_response_get
299 assert "<!-- CONTAINER SETTINGS -->" in parsed_response_get
300 assert "<!-- CONTAINER SETTINGS - TITLE -->" in parsed_response_get
301 assert "Current iteration (2): Settings synthesis" in parsed_response_get
302 assert "<!-- CONTAINER SETTINGS - CONTENT -->" in parsed_response_get
303 assert "<!-- CONTAINER SETTINGS - SETTINGS -->" in parsed_response_get
304 assert "<!-- CARD PREPROCESSING -->" in parsed_response_get
305 assert "<!-- CARD VECTORIZATION -->" in parsed_response_get
306 assert "<!-- CARD SAMPLING -->" not in parsed_response_get
307 assert "<!-- CARD CLUSTERING -->" not in parsed_response_get
308 assert "<!-- CONTAINER SETTINGS - ACTIONS NAVIGATION -->" in parsed_response_get