@@ -48,7 +48,6 @@ def test_error_if_spec_does_not_have_marshmallow_plugin(app):
48
48
with pytest .raises (RuntimeError ):
49
49
ResourceConverter (app = app , spec = bad_spec )
50
50
51
-
52
51
class TestFunctionView :
53
52
54
53
@pytest .fixture
@@ -244,3 +243,80 @@ def test_params(self, app, path):
244
243
}] + rule_to_params (rule )
245
244
)
246
245
assert params == expected
246
+
247
+
248
+ class TestFiledsNoLocationProvided :
249
+
250
+ @pytest .fixture
251
+ def function_view (self , app ):
252
+ @app .route ('/bands/<int:band_id>/' )
253
+ @use_kwargs ({'name' : fields .Str (), 'address' : fields .Str ()})
254
+ def get_band (** kwargs ):
255
+ return kwargs
256
+
257
+ return get_band
258
+
259
+ @pytest .fixture
260
+ def path (self , app , spec , function_view ):
261
+ converter = ViewConverter (app = app , spec = spec )
262
+ paths = converter .convert (function_view )
263
+ for path in paths :
264
+ spec .path (** path )
265
+ return spec ._paths ['/bands/{band_id}/' ]
266
+
267
+ def test_params (self , app , path ):
268
+ params = path ['get' ]['parameters' ]
269
+ rule = app .url_map ._rules_by_endpoint ['get_band' ][0 ]
270
+ expected = (
271
+ [{
272
+ 'in' : 'body' ,
273
+ 'name' : 'body' ,
274
+ 'required' : False ,
275
+ 'schema' : {
276
+ 'properties' : {
277
+ 'address' : {
278
+ 'type' : 'string'
279
+ },
280
+ 'name' : {
281
+ 'type' : 'string'
282
+ }
283
+ },
284
+ 'type' : 'object'
285
+ },
286
+ }] + rule_to_params (rule )
287
+ )
288
+ assert params == expected
289
+
290
+ class TestSchemaNoLocationProvided :
291
+
292
+ @pytest .fixture
293
+ def function_view (self , app , models , schemas ):
294
+ class BodySchema (Schema ):
295
+ address = fields .Str ()
296
+
297
+ @app .route ('/bands/<int:band_id>/' )
298
+ @use_kwargs (BodySchema )
299
+ def get_band (** kwargs ):
300
+ return kwargs
301
+ return get_band
302
+
303
+ @pytest .fixture
304
+ def path (self , app , spec , function_view ):
305
+ converter = ViewConverter (app = app , spec = spec )
306
+ paths = converter .convert (function_view )
307
+ for path in paths :
308
+ spec .path (** path )
309
+ return spec ._paths ['/bands/{band_id}/' ]
310
+
311
+ def test_params (self , app , path ):
312
+ params = path ['get' ]['parameters' ]
313
+ rule = app .url_map ._rules_by_endpoint ['get_band' ][0 ]
314
+ expected = (
315
+ [{
316
+ 'in' : 'body' ,
317
+ 'name' : 'body' ,
318
+ 'required' : False ,
319
+ 'schema' : {'$ref' : '#/definitions/Body' }
320
+ }] + rule_to_params (rule )
321
+ )
322
+ assert params == expected
0 commit comments