add aborter object to app
This commit is contained in:
parent
a25d234cdd
commit
eb5dd9f5ef
5 changed files with 92 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ import io
|
|||
import os
|
||||
|
||||
import pytest
|
||||
import werkzeug.exceptions
|
||||
|
||||
import flask
|
||||
from flask.helpers import get_debug_flag
|
||||
|
|
@ -174,6 +175,35 @@ def test_redirect_with_app(app):
|
|||
flask.redirect("other")
|
||||
|
||||
|
||||
def test_abort_no_app():
|
||||
with pytest.raises(werkzeug.exceptions.Unauthorized):
|
||||
flask.abort(401)
|
||||
|
||||
with pytest.raises(LookupError):
|
||||
flask.abort(900)
|
||||
|
||||
|
||||
def test_app_aborter_class():
|
||||
class MyAborter(werkzeug.exceptions.Aborter):
|
||||
pass
|
||||
|
||||
class MyFlask(flask.Flask):
|
||||
aborter_class = MyAborter
|
||||
|
||||
app = MyFlask(__name__)
|
||||
assert isinstance(app.aborter, MyAborter)
|
||||
|
||||
|
||||
def test_abort_with_app(app):
|
||||
class My900Error(werkzeug.exceptions.HTTPException):
|
||||
code = 900
|
||||
|
||||
app.aborter.mapping[900] = My900Error
|
||||
|
||||
with app.app_context(), pytest.raises(My900Error):
|
||||
flask.abort(900)
|
||||
|
||||
|
||||
class TestNoImports:
|
||||
"""Test Flasks are created without import.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue