@@ -357,6 +357,7 @@ async def test_open_project(
357357 logged_user : UserInfoDict ,
358358 user_project : ProjectDict ,
359359 client_session_id_factory : Callable [[], str ],
360+ socketio_client_factory : Callable ,
360361 expected : HTTPStatus ,
361362 save_state : bool ,
362363 mocked_dynamic_services_interface : dict [str , mock .Mock ],
@@ -370,8 +371,15 @@ async def test_open_project(
370371 # POST /v0/projects/{project_id}:open
371372 # open project
372373 assert client .app
374+ client_id = client_session_id_factory ()
375+ await _connect_websocket (
376+ socketio_client_factory ,
377+ expected != status .HTTP_401_UNAUTHORIZED ,
378+ client ,
379+ client_id ,
380+ )
373381 url = client .app .router ["open_project" ].url_for (project_id = user_project ["uuid" ])
374- resp = await client .post (f"{ url } " , json = client_session_id_factory () )
382+ resp = await client .post (f"{ url } " , json = client_id )
375383
376384 await assert_status (resp , expected )
377385
@@ -440,6 +448,7 @@ async def test_open_project__in_debt(
440448 logged_user : UserInfoDict ,
441449 user_project : ProjectDict ,
442450 client_session_id_factory : Callable [[], str ],
451+ socketio_client_factory : Callable ,
443452 expected : HTTPStatus ,
444453 mocked_dynamic_services_interface : dict [str , mock .Mock ],
445454 mock_service_resources : ServiceResourcesDict ,
@@ -477,8 +486,15 @@ async def test_open_project__in_debt(
477486
478487 # POST /v0/projects/{project_id}:open
479488 assert client .app
489+ client_id = client_session_id_factory ()
490+ await _connect_websocket (
491+ socketio_client_factory ,
492+ check_connection = True , # USER role always connects
493+ client = client ,
494+ client_id = client_id ,
495+ )
480496 url = client .app .router ["open_project" ].url_for (project_id = user_project ["uuid" ])
481- resp = await client .post (f"{ url } " , json = client_session_id_factory () )
497+ resp = await client .post (f"{ url } " , json = client_id )
482498 await assert_status (resp , expected )
483499
484500 assert mock_get_project_wallet_total_credits .assert_called_once
@@ -498,6 +514,7 @@ async def test_open_template_project_for_edition(
498514 logged_user : UserInfoDict ,
499515 create_template_project : Callable [..., Awaitable [ProjectDict ]],
500516 client_session_id_factory : Callable [[], str ],
517+ socketio_client_factory : Callable ,
501518 expected : HTTPStatus ,
502519 save_state : bool ,
503520 mocked_dynamic_services_interface : dict [str , mock .Mock ],
@@ -517,8 +534,15 @@ async def test_open_template_project_for_edition(
517534 logged_user ["primary_gid" ]: {"read" : True , "write" : True , "delete" : False }
518535 }
519536 )
537+ client_id = client_session_id_factory ()
538+ await _connect_websocket (
539+ socketio_client_factory ,
540+ check_connection = expected != status .HTTP_401_UNAUTHORIZED ,
541+ client = client ,
542+ client_id = client_id ,
543+ )
520544 url = client .app .router ["open_project" ].url_for (project_id = template_project ["uuid" ])
521- resp = await client .post (f"{ url } " , json = client_session_id_factory () )
545+ resp = await client .post (f"{ url } " , json = client_id )
522546 await assert_status (resp , expected )
523547
524548 if resp .status == status .HTTP_200_OK :
@@ -579,6 +603,7 @@ async def test_open_template_project_for_edition_with_missing_write_rights(
579603 logged_user : UserInfoDict ,
580604 create_template_project : Callable [..., Awaitable [ProjectDict ]],
581605 client_session_id_factory : Callable [[], str ],
606+ socketio_client_factory : Callable ,
582607 expected : HTTPStatus ,
583608 mocked_dynamic_services_interface : dict [str , mock .Mock ],
584609 mock_service_resources : ServiceResourcesDict ,
@@ -594,8 +619,15 @@ async def test_open_template_project_for_edition_with_missing_write_rights(
594619 logged_user ["primary_gid" ]: {"read" : True , "write" : False , "delete" : True }
595620 }
596621 )
622+ client_id = client_session_id_factory ()
623+ await _connect_websocket (
624+ socketio_client_factory ,
625+ check_connection = expected != status .HTTP_401_UNAUTHORIZED ,
626+ client = client ,
627+ client_id = client_id ,
628+ )
597629 url = client .app .router ["open_project" ].url_for (project_id = template_project ["uuid" ])
598- resp = await client .post (f"{ url } " , json = client_session_id_factory () )
630+ resp = await client .post (f"{ url } " , json = client_id )
599631 await assert_status (resp , expected )
600632
601633
@@ -611,6 +643,7 @@ async def test_open_project_with_small_amount_of_dynamic_services_starts_them_au
611643 logged_user : UserInfoDict ,
612644 user_project_with_num_dynamic_services : Callable [[int ], Awaitable [ProjectDict ]],
613645 client_session_id_factory : Callable ,
646+ socketio_client_factory : Callable ,
614647 expected : ExpectedResponse ,
615648 mocked_dynamic_services_interface : dict [str , mock .Mock ],
616649 mock_catalog_api : dict [str , mock .Mock ],
@@ -636,8 +669,15 @@ async def test_open_project_with_small_amount_of_dynamic_services_starts_them_au
636669 for service_id in range (num_service_already_running )
637670 ]
638671
672+ client_id = client_session_id_factory ()
673+ await _connect_websocket (
674+ socketio_client_factory ,
675+ check_connection = True , # standard_user_role is always USER or TESTER
676+ client = client ,
677+ client_id = client_id ,
678+ )
639679 url = client .app .router ["open_project" ].url_for (project_id = project ["uuid" ])
640- resp = await client .post (f"{ url } " , json = client_session_id_factory () )
680+ resp = await client .post (f"{ url } " , json = client_id )
641681 await assert_status (resp , expected .ok )
642682 mocked_notifications_plugin ["subscribe" ].assert_called_once_with (
643683 client .app , ProjectID (project ["uuid" ])
@@ -657,6 +697,7 @@ async def test_open_project_with_disable_service_auto_start_set_overrides_behavi
657697 logged_user : UserInfoDict ,
658698 user_project_with_num_dynamic_services : Callable [[int ], Awaitable [ProjectDict ]],
659699 client_session_id_factory : Callable ,
700+ socketio_client_factory : Callable ,
660701 expected : ExpectedResponse ,
661702 mocked_dynamic_services_interface : dict [str , mock .Mock ],
662703 mock_catalog_api : dict [str , mock .Mock ],
@@ -678,14 +719,22 @@ async def test_open_project_with_disable_service_auto_start_set_overrides_behavi
678719 for service_id in range (num_service_already_running )
679720 ]
680721
722+ client_id = client_session_id_factory ()
723+ sio = await _connect_websocket (
724+ socketio_client_factory ,
725+ check_connection = True , # standard_user_role is always USER or TESTER
726+ client = client ,
727+ client_id = client_id ,
728+ )
681729 url = (
682730 client .app .router ["open_project" ]
683731 .url_for (project_id = project ["uuid" ])
684732 .with_query (disable_service_auto_start = f"{ True } " )
685733 )
686734
687- resp = await client .post (f"{ url } " , json = client_session_id_factory () )
735+ resp = await client .post (f"{ url } " , json = client_id )
688736 await assert_status (resp , expected .ok )
737+ await sio .disconnect ()
689738 mocked_notifications_plugin ["subscribe" ].assert_called_once_with (
690739 client .app , ProjectID (project ["uuid" ])
691740 )
@@ -701,6 +750,7 @@ async def test_open_project_with_large_amount_of_dynamic_services_does_not_start
701750 logged_user : UserInfoDict ,
702751 user_project_with_num_dynamic_services : Callable [[int ], Awaitable [ProjectDict ]],
703752 client_session_id_factory : Callable ,
753+ socketio_client_factory : Callable ,
704754 expected : ExpectedResponse ,
705755 mocked_dynamic_services_interface : dict [str , mock .Mock ],
706756 mock_catalog_api : dict [str , mock .Mock ],
@@ -728,8 +778,15 @@ async def test_open_project_with_large_amount_of_dynamic_services_does_not_start
728778 for service_id in range (num_service_already_running )
729779 ]
730780
781+ client_id = client_session_id_factory ()
782+ await _connect_websocket (
783+ socketio_client_factory ,
784+ check_connection = True , # standard_user_role is always USER or TESTER
785+ client = client ,
786+ client_id = client_id ,
787+ )
731788 url = client .app .router ["open_project" ].url_for (project_id = project ["uuid" ])
732- resp = await client .post (f"{ url } " , json = client_session_id_factory () )
789+ resp = await client .post (f"{ url } " , json = client_id )
733790 await assert_status (resp , expected .ok )
734791 mocked_notifications_plugin ["subscribe" ].assert_called_once_with (
735792 client .app , ProjectID (project ["uuid" ])
@@ -748,6 +805,7 @@ async def test_open_project_with_large_amount_of_dynamic_services_starts_them_if
748805 logged_user : UserInfoDict ,
749806 user_project_with_num_dynamic_services : Callable [[int ], Awaitable [ProjectDict ]],
750807 client_session_id_factory : Callable ,
808+ socketio_client_factory : Callable ,
751809 expected : ExpectedResponse ,
752810 mocked_dynamic_services_interface : dict [str , mock .Mock ],
753811 mock_catalog_api : dict [str , mock .Mock ],
@@ -778,8 +836,15 @@ async def test_open_project_with_large_amount_of_dynamic_services_starts_them_if
778836 for service_id in range (num_service_already_running )
779837 ]
780838
839+ client_id = client_session_id_factory ()
840+ await _connect_websocket (
841+ socketio_client_factory ,
842+ check_connection = True , # standard_user_role is always USER or TESTER
843+ client = client ,
844+ client_id = client_id ,
845+ )
781846 url = client .app .router ["open_project" ].url_for (project_id = project ["uuid" ])
782- resp = await client .post (f"{ url } " , json = client_session_id_factory () )
847+ resp = await client .post (f"{ url } " , json = client_id )
783848 await assert_status (resp , expected .ok )
784849 mocked_notifications_plugin ["subscribe" ].assert_called_once_with (
785850 client .app , ProjectID (project ["uuid" ])
@@ -796,6 +861,7 @@ async def test_open_project_with_deprecated_services_ok_but_does_not_start_dynam
796861 logged_user ,
797862 user_project ,
798863 client_session_id_factory : Callable ,
864+ socketio_client_factory : Callable ,
799865 expected : ExpectedResponse ,
800866 mocked_dynamic_services_interface : dict [str , mock .Mock ],
801867 mock_service_resources : ServiceResourcesDict ,
@@ -806,8 +872,15 @@ async def test_open_project_with_deprecated_services_ok_but_does_not_start_dynam
806872 mock_catalog_api ["get_service" ].return_value ["deprecated" ] = (
807873 datetime .now (UTC ) - timedelta (days = 1 )
808874 ).isoformat ()
875+ client_id = client_session_id_factory ()
876+ await _connect_websocket (
877+ socketio_client_factory ,
878+ check_connection = True , # standard_user_role is always USER or TESTER
879+ client = client ,
880+ client_id = client_id ,
881+ )
809882 url = client .app .router ["open_project" ].url_for (project_id = user_project ["uuid" ])
810- resp = await client .post (url , json = client_session_id_factory () )
883+ resp = await client .post (url , json = client_id )
811884 await assert_status (resp , expected .ok )
812885 mocked_notifications_plugin ["subscribe" ].assert_called_once_with (
813886 client .app , ProjectID (user_project ["uuid" ])
0 commit comments