8000 🐛Fix `RuntimeError` raised when `HTTPException` has a status code with no content by iudeen · Pull Request #5365 · fastapi/fastapi · GitHub
[go: up one dir, main page]

Skip to content
Merged
Prev Previous commit
Next Next commit
fix: added tests for No Body Status Code Exception Handlers
  • Loading branch information
iudeen committed Sep 8, 2022
commit f96a078bdaa5d8b37e9c7e6e608f67515894d850
24 changes: 24 additions & 0 deletions tests/test_starlette_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ async def read_item(item_id: str):
return {"item": items[item_id]}


@app.get("/http-no-body-statuscode-exception")
async def no_body_status_code_exception():
raise HTTPException(
status_code=204,
)


@app.get("/http-no-body-statuscode-with-detail-exception")
async def no_body_status_code_with_detail_exception():
raise HTTPException(status_code=204, detail="I should not make it!")


@app.get("/starlette-items/{item_id}")
async def read_starlette_item(item_id: str):
if item_id not in items:
Expand Down Expand Up @@ -154,3 +166,15 @@ def test_get_starlette_item_not_found():
assert response.status_code == 404, response.text
assert response.headers.get("x-error") is None
assert response.json() == {"detail": "Item not found"}


def test_no_body_status_code_exception_handlers():
response = client.get("/http-no-body-statuscode-exception")
assert response.status_code == 204
assert not response.content


def test_no_body_status_code_with_detail_exception_handlers():
response = client.get("/http-no-body-statuscode-with-detail-exception")
assert response.status_code == 204
assert not response.content
0