Coverage for tests\test_get_gui_projects_home.py: 100.00%
95 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_home.py
5* Description: Unittests for `app` module on the `GET /gui/projects/{project_id}` 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 `GET /gui/projects/{project_id}` 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 `GET /gui/projects` works.
36 response_get = await async_client.get(url="/gui/projects/UNKNOWN_PROJECT")
37 assert response_get.status_code == 404
38 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
39 assert b"<!-- HEAD -->" in response_get.content
40 assert b"<title>Interactive Clustering</title>" in response_get.content
41 assert b"<!-- BODY -->" in response_get.content
42 assert b"<!-- CONTAINER ERROR -->" in response_get.content
43 assert b"Error: 404" in response_get.content
44 assert b"The project with id 'UNKNOWN_PROJECT' doesn't exist." in response_get.content
47# ==============================================================================
48# test_ok_1
49# ==============================================================================
52@pytest.mark.asyncio()
53async def test_ok_1(async_client, tmp_path):
54 """
55 Test the `GET /gui/projects` route.
57 Arguments:
58 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
59 tmp_path: The temporary path given for this test, declared in `conftest.py`.
60 """
61 # Assert HTTP client is created.
62 assert async_client
64 # Create dummy projects.
65 create_dummy_projects(
66 tmp_path=tmp_path,
67 list_of_dummy_project_ids=[
68 "0a_INITIALIZATION_WITHOUT_MODELIZATION",
69 ],
70 )
72 # Assert route `GET /gui/projects` works.
73 response_get = await async_client.get(url="/gui/projects/0a_INITIALIZATION_WITHOUT_MODELIZATION")
74 assert response_get.status_code == 200
75 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
76 assert b"<!-- HEAD -->" in response_get.content
77 assert b"<title>Interactive Clustering</title>" in response_get.content
78 assert b"<!-- BODY -->" in response_get.content
79 assert b"<!-- CONTAINER PROJECT DESCRIPTION -->" in response_get.content
80 assert b"Description and Settings" in response_get.content
81 assert b"0a_INITIALIZATION_WITHOUT_MODELIZATION" in response_get.content
82 assert b"Iteration (0): Main steps" in response_get.content
83 assert b"<!-- CONTAINER ITERATION MAIN STEPS -->" in response_get.content
84 assert b"<!-- INITIALIZE MODELIZATION -->" in response_get.content
85 assert b"<!-- CONSTRAINTS SAMPLING -->" in response_get.content
86 assert b"<!-- CONSTRAINTS ANNOTATION AND MODELIZATION -->" in response_get.content
87 assert b"<!-- CONSTRAINED CLUSTERING -->" in response_get.content
88 assert b"<!-- NEXT ITERATION CREATION -->" in response_get.content
91# ==============================================================================
92# test_ok_2
93# ==============================================================================
96@pytest.mark.asyncio()
97async def test_ok_2(async_client, tmp_path):
98 """
99 Test the `GET /gui/projects` route.
101 Arguments:
102 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
103 tmp_path: The temporary path given for this test, declared in `conftest.py`.
104 """
105 # Assert HTTP client is created.
106 assert async_client
108 # Create dummy projects.
109 create_dummy_projects(
110 tmp_path=tmp_path,
111 list_of_dummy_project_ids=[
112 "0e_CLUSTERING_PENDING",
113 ],
114 )
116 # Assert route `GET /gui/projects` works.
117 response_get = await async_client.get(url="/gui/projects/0e_CLUSTERING_PENDING")
118 assert response_get.status_code == 200
119 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
120 assert b"<!-- HEAD -->" in response_get.content
121 assert b"<title>Interactive Clustering</title>" in response_get.content
122 assert b"<!-- BODY -->" in response_get.content
123 assert b"<!-- CONTAINER PROJECT DESCRIPTION -->" in response_get.content
124 assert b"Description and Settings" in response_get.content
125 assert b"0e_CLUSTERING_PENDING" in response_get.content
126 assert b"Iteration (0): Main steps" in response_get.content
127 assert b"<!-- CONTAINER ITERATION MAIN STEPS -->" in response_get.content
128 assert b"<!-- INITIALIZE MODELIZATION -->" in response_get.content
129 assert b"<!-- CONSTRAINTS SAMPLING -->" in response_get.content
130 assert b"<!-- CONSTRAINTS ANNOTATION AND MODELIZATION -->" in response_get.content
131 assert b"<!-- CONSTRAINED CLUSTERING -->" in response_get.content
132 assert b"<!-- NEXT ITERATION CREATION -->" in response_get.content
135# ==============================================================================
136# test_ok_3
137# ==============================================================================
140@pytest.mark.asyncio()
141async def test_ok_3(async_client, tmp_path):
142 """
143 Test the `GET /gui/projects` route.
145 Arguments:
146 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
147 tmp_path: The temporary path given for this test, declared in `conftest.py`.
148 """
149 # Assert HTTP client is created.
150 assert async_client
152 # Create dummy projects.
153 create_dummy_projects(
154 tmp_path=tmp_path,
155 list_of_dummy_project_ids=[
156 "1a_SAMPLING_TODO",
157 ],
158 )
160 # Assert route `GET /gui/projects` works.
161 response_get = await async_client.get(url="/gui/projects/1a_SAMPLING_TODO")
162 assert response_get.status_code == 200
163 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
164 assert b"<!-- HEAD -->" in response_get.content
165 assert b"<title>Interactive Clustering</title>" in response_get.content
166 assert b"<!-- BODY -->" in response_get.content
167 assert b"<!-- CONTAINER PROJECT DESCRIPTION -->" in response_get.content
168 assert b"Description and Settings" in response_get.content
169 assert b"1a_SAMPLING_TODO" in response_get.content
170 assert b"Iteration (1): Main steps" in response_get.content
171 assert b"<!-- CONTAINER ITERATION MAIN STEPS -->" in response_get.content
172 assert b"<!-- INITIALIZE MODELIZATION -->" in response_get.content
173 assert b"<!-- CONSTRAINTS SAMPLING -->" in response_get.content
174 assert b"<!-- CONSTRAINTS ANNOTATION AND MODELIZATION -->" in response_get.content
175 assert b"<!-- CONSTRAINED CLUSTERING -->" in response_get.content
176 assert b"<!-- NEXT ITERATION CREATION -->" in response_get.content
179# ==============================================================================
180# test_ok_4
181# ==============================================================================
184@pytest.mark.asyncio()
185async def test_ok_4(async_client, tmp_path):
186 """
187 Test the `GET /gui/projects` route.
189 Arguments:
190 async_client: Fixture providing an HTTP client, declared in `conftest.py`.
191 tmp_path: The temporary path given for this test, declared in `conftest.py`.
192 """
193 # Assert HTTP client is created.
194 assert async_client
196 # Create dummy projects.
197 create_dummy_projects(
198 tmp_path=tmp_path,
199 list_of_dummy_project_ids=[
200 "1k_ANNOTATION_WITH_WORKING_MODELIZATION_WITH_CONFLICTS",
201 ],
202 )
204 # Assert route `GET /gui/projects` works.
205 response_get = await async_client.get(url="/gui/projects/1k_ANNOTATION_WITH_WORKING_MODELIZATION_WITH_CONFLICTS")
206 assert response_get.status_code == 200
207 assert response_get.headers["content-type"] == "text/html; charset=utf-8"
208 assert b"<!-- HEAD -->" in response_get.content
209 assert b"<title>Interactive Clustering</title>" in response_get.content
210 assert b"<!-- BODY -->" in response_get.content
211 assert b"<!-- CONTAINER PROJECT DESCRIPTION -->" in response_get.content
212 assert b"Description and Settings" in response_get.content
213 assert b"1k_ANNOTATION_WITH_WORKING_MODELIZATION_WITH_CONFLICTS" in response_get.content
214 assert b"Iteration (1): Main steps" in response_get.content
215 assert b"<!-- CONTAINER ITERATION MAIN STEPS -->" in response_get.content
216 assert b"<!-- INITIALIZE MODELIZATION -->" in response_get.content
217 assert b"<!-- CONSTRAINTS SAMPLING -->" in response_get.content
218 assert b"<!-- CONSTRAINTS ANNOTATION AND MODELIZATION -->" in response_get.content
219 assert b"<!-- CONSTRAINED CLUSTERING -->" in response_get.content
220 assert b"<!-- NEXT ITERATION CREATION -->" in response_get.content