<s> import pytest <EOL> from apispec import APISpec <EOL> from apispec . ext . marshmallow import swagger <EOL> from marshmallow import fields , Schema <EOL> from flask import make_response <EOL> from flask_apispec . paths import rule_to_params <EOL> from flask_apispec . views import MethodResource <EOL> from flask_apispec import doc , use_kwargs , marshal_with <EOL> from flask_apispec . apidoc import ViewConverter , ResourceConverter <EOL> @ pytest . fixture <EOL> def spec ( ) : <EOL> return APISpec ( <EOL> title = '<STR_LIT:title>' , <EOL> version = '<STR_LIT>' , <EOL> plugins = [ '<STR_LIT>' ] , <EOL> ) <EOL> class TestFunctionView : <EOL> @ pytest . fixture <EOL> def function_view ( self , app , models , schemas ) : <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ doc ( tags = [ '<STR_LIT>' ] ) <EOL> @ use_kwargs ( { '<STR_LIT:name>' : fields . Str ( missing = '<STR_LIT>' ) } , locations = ( '<STR_LIT>' , ) ) <EOL> @ marshal_with ( schemas . BandSchema , description = '<STR_LIT>' ) <EOL> def get_band ( band_id ) : <EOL> return models . Band ( name = '<STR_LIT>' , genre = '<STR_LIT>' ) <EOL> return get_band <EOL> @ pytest . fixture <EOL> def path ( self , app , spec , function_view ) : <EOL> converter = ViewConverter ( app ) <EOL> paths = converter . convert ( function_view ) <EOL> for path in paths : <EOL> spec . add_path ( ** path ) <EOL> return spec . _paths [ '<STR_LIT>' ] <EOL> def test_params ( self , app , path ) : <EOL> params = path [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> rule = app . url_map . _rules_by_endpoint [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> expected = ( <EOL> [ { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:name>' , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> } ] + rule_to_params ( rule ) <EOL> ) <EOL> assert params == expected <EOL> def test_responses ( self , schemas , path ) : <EOL> response = path [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:default>' ] <EOL> assert response [ '<STR_LIT:description>' ] == '<STR_LIT>' <EOL> assert response [ '<STR_LIT>' ] == swagger . schema2jsonschema ( schemas . BandSchema ) <EOL> def test_tags ( self , path ) : <EOL> assert path [ '<STR_LIT>' ] [ '<STR_LIT>' ] == [ '<STR_LIT>' ] <EOL> class TestArgSchema : <EOL> @ pytest . fixture <EOL> def function_view ( self , app , models , schemas ) : <EOL> class ArgSchema ( Schema ) : <EOL> name = fields . Str ( ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ use_kwargs ( ArgSchema , locations = ( '<STR_LIT>' , ) ) <EOL> def get_band ( ** kwargs ) : <EOL> return kwargs <EOL> return get_band <EOL> @ pytest . fixture <EOL> def path ( self , app , spec , function_view ) : <EOL> converter = ViewConverter ( app ) <EOL> paths = converter . convert ( function_view ) <EOL> for path in paths : <EOL> spec . add_path ( ** path ) <EOL> return spec . _paths [ '<STR_LIT>' ] <EOL> def test_params ( self , app , path ) : <EOL> params = path [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> rule = app . url_map . _rules_by_endpoint [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> expected = ( <EOL> swagger . fields2parameters ( { '<STR_LIT:name>' : fields . Str ( ) } , default_in = '<STR_LIT>' ) + <EOL> rule_to_params ( rule ) <EOL> ) <EOL> assert params == expected <EOL> class TestDeleteView : <EOL> @ pytest . fixture <EOL> def function_view ( self , app , models , schemas ) : <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT>' ] ) <EOL> @ marshal_with ( None , code = <NUM_LIT> , description = '<STR_LIT>' ) <EOL> def delete_band ( band_id ) : <EOL> return make_response ( '<STR_LIT>' , <NUM_LIT> ) <EOL> return delete_band <EOL> @ pytest . fixture <EOL> def path ( self , app , spec , function_view ) : <EOL> converter = ViewConverter ( app ) <EOL> paths = converter . convert ( function_view ) <EOL> for path in paths : <EOL> spec . add_path ( ** path ) <EOL> return spec . _paths [ '<STR_LIT>' ] <EOL> def test_responses ( self , schemas , path ) : <EOL> response = path [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT> ] <EOL> assert response [ '<STR_LIT:description>' ] == '<STR_LIT>' <EOL> assert response [ '<STR_LIT>' ] == { } <EOL> class TestResourceView : <EOL> @ pytest . fixture <EOL> def resource_view ( self , app , models , schemas ) : <EOL> @ doc ( tags = [ '<STR_LIT>' ] ) <EOL> class BandResource ( MethodResource ) : <EOL> @ use_kwargs ( { '<STR_LIT:name>' : fields . Str ( ) } , locations = ( '<STR_LIT>' , ) ) <EOL> @ marshal_with ( schemas . BandSchema , description = '<STR_LIT>' ) <EOL> def get ( self , ** kwargs ) : <EOL> return models . Band ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> app . add_url_rule ( '<STR_LIT>' , view_func = BandResource . as_view ( '<STR_LIT>' ) ) <EOL> return BandResource <EOL> @ pytest . fixture <EOL> def path ( self , app , spec , resource_view ) : <EOL> converter = ResourceConverter ( app ) <EOL> paths = converter . convert ( resource_view , endpoint = '<STR_LIT>' ) <EOL> for path in paths : <EOL> spec . add_path ( ** path ) <EOL> return spec . _paths [ '<STR_LIT>' ] <EOL> def test_params ( self , app , path ) : <EOL> params = path [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> rule = app . url_map . _rules_by_endpoint [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> expected = ( <EOL> swagger . fields2parameters ( { '<STR_LIT:name>' : fields . Str ( ) } , default_in = '<STR_LIT>' ) + <EOL> rule_to_params ( rule ) <EOL> ) <EOL> assert params == expected <EOL> def test_responses ( self , schemas , path ) : <EOL> response = path [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:default>' ] <EOL> assert response [ '<STR_LIT:description>' ] == '<STR_LIT>' <EOL> assert response [ '<STR_LIT>' ] == swagger . schema2jsonschema ( schemas . BandSchema ) <EOL> def test_tags ( self , path ) : <EOL> assert path [ '<STR_LIT>' ] [ '<STR_LIT>' ] == [ '<STR_LIT>' ] </s>
