|
18 | 18 | from models_library.api_schemas_directorv2.dynamic_services import ( |
19 | 19 | GetProjectInactivityResponse, |
20 | 20 | ) |
21 | | -from models_library.api_schemas_webserver.projects import ProjectCreateNew |
22 | 21 | from models_library.products import ProductName |
23 | 22 | from models_library.projects_state import ProjectState |
24 | 23 | from pydantic import TypeAdapter |
@@ -416,65 +415,73 @@ async def test_get_project( |
416 | 415 | # POST -------- |
417 | 416 |
|
418 | 417 |
|
| 418 | +@pytest.mark.parametrize(*standard_role_response()) |
| 419 | +async def test_new_project( |
| 420 | + mock_dynamic_scheduler: None, |
| 421 | + client: TestClient, |
| 422 | + logged_user: UserInfoDict, |
| 423 | + primary_group, |
| 424 | + expected: ExpectedResponse, |
| 425 | + request_create_project: Callable[..., Awaitable[ProjectDict]], |
| 426 | + storage_subsystem_mock, |
| 427 | + project_db_cleaner, |
| 428 | +): |
| 429 | + await request_create_project( |
| 430 | + client, expected.accepted, expected.created, logged_user, primary_group |
| 431 | + ) |
| 432 | + |
| 433 | + |
419 | 434 | @pytest.mark.parametrize( |
420 | 435 | "user_role", |
421 | 436 | [UserRole.USER], |
422 | 437 | ) |
423 | | -async def test_create_get_patch_project_icon( |
| 438 | +async def test_create_get_and_patch_project_ui_field( |
| 439 | + mock_dynamic_scheduler: None, |
| 440 | + storage_subsystem_mock, |
424 | 441 | client: TestClient, |
425 | 442 | logged_user: UserInfoDict, |
426 | 443 | primary_group: dict[str, str], |
| 444 | + request_create_project: Callable[..., Awaitable[ProjectDict]], |
| 445 | + catalog_subsystem_mock: Callable[[list[ProjectDict]], None], |
| 446 | + project_db_cleaner, |
427 | 447 | ): |
428 | | - # Step 1: Create a new project with a specific ui.icon |
429 | | - project_data = ProjectCreateNew.model_validate( |
430 | | - { |
431 | | - "name": "Test Project", |
432 | | - "description": "A project to test ui.icon", |
433 | | - "ui": {"icon": "http://example.com/icon.png"}, |
434 | | - "workbench": {}, |
435 | | - "acess_rights": primary_group, |
436 | | - } |
437 | | - ).model_dump(mode="json", exclude_defaults=True, by_alias=True) |
438 | | - |
439 | | - url = client.app.router["create_project"].url_for() |
440 | | - resp = await client.post(f"{url}", json=project_data) |
441 | | - new_project, _ = await assert_status(resp, status.HTTP_201_CREATED) |
442 | | - assert new_project |
| 448 | + assert client.app |
| 449 | + |
| 450 | + gid = logged_user["primary_gid"] |
| 451 | + assert primary_group["gid"] == gid |
443 | 452 |
|
| 453 | + # Step 1: Create project (long running task) |
| 454 | + new_project = await request_create_project( |
| 455 | + client, |
| 456 | + status.HTTP_202_ACCEPTED, |
| 457 | + status.HTTP_201_CREATED, |
| 458 | + logged_user, |
| 459 | + primary_group, |
| 460 | + ) |
444 | 461 | project_id = new_project["uuid"] |
445 | 462 |
|
| 463 | + catalog_subsystem_mock([new_project]) |
| 464 | + |
446 | 465 | # Step 2: Get the project and check the ui.icon |
447 | 466 | url = client.app.router["get_project"].url_for(project_id=project_id) |
448 | 467 | resp = await client.get(f"{url}") |
449 | 468 | got_project, _ = await assert_status(resp, status.HTTP_200_OK) |
450 | | - assert got_project["ui"]["icon"] == "http://example.com/icon.png" |
| 469 | + assert got_project["ui"] == {} |
451 | 470 |
|
452 | 471 | # Step 3: Patch the project to set ui.icon to null |
453 | | - patch_data = {"ui": {"icon": None}} |
454 | | - url = client.app.router["update_project"].url_for(project_id=project_id) |
| 472 | + patch_data = {"ui": {"icon": "http://example.com/icon.png"}} |
| 473 | + url = client.app.router["patch_project"].url_for(project_id=project_id) |
455 | 474 | resp = await client.patch(f"{url}", json=patch_data) |
456 | 475 | await assert_status(resp, status.HTTP_204_NO_CONTENT) |
457 | 476 |
|
458 | 477 | # Step 4: Get the project again and check the ui.icon is now null |
459 | 478 | resp = await client.get(f"{url}") |
460 | 479 | got_project, _ = await assert_status(resp, status.HTTP_200_OK) |
461 | | - assert got_project["ui"]["icon"] is None |
462 | | - |
| 480 | + assert got_project["ui"]["icon"] == "http://example.com/icon.png" |
463 | 481 |
|
464 | | -@pytest.mark.parametrize(*standard_role_response()) |
465 | | -async def test_new_project( |
466 | | - mock_dynamic_scheduler: None, |
467 | | - client: TestClient, |
468 | | - logged_user: UserInfoDict, |
469 | | - primary_group, |
470 | | - expected: ExpectedResponse, |
471 | | - storage_subsystem_mock, |
472 | | - project_db_cleaner, |
473 | | - request_create_project: Callable[..., Awaitable[ProjectDict]], |
474 | | -): |
475 | | - await request_create_project( |
476 | | - client, expected.accepted, expected.created, logged_user, primary_group |
477 | | - ) |
| 482 | + # Step 5: Delete project |
| 483 | + resp = await client.delete(f"{url}") |
| 484 | + await assert_status(resp, status.HTTP_204_NO_CONTENT) |
478 | 485 |
|
479 | 486 |
|
480 | 487 | @pytest.mark.parametrize(*standard_user_role_response()) |
|
0 commit comments