Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions tests/test_beanie/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import pytest
from fastapi import status

# for compatibility with starlette < 0.47.0; HTTP_422_UNPROCESSABLE_ENTITY is deprecated in the later versions
if not hasattr(status, "HTTP_422_UNPROCESSABLE_CONTENT"):
status.HTTP_422_UNPROCESSABLE_CONTENT = status.HTTP_422_UNPROCESSABLE_ENTITY


@pytest.mark.parametrize(
"filter_,expected_count",
Expand Down Expand Up @@ -63,9 +67,9 @@ async def test_api(test_client, uri, filter_, expected_count):
(
({"is_individual": True}, status.HTTP_200_OK),
({"is_individual": False}, status.HTTP_200_OK),
({}, status.HTTP_422_UNPROCESSABLE_ENTITY),
({"is_individual": None}, status.HTTP_422_UNPROCESSABLE_ENTITY),
[{"is_individual": True, "bogus_filter": "bad"}, status.HTTP_422_UNPROCESSABLE_ENTITY],
({}, status.HTTP_422_UNPROCESSABLE_CONTENT),
({"is_individual": None}, status.HTTP_422_UNPROCESSABLE_CONTENT),
[{"is_individual": True, "bogus_filter": "bad"}, status.HTTP_422_UNPROCESSABLE_CONTENT],
),
)
@pytest.mark.asyncio
Expand Down
10 changes: 7 additions & 3 deletions tests/test_beanie/test_order_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from fastapi import status
from pydantic import ValidationError

# for compatibility with starlette < 0.47.0; HTTP_422_UNPROCESSABLE_ENTITY is deprecated in the later versions
if not hasattr(status, "HTTP_422_UNPROCESSABLE_CONTENT"):
status.HTTP_422_UNPROCESSABLE_CONTENT = status.HTTP_422_UNPROCESSABLE_ENTITY


@pytest.mark.parametrize(
"order_by,assert_function",
Expand Down Expand Up @@ -172,7 +176,7 @@ async def test_api_order_by(test_client, order_by, assert_function):
async def test_api_order_by_invalid_field(test_client):
endpoint = "/users_with_order_by?order_by=invalid"
response = await test_client.get(endpoint)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT


@pytest.mark.asyncio
Expand All @@ -189,8 +193,8 @@ async def test_api_no_order_by(test_client):
[
[None, lambda previous_user, user: True, status.HTTP_200_OK],
["", lambda previous_user, user: True, status.HTTP_200_OK],
["name", None, status.HTTP_422_UNPROCESSABLE_ENTITY],
["age,-name", None, status.HTTP_422_UNPROCESSABLE_ENTITY],
["name", None, status.HTTP_422_UNPROCESSABLE_CONTENT],
["age,-name", None, status.HTTP_422_UNPROCESSABLE_CONTENT],
["-age", lambda previous_user, user: previous_user["age"] >= user["age"], status.HTTP_200_OK],
[
"age,-created_at",
Expand Down
10 changes: 7 additions & 3 deletions tests/test_mongoengine/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import pytest
from fastapi import status

# for compatibility with starlette < 0.47.0; HTTP_422_UNPROCESSABLE_ENTITY is deprecated in the later versions
if not hasattr(status, "HTTP_422_UNPROCESSABLE_CONTENT"):
status.HTTP_422_UNPROCESSABLE_CONTENT = status.HTTP_422_UNPROCESSABLE_ENTITY


@pytest.mark.parametrize(
"filter_,expected_count",
Expand Down Expand Up @@ -62,9 +66,9 @@ async def test_api(test_client, uri, filter_, expected_count):
(
({"is_individual": True}, status.HTTP_200_OK),
({"is_individual": False}, status.HTTP_200_OK),
({}, status.HTTP_422_UNPROCESSABLE_ENTITY),
({"is_individual": None}, status.HTTP_422_UNPROCESSABLE_ENTITY),
[{"is_individual": True, "bogus_filter": "bad"}, status.HTTP_422_UNPROCESSABLE_ENTITY],
({}, status.HTTP_422_UNPROCESSABLE_CONTENT),
({"is_individual": None}, status.HTTP_422_UNPROCESSABLE_CONTENT),
[{"is_individual": True, "bogus_filter": "bad"}, status.HTTP_422_UNPROCESSABLE_CONTENT],
),
)
@pytest.mark.asyncio
Expand Down
10 changes: 7 additions & 3 deletions tests/test_mongoengine/test_order_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from fastapi import status
from pydantic import ValidationError

# for compatibility with starlette < 0.47.0; HTTP_422_UNPROCESSABLE_ENTITY is deprecated in the later versions
if not hasattr(status, "HTTP_422_UNPROCESSABLE_CONTENT"):
status.HTTP_422_UNPROCESSABLE_CONTENT = status.HTTP_422_UNPROCESSABLE_ENTITY


@pytest.mark.parametrize(
"order_by,assert_function",
Expand Down Expand Up @@ -166,7 +170,7 @@ async def test_api_order_by(test_client, order_by, assert_function):
async def test_api_order_by_invalid_field(test_client):
endpoint = "/users_with_order_by?order_by=invalid"
response = await test_client.get(endpoint)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT


@pytest.mark.asyncio
Expand All @@ -183,8 +187,8 @@ async def test_api_no_order_by(test_client):
[
[None, lambda previous_user, user: True, status.HTTP_200_OK],
["", lambda previous_user, user: True, status.HTTP_200_OK],
["name", None, status.HTTP_422_UNPROCESSABLE_ENTITY],
["age,-name", None, status.HTTP_422_UNPROCESSABLE_ENTITY],
["name", None, status.HTTP_422_UNPROCESSABLE_CONTENT],
["age,-name", None, status.HTTP_422_UNPROCESSABLE_CONTENT],
["-age", lambda previous_user, user: previous_user["age"] >= user["age"], status.HTTP_200_OK],
[
"age,-created_at",
Expand Down
10 changes: 7 additions & 3 deletions tests/test_sqlalchemy/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from fastapi import status
from sqlalchemy.future import select

# for compatibility with starlette < 0.47.0; HTTP_422_UNPROCESSABLE_ENTITY is deprecated in the later versions
if not hasattr(status, "HTTP_422_UNPROCESSABLE_CONTENT"):
status.HTTP_422_UNPROCESSABLE_CONTENT = status.HTTP_422_UNPROCESSABLE_ENTITY


@pytest.mark.parametrize(
"filter_,expected_count",
Expand Down Expand Up @@ -96,9 +100,9 @@ async def test_api(test_client, uri, filter_, expected_count):
[
[{"is_individual": True}, status.HTTP_200_OK],
[{"is_individual": False}, status.HTTP_200_OK],
[{}, status.HTTP_422_UNPROCESSABLE_ENTITY],
[{"is_individual": None}, status.HTTP_422_UNPROCESSABLE_ENTITY],
[{"is_individual": True, "bogus_filter": "bad"}, status.HTTP_422_UNPROCESSABLE_ENTITY],
[{}, status.HTTP_422_UNPROCESSABLE_CONTENT],
[{"is_individual": None}, status.HTTP_422_UNPROCESSABLE_CONTENT],
[{"is_individual": True, "bogus_filter": "bad"}, status.HTTP_422_UNPROCESSABLE_CONTENT],
],
)
@pytest.mark.usefixtures("sports")
Expand Down
10 changes: 7 additions & 3 deletions tests/test_sqlalchemy/test_order_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from pydantic import ValidationError
from sqlalchemy import select

# for compatibility with starlette < 0.47.0; HTTP_422_UNPROCESSABLE_ENTITY is deprecated in the later versions
if not hasattr(status, "HTTP_422_UNPROCESSABLE_CONTENT"):
status.HTTP_422_UNPROCESSABLE_CONTENT = status.HTTP_422_UNPROCESSABLE_ENTITY


@pytest.mark.parametrize(
"order_by,assert_function",
Expand Down Expand Up @@ -207,7 +211,7 @@ async def test_api_order_by(test_client, users, order_by, assert_function):
async def test_api_order_by_invalid_field(test_client, session):
endpoint = "/users_with_order_by?order_by=invalid"
response = await test_client.get(endpoint)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT


@pytest.mark.asyncio
Expand All @@ -224,8 +228,8 @@ async def test_api_no_order_by(test_client, session):
[
[None, lambda previous_user, user: True, status.HTTP_200_OK],
["", lambda previous_user, user: True, status.HTTP_200_OK],
["name", None, status.HTTP_422_UNPROCESSABLE_ENTITY],
["age,-name", None, status.HTTP_422_UNPROCESSABLE_ENTITY],
["name", None, status.HTTP_422_UNPROCESSABLE_CONTENT],
["age,-name", None, status.HTTP_422_UNPROCESSABLE_CONTENT],
["-age", lambda previous_user, user: previous_user["age"] >= user["age"], status.HTTP_200_OK],
[
"age,-created_at",
Expand Down
Loading