File tree 3 files changed +33
-0
lines changed
tests/integration/contrib/aiohttp
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:
336
336
337
337
openapi_response = WerkzeugOpenAPIResponse(werkzeug_response)
338
338
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):
22
22
23
23
@pytest .fixture
24
24
def response_getter () -> mock .MagicMock :
25
+ # Using a mock here allows us to control the return value for different scenarios.
25
26
return mock .MagicMock (return_value = {"data" : "data" })
26
27
27
28
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ async def test_aiohttp_integration_valid_input(client: TestClient):
26
26
headers = given_headers ,
27
27
)
28
28
response_data = await response .json ()
29
+ # Then
29
30
assert response .status == expected_status_code
30
31
assert response_data == expected_response_data
31
32
@@ -52,5 +53,6 @@ async def test_aiohttp_integration_invalid_input(
52
53
headers = given_headers ,
53
54
)
54
55
response_data = await response .json ()
56
+ # Then
55
57
assert response .status == expected_status_code
56
58
assert response_data == expected_response_data
You can’t perform that action at this time.
0 commit comments