@@ -24,6 +24,15 @@ def spec(marshmallow_plugin):
2424 plugins = [marshmallow_plugin ],
2525 )
2626
27+ @pytest .fixture
28+ def spec_oapi3 (marshmallow_plugin ):
29+ return APISpec (
30+ title = 'title' ,
31+ version = 'v1' ,
32+ openapi_version = '3.0' ,
33+ plugins = [marshmallow_plugin ],
34+ )
35+
2736@pytest .fixture ()
2837def openapi (marshmallow_plugin ):
2938 return marshmallow_plugin .openapi
@@ -88,6 +97,51 @@ def test_responses(self, schemas, path, openapi):
8897 def test_tags (self , path ):
8998 assert path ['get' ]['tags' ] == ['band' ]
9099
100+ class TestFunctionView_OpenAPI3 :
101+
102+ @pytest .fixture
103+ def function_view (self , app , models , schemas ):
104+ @app .route ('/bands/<int:band_id>/' )
105+ @doc (tags = ['band' ])
106+ @use_kwargs ({'name' : fields .Str (missing = 'queen' )}, locations = ('query' ,))
107+ @marshal_with (schemas .BandSchema , description = 'a band' , content_type = 'text/json' )
108+ def get_band (band_id ):
109+ return models .Band (name = 'slowdive' , genre = 'spacerock' )
110+
111+ return get_band
112+
113+ @pytest .fixture
114+ def path (self , app , spec_oapi3 , function_view ):
115+ converter = ViewConverter (app = app , spec = spec_oapi3 )
116+ paths = converter .convert (function_view )
117+ for path in paths :
118+ spec_oapi3 .path (** path )
119+ return spec_oapi3 ._paths ['/bands/{band_id}/' ]
120+
121+ def test_params (self , app , path ):
122+ params = path ['get' ]['parameters' ]
123+ rule = app .url_map ._rules_by_endpoint ['get_band' ][0 ]
124+ expected = (
125+ [{
126+ 'in' : 'query' ,
127+ 'name' : 'name' ,
128+ 'required' : False ,
129+ 'schema' : {
130+ 'type' : 'string' ,
131+ 'default' : 'queen' ,
132+ }
133+ }] + rule_to_params (rule )
134+ )
135+ assert params == expected
136+
137+ def test_responses (self , schemas , path , openapi ):
138+ response = path ['get' ]['responses' ]['default' ]
139+ assert response ['description' ] == 'a band'
140+ assert response ['content' ] == {'text/json' : {'schema' : {'$ref' : ref_path (openapi .spec ) + 'Band' }}}
141+
142+ def test_tags (self , path ):
143+ assert path ['get' ]['tags' ] == ['band' ]
144+
91145class TestArgSchema :
92146
93147 @pytest .fixture
0 commit comments