Skip to content
Myr

Started work on testcases for blueprints

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 dbfa04e · Browse files · 2 files+36 added−3 removed
This commit

State

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

Diff stats

2 files+36 added−3 removed

  • tests:+21 added−0 removed
  • other:+15 added−3 removed

2 files+36 added−3 removed

modified:flask/blueprints.py+15 added-3 removed
7 unmodified lines
89 :copyright: (c) 2011 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""12import os12from functools import update_wrapper1314from .helpers import _PackageBoundObject, _endpoint_from_view_func15
18 unmodified lines
34 if url_prefix is None:35 url_prefix = self.blueprint.url_prefix36 self.url_prefix = url_prefix3738 self.url_defaults = dict(self.blueprint.url_defaults)39 self.url_defaults.update(self.options.get('url_defaults', ()))4041 def add_url_rule(self, rule, endpoint=None, view_func=None, **options):42 """A helper method to register a rule (and optionally a view function)43 to the application. The endpoint is automatically prefixed with the44 blueprint's name.45 """46 if self.url_prefix:47 rule = self.url_prefix + rule48 options.setdefault('subdomain', self.subdomain)49 if endpoint is None:50 endpoint = _endpoint_from_view_func(view_func)51 defaults = self.url_defaults52 if 'defaults' in options:53 defaults = dict(defaults, **options.pop('defaults'))54 self.app.add_url_rule(rule, '%s.%s' % (self.blueprint.name, endpoint),46 view_func, **options)55 view_func, defaults=defaults, **options)565758class Blueprint(_PackageBoundObject):59 """Represents a blueprint.
5 unmodified lines
65 _got_registered_once = False6667 def __init__(self, name, import_name, static_folder=None,68 static_url_path=None, template_folder=None,60 url_prefix=None, subdomain=None):69 url_prefix=None, subdomain=None, url_defaults=None):70 _PackageBoundObject.__init__(self, import_name, template_folder)71 self.name = name72 self.url_prefix = url_prefix73 self.subdomain = subdomain74 self.static_folder = static_folder75 self.static_url_path = static_url_path76 self.deferred_functions = []77 self.view_functions = {}78 if url_defaults is None:79 url_defaults = {}80 self.url_defaults = url_defaults8182 def record(self, func):83 """Registers a function that is called when the blueprint is84 registered on the application. This function is called with the
180 unmodified lines
modified:tests/flask_tests.py+21 added
1270 unmodified lines
1271 assert c.get('/frontend-no').data == 'frontend says no'1272 assert c.get('/backend-no').data == 'backend says no'1273 assert c.get('/what-is-a-sideend').data == 'application itself says no'12741275 def test_blueprint_url_definitions(self):1276 bp = flask.Blueprint('test', __name__)12771278 @bp.route('/foo', defaults={'baz': 42})1279 def foo(bar, baz):1280 return '%s/%d' % (bar, baz)12811282 @bp.route('/bar')1283 def bar(bar):1284 return unicode(bar)12851286 app = flask.Flask(__name__)1287 app.register_blueprint(bp, url_prefix='/1', url_defaults={'bar': 23})1288 app.register_blueprint(bp, url_prefix='/2', url_defaults={'bar': 19})12891290 c = app.test_client()1291 self.assertEqual(c.get('/1/foo').data, u'23/42')1292 self.assertEqual(c.get('/2/foo').data, u'19/42')1293 self.assertEqual(c.get('/1/bar').data, u'23')1294 self.assertEqual(c.get('/2/bar').data, u'19')129512961297class SendfileTestCase(unittest.TestCase):12981299 def test_send_file_regular(self):1300 app = flask.Flask(__name__)
430 unmodified lines