1010from openapi_core .validation .response .validators import ResponseValidator
1111
1212
13- class TestFlaskOpenAPIValidation (object ):
13+ class TestRequestsOpenAPIValidation (object ):
1414
1515 @pytest .fixture
1616 def spec (self , factory ):
@@ -20,10 +20,16 @@ def spec(self, factory):
2020 @responses .activate
2121 def test_response_validator_path_pattern (self , spec ):
2222 responses .add (
23- responses .GET , 'http://localhost/browse/12/' ,
24- json = {"data" : "data" }, status = 200 )
23+ responses .POST , 'http://localhost/browse/12/?q=string' ,
24+ json = {"data" : "data" }, status = 200 , match_querystring = True ,
25+ )
2526 validator = ResponseValidator (spec )
26- request = requests .Request ('GET' , 'http://localhost/browse/12/' )
27+ request = requests .Request (
28+ 'POST' , 'http://localhost/browse/12/' ,
29+ params = {'q' : 'string' },
30+ headers = {'content-type' : 'application/json' },
31+ json = {'param1' : 1 },
32+ )
2733 request_prepared = request .prepare ()
2834 session = requests .Session ()
2935 response = session .send (request_prepared )
@@ -32,10 +38,27 @@ def test_response_validator_path_pattern(self, spec):
3238 result = validator .validate (openapi_request , openapi_response )
3339 assert not result .errors
3440
35- @responses .activate
3641 def test_request_validator_path_pattern (self , spec ):
3742 validator = RequestValidator (spec )
38- request = requests .Request ('GET' , 'http://localhost/browse/12/' )
43+ request = requests .Request (
44+ 'POST' , 'http://localhost/browse/12/' ,
45+ params = {'q' : 'string' },
46+ headers = {'content-type' : 'application/json' },
47+ json = {'param1' : 1 },
48+ )
3949 openapi_request = RequestsOpenAPIRequest (request )
4050 result = validator .validate (openapi_request )
4151 assert not result .errors
52+
53+ def test_request_validator_prepared_request (self , spec ):
54+ validator = RequestValidator (spec )
55+ request = requests .Request (
56+ 'POST' , 'http://localhost/browse/12/' ,
57+ params = {'q' : 'string' },
58+ headers = {'content-type' : 'application/json' },
59+ json = {'param1' : 1 },
60+ )
61+ request_prepared = request .prepare ()
62+ openapi_request = RequestsOpenAPIRequest (request_prepared )
63+ result = validator .validate (openapi_request )
64+ assert not result .errors
0 commit comments