forked from orbit-oss/flask
Fixed class-based views support
This commit is contained in:
parent
c9337c044c
commit
44e39ab071
2 changed files with 30 additions and 1 deletions
|
|
@ -979,7 +979,7 @@ class Flask(_PackageBoundObject):
|
||||||
self.url_map.add(rule)
|
self.url_map.add(rule)
|
||||||
if view_func is not None:
|
if view_func is not None:
|
||||||
old_func = self.view_functions.get(endpoint)
|
old_func = self.view_functions.get(endpoint)
|
||||||
if old_func is not None and old_func is not view_func:
|
if old_func is not None and old_func != view_func:
|
||||||
raise AssertionError('View function mapping is overwriting an '
|
raise AssertionError('View function mapping is overwriting an '
|
||||||
'existing endpoint function: %s' % endpoint)
|
'existing endpoint function: %s' % endpoint)
|
||||||
self.view_functions[endpoint] = view_func
|
self.view_functions[endpoint] = view_func
|
||||||
|
|
|
||||||
|
|
@ -1217,6 +1217,35 @@ class SubdomainTestCase(FlaskTestCase):
|
||||||
rv = c.get('/outside', 'http://xtesting.localhost/')
|
rv = c.get('/outside', 'http://xtesting.localhost/')
|
||||||
self.assert_equal(rv.data, b'Outside')
|
self.assert_equal(rv.data, b'Outside')
|
||||||
|
|
||||||
|
def test_multi_route_rules(self):
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
@app.route('/<test>/')
|
||||||
|
def index(test='a'):
|
||||||
|
return test
|
||||||
|
|
||||||
|
rv = app.test_client().open('/')
|
||||||
|
self.assert_equal(rv.data, b'a')
|
||||||
|
rv = app.test_client().open('/b/')
|
||||||
|
self.assert_equal(rv.data, b'b')
|
||||||
|
|
||||||
|
def test_multi_route_class_views(self):
|
||||||
|
class View(object):
|
||||||
|
def __init__(self, app):
|
||||||
|
app.add_url_rule('/', 'index', self.index)
|
||||||
|
app.add_url_rule('/<test>/', 'index', self.index)
|
||||||
|
|
||||||
|
def index(self, test='a'):
|
||||||
|
return test
|
||||||
|
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
_ = View(app)
|
||||||
|
rv = app.test_client().open('/')
|
||||||
|
self.assert_equal(rv.data, b'a')
|
||||||
|
rv = app.test_client().open('/b/')
|
||||||
|
self.assert_equal(rv.data, b'b')
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue