|
8 | 8 | from tests.http.conftest import AsyncDummyService |
9 | 9 |
|
10 | 10 |
|
| 11 | +async def test_async_create_mixin(async_dummy_service): # noqa: WPS210 |
| 12 | + resource_data = {"name": "Test Resource", "status": "active"} |
| 13 | + new_resource_data = {"id": "new-resource-id", "name": "Test Resource", "status": "active"} |
| 14 | + create_response = httpx.Response(httpx.codes.OK, json=new_resource_data) |
| 15 | + |
| 16 | + with respx.mock: |
| 17 | + mock_route = respx.post("https://api.example.com/api/v1/test").mock( |
| 18 | + return_value=create_response |
| 19 | + ) |
| 20 | + |
| 21 | + created_resource = await async_dummy_service.create(resource_data) |
| 22 | + |
| 23 | + assert created_resource.to_dict() == new_resource_data |
| 24 | + assert mock_route.call_count == 1 |
| 25 | + request = mock_route.calls[0].request |
| 26 | + assert request.method == "POST" |
| 27 | + assert request.url == "https://api.example.com/api/v1/test" |
| 28 | + assert json.loads(request.content.decode()) == resource_data |
| 29 | + |
| 30 | + |
| 31 | +async def test_async_delete_mixin(async_dummy_service): # noqa: WPS210 |
| 32 | + delete_response = httpx.Response(httpx.codes.NO_CONTENT, json=None) |
| 33 | + |
| 34 | + with respx.mock: |
| 35 | + mock_route = respx.delete("https://api.example.com/api/v1/test/RES-123").mock( |
| 36 | + return_value=delete_response |
| 37 | + ) |
| 38 | + |
| 39 | + await async_dummy_service.delete("RES-123") |
| 40 | + |
| 41 | + assert mock_route.call_count == 1 |
| 42 | + |
| 43 | + |
11 | 44 | async def test_async_fetch_one_success(async_dummy_service, single_result_response): |
12 | 45 | with respx.mock: |
13 | 46 | mock_route = respx.get("https://api.example.com/api/v1/test").mock( |
@@ -244,39 +277,6 @@ async def test_async_iterate_lazy_evaluation(async_dummy_service): |
244 | 277 | assert mock_route.call_count == 1 |
245 | 278 |
|
246 | 279 |
|
247 | | -async def test_async_create_resource(async_dummy_service): # noqa: WPS210 |
248 | | - resource_data = {"name": "Test Resource", "status": "active"} |
249 | | - new_resource_data = {"id": "new-resource-id", "name": "Test Resource", "status": "active"} |
250 | | - create_response = httpx.Response(httpx.codes.OK, json=new_resource_data) |
251 | | - |
252 | | - with respx.mock: |
253 | | - mock_route = respx.post("https://api.example.com/api/v1/test").mock( |
254 | | - return_value=create_response |
255 | | - ) |
256 | | - |
257 | | - created_resource = await async_dummy_service.create(resource_data) |
258 | | - |
259 | | - assert created_resource.to_dict() == new_resource_data |
260 | | - assert mock_route.call_count == 1 |
261 | | - request = mock_route.calls[0].request |
262 | | - assert request.method == "POST" |
263 | | - assert request.url == "https://api.example.com/api/v1/test" |
264 | | - assert json.loads(request.content.decode()) == resource_data |
265 | | - |
266 | | - |
267 | | -async def test_async_delete_resource(async_dummy_service): # noqa: WPS210 |
268 | | - delete_response = httpx.Response(httpx.codes.NO_CONTENT, json=None) |
269 | | - |
270 | | - with respx.mock: |
271 | | - mock_route = respx.delete("https://api.example.com/api/v1/test/RES-123").mock( |
272 | | - return_value=delete_response |
273 | | - ) |
274 | | - |
275 | | - await async_dummy_service.delete("RES-123") |
276 | | - |
277 | | - assert mock_route.call_count == 1 |
278 | | - |
279 | | - |
280 | 280 | async def test_async_update_resource(async_dummy_service): # noqa: WPS210 |
281 | 281 | resource_data = {"name": "Test Resource", "status": "active"} |
282 | 282 | update_response = httpx.Response(httpx.codes.OK, json=resource_data) |
|
0 commit comments