deprecate abort (#2077)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
from collections import deque, namedtuple
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from sanic import Sanic
|
||||
from sanic.exceptions import (
|
||||
SanicException,
|
||||
Forbidden,
|
||||
InvalidUsage,
|
||||
NotFound,
|
||||
ServerError,
|
||||
Unauthorized,
|
||||
abort,
|
||||
abort
|
||||
)
|
||||
from sanic.response import text
|
||||
|
||||
@@ -68,16 +71,19 @@ def exception_app():
|
||||
|
||||
@app.route("/abort/401")
|
||||
def handler_401_error(request):
|
||||
abort(401)
|
||||
raise SanicException(status_code=401)
|
||||
|
||||
@app.route("/abort")
|
||||
def handler_500_error(request):
|
||||
raise SanicException(status_code=500)
|
||||
|
||||
@app.route("/old_abort")
|
||||
def handler_old_abort_error(request):
|
||||
abort(500)
|
||||
return text("OK")
|
||||
|
||||
@app.route("/abort/message")
|
||||
def handler_abort_message(request):
|
||||
abort(500, message="Abort")
|
||||
raise SanicException(message="Custom Message", status_code=500)
|
||||
|
||||
@app.route("/divide_by_zero")
|
||||
def handle_unhandled_exception(request):
|
||||
@@ -208,14 +214,21 @@ def test_exception_in_exception_handler_debug_on(exception_app):
|
||||
assert response.body.startswith(b"Exception raised in exception ")
|
||||
|
||||
|
||||
def test_abort(exception_app):
|
||||
"""Test the abort function"""
|
||||
def test_sanic_exception(exception_app):
|
||||
"""Test sanic exceptions are handled"""
|
||||
request, response = exception_app.test_client.get("/abort/401")
|
||||
assert response.status == 401
|
||||
|
||||
request, response = exception_app.test_client.get("/abort")
|
||||
assert response.status == 500
|
||||
# check fallback message
|
||||
assert "Internal Server Error" in response.text
|
||||
|
||||
request, response = exception_app.test_client.get("/abort/message")
|
||||
assert response.status == 500
|
||||
assert "Abort" in response.text
|
||||
assert "Custom Message" in response.text
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
request, response = exception_app.test_client.get("/old_abort")
|
||||
assert response.status == 500
|
||||
assert len(w) == 1 and 'deprecated' in w[0].message.args[0]
|
||||
|
||||
@@ -3,7 +3,7 @@ import logging
|
||||
from asyncio import CancelledError
|
||||
from itertools import count
|
||||
|
||||
from sanic.exceptions import NotFound, SanicException
|
||||
from sanic.exceptions import NotFound
|
||||
from sanic.request import Request
|
||||
from sanic.response import HTTPResponse, text
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from urllib.parse import quote, unquote
|
||||
from urllib.parse import quote
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import pytest
|
||||
from sanic import Sanic
|
||||
from sanic.blueprints import Blueprint
|
||||
from sanic.response import json, text
|
||||
from sanic.server import HttpProtocol
|
||||
from sanic.views import CompositionView, HTTPMethodView
|
||||
from sanic.views import stream as stream_decorator
|
||||
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
import asyncio
|
||||
|
||||
from typing import cast
|
||||
|
||||
import httpcore
|
||||
import httpx
|
||||
|
||||
from httpcore._async.base import (
|
||||
AsyncByteStream,
|
||||
AsyncHTTPTransport,
|
||||
ConnectionState,
|
||||
NewConnectionRequired,
|
||||
)
|
||||
from httpcore._async.connection import AsyncHTTPConnection
|
||||
from httpcore._async.connection_pool import ResponseByteStream
|
||||
from httpcore._exceptions import LocalProtocolError, UnsupportedProtocol
|
||||
from httpcore._types import TimeoutDict
|
||||
from httpcore._utils import url_to_origin
|
||||
|
||||
from sanic_testing.testing import SanicTestClient
|
||||
|
||||
from sanic import Sanic
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
import asyncio
|
||||
import inspect
|
||||
import os
|
||||
import warnings
|
||||
|
||||
from collections import namedtuple
|
||||
from mimetypes import guess_type
|
||||
from random import choice
|
||||
from unittest.mock import MagicMock
|
||||
from urllib.parse import unquote
|
||||
|
||||
import pytest
|
||||
|
||||
from aiofiles import os as async_os
|
||||
from sanic_testing.testing import HOST, PORT
|
||||
|
||||
from sanic import Sanic
|
||||
from sanic.response import (
|
||||
HTTPResponse,
|
||||
StreamingHTTPResponse,
|
||||
empty,
|
||||
file,
|
||||
file_stream,
|
||||
@@ -26,7 +22,6 @@ from sanic.response import (
|
||||
stream,
|
||||
text,
|
||||
)
|
||||
from sanic.server import HttpProtocol
|
||||
|
||||
|
||||
JSON_DATA = {"ok": True}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import asyncio
|
||||
|
||||
from time import monotonic as current_time
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
Reference in New Issue
Block a user