77
88import httpx
99import pytest
10+ from faker import Faker
1011
1112# from aioresponses.core import CallbackResult, aioresponses
1213from fastapi import status
14+ from models_library .projects import ProjectID
15+ from models_library .users import UserID
1316
1417
1518def _assert_response_and_unwrap_envelope (got : httpx .Response ):
@@ -50,26 +53,28 @@ async def test_running_services_post_and_delete_no_swarm(
5053)
5154async def test_running_services_post_and_delete (
5255 configure_swarm_stack_name ,
56+ configure_registry_access ,
5357 client : httpx .AsyncClient ,
5458 push_services ,
55- docker_swarm ,
56- user_id ,
57- project_id ,
58- api_version_prefix ,
59+ docker_swarm : None ,
60+ user_id : UserID ,
61+ project_id : ProjectID ,
62+ api_version_prefix : str ,
5963 save_state : bool | None ,
6064 expected_save_state_call : bool ,
6165 mocker ,
66+ faker : Faker ,
6267):
6368 params = {}
6469 resp = await client .post (
6570 f"/{ api_version_prefix } /running_interactive_services" , params = params
6671 )
67- assert resp .status_code == status .HTTP_400_BAD_REQUEST
72+ assert resp .status_code == status .HTTP_422_UNPROCESSABLE_ENTITY
6873
6974 params = {
70- "user_id" : "None " ,
71- "project_id" : "None " ,
72- "service_uuid" : "sdlfkj4 " ,
75+ "user_id" : f" { faker . pyint ( min_value = 1 ) } " ,
76+ "project_id" : f" { faker . uuid4 () } " ,
77+ "service_uuid" : f" { faker . uuid4 () } " ,
7378 "service_key" : "None" ,
7479 "service_tag" : "None" , # optional
7580 "service_basepath" : "None" , # optional
@@ -78,31 +83,39 @@ async def test_running_services_post_and_delete(
7883 f"/{ api_version_prefix } /running_interactive_services" , params = params
7984 )
8085 data = resp .json ()
81- assert resp .status_code == status .HTTP_400_BAD_REQUEST , data
86+ assert resp .status_code == status .HTTP_422_UNPROCESSABLE_ENTITY , data
87+
88+ fake_headers = {"x-simcore-user-agent" : faker .pystr ()}
8289
8390 params ["service_key" ] = "simcore/services/comp/somfunkyname-nhsd"
8491 params ["service_tag" ] = "1.2.3"
8592 resp = await client .post (
86- f"/{ api_version_prefix } /running_interactive_services" , params = params
93+ f"/{ api_version_prefix } /running_interactive_services" ,
94+ params = params ,
95+ headers = fake_headers ,
8796 )
8897 data = resp .json ()
8998 assert resp .status_code == status .HTTP_404_NOT_FOUND , data
9099
91- created_services = await push_services (0 , 2 )
100+ created_services = await push_services (
101+ number_of_computational_services = 0 , number_of_interactive_services = 2
102+ )
92103 assert len (created_services ) == 2
93104 for created_service in created_services :
94105 service_description = created_service ["service_description" ]
95- params ["user_id" ] = user_id
96- params ["project_id" ] = project_id
106+ params ["user_id" ] = f" { user_id } "
107+ params ["project_id" ] = f" { project_id } "
97108 params ["service_key" ] = service_description ["key" ]
98109 params ["service_tag" ] = service_description ["version" ]
99110 service_port = created_service ["internal_port" ]
100111 service_entry_point = created_service ["entry_point" ]
101112 params ["service_basepath" ] = "/i/am/a/basepath"
102- params ["service_uuid" ] = str ( uuid .uuid4 ())
113+ params ["service_uuid" ] = f" { faker .uuid4 ()} "
103114 # start the service
104115 resp = await client .post (
105- f"/{ api_version_prefix } /running_interactive_services" , params = params
116+ f"/{ api_version_prefix } /running_interactive_services" ,
117+ params = params ,
118+ headers = fake_headers ,
106119 )
107120 assert resp .status_code == status .HTTP_201_CREATED
108121 assert resp .encoding == "application/json"
0 commit comments