Test that dotted names work. This fixes #258

This commit is contained in:
Armin Ronacher 2011-06-27 09:20:50 +02:00
parent 85efa3f895
commit ea7a172077
2 changed files with 26 additions and 1 deletions

View file

@ -80,7 +80,7 @@ class Request(RequestBase):
def blueprint(self):
"""The name of the current blueprint"""
if self.url_rule and '.' in self.url_rule.endpoint:
return self.url_rule.endpoint.split('.', 1)[0]
return self.url_rule.endpoint.rsplit('.', 1)[0]
@cached_property
def json(self):

View file

@ -1323,6 +1323,31 @@ class BlueprintTestCase(unittest.TestCase):
with flask.Flask(__name__).test_request_context():
assert flask.render_template('nested/nested.txt') == 'I\'m nested'
def test_dotted_names(self):
frontend = flask.Blueprint('myapp.frontend', __name__)
backend = flask.Blueprint('myapp.backend', __name__)
@frontend.route('/fe')
def frontend_index():
return flask.url_for('myapp.backend.backend_index')
@frontend.route('/fe2')
def frontend_page2():
return flask.url_for('.frontend_index')
@backend.route('/be')
def backend_index():
return flask.url_for('myapp.frontend.frontend_index')
app = flask.Flask(__name__)
app.register_blueprint(frontend)
app.register_blueprint(backend)
c = app.test_client()
self.assertEqual(c.get('/fe').data.strip(), '/be')
self.assertEqual(c.get('/fe2').data.strip(), '/fe')
self.assertEqual(c.get('/be').data.strip(), '/fe')
class SendfileTestCase(unittest.TestCase):