Skip to content
Myr

Raise exceptions if a function is overridden by a new endpoint. This fixes #570

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

authored by Armin Ronacher · committed by Armin Ronacher · parent e2b3f07 · Browse files · 3 files+23 added−1 removed
This commit

State

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

Diff stats

3 files+23 added−1 removed

  • other:+23 added−1 removed

3 files+23 added−1 removed

modified:flask/testsuite/basic.py+1 added-1 removed
385 unmodified lines
386 self.assert_equal(messages[1], ('warning', flask.Markup(u'<em>Testing</em>')))387 return ''388389 @app.route('/test_filters_without_returning_categories/')390 def test_filters():390 def test_filters2():391 messages = flask.get_flashed_messages(category_filter=['message', 'warning'])392 self.assert_equal(len(messages), 2)393 self.assert_equal(messages[0], u'Hello World')394 self.assert_equal(messages[1], flask.Markup(u'<em>Testing</em>'))
843 unmodified lines
modified:flask/testsuite/views.py+17 added
143 unmodified lines
144 rv = c.head('/')145 self.assert_equal(rv.data, '')146 self.assert_equal(rv.headers['X-Method'], 'HEAD')147148 def test_endpoint_override(self):149 app = flask.Flask(__name__)150 app.debug = True151152 class Index(flask.views.View):153 methods = ['GET', 'POST']154 def dispatch_request(self):155 return flask.request.method156157 app.add_url_rule('/', view_func=Index.as_view('index'))158159 with self.assert_raises(AssertionError):160 app.add_url_rule('/', view_func=Index.as_view('index'))161162 # But these tests should still pass. We just log a warning.163 self.common_test(app)164165166def suite():167 suite = unittest.TestSuite()168 suite.addTest(unittest.makeSuite(ViewTestCase))169 return suite
modified:flask/app.py+5 added
940 unmodified lines
941 options['defaults'] = options.get('defaults') or None942943 rule = self.url_rule_class(rule, methods=methods, **options)944 rule.provide_automatic_options = provide_automatic_options945946 self.url_map.add(rule)947 if view_func is not None:948 old_func = self.view_functions.get(endpoint)949 if old_func is not None and old_func is not view_func:950 raise AssertionError('View function mapping is overwriting an '951 'existing endpoint function: %s' % endpoint)952 self.view_functions[endpoint] = view_func953954 def route(self, rule, **options):955 """A decorator that is used to register a view function for a
789 unmodified lines