Coverage for tests\test_put_api_projects_constraints_annotate.py: 100.00%

167 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_put_api_projects_constraints_annotate.py 

5* Description: Unittests for `app` module on the `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` 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_1 

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

22 

23 

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}/annotate` 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 `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

36 response_put = await async_client.put(url="/api/projects/UNKNOWN_PROJECT/constraints/UNKNOWN_CONSTRAINT/annotate") 

37 assert response_put.status_code == 404 

38 assert response_put.json() == { 

39 "detail": "The project with id 'UNKNOWN_PROJECT' doesn't exist.", 

40 } 

41 

42 

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

44# test_ko_not_found_2 

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

46 

47 

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}/annotate` route with not existing project. 

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 "1a_SAMPLING_TODO", 

65 ], 

66 ) 

67 

68 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

69 response_put = await async_client.put(url="/api/projects/1a_SAMPLING_TODO/constraints/UNKNOWN_CONSTRAINT/annotate") 

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 } 

74 

75 

76# ============================================================================== 

77# test_ko_bad_state_1 

78# ============================================================================== 

79 

80 

81@pytest.mark.asyncio() 

82async def test_ko_bad_state_1(async_client, tmp_path): 

83 """ 

84 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` route with bad state. 

85 

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 

92 

93 # Create dummy projects. 

94 create_dummy_projects( 

95 tmp_path=tmp_path, 

96 list_of_dummy_project_ids=[ 

97 "1f_ANNOTATION_WITH_PENDING_MODELIZATION_WITHOUT_CONFLICTS", 

98 ], 

99 ) 

100 

101 # Get texts before test. 

102 response_get_constraints_before = await async_client.get( 

103 url="/api/projects/1f_ANNOTATION_WITH_PENDING_MODELIZATION_WITHOUT_CONFLICTS/constraints?without_hidden_constraints=false" 

104 ) 

105 assert response_get_constraints_before.status_code == 200 

106 assert response_get_constraints_before.json()["constraints"]["(14,9)"]["constraint_type"] is None 

107 

108 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

109 response_put = await async_client.put( 

110 url="/api/projects/1f_ANNOTATION_WITH_PENDING_MODELIZATION_WITHOUT_CONFLICTS/constraints/(14,9)/annotate?constraint_type=MUST_LINK" 

111 ) 

112 assert response_put.status_code == 403 

113 assert response_put.json() == { 

114 "detail": "The project with id '1f_ANNOTATION_WITH_PENDING_MODELIZATION_WITHOUT_CONFLICTS' doesn't allow modification during this state (state='ANNOTATION_WITH_PENDING_MODELIZATION_WITHOUT_CONFLICTS').", 

115 } 

116 

117 # Assert route `GET /api/projects/{project_id}/constraints` is still the same. 

118 response_get_constraints_after = await async_client.get( 

119 url="/api/projects/1f_ANNOTATION_WITH_PENDING_MODELIZATION_WITHOUT_CONFLICTS/constraints?without_hidden_constraints=false" 

120 ) 

121 assert response_get_constraints_after.status_code == 200 

122 assert response_get_constraints_after.json() == response_get_constraints_before.json() 

123 assert response_get_constraints_after.json()["constraints"]["(14,9)"]["constraint_type"] is None 

124 

125 

126# ============================================================================== 

127# test_ko_bad_state_2 

128# ============================================================================== 

129 

130 

131@pytest.mark.asyncio() 

132async def test_ko_bad_state_2(async_client, tmp_path): 

133 """ 

134 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` route with bad state. 

135 

136 Arguments: 

137 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

138 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

139 """ 

140 # Assert HTTP client is created. 

141 assert async_client 

142 

143 # Create dummy projects. 

144 create_dummy_projects( 

145 tmp_path=tmp_path, 

146 list_of_dummy_project_ids=[ 

147 "1m_CLUSTERING_TODO", 

148 ], 

149 ) 

150 

151 # Get texts before test. 

152 response_get_constraints_before = await async_client.get( 

153 url="/api/projects/1m_CLUSTERING_TODO/constraints?without_hidden_constraints=false" 

154 ) 

155 assert response_get_constraints_before.status_code == 200 

156 assert response_get_constraints_before.json()["constraints"]["(1,2)"]["constraint_type"] == "MUST_LINK" 

157 

158 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

159 response_put = await async_client.put( 

160 url="/api/projects/1m_CLUSTERING_TODO/constraints/(1,2)/annotate?constraint_type=MUST_LINK" 

161 ) 

162 assert response_put.status_code == 403 

163 assert response_put.json() == { 

164 "detail": "The project with id '1m_CLUSTERING_TODO' doesn't allow modification during this state (state='CLUSTERING_TODO').", 

165 } 

166 

167 # Assert route `GET /api/projects/{project_id}/constraints` is still the same. 

168 response_get_constraints_after = await async_client.get( 

169 url="/api/projects/1m_CLUSTERING_TODO/constraints?without_hidden_constraints=false" 

170 ) 

171 assert response_get_constraints_after.status_code == 200 

172 assert response_get_constraints_after.json() == response_get_constraints_before.json() 

173 assert response_get_constraints_after.json()["constraints"]["(1,2)"]["constraint_type"] == "MUST_LINK" 

174 

175 

176# ============================================================================== 

177# test_ko_bad_annotation 

178# ============================================================================== 

179 

180 

181@pytest.mark.asyncio() 

182async def test_ko_bad_annotation(async_client, tmp_path): 

183 """ 

184 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` route with bad annotation. 

185 

186 Arguments: 

187 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

188 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

189 """ 

190 # Assert HTTP client is created. 

191 assert async_client 

192 

193 # Create dummy projects. 

194 create_dummy_projects( 

195 tmp_path=tmp_path, 

196 list_of_dummy_project_ids=[ 

197 "1d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

198 ], 

199 ) 

200 

201 # Get texts before test. 

202 response_get_constraints_before = await async_client.get( 

203 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints?without_hidden_constraints=false" 

204 ) 

205 assert response_get_constraints_before.status_code == 200 

206 assert response_get_constraints_before.json()["constraints"]["(0,4)"]["constraint_type"] is None 

207 

208 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

209 response_put = await async_client.put( 

210 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints/(0,4)/annotate?constraint_type=UNKNOWN_ANNOTATION" 

211 ) 

212 assert response_put.status_code == 422 

213 

214 # Assert route `GET /api/projects/{project_id}/constraints` is still the same. 

215 response_get_constraints_after = await async_client.get( 

216 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints?without_hidden_constraints=false" 

217 ) 

218 assert response_get_constraints_after.status_code == 200 

219 assert response_get_constraints_after.json() == response_get_constraints_before.json() 

220 assert response_get_constraints_after.json()["constraints"]["(0,4)"]["constraint_type"] is None 

221 

222 

223# ============================================================================== 

224# test_ok_good_state_none 

225# ============================================================================== 

226 

227 

228@pytest.mark.asyncio() 

229async def test_ok_good_state_none(async_client, tmp_path): 

230 """ 

231 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` route with good state. 

232 

233 Arguments: 

234 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

235 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

236 """ 

237 # Assert HTTP client is created. 

238 assert async_client 

239 

240 # Create dummy projects. 

241 create_dummy_projects( 

242 tmp_path=tmp_path, 

243 list_of_dummy_project_ids=[ 

244 "1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS", 

245 ], 

246 ) 

247 

248 # Get texts before test. 

249 response_get_constraints_before = await async_client.get( 

250 url="/api/projects/1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/constraints?without_hidden_constraints=false" 

251 ) 

252 assert response_get_constraints_before.status_code == 200 

253 assert response_get_constraints_before.json()["constraints"]["(12,9)"]["constraint_type"] == "MUST_LINK" 

254 assert response_get_constraints_before.json()["constraints"]["(12,9)"]["constraint_type_previous"] == [ 

255 None, 

256 "CANNOT_LINK", 

257 ] 

258 assert response_get_constraints_before.json()["constraints"]["(12,9)"]["to_annotate"] is False 

259 assert response_get_constraints_before.json()["constraints"]["(12,9)"]["date_of_update"] is not None 

260 

261 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

262 response_put = await async_client.put( 

263 url="/api/projects/1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/constraints/(12,9)/annotate" 

264 ) 

265 assert response_put.status_code == 202 

266 assert response_put.json() == { 

267 "project_id": "1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS", 

268 "constraint_id": "(12,9)", 

269 "detail": "In project with id '1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS', the constraint with id '(12,9)' has been annotated at `None`.", 

270 } 

271 

272 # Assert route `GET /api/projects/{project_id}/constraints` is updated. 

273 response_get_constraints_after = await async_client.get( 

274 url="/api/projects/1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/constraints?without_hidden_constraints=false" 

275 ) 

276 assert response_get_constraints_after.status_code == 200 

277 for constraint_id in response_get_constraints_before.json()["constraints"].keys(): 

278 if constraint_id != "(12,9)": 

279 assert ( 

280 response_get_constraints_after.json()["constraints"][constraint_id] 

281 == response_get_constraints_before.json()["constraints"][constraint_id] 

282 ) 

283 assert response_get_constraints_after.json()["constraints"]["(12,9)"]["constraint_type"] is None 

284 assert response_get_constraints_after.json()["constraints"]["(12,9)"]["constraint_type_previous"] == [ 

285 None, 

286 "CANNOT_LINK", 

287 "MUST_LINK", 

288 ] 

289 assert response_get_constraints_after.json()["constraints"]["(12,9)"]["to_annotate"] is False 

290 assert response_get_constraints_after.json()["constraints"]["(12,9)"]["date_of_update"] is not None 

291 

292 # Assert route `GET /api/projects/{project_id}/status` is updated. 

293 response_get_status = await async_client.get( 

294 url="/api/projects/1h_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/status" 

295 ) 

296 assert response_get_status.status_code == 200 

297 assert response_get_status.json()["status"]["iteration_id"] == 1 

298 assert response_get_status.json()["status"]["state"] == "ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS" 

299 

300 

301# ============================================================================== 

302# test_ok_good_state_must_link 

303# ============================================================================== 

304 

305 

306@pytest.mark.asyncio() 

307async def test_ok_good_state_must_link(async_client, tmp_path): 

308 """ 

309 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` route with good state. 

310 

311 Arguments: 

312 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

313 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

314 """ 

315 # Assert HTTP client is created. 

316 assert async_client 

317 

318 # Create dummy projects. 

319 create_dummy_projects( 

320 tmp_path=tmp_path, 

321 list_of_dummy_project_ids=[ 

322 "1d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

323 ], 

324 ) 

325 

326 # Get texts before test. 

327 response_get_constraints_before = await async_client.get( 

328 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints?without_hidden_constraints=false" 

329 ) 

330 assert response_get_constraints_before.status_code == 200 

331 assert response_get_constraints_before.json()["constraints"]["(0,4)"]["constraint_type"] is None 

332 assert ( 

333 response_get_constraints_before.json()["constraints"]["(0,4)"]["constraint_type_previous"] == [] # noqa: WPS520 

334 ) 

335 assert response_get_constraints_before.json()["constraints"]["(0,4)"]["to_annotate"] is True 

336 assert response_get_constraints_before.json()["constraints"]["(0,4)"]["date_of_update"] is None 

337 

338 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

339 response_put = await async_client.put( 

340 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints/(0,4)/annotate?constraint_type=MUST_LINK" 

341 ) 

342 assert response_put.status_code == 202 

343 assert response_put.json() == { 

344 "project_id": "1d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

345 "constraint_id": "(0,4)", 

346 "detail": "In project with id '1d_ANNOTATION_WITH_UPTODATE_MODELIZATION', the constraint with id '(0,4)' has been annotated at `MUST_LINK`.", 

347 } 

348 

349 # Assert route `GET /api/projects/{project_id}/constraints` is updated. 

350 response_get_constraints_after = await async_client.get( 

351 url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints?without_hidden_constraints=false" 

352 ) 

353 assert response_get_constraints_after.status_code == 200 

354 for constraint_id in response_get_constraints_before.json()["constraints"].keys(): 

355 if constraint_id != "(0,4)": 

356 assert ( 

357 response_get_constraints_after.json()["constraints"][constraint_id] 

358 == response_get_constraints_before.json()["constraints"][constraint_id] 

359 ) 

360 assert response_get_constraints_after.json()["constraints"]["(0,4)"]["constraint_type"] == "MUST_LINK" 

361 assert response_get_constraints_after.json()["constraints"]["(0,4)"]["constraint_type_previous"] == [ 

362 None, 

363 ] 

364 assert response_get_constraints_after.json()["constraints"]["(0,4)"]["to_annotate"] is False 

365 assert response_get_constraints_after.json()["constraints"]["(0,4)"]["date_of_update"] is not None 

366 

367 # Assert route `GET /api/projects/{project_id}/status` is updated. 

368 response_get_status = await async_client.get(url="/api/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

369 assert response_get_status.status_code == 200 

370 assert response_get_status.json()["status"]["iteration_id"] == 1 

371 assert response_get_status.json()["status"]["state"] == "ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS" 

372 

373 

374# ============================================================================== 

375# test_ok_good_state_cannot_link 

376# ============================================================================== 

377 

378 

379@pytest.mark.asyncio() 

380async def test_ok_good_state_cannot_link(async_client, tmp_path): 

381 """ 

382 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` route with good state. 

383 

384 Arguments: 

385 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

386 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

387 """ 

388 # Assert HTTP client is created. 

389 assert async_client 

390 

391 # Create dummy projects. 

392 create_dummy_projects( 

393 tmp_path=tmp_path, 

394 list_of_dummy_project_ids=[ 

395 "1i_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS", 

396 ], 

397 ) 

398 

399 # Get texts before test. 

400 response_get_constraints_before = await async_client.get( 

401 url="/api/projects/1i_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/constraints?without_hidden_constraints=false" 

402 ) 

403 assert response_get_constraints_before.status_code == 200 

404 assert response_get_constraints_before.json()["constraints"]["(12,9)"]["constraint_type"] == "MUST_LINK" 

405 assert response_get_constraints_before.json()["constraints"]["(12,9)"]["constraint_type_previous"] == [ 

406 None, 

407 "CANNOT_LINK", 

408 ] 

409 assert response_get_constraints_before.json()["constraints"]["(12,9)"]["to_annotate"] is False 

410 assert response_get_constraints_before.json()["constraints"]["(12,9)"]["date_of_update"] is not None 

411 

412 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

413 response_put = await async_client.put( 

414 url="/api/projects/1i_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/constraints/(12,9)/annotate?constraint_type=CANNOT_LINK" 

415 ) 

416 assert response_put.status_code == 202 

417 assert response_put.json() == { 

418 "project_id": "1i_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS", 

419 "constraint_id": "(12,9)", 

420 "detail": "In project with id '1i_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS', the constraint with id '(12,9)' has been annotated at `CANNOT_LINK`.", 

421 } 

422 

423 # Assert route `GET /api/projects/{project_id}/constraints` is updated. 

424 response_get_constraints_after = await async_client.get( 

425 url="/api/projects/1i_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/constraints?without_hidden_constraints=false" 

426 ) 

427 assert response_get_constraints_after.status_code == 200 

428 for constraint_id in response_get_constraints_before.json()["constraints"].keys(): 

429 if constraint_id != "(12,9)": 

430 assert ( 

431 response_get_constraints_after.json()["constraints"][constraint_id] 

432 == response_get_constraints_before.json()["constraints"][constraint_id] 

433 ) 

434 assert response_get_constraints_after.json()["constraints"]["(12,9)"]["constraint_type"] == "CANNOT_LINK" 

435 assert response_get_constraints_after.json()["constraints"]["(12,9)"]["constraint_type_previous"] == [ 

436 None, 

437 "CANNOT_LINK", 

438 "MUST_LINK", 

439 ] 

440 assert response_get_constraints_after.json()["constraints"]["(12,9)"]["to_annotate"] is False 

441 assert response_get_constraints_after.json()["constraints"]["(12,9)"]["date_of_update"] is not None 

442 

443 # Assert route `GET /api/projects/{project_id}/status` is updated. 

444 response_get_status = await async_client.get( 

445 url="/api/projects/1i_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS/status" 

446 ) 

447 assert response_get_status.status_code == 200 

448 assert response_get_status.json()["status"]["iteration_id"] == 1 

449 assert response_get_status.json()["status"]["state"] == "ANNOTATION_WITH_OUTDATED_MODELIZATION_WITH_CONFLICTS" 

450 

451 

452# ============================================================================== 

453# test_ok_double_request 

454# ============================================================================== 

455 

456 

457@pytest.mark.asyncio() 

458async def test_ok_double_request(async_client, tmp_path): 

459 """ 

460 Test the `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` route with double requests. 

461 

462 Arguments: 

463 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

464 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

465 """ 

466 # Assert HTTP client is created. 

467 assert async_client 

468 

469 # Create dummy projects. 

470 create_dummy_projects( 

471 tmp_path=tmp_path, 

472 list_of_dummy_project_ids=[ 

473 "1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS", 

474 ], 

475 ) 

476 

477 # Get texts before test. 

478 response_get_constraints_before = await async_client.get( 

479 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/constraints?without_hidden_constraints=false" 

480 ) 

481 assert response_get_constraints_before.status_code == 200 

482 assert response_get_constraints_before.json()["constraints"]["(11,12)"]["constraint_type"] == "MUST_LINK" 

483 assert response_get_constraints_before.json()["constraints"]["(11,12)"]["constraint_type_previous"] == [ 

484 None, 

485 ] 

486 assert response_get_constraints_before.json()["constraints"]["(11,12)"]["to_annotate"] is False 

487 assert response_get_constraints_before.json()["constraints"]["(11,12)"]["date_of_update"] is not None 

488 

489 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

490 response_put_1 = await async_client.put( 

491 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/constraints/(11,12)/annotate?constraint_type=MUST_LINK" 

492 ) 

493 assert response_put_1.status_code == 202 

494 assert response_put_1.json() == { 

495 "project_id": "1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS", 

496 "constraint_id": "(11,12)", 

497 "detail": "In project with id '1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS', the constraint with id '(11,12)' has been annotated at `MUST_LINK`.", 

498 } 

499 

500 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

501 response_put_2 = await async_client.put( 

502 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/constraints/(11,12)/annotate?constraint_type=CANNOT_LINK" 

503 ) 

504 assert response_put_2.status_code == 202 

505 assert response_put_2.json() == { 

506 "project_id": "1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS", 

507 "constraint_id": "(11,12)", 

508 "detail": "In project with id '1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS', the constraint with id '(11,12)' has been annotated at `CANNOT_LINK`.", 

509 } 

510 

511 # Assert route `PUT /api/projects/{project_id}/constraints/{constraint_id}/annotate` works. 

512 response_put_3 = await async_client.put( 

513 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/constraints/(11,12)/annotate" 

514 ) 

515 assert response_put_3.status_code == 202 

516 assert response_put_3.json() == { 

517 "project_id": "1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS", 

518 "constraint_id": "(11,12)", 

519 "detail": "In project with id '1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS', the constraint with id '(11,12)' has been annotated at `None`.", 

520 } 

521 

522 # Assert route `GET /api/projects/{project_id}/constraints` is updated. 

523 response_get_constraints_after = await async_client.get( 

524 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/constraints?without_hidden_constraints=false" 

525 ) 

526 assert response_get_constraints_after.status_code == 200 

527 for constraint_id in response_get_constraints_before.json()["constraints"].keys(): 

528 if constraint_id != "(11,12)": 

529 assert ( 

530 response_get_constraints_after.json()["constraints"][constraint_id] 

531 == response_get_constraints_before.json()["constraints"][constraint_id] 

532 ) 

533 assert response_get_constraints_after.json()["constraints"]["(11,12)"]["constraint_type"] is None 

534 assert response_get_constraints_after.json()["constraints"]["(11,12)"]["constraint_type_previous"] == [ 

535 None, 

536 "MUST_LINK", 

537 "MUST_LINK", 

538 "CANNOT_LINK", 

539 ] 

540 assert response_get_constraints_after.json()["constraints"]["(11,12)"]["to_annotate"] is False 

541 assert response_get_constraints_after.json()["constraints"]["(11,12)"]["date_of_update"] is not None 

542 

543 # Assert route `GET /api/projects/{project_id}/status` is updated. 

544 response_get_status = await async_client.get( 

545 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/status" 

546 ) 

547 assert response_get_status.status_code == 200 

548 assert response_get_status.json()["status"]["iteration_id"] == 1 

549 assert response_get_status.json()["status"]["state"] == "ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS"