Browse Source

test: use HTTPStatus.UNPROCESSABLE_ENTITY instead of starlette's status

pull/15477/head
Suren Khorenyan 1 month ago
parent
commit
ae1bb957bb
  1. 4
      tests/test_annotated_body_depends_merge_body.py
  2. 4
      tests/test_annotated_body_depends_merge_file.py
  3. 4
      tests/test_annotated_body_depends_merge_form.py

4
tests/test_annotated_body_depends_merge_body.py

@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Annotated, Any
import pytest
@ -83,7 +84,8 @@ class TestAnnotatedBodyDependsMergeBody:
assert r.json() == {"extra": "x"}
bad = client.post("/c", json={"kind": "foo"})
assert bad.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
# not status.*: Starlette confused HTTP_422_UNPROCESSABLE_CONTENT HTTP_422_UNPROCESSABLE_ENTITY
assert bad.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
def test_merge_depends_empty_falls_back_to_declared_model(self) -> None:
app = FastAPI()

4
tests/test_annotated_body_depends_merge_file.py

@ -1,3 +1,4 @@
from http import HTTPStatus
from io import BytesIO
from typing import Annotated, Any
@ -81,7 +82,8 @@ class TestAnnotatedBodyDependsMergeFile:
data={"kind": "foo"},
files={"blob": ("up.txt", BytesIO(b"x"), "text/plain")},
)
assert bad.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
# not status.*: Starlette confused HTTP_422_UNPROCESSABLE_CONTENT HTTP_422_UNPROCESSABLE_ENTITY
assert bad.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
def test_rejects_file_and_form_together(self) -> None:
app = FastAPI()

4
tests/test_annotated_body_depends_merge_form.py

@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Annotated, Any
import pytest
@ -61,4 +62,5 @@ class TestAnnotatedBodyDependsMergeForm:
assert r.json() == {"extra": "z"}
bad = client.post("/form-c", data={"kind": "foo"})
assert bad.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
# not status.*: Starlette confused HTTP_422_UNPROCESSABLE_CONTENT HTTP_422_UNPROCESSABLE_ENTITY
assert bad.status_code == HTTPStatus.UNPROCESSABLE_ENTITY

Loading…
Cancel
Save