33
44from openapi_core .contrib .flask .decorators import FlaskOpenAPIViewDecorator
55from openapi_core .shortcuts import create_spec
6+ from openapi_core .validation .request .datatypes import RequestParameters
67
78
89class TestFlaskOpenAPIDecorator (object ):
910
10- view_response = None
11+ view_response_callable = None
1112
1213 @pytest .fixture
1314 def spec (self , factory ):
@@ -31,17 +32,30 @@ def client(self, app):
3132 with app .app_context ():
3233 yield client
3334
35+ @pytest .fixture
36+ def view_response (self ):
37+ def view_response (* args , ** kwargs ):
38+ return self .view_response_callable (* args , ** kwargs )
39+ return view_response
40+
3441 @pytest .fixture (autouse = True )
35- def view (self , app , decorator ):
42+ def view (self , app , decorator , view_response ):
3643 @app .route ("/browse/<id>/" )
3744 @decorator
38- def browse_details (id ):
39- return self . view_response
45+ def browse_details (* args , ** kwargs ):
46+ return view_response ( * args , ** kwargs )
4047 return browse_details
4148
4249 def test_invalid_content_type (self , client ):
43- self .view_response = make_response ('success' , 200 )
44-
50+ def view_response_callable (* args , ** kwargs ):
51+ from flask .globals import request
52+ assert request .openapi
53+ assert not request .openapi .errors
54+ assert request .openapi .parameters == RequestParameters (path = {
55+ 'id' : 12 ,
56+ })
57+ return make_response ('success' , 200 )
58+ self .view_response_callable = view_response_callable
4559 result = client .get ('/browse/12/' )
4660
4761 assert result .json == {
@@ -101,7 +115,15 @@ def test_endpoint_error(self, client):
101115 assert result .json == expected_data
102116
103117 def test_valid (self , client ):
104- self .view_response = jsonify (data = 'data' )
118+ def view_response_callable (* args , ** kwargs ):
119+ from flask .globals import request
120+ assert request .openapi
121+ assert not request .openapi .errors
122+ assert request .openapi .parameters == RequestParameters (path = {
123+ 'id' : 12 ,
124+ })
125+ return jsonify (data = 'data' )
126+ self .view_response_callable = view_response_callable
105127
106128 result = client .get ('/browse/12/' )
107129
0 commit comments