Resolve headers on different renderers - Issue 2749 (#2774)

* Resolve headers on different renderers - Issue 2749

* Make pretty
This commit is contained in:
Adam Hopkins
2023-07-09 09:57:22 +03:00
committed by GitHub
parent c17230ef94
commit c21999a248
2 changed files with 32 additions and 10 deletions

View File

@@ -527,3 +527,26 @@ def test_guess_mime_logging(
]
assert logmsg == expected
@pytest.mark.parametrize(
"format,expected",
(
("html", "text/html; charset=utf-8"),
("text", "text/plain; charset=utf-8"),
("json", "application/json"),
),
)
def test_exception_header_on_renderers(app: Sanic, format, expected):
app.config.FALLBACK_ERROR_FORMAT = format
@app.get("/test")
def test(request):
raise SanicException(
"test", status_code=400, headers={"exception": "test"}
)
_, response = app.test_client.get("/test")
assert response.status == 400
assert response.headers.get("exception") == "test"
assert response.content_type == expected