From 8a73097fe528430eb77ac26c81ba85229a8af553 Mon Sep 17 00:00:00 2001 From: mvantellingen Date: Sun, 23 Jan 2011 19:52:27 +0100 Subject: [PATCH] Add unittests for the endpoint decorator Signed-off-by: Armin Ronacher --- tests/flask_tests.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/flask_tests.py b/tests/flask_tests.py index e045290a..db2616a9 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -224,6 +224,26 @@ class BasicFunctionalityTestCase(unittest.TestCase): assert c.get('/foo/').data == 'index' assert c.get('/foo/bar').data == 'bar' + def test_endpoint_decorator(self): + from werkzeug.routing import Submount, Rule + app = flask.Flask(__name__) + app.url_map.add(Submount('/foo', [ + Rule('/bar', endpoint='bar'), + Rule('/', endpoint='index') + ])) + + @app.endpoint('bar') + def bar(): + return 'bar' + + @app.endpoint('index') + def index(): + return 'index' + + c = app.test_client() + assert c.get('/foo/').data == 'index' + assert c.get('/foo/bar').data == 'bar' + def test_session(self): app = flask.Flask(__name__) app.secret_key = 'testkey' @@ -1029,6 +1049,31 @@ class ModuleTestCase(unittest.TestCase): finally: os.path = old_path + def test_endpoint_decorator(self): + from werkzeug.routing import Submount, Rule + from flask import Module + + app = flask.Flask(__name__) + app.url_map.add(Submount('/foo', [ + Rule('/bar', endpoint='bar'), + Rule('/', endpoint='index') + ])) + module = Module(__name__, __name__) + + @module.endpoint('bar') + def bar(): + return 'bar' + + @module.endpoint('index') + def index(): + return 'index' + + app.register_module(module) + + c = app.test_client() + assert c.get('/foo/').data == 'index' + assert c.get('/foo/bar').data == 'bar' + class SendfileTestCase(unittest.TestCase):