File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
tests/integration/contrib/aiohttp Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -336,3 +336,33 @@ You can use ``WerkzeugOpenAPIResponse`` as a Werkzeug response factory:
336336
337337 openapi_response = WerkzeugOpenAPIResponse(werkzeug_response)
338338 result = unmarshal_response(openapi_request, openapi_response, spec = spec)
339+
340+
341+ aiohttp.web
342+ ---------
343+
344+ This section describes integration with `aiohttp.web <https://docs.aiohttp.org/en/stable/web.html >`__ framework.
345+
346+ Low level
347+ ~~~~~~~~~
348+
349+ You can use ``AIOHTTPOpenAPIWebRequest `` as an aiohttp request factory:
350+
351+ .. code-block :: python
352+
353+ from openapi_core import unmarshal_request
354+ from openapi_core.contrib.aiohttp import AIOHTTPOpenAPIWebRequest
355+
356+ request_body = await aiohttp_request.text()
357+ openapi_request = AIOHTTPOpenAPIWebRequest(aiohttp_request, body = request_body)
358+ result = unmarshal_request(openapi_request, spec = spec)
359+
360+ You can use ``AIOHTTPOpenAPIWebRequest `` as an aiohttp response factory:
361+
362+ .. code-block :: python
363+
364+ from openapi_core import unmarshal_response
365+ from openapi_core.contrib.starlette import AIOHTTPOpenAPIWebRequest
366+
367+ openapi_response = StarletteOpenAPIResponse(aiohttp_response)
368+ result = unmarshal_response(openapi_request, openapi_response, spec = spec)
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ def spec(factory):
2222
2323@pytest .fixture
2424def response_getter () -> mock .MagicMock :
25+ # Using a mock here allows us to control the return value for different scenarios.
2526 return mock .MagicMock (return_value = {"data" : "data" })
2627
2728
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ async def test_aiohttp_integration_valid_input(client: TestClient):
2626 headers = given_headers ,
2727 )
2828 response_data = await response .json ()
29+ # Then
2930 assert response .status == expected_status_code
3031 assert response_data == expected_response_data
3132
@@ -52,5 +53,6 @@ async def test_aiohttp_integration_invalid_input(
5253 headers = given_headers ,
5354 )
5455 response_data = await response .json ()
56+ # Then
5557 assert response .status == expected_status_code
5658 assert response_data == expected_response_data
You can’t perform that action at this time.
0 commit comments