99from fastapi import status
1010from fixtures .fake_services import ServiceInRegistryInfoDict
1111from models_library .api_schemas_director .services import ServiceDataGet
12+ from pytest_simcore .helpers .typing_env import EnvVarsDict
1213
1314
1415def _assert_response_and_unwrap_envelope (got : httpx .Response ):
15- assert got .encoding == "application/json"
16+ assert got .headers ["content-type" ] == "application/json"
17+ assert got .encoding == "utf-8"
1618
1719 body = got .json ()
1820 assert isinstance (body , dict )
@@ -43,6 +45,7 @@ def _assert_services(
4345
4446async def test_list_services_with_empty_registry (
4547 docker_registry : str ,
48+ configure_registry_access : EnvVarsDict ,
4649 client : httpx .AsyncClient ,
4750 api_version_prefix : str ,
4851):
@@ -52,7 +55,7 @@ async def test_list_services_with_empty_registry(
5255 resp = await client .get (f"/{ api_version_prefix } /services" )
5356 assert resp .status_code == status .HTTP_200_OK , f"Got f{ resp .text } "
5457
55- services , error = _assert_response_and_unwrap_envelope (resp . json () )
58+ services , error = _assert_response_and_unwrap_envelope (resp )
5659 assert not error
5760 assert isinstance (services , list )
5861
@@ -61,6 +64,7 @@ async def test_list_services_with_empty_registry(
6164
6265async def test_list_services (
6366 docker_registry : str ,
67+ configure_registry_access : EnvVarsDict ,
6468 client : httpx .AsyncClient ,
6569 created_services : list [ServiceInRegistryInfoDict ],
6670 api_version_prefix : str ,
@@ -70,7 +74,7 @@ async def test_list_services(
7074 resp = await client .get (f"/{ api_version_prefix } /services" )
7175 assert resp .status_code == status .HTTP_200_OK , f"Got f{ resp .text } "
7276
73- services , error = _assert_response_and_unwrap_envelope (resp . json () )
77+ services , error = _assert_response_and_unwrap_envelope (resp )
7478 assert not error
7579 assert isinstance (services , list )
7680
@@ -79,6 +83,7 @@ async def test_list_services(
7983
8084async def test_get_service_bad_request (
8185 docker_registry : str ,
86+ configure_registry_access : EnvVarsDict ,
8287 client : httpx .AsyncClient ,
8388 created_services : list [ServiceInRegistryInfoDict ],
8489 api_version_prefix : str ,
@@ -87,15 +92,16 @@ async def test_get_service_bad_request(
8792 assert len (created_services ) > 0
8893
8994 resp = await client .get (f"/{ api_version_prefix } /services?service_type=blahblah" )
90- assert resp .status_code == status .HTTP_400_BAD_REQUEST , f"Got f{ resp .text } "
95+ assert resp .status_code == status .HTTP_422_UNPROCESSABLE_ENTITY , f"Got f{ resp .text } "
9196
92- services , error = _assert_response_and_unwrap_envelope (resp . json () )
97+ services , error = _assert_response_and_unwrap_envelope (resp )
9398 assert not services
9499 assert error
95100
96101
97102async def test_list_services_by_service_type (
98103 docker_registry : str ,
104+ configure_registry_access : EnvVarsDict ,
99105 client : httpx .AsyncClient ,
100106 created_services : list [ServiceInRegistryInfoDict ],
101107 api_version_prefix : str ,
@@ -108,25 +114,27 @@ async def test_list_services_by_service_type(
108114 )
109115 assert resp .status_code == status .HTTP_200_OK , f"Got f{ resp .text } "
110116
111- services , error = _assert_response_and_unwrap_envelope (resp . json () )
117+ services , error = _assert_response_and_unwrap_envelope (resp )
112118 assert not error
113119 assert services
114120 assert len (services ) == 3
115121
116122 resp = await client .get (f"/{ api_version_prefix } /services?service_type=interactive" )
117123 assert resp .status_code == status .HTTP_200_OK , f"Got f{ resp .text } "
118124
119- services , error = _assert_response_and_unwrap_envelope (resp . json () )
125+ services , error = _assert_response_and_unwrap_envelope (resp )
120126 assert not error
121127 assert services
122128 assert len (services ) == 2
123129
124130
125131async def test_get_services_by_key_and_version_with_empty_registry (
126- client : httpx .AsyncClient , api_version_prefix : str
132+ configure_registry_access : EnvVarsDict ,
133+ client : httpx .AsyncClient ,
134+ api_version_prefix : str ,
127135):
128136 resp = await client .get (f"/{ api_version_prefix } /services/whatever/someversion" )
129- assert resp .status_code == status .HTTP_400_BAD_REQUEST , f"Got f{ resp .text } "
137+ assert resp .status_code == status .HTTP_422_UNPROCESSABLE_ENTITY , f"Got f{ resp .text } "
130138
131139 resp = await client .get (
132140 f"/{ api_version_prefix } /services/simcore/services/dynamic/something/someversion"
@@ -140,6 +148,7 @@ async def test_get_services_by_key_and_version_with_empty_registry(
140148
141149
142150async def test_get_services_by_key_and_version (
151+ configure_registry_access : EnvVarsDict ,
143152 client : httpx .AsyncClient ,
144153 created_services : list [ServiceInRegistryInfoDict ],
145154 api_version_prefix : str ,
@@ -158,7 +167,7 @@ async def test_get_services_by_key_and_version(
158167
159168 assert resp .status_code == status .HTTP_200_OK , f"Got f{ resp .text } "
160169
161- services , error = _assert_response_and_unwrap_envelope (resp . json () )
170+ services , error = _assert_response_and_unwrap_envelope (resp )
162171 assert not error
163172 assert isinstance (services , list )
164173 assert len (services ) == 1
@@ -169,6 +178,7 @@ async def test_get_services_by_key_and_version(
169178
170179
171180async def test_get_service_labels (
181+ configure_registry_access : EnvVarsDict ,
172182 client : httpx .AsyncClient ,
173183 created_services : list [ServiceInRegistryInfoDict ],
174184 api_version_prefix : str ,
@@ -185,7 +195,7 @@ async def test_get_service_labels(
185195 resp = await client .get (url )
186196 assert resp .status_code == status .HTTP_200_OK , f"Got f{ resp .text } "
187197
188- labels , error = _assert_response_and_unwrap_envelope (resp . json () )
198+ labels , error = _assert_response_and_unwrap_envelope (resp )
189199 assert not error
190200
191201 assert service ["docker_labels" ] == labels
0 commit comments