2017-05-23 15:18:39 -07:00
|
|
|
import flask
|
2011-11-05 17:43:40 +01:00
|
|
|
|
2012-10-07 22:58:41 +02:00
|
|
|
|
2017-05-24 17:27:36 -07:00
|
|
|
def test_aborting(app):
|
2014-09-04 15:32:50 +02:00
|
|
|
class Foo(Exception):
|
|
|
|
|
whatever = 42
|
2014-08-31 21:56:15 +02:00
|
|
|
|
2014-09-04 15:32:50 +02:00
|
|
|
@app.errorhandler(Foo)
|
|
|
|
|
def handle_foo(e):
|
|
|
|
|
return str(e.whatever)
|
2014-08-31 21:56:15 +02:00
|
|
|
|
2019-05-06 15:39:41 -04:00
|
|
|
@app.route("/")
|
2014-09-04 15:32:50 +02:00
|
|
|
def index():
|
2019-05-06 15:39:41 -04:00
|
|
|
raise flask.abort(flask.redirect(flask.url_for("test")))
|
2014-08-31 21:56:15 +02:00
|
|
|
|
2019-05-06 15:39:41 -04:00
|
|
|
@app.route("/test")
|
2014-09-04 15:32:50 +02:00
|
|
|
def test():
|
|
|
|
|
raise Foo()
|
2013-01-21 17:55:07 +00:00
|
|
|
|
2014-09-04 15:32:50 +02:00
|
|
|
with app.test_client() as c:
|
2019-05-06 15:39:41 -04:00
|
|
|
rv = c.get("/")
|
|
|
|
|
assert rv.headers["Location"] == "http://localhost/test"
|
|
|
|
|
rv = c.get("/test")
|
|
|
|
|
assert rv.data == b"42"
|