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

1# -*- coding: utf-8 -*- 

2 

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""" 

10 

11# ============================================================================== 

12# IMPORT PYTHON DEPENDENCIES 

13# ============================================================================== 

14 

15import pytest 

16 

17from tests.dummies_utils import create_dummy_projects 

18 

19# ============================================================================== 

20# test_ko_not_found 

21# ============================================================================== 

22 

23 

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. 

28 

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 

34 

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 } 

41 

42 

43# ============================================================================== 

44# test_ko_bad_state_1 

45# ============================================================================== 

46 

47 

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. 

52 

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 

59 

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 ) 

67 

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 } 

76 

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" 

82 

83 

84# ============================================================================== 

85# test_ko_bad_state_2 

86# ============================================================================== 

87 

88 

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. 

93 

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 

100 

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 ) 

108 

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 } 

115 

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" 

121 

122 

123# ============================================================================== 

124# test_ko_bad_state_3 

125# ============================================================================== 

126 

127 

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. 

132 

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 

139 

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 ) 

147 

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 } 

154 

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" 

160 

161 

162# ============================================================================== 

163# test_ko_bad_state_4 

164# ============================================================================== 

165 

166 

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. 

171 

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 

178 

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 ) 

186 

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 } 

195 

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" 

203 

204 

205# ============================================================================== 

206# test_ok_1 

207# ============================================================================== 

208 

209 

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. 

214 

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 

221 

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 ) 

229 

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 } 

239 

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" 

245 

246 

247# ============================================================================== 

248# test_ok_2 

249# ============================================================================== 

250 

251 

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. 

256 

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 

263 

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 ) 

271 

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 } 

281 

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"