Skip to content

Commit 83148bd

Browse files
committed
replace aioresponses with httpx
1 parent 9ebba79 commit 83148bd

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

services/director/tests/unit/api/test_rest_running_interactive_services.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import httpx
99
import pytest
10-
from aioresponses import CallbackResult, aioresponses
10+
import respx
1111
from faker import Faker
1212
from fastapi import status
1313
from models_library.projects import ProjectID
@@ -172,29 +172,23 @@ async def test_running_services_post_and_delete(
172172
if save_state:
173173
query_params.update({"save_state": "true" if save_state else "false"})
174174

175-
mocked_save_state_cb = mocker.MagicMock(
176-
return_value=CallbackResult(status=200, payload={})
177-
)
178-
PASSTHROUGH_REQUESTS_PREFIXES = [
179-
"http://127.0.0.1",
180-
"http://localhost",
181-
"unix://", # docker engine
182-
"ws://", # websockets
183-
]
184-
with aioresponses(passthrough=PASSTHROUGH_REQUESTS_PREFIXES) as mock:
175+
with respx.mock(
176+
base_url=f"http://{service_host}:{service_port}{service_basepath}",
177+
assert_all_called=False,
178+
assert_all_mocked=False,
179+
) as respx_mock:
180+
181+
def _save_me(request) -> httpx.Response:
182+
return httpx.Response(status.HTTP_200_OK, json={})
183+
184+
respx_mock.post("/state", name="save_state").mock(side_effect=_save_me)
185+
respx_mock.route(host="127.0.0.1", name="host").pass_through()
186+
respx_mock.route(host="localhost", name="localhost").pass_through()
185187

186-
# POST /http://service_host:service_port service_basepath/state -------------------------------------------------
187-
mock.post(
188-
f"http://{service_host}:{service_port}{service_basepath}/state",
189-
status=200,
190-
callback=mocked_save_state_cb,
191-
)
192188
resp = await client.delete(
193189
f"/{api_version_prefix}/running_interactive_services/{params['service_uuid']}",
194190
params=query_params,
195191
)
196-
if expected_save_state_call:
197-
mocked_save_state_cb.assert_called_once()
198192

199193
text = resp.text
200194
assert resp.status_code == status.HTTP_204_NO_CONTENT, text

0 commit comments

Comments
 (0)