Skip to content

Commit

Permalink
Test case for paginating multiple response types
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaoming committed May 2, 2024
1 parent 9dcebe9 commit 7f04bcb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ def items_9(request):
return list(range(100))


@api.get("/items_12", response={101: int, 200: List[Any], 220: List[Any]})
@paginate(PageNumberPagination, page_size=10, pass_parameter="page_info")
def items_12(request, **kwargs):
return 220, ITEMS + [kwargs["page_info"]]


client = TestClient(api)


Expand Down Expand Up @@ -326,6 +332,18 @@ def test_case9():
}


def test_case12_status_code():
page = 11
response = client.get(f"/items_12?page={page}")
assert response.status_code == 220
assert response.json() == {"items": [{"page": 11}], "count": 101}

schema = api.get_openapi_schema()["paths"]["/api/items_12"]["get"]

assert schema["responses"][200] == {'description': 'OK', 'content': {'application/json': {'schema': {'$ref': '#/components/schemas/PagedAny'}}}}
assert schema["responses"][220] == {'description': 'Unknown Status Code', 'content': {'application/json': {'schema': {'$ref': '#/components/schemas/PagedAny'}}}}


@override_settings(NINJA_PAGINATION_MAX_LIMIT=1000)
def test_10_max_limit_set():
# reload to apply django settings
Expand Down

0 comments on commit 7f04bcb

Please sign in to comment.