11import pytest
2+ import requests
3+ import responses
24
35from openapi_core .contrib .requests import (
46 RequestsOpenAPIRequest , RequestsOpenAPIResponse ,
@@ -15,21 +17,25 @@ def spec(self, factory):
1517 specfile = 'contrib/requests/data/v3.0/requests_factory.yaml'
1618 return create_spec (factory .spec_from_file (specfile ))
1719
18- def test_response_validator_path_pattern (self ,
19- spec ,
20- request_factory ,
21- response_factory ):
20+ @responses .activate
21+ def test_response_validator_path_pattern (self , spec ):
22+ responses .add (
23+ responses .GET , 'http://localhost/browse/12/' ,
24+ json = {"data" : "data" }, status = 200 )
2225 validator = ResponseValidator (spec )
23- request = request_factory ('GET' , '/browse/12/' , subdomain = 'kb' )
26+ request = requests .Request ('GET' , 'http://localhost/browse/12/' )
27+ request_prepared = request .prepare ()
28+ session = requests .Session ()
29+ response = session .send (request_prepared )
2430 openapi_request = RequestsOpenAPIRequest (request )
25- response = response_factory ('{"data": "data"}' , status_code = 200 )
2631 openapi_response = RequestsOpenAPIResponse (response )
2732 result = validator .validate (openapi_request , openapi_response )
2833 assert not result .errors
2934
30- def test_request_validator_path_pattern (self , spec , request_factory ):
35+ @responses .activate
36+ def test_request_validator_path_pattern (self , spec ):
3137 validator = RequestValidator (spec )
32- request = request_factory ('GET' , '/ browse/12/' , subdomain = 'kb ' )
38+ request = requests . Request ('GET' , 'http://localhost/ browse/12/' )
3339 openapi_request = RequestsOpenAPIRequest (request )
3440 result = validator .validate (openapi_request )
3541 assert not result .errors
0 commit comments