change(fastapi): centralize HTTPException

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-12-02 23:22:31 -08:00
parent a747548254
commit abfd41f31e
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
6 changed files with 28 additions and 51 deletions

View file

@ -11,6 +11,8 @@ import aurweb.asgi
import aurweb.config
import aurweb.redis
from aurweb.testing.requests import Request
@pytest.mark.asyncio
async def test_asgi_startup_session_secret_exception(monkeypatch):
@ -42,9 +44,11 @@ async def test_asgi_startup_exception(monkeypatch):
async def test_asgi_http_exception_handler():
exc = HTTPException(status_code=422, detail="EXCEPTION!")
phrase = http.HTTPStatus(exc.status_code).phrase
response = await aurweb.asgi.http_exception_handler(None, exc)
assert response.body.decode() == \
f"<h1>{exc.status_code} {phrase}</h1><p>{exc.detail}</p>"
response = await aurweb.asgi.http_exception_handler(Request(), exc)
assert response.status_code == 422
content = response.body.decode()
assert f"{exc.status_code} - {phrase}" in content
assert "EXCEPTION!" in content
@pytest.mark.asyncio