@@ -57,7 +57,6 @@ def test_error_if_spec_does_not_have_marshmallow_plugin(app):
57
57
with pytest .raises (RuntimeError ):
58
58
ResourceConverter (app = app , spec = bad_spec )
59
59
60
-
61
60
class TestFunctionView :
62
61
63
62
@pytest .fixture
@@ -298,3 +297,80 @@ def test_params(self, app, path):
298
297
}] + rule_to_params (rule )
299
298
)
300
299
assert params == expected
300
+
301
+
302
+ class TestFiledsNoLocationProvided :
303
+
304
+ @pytest .fixture
305
+ def function_view (self , app ):
306
+ @app .route ('/bands/<int:band_id>/' )
307
+ @use_kwargs ({'name' : fields .Str (), 'address' : fields .Str ()})
308
+ def get_band (** kwargs ):
309
+ return kwargs
310
+
311
+ return get_band
312
+
313
+ @pytest .fixture
314
+ def path (self , app , spec , function_view ):
315
+ converter = ViewConverter (app = app , spec = spec )
316
+ paths = converter .convert (function_view )
317
+ for path in paths :
318
+ spec .path (** path )
319
+ return spec ._paths ['/bands/{band_id}/' ]
320
+
321
+ def test_params (self , app , path ):
322
+ params = path ['get' ]['parameters' ]
323
+ rule = app .url_map ._rules_by_endpoint ['get_band' ][0 ]
324
+ expected = (
325
+ [{
326
+ 'in' : 'body' ,
327
+ 'name' : 'body' ,
328
+ 'required' : False ,
329
+ 'schema' : {
330
+ 'properties' : {
331
+ 'address' : {
332
+ 'type' : 'string'
333
+ },
334
+ 'name' : {
335
+ 'type' : 'string'
336
+ }
337
+ },
338
+ 'type' : 'object'
339
+ },
340
+ }] + rule_to_params (rule )
341
+ )
342
+ assert params == expected
343
+
344
+ class TestSchemaNoLocationProvided :
345
+
346
+ @pytest .fixture
347
+ def function_view (self , app , models , schemas ):
348
+ class BodySchema (Schema ):
349
+ address = fields .Str ()
350
+
351
+ @app .route ('/bands/<int:band_id>/' )
352
+ @use_kwargs (BodySchema )
353
+ def get_band (** kwargs ):
354
+ return kwargs
355
+ return get_band
356
+
357
+ @pytest .fixture
358
+ def path (self , app , spec , function_view ):
359
+ converter = ViewConverter (app = app , spec = spec )
360
+ paths = converter .convert (function_view )
361
+ for path in paths :
362
+ spec .path (** path )
363
+ return spec ._paths ['/bands/{band_id}/' ]
364
+
365
+ def test_params (self , app , path ):
366
+ params = path ['get' ]['parameters' ]
367
+ rule = app .url_map ._rules_by_endpoint ['get_band' ][0 ]
368
+ expected = (
369
+ [{
370
+ 'in' : 'body' ,
371
+ 'name' : 'body' ,
372
+ 'required' : False ,
373
+ 'schema' : {'$ref' : '#/definitions/Body' }
374
+ }] + rule_to_params (rule )
375
+ )
376
+ assert params == expected
0 commit comments