@@ -14,7 +14,10 @@ async def test_aiohttp_integration_valid_input(client: TestClient):
1414 given_query_string = {
1515 "q" : "string" ,
1616 }
17- given_headers = {"content-type" : "application/json" }
17+ given_headers = {
18+ "content-type" : "application/json" ,
19+ "Host" : "localhost" ,
20+ }
1821 given_data = {"param1" : 1 }
1922 expected_status_code = 200
2023 expected_response_data = {"data" : "data" }
@@ -31,6 +34,42 @@ async def test_aiohttp_integration_valid_input(client: TestClient):
3134 assert response_data == expected_response_data
3235
3336
37+ async def test_aiohttp_integration_invalid_server (client : TestClient , request ):
38+ if "no_validation" in request .node .name :
39+ pytest .skip ("No validation for given handler." )
40+ # Given
41+ given_query_string = {
42+ "q" : "string" ,
43+ }
44+ given_headers = {
45+ "content-type" : "application/json" ,
46+ "Host" : "petstore.swagger.io" ,
47+ }
48+ given_data = {"param1" : 1 }
49+ expected_status_code = 400
50+ expected_response_data = {
51+ "errors" : [
52+ {
53+ "message" : (
54+ "Server not found for "
55+ "http://petstore.swagger.io/browse/12/"
56+ ),
57+ }
58+ ]
59+ }
60+ # When
61+ response = await client .post (
62+ "/browse/12/" ,
63+ params = given_query_string ,
64+ json = given_data ,
65+ headers = given_headers ,
66+ )
67+ response_data = await response .json ()
68+ # Then
69+ assert response .status == expected_status_code
70+ assert response_data == expected_response_data
71+
72+
3473async def test_aiohttp_integration_invalid_input (
3574 client : TestClient , response_getter , request
3675):
@@ -40,7 +79,10 @@ async def test_aiohttp_integration_invalid_input(
4079 given_query_string = {
4180 "q" : "string" ,
4281 }
43- given_headers = {"content-type" : "application/json" }
82+ given_headers = {
83+ "content-type" : "application/json" ,
84+ "Host" : "localhost" ,
85+ }
4486 given_data = {"param1" : "string" }
4587 response_getter .return_value = {"data" : 1 }
4688 expected_status_code = 400
0 commit comments