2017-05-24 06:18:39 +08:00
|
|
|
import flask
|
2011-11-06 00:43:40 +08:00
|
|
|
|
2012-10-08 04:58:41 +08:00
|
|
|
|
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
|
|
|
|
2019-05-07 03:39:41 +08:00
|
|
|
@app.route("/")
|
2014-09-04 21:32:50 +08:00
|
|
|
def index():
|
2019-05-07 03:39:41 +08:00
|
|
|
raise flask.abort(flask.redirect(flask.url_for("test")))
|
2014-09-01 03:56:15 +08:00
|
|
|
|
2019-05-07 03:39:41 +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:
|
2019-05-07 03:39:41 +08:00
|
|
|
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"
|
2019-05-07 03:39:41 +08:00
|
|
|
rv = c.get("/test")
|
|
|
|
assert rv.data == b"42"
|