|
7 | 7 |
|
8 | 8 | import httpx |
9 | 9 | import pytest |
10 | | -from aioresponses import CallbackResult, aioresponses |
| 10 | +import respx |
11 | 11 | from faker import Faker |
12 | 12 | from fastapi import status |
13 | 13 | from models_library.projects import ProjectID |
@@ -172,29 +172,23 @@ async def test_running_services_post_and_delete( |
172 | 172 | if save_state: |
173 | 173 | query_params.update({"save_state": "true" if save_state else "false"}) |
174 | 174 |
|
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() |
185 | 187 |
|
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 | | - ) |
192 | 188 | resp = await client.delete( |
193 | 189 | f"/{api_version_prefix}/running_interactive_services/{params['service_uuid']}", |
194 | 190 | params=query_params, |
195 | 191 | ) |
196 | | - if expected_save_state_call: |
197 | | - mocked_save_state_cb.assert_called_once() |
198 | 192 |
|
199 | 193 | text = resp.text |
200 | 194 | assert resp.status_code == status.HTTP_204_NO_CONTENT, text |
|
0 commit comments