Coverage for tests\test_put_api_projects_settings.py: 100.00%

451 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_settings.py 

5* Description: Unittests for `app` module on the `PUT /api/projects/{project_id}/settings` 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 `PUT /api/projects/{project_id}/settings` 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}/settings` works. 

36 response_put = await async_client.put( 

37 url="/api/projects/UNKNOWN_PROJECT/settings", 

38 ) 

39 assert response_put.status_code == 404 

40 assert response_put.json() == { 

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

42 } 

43 

44 

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

46# test_ko_preprocessing_bad_state 

47# ============================================================================== 

48 

49 

50@pytest.mark.asyncio() 

51async def test_ko_preprocessing_bad_state(async_client, tmp_path): 

52 """ 

53 Test the `PUT /api/projects/{project_id}/settings` route with bad state. 

54 

55 Arguments: 

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

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

58 """ 

59 # Assert HTTP client is created. 

60 assert async_client 

61 

62 # Create dummy projects. 

63 create_dummy_projects( 

64 tmp_path=tmp_path, 

65 list_of_dummy_project_ids=[ 

66 "1a_SAMPLING_TODO", 

67 ], 

68 ) 

69 

70 # Get settings before test. 

71 response_get_settings_before = await async_client.get(url="/api/projects/1a_SAMPLING_TODO/settings") 

72 assert response_get_settings_before.status_code == 200 

73 

74 # Assert route `PUT /api/projects/{project_id}/settings` works. 

75 response_put = await async_client.put( 

76 url="/api/projects/1a_SAMPLING_TODO/settings", 

77 json={ 

78 "preprocessing": { 

79 "apply_stopwords_deletion": True, 

80 "apply_parsing_filter": True, 

81 "apply_lemmatization": True, 

82 "spacy_language_model": "fr_core_news_md", 

83 } 

84 }, 

85 ) 

86 assert response_put.status_code == 403 

87 assert response_put.json() == { 

88 "detail": "The 'preprocessing' settings of project with id '1a_SAMPLING_TODO' cant't be modified during this state (state='SAMPLING_TODO'). No changes have been taken into account.", 

89 } 

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

91 response_get = await async_client.get(url="/api/projects/1a_SAMPLING_TODO/status") 

92 assert response_get.status_code == 200 

93 assert response_get.json()["status"]["iteration_id"] == 1 

94 assert response_get.json()["status"]["state"] == "SAMPLING_TODO" 

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

96 response_get_settings_after = await async_client.get(url="/api/projects/1a_SAMPLING_TODO/settings") 

97 assert response_get_settings_after.status_code == 200 

98 assert response_get_settings_after.json() == response_get_settings_before.json() 

99 

100 

101# ============================================================================== 

102# test_ko_vectorization_bad_state 

103# ============================================================================== 

104 

105 

106@pytest.mark.asyncio() 

107async def test_ko_vectorization_bad_state(async_client, tmp_path): 

108 """ 

109 Test the `PUT /api/projects/{project_id}/settings` route with bad state. 

110 

111 Arguments: 

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

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

114 """ 

115 # Assert HTTP client is created. 

116 assert async_client 

117 

118 # Create dummy projects. 

119 create_dummy_projects( 

120 tmp_path=tmp_path, 

121 list_of_dummy_project_ids=[ 

122 "1a_SAMPLING_TODO", 

123 ], 

124 ) 

125 

126 # Get settings before test. 

127 response_get_settings_before = await async_client.get(url="/api/projects/1a_SAMPLING_TODO/settings") 

128 assert response_get_settings_before.status_code == 200 

129 

130 # Assert route `PUT /api/projects/{project_id}/settings` works. 

131 response_put = await async_client.put( 

132 url="/api/projects/1a_SAMPLING_TODO/settings", 

133 json={ 

134 "vectorization": {"vectorizer_type": "spacy", "spacy_language_model": "fr_core_news_md", "random_seed": 88} 

135 }, 

136 ) 

137 assert response_put.status_code == 403 

138 assert response_put.json() == { 

139 "detail": "The 'vectorization' settings of project with id '1a_SAMPLING_TODO' cant't be modified during this state (state='SAMPLING_TODO'). No changes have been taken into account.", 

140 } 

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

142 response_get = await async_client.get(url="/api/projects/1a_SAMPLING_TODO/status") 

143 assert response_get.status_code == 200 

144 assert response_get.json()["status"]["iteration_id"] == 1 

145 assert response_get.json()["status"]["state"] == "SAMPLING_TODO" 

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

147 response_get_settings_after = await async_client.get(url="/api/projects/1a_SAMPLING_TODO/settings") 

148 assert response_get_settings_after.status_code == 200 

149 assert response_get_settings_after.json() == response_get_settings_before.json() 

150 

151 

152# ============================================================================== 

153# test_ko_sampling_bad_state 

154# ============================================================================== 

155 

156 

157@pytest.mark.asyncio() 

158async def test_ko_sampling_bad_state(async_client, tmp_path): 

159 """ 

160 Test the `PUT /api/projects/{project_id}/settings` route with bad state. 

161 

162 Arguments: 

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

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

165 """ 

166 # Assert HTTP client is created. 

167 assert async_client 

168 

169 # Create dummy projects. 

170 create_dummy_projects( 

171 tmp_path=tmp_path, 

172 list_of_dummy_project_ids=[ 

173 "1b_SAMPLING_PENDING", 

174 ], 

175 ) 

176 

177 # Get settings before test. 

178 response_get_settings_before = await async_client.get(url="/api/projects/1b_SAMPLING_PENDING/settings") 

179 assert response_get_settings_before.status_code == 200 

180 

181 # Assert route `PUT /api/projects/{project_id}/settings` works. 

182 response_put = await async_client.put( 

183 url="/api/projects/1b_SAMPLING_PENDING/settings", 

184 json={"sampling": {"algorithm": "random", "random_seed": 88, "nb_to_select": 10}}, 

185 ) 

186 assert response_put.status_code == 403 

187 assert response_put.json() == { 

188 "detail": "The 'sampling' settings of project with id '1b_SAMPLING_PENDING' cant't be modified during this state (state='SAMPLING_PENDING'). No changes have been taken into account.", 

189 } 

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

191 response_get = await async_client.get(url="/api/projects/1b_SAMPLING_PENDING/status") 

192 assert response_get.status_code == 200 

193 assert response_get.json()["status"]["iteration_id"] == 1 

194 assert response_get.json()["status"]["state"] == "SAMPLING_PENDING" 

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

196 response_get_settings_after = await async_client.get(url="/api/projects/1b_SAMPLING_PENDING/settings") 

197 assert response_get_settings_after.status_code == 200 

198 assert response_get_settings_after.json() == response_get_settings_before.json() 

199 

200 

201# ============================================================================== 

202# test_ko_clustering_bad_state 

203# ============================================================================== 

204 

205 

206@pytest.mark.asyncio() 

207async def test_ko_clustering_bad_state(async_client, tmp_path): 

208 """ 

209 Test the `PUT /api/projects/{project_id}/settings` route with bad state. 

210 

211 Arguments: 

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

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

214 """ 

215 # Assert HTTP client is created. 

216 assert async_client 

217 

218 # Create dummy projects. 

219 create_dummy_projects( 

220 tmp_path=tmp_path, 

221 list_of_dummy_project_ids=[ 

222 "1n_CLUSTERING_PENDING", 

223 ], 

224 ) 

225 

226 # Get settings before test. 

227 response_get_settings_before = await async_client.get(url="/api/projects/1n_CLUSTERING_PENDING/settings") 

228 assert response_get_settings_before.status_code == 200 

229 

230 # Assert route `PUT /api/projects/{project_id}/settings` works. 

231 response_put = await async_client.put( 

232 url="/api/projects/1n_CLUSTERING_PENDING/settings", 

233 json={ 

234 "clustering": { 

235 "algorithm": "hierarchical", 

236 "random_seed": 41, 

237 "nb_clusters": 3, 

238 "init_kargs": {"linkage": "complete"}, 

239 } 

240 }, 

241 ) 

242 assert response_put.status_code == 403 

243 assert response_put.json() == { 

244 "detail": "The 'clustering' settings of project with id '1n_CLUSTERING_PENDING' cant't be modified during this state (state='CLUSTERING_PENDING'). No changes have been taken into account.", 

245 } 

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

247 response_get = await async_client.get(url="/api/projects/1n_CLUSTERING_PENDING/status") 

248 assert response_get.status_code == 200 

249 assert response_get.json()["status"]["iteration_id"] == 1 

250 assert response_get.json()["status"]["state"] == "CLUSTERING_PENDING" 

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

252 response_get_settings_after = await async_client.get(url="/api/projects/1n_CLUSTERING_PENDING/settings") 

253 assert response_get_settings_after.status_code == 200 

254 assert response_get_settings_after.json() == response_get_settings_before.json() 

255 

256 

257# ============================================================================== 

258# test_ko_preprocessing_bad_value 

259# ============================================================================== 

260 

261 

262@pytest.mark.asyncio() 

263async def test_ko_preprocessing_bad_value(async_client, tmp_path): 

264 """ 

265 Test the `PUT /api/projects/{project_id}/settings` route with bad value. 

266 

267 Arguments: 

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

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

270 """ 

271 # Assert HTTP client is created. 

272 assert async_client 

273 

274 # Create dummy projects. 

275 create_dummy_projects( 

276 tmp_path=tmp_path, 

277 list_of_dummy_project_ids=[ 

278 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

279 ], 

280 ) 

281 

282 # Get settings before test. 

283 response_get_settings_before = await async_client.get( 

284 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

285 ) 

286 assert response_get_settings_before.status_code == 200 

287 

288 # Assert route `PUT /api/projects/{project_id}/settings` works. 

289 response_put_1 = await async_client.put( 

290 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

291 json={ 

292 "preprocessing": { 

293 "apply_stopwords_deletion": "UNKNOWN", 

294 "apply_parsing_filter": True, 

295 "apply_lemmatization": True, 

296 "spacy_language_model": "fr_core_news_md", 

297 } 

298 }, 

299 ) 

300 assert response_put_1.status_code == 422 

301 

302 # Assert route `PUT /api/projects/{project_id}/settings` works. 

303 response_put_2 = await async_client.put( 

304 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

305 json={ 

306 "preprocessing": { 

307 "apply_stopwords_deletion": True, 

308 "apply_parsing_filter": "UNKNOWN", 

309 "apply_lemmatization": True, 

310 "spacy_language_model": "fr_core_news_md", 

311 } 

312 }, 

313 ) 

314 assert response_put_2.status_code == 422 

315 

316 # Assert route `PUT /api/projects/{project_id}/settings` works. 

317 response_put_3 = await async_client.put( 

318 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

319 json={ 

320 "preprocessing": { 

321 "apply_stopwords_deletion": True, 

322 "apply_parsing_filter": True, 

323 "apply_lemmatization": "UNKNOWN", 

324 "spacy_language_model": "fr_core_news_md", 

325 } 

326 }, 

327 ) 

328 assert response_put_3.status_code == 422 

329 

330 # Assert route `PUT /api/projects/{project_id}/settings` works. 

331 response_put_4 = await async_client.put( 

332 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

333 json={ 

334 "preprocessing": { 

335 "apply_stopwords_deletion": True, 

336 "apply_parsing_filter": True, 

337 "apply_lemmatization": True, 

338 "spacy_language_model": "UNKNOWN", 

339 } 

340 }, 

341 ) 

342 assert response_put_4.status_code == 422 

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

344 response_get = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

345 assert response_get.status_code == 200 

346 assert response_get.json()["status"]["iteration_id"] == 2 

347 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION" 

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

349 response_get_settings_after = await async_client.get( 

350 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

351 ) 

352 assert response_get_settings_after.status_code == 200 

353 assert response_get_settings_after.json() == response_get_settings_before.json() 

354 

355 

356# ============================================================================== 

357# test_ko_preprocessing_missing_value 

358# ============================================================================== 

359 

360 

361@pytest.mark.asyncio() 

362async def test_ko_preprocessing_missing_value(async_client, tmp_path): 

363 """ 

364 Test the `PUT /api/projects/{project_id}/settings` route with missing value. 

365 

366 Arguments: 

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

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

369 """ 

370 # Assert HTTP client is created. 

371 assert async_client 

372 

373 # Create dummy projects. 

374 create_dummy_projects( 

375 tmp_path=tmp_path, 

376 list_of_dummy_project_ids=[ 

377 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

378 ], 

379 ) 

380 

381 # Get settings before test. 

382 response_get_settings_before = await async_client.get( 

383 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

384 ) 

385 assert response_get_settings_before.status_code == 200 

386 

387 # Assert route `PUT /api/projects/{project_id}/settings` works. 

388 response_put_1 = await async_client.put( 

389 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

390 json={ 

391 "preprocessing": { 

392 "apply_parsing_filter": True, 

393 "apply_lemmatization": True, 

394 "spacy_language_model": "fr_core_news_md", 

395 } 

396 }, 

397 ) 

398 assert response_put_1.status_code == 422 

399 

400 # Assert route `PUT /api/projects/{project_id}/settings` works. 

401 response_put_2 = await async_client.put( 

402 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

403 json={ 

404 "preprocessing": { 

405 "apply_stopwords_deletion": True, 

406 "apply_lemmatization": True, 

407 "spacy_language_model": "fr_core_news_md", 

408 } 

409 }, 

410 ) 

411 assert response_put_2.status_code == 422 

412 

413 # Assert route `PUT /api/projects/{project_id}/settings` works. 

414 response_put_3 = await async_client.put( 

415 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

416 json={ 

417 "preprocessing": { 

418 "apply_stopwords_deletion": True, 

419 "apply_parsing_filter": True, 

420 "spacy_language_model": "fr_core_news_md", 

421 } 

422 }, 

423 ) 

424 assert response_put_3.status_code == 422 

425 

426 # Assert route `PUT /api/projects/{project_id}/settings` works. 

427 response_put_4 = await async_client.put( 

428 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

429 json={ 

430 "preprocessing": { 

431 "apply_stopwords_deletion": True, 

432 "apply_parsing_filter": True, 

433 "apply_lemmatization": True, 

434 } 

435 }, 

436 ) 

437 assert response_put_4.status_code == 422 

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

439 response_get = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

440 assert response_get.status_code == 200 

441 assert response_get.json()["status"]["iteration_id"] == 2 

442 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION" 

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

444 response_get_settings_after = await async_client.get( 

445 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

446 ) 

447 assert response_get_settings_after.status_code == 200 

448 assert response_get_settings_after.json() == response_get_settings_before.json() 

449 

450 

451# ============================================================================== 

452# test_ko_vectorization_bad_value 

453# ============================================================================== 

454 

455 

456@pytest.mark.asyncio() 

457async def test_ko_vectorization_bad_value(async_client, tmp_path): 

458 """ 

459 Test the `PUT /api/projects/{project_id}/settings` route with bad value. 

460 

461 Arguments: 

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

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

464 """ 

465 # Assert HTTP client is created. 

466 assert async_client 

467 

468 # Create dummy projects. 

469 create_dummy_projects( 

470 tmp_path=tmp_path, 

471 list_of_dummy_project_ids=[ 

472 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

473 ], 

474 ) 

475 

476 # Get settings before test. 

477 response_get_settings_before = await async_client.get( 

478 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

479 ) 

480 assert response_get_settings_before.status_code == 200 

481 

482 # Assert route `PUT /api/projects/{project_id}/settings` works. 

483 response_put_1 = await async_client.put( 

484 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

485 json={ 

486 "vectorization": { 

487 "vectorizer_type": "UNKNOWN", 

488 "spacy_language_model": "fr_core_news_md", 

489 "random_seed": 88, 

490 } 

491 }, 

492 ) 

493 assert response_put_1.status_code == 422 

494 

495 # Assert route `PUT /api/projects/{project_id}/settings` works. 

496 response_put_2 = await async_client.put( 

497 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

498 json={"vectorization": {"vectorizer_type": "spacy", "spacy_language_model": "UNKNOWN", "random_seed": 88}}, 

499 ) 

500 assert response_put_2.status_code == 422 

501 

502 # Assert route `PUT /api/projects/{project_id}/settings` works. 

503 response_put_3 = await async_client.put( 

504 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

505 json={ 

506 "vectorization": {"vectorizer_type": "tfidf", "spacy_language_model": "fr_core_news_md", "random_seed": 88} 

507 }, 

508 ) 

509 assert response_put_3.status_code == 422 

510 

511 # Assert route `PUT /api/projects/{project_id}/settings` works. 

512 response_put_4 = await async_client.put( 

513 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

514 json={"vectorization": {"vectorizer_type": "tfidf", "random_seed": -99}}, 

515 ) 

516 assert response_put_4.status_code == 422 

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

518 response_get = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

519 assert response_get.status_code == 200 

520 assert response_get.json()["status"]["iteration_id"] == 2 

521 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION" 

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

523 response_get_settings_after = await async_client.get( 

524 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

525 ) 

526 assert response_get_settings_after.status_code == 200 

527 assert response_get_settings_after.json() == response_get_settings_before.json() 

528 

529 

530# ============================================================================== 

531# test_ko_vectorization_missing_value 

532# ============================================================================== 

533 

534 

535@pytest.mark.asyncio() 

536async def test_ko_vectorization_missing_value(async_client, tmp_path): 

537 """ 

538 Test the `PUT /api/projects/{project_id}/settings` route with missing value. 

539 

540 Arguments: 

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

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

543 """ 

544 # Assert HTTP client is created. 

545 assert async_client 

546 

547 # Create dummy projects. 

548 create_dummy_projects( 

549 tmp_path=tmp_path, 

550 list_of_dummy_project_ids=[ 

551 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

552 ], 

553 ) 

554 

555 # Get settings before test. 

556 response_get_settings_before = await async_client.get( 

557 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

558 ) 

559 assert response_get_settings_before.status_code == 200 

560 

561 # Assert route `PUT /api/projects/{project_id}/settings` works. 

562 response_put_1 = await async_client.put( 

563 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

564 json={"vectorization": {"spacy_language_model": "fr_core_news_md", "random_seed": 88}}, 

565 ) 

566 assert response_put_1.status_code == 422 

567 

568 # Assert route `PUT /api/projects/{project_id}/settings` works. 

569 response_put_2 = await async_client.put( 

570 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

571 json={"vectorization": {"vectorizer_type": "spacy", "random_seed": 88}}, 

572 ) 

573 assert response_put_2.status_code == 422 

574 

575 # Assert route `PUT /api/projects/{project_id}/settings` works. 

576 response_put_3 = await async_client.put( 

577 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

578 json={"vectorization": {"vectorizer_type": "spacy", "spacy_language_model": "fr_core_news_md"}}, 

579 ) 

580 assert response_put_3.status_code == 422 

581 

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

583 response_get = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

584 assert response_get.status_code == 200 

585 assert response_get.json()["status"]["iteration_id"] == 2 

586 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION" 

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

588 response_get_settings_after = await async_client.get( 

589 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

590 ) 

591 assert response_get_settings_after.status_code == 200 

592 assert response_get_settings_after.json() == response_get_settings_before.json() 

593 

594 

595# ============================================================================== 

596# test_ko_sampling_bad_value 

597# ============================================================================== 

598 

599 

600@pytest.mark.asyncio() 

601async def test_ko_sampling_bad_value(async_client, tmp_path): 

602 """ 

603 Test the `PUT /api/projects/{project_id}/settings` route with bad value. 

604 

605 Arguments: 

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

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

608 """ 

609 # Assert HTTP client is created. 

610 assert async_client 

611 

612 # Create dummy projects. 

613 create_dummy_projects( 

614 tmp_path=tmp_path, 

615 list_of_dummy_project_ids=[ 

616 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

617 ], 

618 ) 

619 

620 # Get settings before test. 

621 response_get_settings_before = await async_client.get( 

622 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

623 ) 

624 assert response_get_settings_before.status_code == 200 

625 

626 # Assert route `PUT /api/projects/{project_id}/settings` works. 

627 response_put_1 = await async_client.put( 

628 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

629 json={"sampling": {"algorithm": "UNKNOWN", "random_seed": 88, "nb_to_select": 10}}, 

630 ) 

631 assert response_put_1.status_code == 422 

632 

633 # Assert route `PUT /api/projects/{project_id}/settings` works. 

634 response_put_2 = await async_client.put( 

635 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

636 json={"sampling": {"algorithm": "random", "random_seed": -99, "nb_to_select": 10}}, 

637 ) 

638 assert response_put_2.status_code == 422 

639 

640 # Assert route `PUT /api/projects/{project_id}/settings` works. 

641 response_put_3 = await async_client.put( 

642 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

643 json={"sampling": {"algorithm": "random", "random_seed": 88, "nb_to_select": -99}}, 

644 ) 

645 assert response_put_3.status_code == 422 

646 

647 # Assert route `PUT /api/projects/{project_id}/settings` works. 

648 response_put_4 = await async_client.put( 

649 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

650 json={ 

651 "sampling": { 

652 "algorithm": "custom", 

653 "random_seed": 88, 

654 "nb_to_select": 10, 

655 "init_kargs": { 

656 "clusters_restriction": "UNKNOWN1", 

657 "distance_restriction": "UNKNOWN2", 

658 "without_inferred_constraints": "UKNOWN3", 

659 }, 

660 } 

661 }, 

662 ) 

663 assert response_put_4.status_code == 422 

664 

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

666 response_get = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

667 assert response_get.status_code == 200 

668 assert response_get.json()["status"]["iteration_id"] == 2 

669 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION" 

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

671 response_get_settings_after = await async_client.get( 

672 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

673 ) 

674 assert response_get_settings_after.status_code == 200 

675 assert response_get_settings_after.json() == response_get_settings_before.json() 

676 

677 

678# ============================================================================== 

679# test_ko_sampling_missing_value 

680# ============================================================================== 

681 

682 

683@pytest.mark.asyncio() 

684async def test_ko_sampling_missing_value(async_client, tmp_path): 

685 """ 

686 Test the `PUT /api/projects/{project_id}/settings` route with missing value. 

687 

688 Arguments: 

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

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

691 """ 

692 # Assert HTTP client is created. 

693 assert async_client 

694 

695 # Create dummy projects. 

696 create_dummy_projects( 

697 tmp_path=tmp_path, 

698 list_of_dummy_project_ids=[ 

699 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

700 ], 

701 ) 

702 

703 # Get settings before test. 

704 response_get_settings_before = await async_client.get( 

705 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

706 ) 

707 assert response_get_settings_before.status_code == 200 

708 

709 # Assert route `PUT /api/projects/{project_id}/settings` works. 

710 response_put_1 = await async_client.put( 

711 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

712 json={"sampling": {"random_seed": 88, "nb_to_select": 10}}, 

713 ) 

714 assert response_put_1.status_code == 422 

715 

716 # Assert route `PUT /api/projects/{project_id}/settings` works. 

717 response_put_2 = await async_client.put( 

718 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

719 json={"sampling": {"algorithm": "random", "nb_to_select": 10}}, 

720 ) 

721 assert response_put_2.status_code == 422 

722 

723 # Assert route `PUT /api/projects/{project_id}/settings` works. 

724 response_put_3 = await async_client.put( 

725 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

726 json={"sampling": {"algorithm": "random", "random_seed": 88}}, 

727 ) 

728 assert response_put_3.status_code == 422 

729 

730 # Assert route `PUT /api/projects/{project_id}/settings` works. 

731 response_put_4 = await async_client.put( 

732 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

733 json={ 

734 "sampling": { 

735 "algorithm": "random", 

736 "random_seed": 88, 

737 "nb_to_select": 10, 

738 "init_kargs": { 

739 "clusters_restriction": "same_cluster", 

740 "distance_restriction": "closest_neighbors", 

741 "without_inferred_constraints": False, 

742 }, 

743 } 

744 }, 

745 ) 

746 assert response_put_4.status_code == 422 

747 

748 # Assert route `PUT /api/projects/{project_id}/settings` works. 

749 response_put_5 = await async_client.put( 

750 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

751 json={"sampling": {"algorithm": "custom", "random_seed": 88, "nb_to_select": 10}}, 

752 ) 

753 assert response_put_5.status_code == 422 

754 

755 # Assert route `PUT /api/projects/{project_id}/settings` works. 

756 response_put_6 = await async_client.put( 

757 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

758 json={ 

759 "sampling": { 

760 "algorithm": "custom", 

761 "random_seed": 88, 

762 "nb_to_select": 10, 

763 "init_kargs": {"distance_restriction": "closest_neighbors", "without_inferred_constraints": False}, 

764 } 

765 }, 

766 ) 

767 assert response_put_6.status_code == 422 

768 

769 # Assert route `PUT /api/projects/{project_id}/settings` works. 

770 response_put_7 = await async_client.put( 

771 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

772 json={ 

773 "sampling": { 

774 "algorithm": "custom", 

775 "random_seed": 88, 

776 "nb_to_select": 10, 

777 "init_kargs": {"clusters_restriction": "same_cluster", "without_inferred_constraints": False}, 

778 } 

779 }, 

780 ) 

781 assert response_put_7.status_code == 422 

782 

783 # Assert route `PUT /api/projects/{project_id}/settings` works. 

784 response_put_8 = await async_client.put( 

785 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

786 json={ 

787 "sampling": { 

788 "algorithm": "custom", 

789 "random_seed": 88, 

790 "nb_to_select": 10, 

791 "init_kargs": {"clusters_restriction": "same_cluster", "distance_restriction": "closest_neighbors"}, 

792 } 

793 }, 

794 ) 

795 assert response_put_8.status_code == 422 

796 

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

798 response_get = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

799 assert response_get.status_code == 200 

800 assert response_get.json()["status"]["iteration_id"] == 2 

801 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION" 

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

803 response_get_settings_after = await async_client.get( 

804 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

805 ) 

806 assert response_get_settings_after.status_code == 200 

807 assert response_get_settings_after.json() == response_get_settings_before.json() 

808 

809 

810# ============================================================================== 

811# test_ko_clustering_bad_value 

812# ============================================================================== 

813 

814 

815@pytest.mark.asyncio() 

816async def test_ko_clustering_bad_value(async_client, tmp_path): 

817 """ 

818 Test the `PUT /api/projects/{project_id}/settings` route with bad value. 

819 

820 Arguments: 

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

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

823 """ 

824 # Assert HTTP client is created. 

825 assert async_client 

826 

827 # Create dummy projects. 

828 create_dummy_projects( 

829 tmp_path=tmp_path, 

830 list_of_dummy_project_ids=[ 

831 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

832 ], 

833 ) 

834 

835 # Get settings before test. 

836 response_get_settings_before = await async_client.get( 

837 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

838 ) 

839 assert response_get_settings_before.status_code == 200 

840 

841 # Assert route `PUT /api/projects/{project_id}/settings` works. 

842 response_put_1 = await async_client.put( 

843 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

844 json={ 

845 "clustering": { 

846 "algorithm": "UNKNOWN", 

847 "random_seed": 41, 

848 "nb_clusters": 3, 

849 "init_kargs": {"linkage": "complete"}, 

850 } 

851 }, 

852 ) 

853 assert response_put_1.status_code == 422 

854 

855 # Assert route `PUT /api/projects/{project_id}/settings` works. 

856 response_put_2 = await async_client.put( 

857 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

858 json={ 

859 "clustering": { 

860 "algorithm": "hierarchical", 

861 "random_seed": -99, 

862 "nb_clusters": 3, 

863 "init_kargs": {"linkage": "complete"}, 

864 } 

865 }, 

866 ) 

867 assert response_put_2.status_code == 422 

868 

869 # Assert route `PUT /api/projects/{project_id}/settings` works. 

870 response_put_3 = await async_client.put( 

871 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

872 json={ 

873 "clustering": { 

874 "algorithm": "kmeans", 

875 "random_seed": 41, 

876 "nb_clusters": -99, 

877 "init_kargs": {"model": "COP", "max_iteration": 200, "tolerance": 0.1}, 

878 } 

879 }, 

880 ) 

881 assert response_put_3.status_code == 422 

882 

883 # Assert route `PUT /api/projects/{project_id}/settings` works. 

884 response_put_4 = await async_client.put( 

885 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

886 json={ 

887 "clustering": { 

888 "algorithm": "hierarchical", 

889 "random_seed": 88, 

890 "nb_clusters": 3, 

891 "init_kargs": {"linkage": "UNKNOWN"}, 

892 } 

893 }, 

894 ) 

895 assert response_put_4.status_code == 422 

896 

897 # Assert route `PUT /api/projects/{project_id}/settings` works. 

898 response_put_5 = await async_client.put( 

899 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

900 json={ 

901 "clustering": { 

902 "algorithm": "kmeans", 

903 "random_seed": 88, 

904 "nb_clusters": 3, 

905 "init_kargs": {"model": "UNKNOWN", "max_iteration": -99, "tolerance": -99}, 

906 } 

907 }, 

908 ) 

909 assert response_put_5.status_code == 422 

910 

911 # Assert route `PUT /api/projects/{project_id}/settings` works. 

912 response_put_6 = await async_client.put( 

913 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

914 json={ 

915 "clustering": { 

916 "algorithm": "spectral", 

917 "random_seed": 88, 

918 "nb_clusters": 3, 

919 "init_kargs": {"model": "UNKNOWN", "nb_components": -99}, 

920 } 

921 }, 

922 ) 

923 assert response_put_6.status_code == 422 

924 

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

926 response_get = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

927 assert response_get.status_code == 200 

928 assert response_get.json()["status"]["iteration_id"] == 2 

929 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION" 

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

931 response_get_settings_after = await async_client.get( 

932 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

933 ) 

934 assert response_get_settings_after.status_code == 200 

935 assert response_get_settings_after.json() == response_get_settings_before.json() 

936 

937 

938# ============================================================================== 

939# test_ko_clustering_missing_value 

940# ============================================================================== 

941 

942 

943@pytest.mark.asyncio() 

944async def test_ko_clustering_missing_value(async_client, tmp_path): 

945 """ 

946 Test the `PUT /api/projects/{project_id}/settings` route with missing value. 

947 

948 Arguments: 

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

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

951 """ 

952 # Assert HTTP client is created. 

953 assert async_client 

954 

955 # Create dummy projects. 

956 create_dummy_projects( 

957 tmp_path=tmp_path, 

958 list_of_dummy_project_ids=[ 

959 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

960 ], 

961 ) 

962 

963 # Get settings before test. 

964 response_get_settings_before = await async_client.get( 

965 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

966 ) 

967 assert response_get_settings_before.status_code == 200 

968 

969 # Assert route `PUT /api/projects/{project_id}/settings` works. 

970 response_put_1 = await async_client.put( 

971 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

972 json={"clustering": {"random_seed": 88, "nb_clusters": 3, "init_kargs": {"linkage": "ward"}}}, 

973 ) 

974 assert response_put_1.status_code == 422 

975 

976 # Assert route `PUT /api/projects/{project_id}/settings` works. 

977 response_put_2 = await async_client.put( 

978 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

979 json={ 

980 "clustering": { 

981 "algorithm": "spectral", 

982 "nb_clusters": 3, 

983 "init_kargs": {"model": "SPEC", "nb_components": 12}, 

984 } 

985 }, 

986 ) 

987 assert response_put_2.status_code == 422 

988 

989 # Assert route `PUT /api/projects/{project_id}/settings` works. 

990 response_put_3 = await async_client.put( 

991 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

992 json={ 

993 "clustering": { 

994 "algorithm": "spectral", 

995 "random_seed": 88, 

996 "init_kargs": {"model": "SPEC", "nb_components": None}, 

997 } 

998 }, 

999 ) 

1000 assert response_put_3.status_code == 422 

1001 

1002 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1003 response_put_3 = await async_client.put( 

1004 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

1005 json={ 

1006 "clustering": { 

1007 "algorithm": "spectral", 

1008 "nb_clusters": 3, 

1009 "random_seed": 88, 

1010 "init_kargs": {"linkage": "ward"}, 

1011 } 

1012 }, 

1013 ) 

1014 assert response_put_3.status_code == 422 

1015 

1016 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1017 response_put_4 = await async_client.put( 

1018 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

1019 json={"clustering": {"algorithm": "kmeans", "random_seed": 42, "nb_clusters": 2}}, 

1020 ) 

1021 assert response_put_4.status_code == 422 

1022 

1023 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1024 response_put_5 = await async_client.put( 

1025 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

1026 json={ 

1027 "clustering": { 

1028 "algorithm": "kmeans", 

1029 "random_seed": 42, 

1030 "nb_clusters": 2, 

1031 "init_kargs": {"tolerance": 0.0001}, 

1032 } 

1033 }, 

1034 ) 

1035 assert response_put_5.status_code == 422 

1036 

1037 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1038 response_put_6 = await async_client.put( 

1039 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

1040 json={ 

1041 "clustering": { 

1042 "algorithm": "kmeans", 

1043 "random_seed": 42, 

1044 "nb_clusters": 2, 

1045 "init_kargs": {"max_iteration": 150}, 

1046 } 

1047 }, 

1048 ) 

1049 assert response_put_6.status_code == 422 

1050 

1051 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1052 response_put_7 = await async_client.put( 

1053 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

1054 json={"clustering": {"algorithm": "hierarchical", "random_seed": 41, "nb_clusters": 3}}, 

1055 ) 

1056 assert response_put_7.status_code == 422 

1057 

1058 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1059 response_put_8 = await async_client.put( 

1060 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

1061 json={"clustering": {"algorithm": "hierarchical", "random_seed": 41, "nb_clusters": 3}}, 

1062 ) 

1063 assert response_put_8.status_code == 422 

1064 

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

1066 response_get = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

1067 assert response_get.status_code == 200 

1068 assert response_get.json()["status"]["iteration_id"] == 2 

1069 assert response_get.json()["status"]["state"] == "ANNOTATION_WITH_UPTODATE_MODELIZATION" 

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

1071 response_get_settings_after = await async_client.get( 

1072 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

1073 ) 

1074 assert response_get_settings_after.status_code == 200 

1075 assert response_get_settings_after.json() == response_get_settings_before.json() 

1076 

1077 

1078# ============================================================================== 

1079# test_ok_all_1 

1080# ============================================================================== 

1081 

1082 

1083@pytest.mark.asyncio() 

1084async def test_ok_all_1(async_client, tmp_path): 

1085 """ 

1086 Test the `PUT /api/projects/{project_id}/settings` route. 

1087 

1088 Arguments: 

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

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

1091 """ 

1092 # Assert HTTP client is created. 

1093 assert async_client 

1094 

1095 # Create dummy projects. 

1096 create_dummy_projects( 

1097 tmp_path=tmp_path, 

1098 list_of_dummy_project_ids=[ 

1099 "2a_SAMPLING_TODO", 

1100 ], 

1101 ) 

1102 

1103 # Get settings before test. 

1104 response_get_settings_before = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1105 assert response_get_settings_before.status_code == 200 

1106 

1107 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1108 response_put = await async_client.put( 

1109 url="/api/projects/2a_SAMPLING_TODO/settings", 

1110 json={ 

1111 "sampling": {"algorithm": "random", "random_seed": 88, "nb_to_select": 10}, 

1112 "clustering": { 

1113 "algorithm": "hierarchical", 

1114 "random_seed": 41, 

1115 "nb_clusters": 3, 

1116 "init_kargs": {"linkage": "complete"}, 

1117 }, 

1118 }, 

1119 ) 

1120 assert response_put.status_code == 201 

1121 assert response_put.json() == { 

1122 "project_id": "2a_SAMPLING_TODO", 

1123 "detail": "The project with id '2a_SAMPLING_TODO' has updated the following settings: sampling, clustering.", 

1124 } 

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

1126 response_get_status = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/status") 

1127 assert response_get_status.status_code == 200 

1128 assert response_get_status.json()["status"]["iteration_id"] == 2 

1129 assert response_get_status.json()["status"]["state"] == "SAMPLING_TODO" 

1130 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1131 response_get_settings_after = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1132 assert response_get_settings_after.status_code == 200 

1133 assert ( 

1134 response_get_settings_after.json()["settings"]["preprocessing"] 

1135 == response_get_settings_before.json()["settings"]["preprocessing"] 

1136 ) 

1137 assert ( 

1138 response_get_settings_after.json()["settings"]["vectorization"] 

1139 == response_get_settings_before.json()["settings"]["vectorization"] 

1140 ) 

1141 assert response_get_settings_after.json()["settings"]["sampling"] == { 

1142 "algorithm": "random", 

1143 "random_seed": 88, 

1144 "nb_to_select": 10, 

1145 "init_kargs": None, 

1146 } 

1147 assert response_get_settings_after.json()["settings"]["clustering"] == { 

1148 "algorithm": "hierarchical", 

1149 "random_seed": 41, 

1150 "nb_clusters": 3, 

1151 "init_kargs": {"linkage": "complete"}, 

1152 } 

1153 

1154 

1155# ============================================================================== 

1156# test_ok_all_2 

1157# ============================================================================== 

1158 

1159 

1160@pytest.mark.asyncio() 

1161async def test_ok_all_2(async_client, tmp_path): 

1162 """ 

1163 Test the `PUT /api/projects/{project_id}/settings` route. 

1164 

1165 Arguments: 

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

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

1168 """ 

1169 # Assert HTTP client is created. 

1170 assert async_client 

1171 

1172 # Create dummy projects. 

1173 create_dummy_projects( 

1174 tmp_path=tmp_path, 

1175 list_of_dummy_project_ids=[ 

1176 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

1177 ], 

1178 ) 

1179 

1180 # Get settings before test. 

1181 response_get_settings_before = await async_client.get( 

1182 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

1183 ) 

1184 assert response_get_settings_before.status_code == 200 

1185 

1186 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1187 response_put = await async_client.put( 

1188 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

1189 json={ 

1190 "preprocessing": { 

1191 "apply_stopwords_deletion": True, 

1192 "apply_parsing_filter": True, 

1193 "apply_lemmatization": True, 

1194 "spacy_language_model": "fr_core_news_md", 

1195 }, 

1196 "vectorization": {"vectorizer_type": "spacy", "spacy_language_model": "fr_core_news_md", "random_seed": 88}, 

1197 "clustering": { 

1198 "algorithm": "hierarchical", 

1199 "random_seed": 41, 

1200 "nb_clusters": 3, 

1201 "init_kargs": {"linkage": "complete"}, 

1202 }, 

1203 }, 

1204 ) 

1205 assert response_put.status_code == 201 

1206 assert response_put.json() == { 

1207 "project_id": "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

1208 "detail": "The project with id '2d_ANNOTATION_WITH_UPTODATE_MODELIZATION' has updated the following settings: preprocessing, vectorization, clustering.", 

1209 } 

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

1211 response_get_status = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

1212 assert response_get_status.status_code == 200 

1213 assert response_get_status.json()["status"]["iteration_id"] == 2 

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

1215 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1216 response_get_settings_after = await async_client.get( 

1217 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

1218 ) 

1219 assert response_get_settings_after.status_code == 200 

1220 assert response_get_settings_after.json()["settings"]["preprocessing"] == { 

1221 "apply_stopwords_deletion": True, 

1222 "apply_parsing_filter": True, 

1223 "apply_lemmatization": True, 

1224 "spacy_language_model": "fr_core_news_md", 

1225 } 

1226 assert response_get_settings_after.json()["settings"]["vectorization"] == { 

1227 "vectorizer_type": "spacy", 

1228 "spacy_language_model": "fr_core_news_md", 

1229 "random_seed": 88, 

1230 } 

1231 assert ( 

1232 response_get_settings_after.json()["settings"]["sampling"] 

1233 == response_get_settings_before.json()["settings"]["sampling"] 

1234 ) 

1235 assert response_get_settings_after.json()["settings"]["clustering"] == { 

1236 "algorithm": "hierarchical", 

1237 "random_seed": 41, 

1238 "nb_clusters": 3, 

1239 "init_kargs": {"linkage": "complete"}, 

1240 } 

1241 

1242 

1243# ============================================================================== 

1244# test_ok_preprocessing_1 

1245# ============================================================================== 

1246 

1247 

1248@pytest.mark.asyncio() 

1249async def test_ok_preprocessing_1(async_client, tmp_path): 

1250 """ 

1251 Test the `PUT /api/projects/{project_id}/settings` route. 

1252 

1253 Arguments: 

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

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

1256 """ 

1257 # Assert HTTP client is created. 

1258 assert async_client 

1259 

1260 # Create dummy projects. 

1261 create_dummy_projects( 

1262 tmp_path=tmp_path, 

1263 list_of_dummy_project_ids=[ 

1264 "1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS", 

1265 ], 

1266 ) 

1267 

1268 # Get settings before test. 

1269 response_get_settings_before = await async_client.get( 

1270 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/settings" 

1271 ) 

1272 assert response_get_settings_before.status_code == 200 

1273 

1274 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1275 response_put = await async_client.put( 

1276 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/settings", 

1277 json={ 

1278 "preprocessing": { 

1279 "apply_stopwords_deletion": True, 

1280 "apply_parsing_filter": True, 

1281 "apply_lemmatization": True, 

1282 "spacy_language_model": "fr_core_news_md", 

1283 }, 

1284 "vectorization": {"vectorizer_type": "tfidf", "spacy_language_model": None, "random_seed": 88}, 

1285 }, 

1286 ) 

1287 assert response_put.status_code == 201 

1288 assert response_put.json() == { 

1289 "project_id": "1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS", 

1290 "detail": "The project with id '1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS' has updated the following settings: preprocessing, vectorization.", 

1291 } 

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

1293 response_get_status = await async_client.get( 

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

1295 ) 

1296 assert response_get_status.status_code == 200 

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

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

1299 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1300 response_get_settings_after = await async_client.get( 

1301 url="/api/projects/1e_ANNOTATION_WITH_OUTDATED_MODELIZATION_WITHOUT_CONFLICTS/settings" 

1302 ) 

1303 assert response_get_settings_after.status_code == 200 

1304 assert response_get_settings_after.json()["settings"]["preprocessing"] == { 

1305 "apply_stopwords_deletion": True, 

1306 "apply_parsing_filter": True, 

1307 "apply_lemmatization": True, 

1308 "spacy_language_model": "fr_core_news_md", 

1309 } 

1310 assert response_get_settings_after.json()["settings"]["vectorization"] == { 

1311 "vectorizer_type": "tfidf", 

1312 "spacy_language_model": None, 

1313 "random_seed": 88, 

1314 } 

1315 assert ( 

1316 response_get_settings_after.json()["settings"]["sampling"] 

1317 == response_get_settings_before.json()["settings"]["sampling"] 

1318 ) 

1319 assert ( 

1320 response_get_settings_after.json()["settings"]["clustering"] 

1321 == response_get_settings_before.json()["settings"]["clustering"] 

1322 ) 

1323 

1324 

1325# ============================================================================== 

1326# test_ok_vectorization_1 

1327# ============================================================================== 

1328 

1329 

1330@pytest.mark.asyncio() 

1331async def test_ok_vectorization_1(async_client, tmp_path): 

1332 """ 

1333 Test the `PUT /api/projects/{project_id}/settings` route. 

1334 

1335 Arguments: 

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

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

1338 """ 

1339 # Assert HTTP client is created. 

1340 assert async_client 

1341 

1342 # Create dummy projects. 

1343 create_dummy_projects( 

1344 tmp_path=tmp_path, 

1345 list_of_dummy_project_ids=[ 

1346 "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

1347 ], 

1348 ) 

1349 

1350 # Get settings before test. 

1351 response_get_settings_before = await async_client.get( 

1352 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

1353 ) 

1354 assert response_get_settings_before.status_code == 200 

1355 

1356 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1357 response_put = await async_client.put( 

1358 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings", 

1359 json={"vectorization": {"vectorizer_type": "tfidf", "random_seed": 88}}, 

1360 ) 

1361 assert response_put.status_code == 201 

1362 assert response_put.json() == { 

1363 "project_id": "2d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

1364 "detail": "The project with id '2d_ANNOTATION_WITH_UPTODATE_MODELIZATION' has updated the following settings: vectorization.", 

1365 } 

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

1367 response_get_status = await async_client.get(url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/status") 

1368 assert response_get_status.status_code == 200 

1369 assert response_get_status.json()["status"]["iteration_id"] == 2 

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

1371 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1372 response_get_settings_after = await async_client.get( 

1373 url="/api/projects/2d_ANNOTATION_WITH_UPTODATE_MODELIZATION/settings" 

1374 ) 

1375 assert response_get_settings_after.status_code == 200 

1376 assert ( 

1377 response_get_settings_after.json()["settings"]["preprocessing"] 

1378 == response_get_settings_before.json()["settings"]["preprocessing"] 

1379 ) 

1380 assert response_get_settings_after.json()["settings"]["vectorization"] == { 

1381 "vectorizer_type": "tfidf", 

1382 "spacy_language_model": None, 

1383 "random_seed": 88, 

1384 } 

1385 assert ( 

1386 response_get_settings_after.json()["settings"]["sampling"] 

1387 == response_get_settings_before.json()["settings"]["sampling"] 

1388 ) 

1389 assert ( 

1390 response_get_settings_after.json()["settings"]["clustering"] 

1391 == response_get_settings_before.json()["settings"]["clustering"] 

1392 ) 

1393 

1394 

1395# ============================================================================== 

1396# test_ok_sampling_1 

1397# ============================================================================== 

1398 

1399 

1400@pytest.mark.asyncio() 

1401async def test_ok_sampling_1(async_client, tmp_path): 

1402 """ 

1403 Test the `PUT /api/projects/{project_id}/settings` route. 

1404 

1405 Arguments: 

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

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

1408 """ 

1409 # Assert HTTP client is created. 

1410 assert async_client 

1411 

1412 # Create dummy projects. 

1413 create_dummy_projects( 

1414 tmp_path=tmp_path, 

1415 list_of_dummy_project_ids=[ 

1416 "2a_SAMPLING_TODO", 

1417 ], 

1418 ) 

1419 

1420 # Get settings before test. 

1421 response_get_settings_before = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1422 assert response_get_settings_before.status_code == 200 

1423 

1424 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1425 response_put = await async_client.put( 

1426 url="/api/projects/2a_SAMPLING_TODO/settings", 

1427 json={ 

1428 "sampling": { 

1429 "algorithm": "custom", 

1430 "random_seed": 88, 

1431 "nb_to_select": 10, 

1432 "init_kargs": { 

1433 "clusters_restriction": "same_cluster", 

1434 "distance_restriction": "closest_neighbors", 

1435 "without_inferred_constraints": False, 

1436 }, 

1437 }, 

1438 }, 

1439 ) 

1440 assert response_put.status_code == 201 

1441 assert response_put.json() == { 

1442 "project_id": "2a_SAMPLING_TODO", 

1443 "detail": "The project with id '2a_SAMPLING_TODO' has updated the following settings: sampling.", 

1444 } 

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

1446 response_get_status = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/status") 

1447 assert response_get_status.status_code == 200 

1448 assert response_get_status.json()["status"]["iteration_id"] == 2 

1449 assert response_get_status.json()["status"]["state"] == "SAMPLING_TODO" 

1450 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1451 response_get_settings_after = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1452 assert response_get_settings_after.status_code == 200 

1453 assert ( 

1454 response_get_settings_after.json()["settings"]["preprocessing"] 

1455 == response_get_settings_before.json()["settings"]["preprocessing"] 

1456 ) 

1457 assert ( 

1458 response_get_settings_after.json()["settings"]["vectorization"] 

1459 == response_get_settings_before.json()["settings"]["vectorization"] 

1460 ) 

1461 assert response_get_settings_after.json()["settings"]["sampling"] == { 

1462 "algorithm": "custom", 

1463 "random_seed": 88, 

1464 "nb_to_select": 10, 

1465 "init_kargs": { 

1466 "clusters_restriction": "same_cluster", 

1467 "distance_restriction": "closest_neighbors", 

1468 "without_inferred_constraints": False, 

1469 }, 

1470 } 

1471 assert ( 

1472 response_get_settings_after.json()["settings"]["clustering"] 

1473 == response_get_settings_before.json()["settings"]["clustering"] 

1474 ) 

1475 

1476 

1477# ============================================================================== 

1478# test_ok_sampling_2 

1479# ============================================================================== 

1480 

1481 

1482@pytest.mark.asyncio() 

1483async def test_ok_sampling_2(async_client, tmp_path): 

1484 """ 

1485 Test the `PUT /api/projects/{project_id}/settings` route. 

1486 

1487 Arguments: 

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

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

1490 """ 

1491 # Assert HTTP client is created. 

1492 assert async_client 

1493 

1494 # Create dummy projects. 

1495 create_dummy_projects( 

1496 tmp_path=tmp_path, 

1497 list_of_dummy_project_ids=[ 

1498 "2a_SAMPLING_TODO", 

1499 ], 

1500 ) 

1501 

1502 # Get settings before test. 

1503 response_get_settings_before = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1504 assert response_get_settings_before.status_code == 200 

1505 

1506 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1507 response_put = await async_client.put( 

1508 url="/api/projects/2a_SAMPLING_TODO/settings", 

1509 json={ 

1510 "sampling": {"algorithm": "random", "random_seed": 88, "nb_to_select": 10, "init_kargs": None}, 

1511 }, 

1512 ) 

1513 assert response_put.status_code == 201 

1514 assert response_put.json() == { 

1515 "project_id": "2a_SAMPLING_TODO", 

1516 "detail": "The project with id '2a_SAMPLING_TODO' has updated the following settings: sampling.", 

1517 } 

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

1519 response_get_status = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/status") 

1520 assert response_get_status.status_code == 200 

1521 assert response_get_status.json()["status"]["iteration_id"] == 2 

1522 assert response_get_status.json()["status"]["state"] == "SAMPLING_TODO" 

1523 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1524 response_get_settings_after = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1525 assert response_get_settings_after.status_code == 200 

1526 assert ( 

1527 response_get_settings_after.json()["settings"]["preprocessing"] 

1528 == response_get_settings_before.json()["settings"]["preprocessing"] 

1529 ) 

1530 assert ( 

1531 response_get_settings_after.json()["settings"]["vectorization"] 

1532 == response_get_settings_before.json()["settings"]["vectorization"] 

1533 ) 

1534 assert response_get_settings_after.json()["settings"]["sampling"] == { 

1535 "algorithm": "random", 

1536 "random_seed": 88, 

1537 "nb_to_select": 10, 

1538 "init_kargs": None, 

1539 } 

1540 assert ( 

1541 response_get_settings_after.json()["settings"]["clustering"] 

1542 == response_get_settings_before.json()["settings"]["clustering"] 

1543 ) 

1544 

1545 

1546# ============================================================================== 

1547# test_ok_clustering_1 

1548# ============================================================================== 

1549 

1550 

1551@pytest.mark.asyncio() 

1552async def test_ok_clustering_1(async_client, tmp_path): 

1553 """ 

1554 Test the `PUT /api/projects/{project_id}/settings` route. 

1555 

1556 Arguments: 

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

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

1559 """ 

1560 # Assert HTTP client is created. 

1561 assert async_client 

1562 

1563 # Create dummy projects. 

1564 create_dummy_projects( 

1565 tmp_path=tmp_path, 

1566 list_of_dummy_project_ids=[ 

1567 "2a_SAMPLING_TODO", 

1568 ], 

1569 ) 

1570 

1571 # Get settings before test. 

1572 response_get_settings_before = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1573 assert response_get_settings_before.status_code == 200 

1574 

1575 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1576 response_put = await async_client.put( 

1577 url="/api/projects/2a_SAMPLING_TODO/settings", 

1578 json={ 

1579 "clustering": { 

1580 "algorithm": "kmeans", 

1581 "random_seed": 88, 

1582 "nb_clusters": 8, 

1583 "init_kargs": {"model": "COP", "tolerance": 0.1, "max_iteration": 12}, 

1584 } 

1585 }, 

1586 ) 

1587 assert response_put.status_code == 201 

1588 assert response_put.json() == { 

1589 "project_id": "2a_SAMPLING_TODO", 

1590 "detail": "The project with id '2a_SAMPLING_TODO' has updated the following settings: clustering.", 

1591 } 

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

1593 response_get_status = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/status") 

1594 assert response_get_status.status_code == 200 

1595 assert response_get_status.json()["status"]["iteration_id"] == 2 

1596 assert response_get_status.json()["status"]["state"] == "SAMPLING_TODO" 

1597 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1598 response_get_settings_after = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1599 assert response_get_settings_after.status_code == 200 

1600 assert ( 

1601 response_get_settings_after.json()["settings"]["preprocessing"] 

1602 == response_get_settings_before.json()["settings"]["preprocessing"] 

1603 ) 

1604 assert ( 

1605 response_get_settings_after.json()["settings"]["vectorization"] 

1606 == response_get_settings_before.json()["settings"]["vectorization"] 

1607 ) 

1608 assert ( 

1609 response_get_settings_after.json()["settings"]["sampling"] 

1610 == response_get_settings_before.json()["settings"]["sampling"] 

1611 ) 

1612 assert response_get_settings_after.json()["settings"]["clustering"] == { 

1613 "algorithm": "kmeans", 

1614 "random_seed": 88, 

1615 "nb_clusters": 8, 

1616 "init_kargs": {"model": "COP", "tolerance": 0.1, "max_iteration": 12}, 

1617 } 

1618 

1619 

1620# ============================================================================== 

1621# test_ok_clustering_2 

1622# ============================================================================== 

1623 

1624 

1625@pytest.mark.asyncio() 

1626async def test_ok_clustering_2(async_client, tmp_path): 

1627 """ 

1628 Test the `PUT /api/projects/{project_id}/settings` route. 

1629 

1630 Arguments: 

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

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

1633 """ 

1634 # Assert HTTP client is created. 

1635 assert async_client 

1636 

1637 # Create dummy projects. 

1638 create_dummy_projects( 

1639 tmp_path=tmp_path, 

1640 list_of_dummy_project_ids=[ 

1641 "2a_SAMPLING_TODO", 

1642 ], 

1643 ) 

1644 

1645 # Get settings before test. 

1646 response_get_settings_before = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1647 assert response_get_settings_before.status_code == 200 

1648 

1649 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1650 response_put = await async_client.put( 

1651 url="/api/projects/2a_SAMPLING_TODO/settings", 

1652 json={ 

1653 "clustering": { 

1654 "algorithm": "hierarchical", 

1655 "random_seed": 88, 

1656 "nb_clusters": 8, 

1657 "init_kargs": {"linkage": "average"}, 

1658 } 

1659 }, 

1660 ) 

1661 assert response_put.status_code == 201 

1662 assert response_put.json() == { 

1663 "project_id": "2a_SAMPLING_TODO", 

1664 "detail": "The project with id '2a_SAMPLING_TODO' has updated the following settings: clustering.", 

1665 } 

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

1667 response_get_status = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/status") 

1668 assert response_get_status.status_code == 200 

1669 assert response_get_status.json()["status"]["iteration_id"] == 2 

1670 assert response_get_status.json()["status"]["state"] == "SAMPLING_TODO" 

1671 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1672 response_get_settings_after = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1673 assert response_get_settings_after.status_code == 200 

1674 assert ( 

1675 response_get_settings_after.json()["settings"]["preprocessing"] 

1676 == response_get_settings_before.json()["settings"]["preprocessing"] 

1677 ) 

1678 assert ( 

1679 response_get_settings_after.json()["settings"]["vectorization"] 

1680 == response_get_settings_before.json()["settings"]["vectorization"] 

1681 ) 

1682 assert ( 

1683 response_get_settings_after.json()["settings"]["sampling"] 

1684 == response_get_settings_before.json()["settings"]["sampling"] 

1685 ) 

1686 assert response_get_settings_after.json()["settings"]["clustering"] == { 

1687 "algorithm": "hierarchical", 

1688 "random_seed": 88, 

1689 "nb_clusters": 8, 

1690 "init_kargs": {"linkage": "average"}, 

1691 } 

1692 

1693 

1694# ============================================================================== 

1695# test_ok_clustering_3 

1696# ============================================================================== 

1697 

1698 

1699@pytest.mark.asyncio() 

1700async def test_ok_clustering_3(async_client, tmp_path): 

1701 """ 

1702 Test the `PUT /api/projects/{project_id}/settings` route. 

1703 

1704 Arguments: 

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

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

1707 """ 

1708 # Assert HTTP client is created. 

1709 assert async_client 

1710 

1711 # Create dummy projects. 

1712 create_dummy_projects( 

1713 tmp_path=tmp_path, 

1714 list_of_dummy_project_ids=[ 

1715 "2a_SAMPLING_TODO", 

1716 ], 

1717 ) 

1718 

1719 # Get settings before test. 

1720 response_get_settings_before = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1721 assert response_get_settings_before.status_code == 200 

1722 

1723 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1724 response_put = await async_client.put( 

1725 url="/api/projects/2a_SAMPLING_TODO/settings", 

1726 json={ 

1727 "clustering": { 

1728 "algorithm": "spectral", 

1729 "random_seed": 40, 

1730 "nb_clusters": 4, 

1731 "init_kargs": {"model": "SPEC", "nb_components": 12}, 

1732 } 

1733 }, 

1734 ) 

1735 assert response_put.status_code == 201 

1736 assert response_put.json() == { 

1737 "project_id": "2a_SAMPLING_TODO", 

1738 "detail": "The project with id '2a_SAMPLING_TODO' has updated the following settings: clustering.", 

1739 } 

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

1741 response_get_status = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/status") 

1742 assert response_get_status.status_code == 200 

1743 assert response_get_status.json()["status"]["iteration_id"] == 2 

1744 assert response_get_status.json()["status"]["state"] == "SAMPLING_TODO" 

1745 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1746 response_get_settings_after = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1747 assert response_get_settings_after.status_code == 200 

1748 assert ( 

1749 response_get_settings_after.json()["settings"]["preprocessing"] 

1750 == response_get_settings_before.json()["settings"]["preprocessing"] 

1751 ) 

1752 assert ( 

1753 response_get_settings_after.json()["settings"]["vectorization"] 

1754 == response_get_settings_before.json()["settings"]["vectorization"] 

1755 ) 

1756 assert ( 

1757 response_get_settings_after.json()["settings"]["sampling"] 

1758 == response_get_settings_before.json()["settings"]["sampling"] 

1759 ) 

1760 assert response_get_settings_after.json()["settings"]["clustering"] == { 

1761 "algorithm": "spectral", 

1762 "random_seed": 40, 

1763 "nb_clusters": 4, 

1764 "init_kargs": {"model": "SPEC", "nb_components": 12}, 

1765 } 

1766 

1767 

1768# ============================================================================== 

1769# test_ok_clustering_4 

1770# ============================================================================== 

1771 

1772 

1773@pytest.mark.asyncio() 

1774async def test_ok_clustering_4(async_client, tmp_path): 

1775 """ 

1776 Test the `PUT /api/projects/{project_id}/settings` route. 

1777 

1778 Arguments: 

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

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

1781 """ 

1782 # Assert HTTP client is created. 

1783 assert async_client 

1784 

1785 # Create dummy projects. 

1786 create_dummy_projects( 

1787 tmp_path=tmp_path, 

1788 list_of_dummy_project_ids=[ 

1789 "2a_SAMPLING_TODO", 

1790 ], 

1791 ) 

1792 

1793 # Get settings before test. 

1794 response_get_settings_before = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1795 assert response_get_settings_before.status_code == 200 

1796 

1797 # Assert route `PUT /api/projects/{project_id}/settings` works. 

1798 response_put = await async_client.put( 

1799 url="/api/projects/2a_SAMPLING_TODO/settings", 

1800 json={ 

1801 "clustering": { 

1802 "algorithm": "spectral", 

1803 "random_seed": 40, 

1804 "nb_clusters": 4, 

1805 "init_kargs": {"model": "SPEC", "nb_components": None}, 

1806 } 

1807 }, 

1808 ) 

1809 assert response_put.status_code == 201 

1810 assert response_put.json() == { 

1811 "project_id": "2a_SAMPLING_TODO", 

1812 "detail": "The project with id '2a_SAMPLING_TODO' has updated the following settings: clustering.", 

1813 } 

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

1815 response_get_status = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/status") 

1816 assert response_get_status.status_code == 200 

1817 assert response_get_status.json()["status"]["iteration_id"] == 2 

1818 assert response_get_status.json()["status"]["state"] == "SAMPLING_TODO" 

1819 # Assert route `GET /api/projects/{project_id}/settings` is updated. 

1820 response_get_settings_after = await async_client.get(url="/api/projects/2a_SAMPLING_TODO/settings") 

1821 assert response_get_settings_after.status_code == 200 

1822 assert ( 

1823 response_get_settings_after.json()["settings"]["preprocessing"] 

1824 == response_get_settings_before.json()["settings"]["preprocessing"] 

1825 ) 

1826 assert ( 

1827 response_get_settings_after.json()["settings"]["vectorization"] 

1828 == response_get_settings_before.json()["settings"]["vectorization"] 

1829 ) 

1830 assert ( 

1831 response_get_settings_after.json()["settings"]["sampling"] 

1832 == response_get_settings_before.json()["settings"]["sampling"] 

1833 ) 

1834 assert response_get_settings_after.json()["settings"]["clustering"] == { 

1835 "algorithm": "spectral", 

1836 "random_seed": 40, 

1837 "nb_clusters": 4, 

1838 "init_kargs": {"model": "SPEC", "nb_components": None}, 

1839 }