flask/tests/test_regression.py

25 lines
516 B
Python
Raw Normal View History

import flask
2017-05-25 08:27:36 +08:00
def test_aborting(app):
2014-09-04 21:32:50 +08:00
class Foo(Exception):
whatever = 42
2014-09-01 03:56:15 +08:00
2014-09-04 21:32:50 +08:00
@app.errorhandler(Foo)
def handle_foo(e):
return str(e.whatever)
2014-09-01 03:56:15 +08:00
@app.route("/")
2014-09-04 21:32:50 +08:00
def index():
raise flask.abort(flask.redirect(flask.url_for("test")))
2014-09-01 03:56:15 +08:00
@app.route("/test")
2014-09-04 21:32:50 +08:00
def test():
raise Foo()
2013-01-22 01:55:07 +08:00
2014-09-04 21:32:50 +08:00
with app.test_client() as c:
rv = c.get("/")
assert rv.headers["Location"] == "http://localhost/test"
rv = c.get("/test")
assert rv.data == b"42"