flask/tests/test_regression.py

31 lines
712 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("/")
2022-03-26 02:48:26 +08:00
location_parts = rv.headers["Location"].rpartition("/")
if location_parts[0]:
# For older Werkzeug that used absolute redirects.
assert location_parts[0] == "http://localhost"
assert location_parts[2] == "test"
rv = c.get("/test")
assert rv.data == b"42"