Browse Source

Remove class from test_views

pull/1165/head
Markus Unterwaditzer 11 years ago
parent
commit
e77bc2d86c
  1. 34
      tests/test_views.py

34
tests/test_views.py

@ -17,9 +17,7 @@ import unittest
from tests import TestFlask from tests import TestFlask
from werkzeug.http import parse_set_header from werkzeug.http import parse_set_header
class TestView(TestFlask): def common_test(app):
def common_test(self, app):
c = app.test_client() c = app.test_client()
assert c.get('/').data == b'GET' assert c.get('/').data == b'GET'
@ -28,7 +26,7 @@ class TestView(TestFlask):
meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow']) meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow'])
assert sorted(meths) == ['GET', 'HEAD', 'OPTIONS', 'POST'] assert sorted(meths) == ['GET', 'HEAD', 'OPTIONS', 'POST']
def test_basic_view(self): def test_basic_view():
app = flask.Flask(__name__) app = flask.Flask(__name__)
class Index(flask.views.View): class Index(flask.views.View):
@ -37,9 +35,9 @@ class TestView(TestFlask):
return flask.request.method return flask.request.method
app.add_url_rule('/', view_func=Index.as_view('index')) app.add_url_rule('/', view_func=Index.as_view('index'))
self.common_test(app) common_test(app)
def test_method_based_view(self): def test_method_based_view():
app = flask.Flask(__name__) app = flask.Flask(__name__)
class Index(flask.views.MethodView): class Index(flask.views.MethodView):
@ -50,9 +48,9 @@ class TestView(TestFlask):
app.add_url_rule('/', view_func=Index.as_view('index')) app.add_url_rule('/', view_func=Index.as_view('index'))
self.common_test(app) common_test(app)
def test_view_patching(self): def test_view_patching():
app = flask.Flask(__name__) app = flask.Flask(__name__)
class Index(flask.views.MethodView): class Index(flask.views.MethodView):
@ -70,9 +68,9 @@ class TestView(TestFlask):
view = Index.as_view('index') view = Index.as_view('index')
view.view_class = Other view.view_class = Other
app.add_url_rule('/', view_func=view) app.add_url_rule('/', view_func=view)
self.common_test(app) common_test(app)
def test_view_inheritance(self): def test_view_inheritance():
app = flask.Flask(__name__) app = flask.Flask(__name__)
class Index(flask.views.MethodView): class Index(flask.views.MethodView):
@ -91,7 +89,7 @@ class TestView(TestFlask):
meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow']) meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow'])
assert sorted(meths) == ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST'] assert sorted(meths) == ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST']
def test_view_decorators(self): def test_view_decorators():
app = flask.Flask(__name__) app = flask.Flask(__name__)
def add_x_parachute(f): def add_x_parachute(f):
@ -112,7 +110,7 @@ class TestView(TestFlask):
assert rv.headers['X-Parachute'] == 'awesome' assert rv.headers['X-Parachute'] == 'awesome'
assert rv.data == b'Awesome' assert rv.data == b'Awesome'
def test_implicit_head(self): def test_implicit_head():
app = flask.Flask(__name__) app = flask.Flask(__name__)
class Index(flask.views.MethodView): class Index(flask.views.MethodView):
@ -130,7 +128,7 @@ class TestView(TestFlask):
assert rv.data == b'' assert rv.data == b''
assert rv.headers['X-Method'] == 'HEAD' assert rv.headers['X-Method'] == 'HEAD'
def test_explicit_head(self): def test_explicit_head():
app = flask.Flask(__name__) app = flask.Flask(__name__)
class Index(flask.views.MethodView): class Index(flask.views.MethodView):
@ -147,7 +145,7 @@ class TestView(TestFlask):
assert rv.data == b'' assert rv.data == b''
assert rv.headers['X-Method'] == 'HEAD' assert rv.headers['X-Method'] == 'HEAD'
def test_endpoint_override(self): def test_endpoint_override():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.debug = True app.debug = True
@ -162,10 +160,4 @@ class TestView(TestFlask):
app.add_url_rule('/', view_func=Index.as_view('index')) app.add_url_rule('/', view_func=Index.as_view('index'))
# But these tests should still pass. We just log a warning. # But these tests should still pass. We just log a warning.
self.common_test(app) common_test(app)
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestView))
return suite

Loading…
Cancel
Save