Skip to content
Myr

Remove class from test_views

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 7e8f105 · Browse files · 1 file+111 added−119 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+111 added−119 removed

  • tests:+111 added−119 removed

1 file+111 added−119 removed

modified:tests/test_views.py+111 added-119 removed
15 unmodified lines
16import unittest17from tests import TestFlask18from werkzeug.http import parse_set_header1920class TestView(TestFlask):20def common_test(app):21 c = app.test_client()2222 def common_test(self, app):23 c = app.test_client()23 assert c.get('/').data == b'GET'24 assert c.post('/').data == b'POST'25 assert c.put('/').status_code == 40526 meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow'])27 assert sorted(meths) == ['GET', 'HEAD', 'OPTIONS', 'POST']2825 assert c.get('/').data == b'GET'26 assert c.post('/').data == b'POST'27 assert c.put('/').status_code == 40528 meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow'])29 assert sorted(meths) == ['GET', 'HEAD', 'OPTIONS', 'POST']29def test_basic_view():30 app = flask.Flask(__name__)3131 def test_basic_view(self):32 app = flask.Flask(__name__)32 class Index(flask.views.View):33 methods = ['GET', 'POST']34 def dispatch_request(self):35 return flask.request.method3634 class Index(flask.views.View):35 methods = ['GET', 'POST']36 def dispatch_request(self):37 return flask.request.method37 app.add_url_rule('/', view_func=Index.as_view('index'))38 common_test(app)3939 app.add_url_rule('/', view_func=Index.as_view('index'))40 self.common_test(app)40def test_method_based_view():41 app = flask.Flask(__name__)4242 def test_method_based_view(self):43 app = flask.Flask(__name__)43 class Index(flask.views.MethodView):44 def get(self):45 return 'GET'46 def post(self):47 return 'POST'4845 class Index(flask.views.MethodView):46 def get(self):47 return 'GET'48 def post(self):49 return 'POST'49 app.add_url_rule('/', view_func=Index.as_view('index'))5051 app.add_url_rule('/', view_func=Index.as_view('index'))51 common_test(app)5253 self.common_test(app)53def test_view_patching():54 app = flask.Flask(__name__)5555 def test_view_patching(self):56 app = flask.Flask(__name__)56 class Index(flask.views.MethodView):57 def get(self):58 1 // 059 def post(self):60 1 // 06158 class Index(flask.views.MethodView):59 def get(self):60 1 // 061 def post(self):62 1 // 062 class Other(Index):63 def get(self):64 return 'GET'65 def post(self):66 return 'POST'6764 class Other(Index):65 def get(self):66 return 'GET'67 def post(self):68 return 'POST'68 view = Index.as_view('index')69 view.view_class = Other70 app.add_url_rule('/', view_func=view)71 common_test(app)7270 view = Index.as_view('index')71 view.view_class = Other72 app.add_url_rule('/', view_func=view)73 self.common_test(app)73def test_view_inheritance():74 app = flask.Flask(__name__)7575 def test_view_inheritance(self):76 app = flask.Flask(__name__)76 class Index(flask.views.MethodView):77 def get(self):78 return 'GET'79 def post(self):80 return 'POST'8178 class Index(flask.views.MethodView):79 def get(self):80 return 'GET'81 def post(self):82 return 'POST'82 class BetterIndex(Index):83 def delete(self):84 return 'DELETE'8584 class BetterIndex(Index):85 def delete(self):86 return 'DELETE'86 app.add_url_rule('/', view_func=BetterIndex.as_view('index'))87 c = app.test_client()8888 app.add_url_rule('/', view_func=BetterIndex.as_view('index'))89 c = app.test_client()89 meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow'])90 assert sorted(meths) == ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST']9191 meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow'])92 assert sorted(meths) == ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST']92def test_view_decorators():93 app = flask.Flask(__name__)9494 def test_view_decorators(self):95 app = flask.Flask(__name__)95 def add_x_parachute(f):96 def new_function(*args, **kwargs):97 resp = flask.make_response(f(*args, **kwargs))98 resp.headers['X-Parachute'] = 'awesome'99 return resp100 return new_function10197 def add_x_parachute(f):98 def new_function(*args, **kwargs):99 resp = flask.make_response(f(*args, **kwargs))100 resp.headers['X-Parachute'] = 'awesome'101 return resp102 return new_function102 class Index(flask.views.View):103 decorators = [add_x_parachute]104 def dispatch_request(self):105 return 'Awesome'106104 class Index(flask.views.View):105 decorators = [add_x_parachute]106 def dispatch_request(self):107 return 'Awesome'107 app.add_url_rule('/', view_func=Index.as_view('index'))108 c = app.test_client()109 rv = c.get('/')110 assert rv.headers['X-Parachute'] == 'awesome'111 assert rv.data == b'Awesome'112109 app.add_url_rule('/', view_func=Index.as_view('index'))110 c = app.test_client()111 rv = c.get('/')112 assert rv.headers['X-Parachute'] == 'awesome'113 assert rv.data == b'Awesome'113def test_implicit_head():114 app = flask.Flask(__name__)115115 def test_implicit_head(self):116 app = flask.Flask(__name__)116 class Index(flask.views.MethodView):117 def get(self):118 return flask.Response('Blub', headers={119 'X-Method': flask.request.method120 })121118 class Index(flask.views.MethodView):119 def get(self):120 return flask.Response('Blub', headers={121 'X-Method': flask.request.method122 })122 app.add_url_rule('/', view_func=Index.as_view('index'))123 c = app.test_client()124 rv = c.get('/')125 assert rv.data == b'Blub'126 assert rv.headers['X-Method'] == 'GET'127 rv = c.head('/')128 assert rv.data == b''129 assert rv.headers['X-Method'] == 'HEAD'130124 app.add_url_rule('/', view_func=Index.as_view('index'))125 c = app.test_client()126 rv = c.get('/')127 assert rv.data == b'Blub'128 assert rv.headers['X-Method'] == 'GET'129 rv = c.head('/')130 assert rv.data == b''131 assert rv.headers['X-Method'] == 'HEAD'131def test_explicit_head():132 app = flask.Flask(__name__)133133 def test_explicit_head(self):134 app = flask.Flask(__name__)134 class Index(flask.views.MethodView):135 def get(self):136 return 'GET'137 def head(self):138 return flask.Response('', headers={'X-Method': 'HEAD'})139136 class Index(flask.views.MethodView):137 def get(self):138 return 'GET'139 def head(self):140 return flask.Response('', headers={'X-Method': 'HEAD'})140 app.add_url_rule('/', view_func=Index.as_view('index'))141 c = app.test_client()142 rv = c.get('/')143 assert rv.data == b'GET'144 rv = c.head('/')145 assert rv.data == b''146 assert rv.headers['X-Method'] == 'HEAD'147142 app.add_url_rule('/', view_func=Index.as_view('index'))143 c = app.test_client()144 rv = c.get('/')145 assert rv.data == b'GET'146 rv = c.head('/')147 assert rv.data == b''148 assert rv.headers['X-Method'] == 'HEAD'148def test_endpoint_override():149 app = flask.Flask(__name__)150 app.debug = True151150 def test_endpoint_override(self):151 app = flask.Flask(__name__)152 app.debug = True152 class Index(flask.views.View):153 methods = ['GET', 'POST']154 def dispatch_request(self):155 return flask.request.method156154 class Index(flask.views.View):155 methods = ['GET', 'POST']156 def dispatch_request(self):157 return flask.request.method157 app.add_url_rule('/', view_func=Index.as_view('index'))158159 with pytest.raises(AssertionError):160 app.add_url_rule('/', view_func=Index.as_view('index'))161161 with pytest.raises(AssertionError):162 app.add_url_rule('/', view_func=Index.as_view('index'))163164 # But these tests should still pass. We just log a warning.165 self.common_test(app)162 # But these tests should still pass. We just log a warning.163 common_test(app)166167168def suite():169 suite = unittest.TestSuite()170 suite.addTest(unittest.makeSuite(TestView))171 return suite