forked from orbit-oss/flask
Add unittests for the endpoint decorator
Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>
This commit is contained in:
parent
384ad219cb
commit
8a73097fe5
1 changed files with 45 additions and 0 deletions
|
|
@ -224,6 +224,26 @@ class BasicFunctionalityTestCase(unittest.TestCase):
|
||||||
assert c.get('/foo/').data == 'index'
|
assert c.get('/foo/').data == 'index'
|
||||||
assert c.get('/foo/bar').data == 'bar'
|
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):
|
def test_session(self):
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
app.secret_key = 'testkey'
|
app.secret_key = 'testkey'
|
||||||
|
|
@ -1029,6 +1049,31 @@ class ModuleTestCase(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
os.path = old_path
|
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):
|
class SendfileTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue