Skip to content

Commit 652c43f

Browse files
author
kedod
committed
test: Refactor and add test for paginated_return_data.py
1 parent d5196ed commit 652c43f

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

docs/examples/data_transfer_objects/factory/paginated_return_data.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from datetime import datetime
22

3-
from sqlalchemy.orm import Mapped
3+
from sqlalchemy.orm import DeclarativeBase, Mapped
44

55
from litestar import Litestar, get
6+
from litestar.contrib.sqlalchemy.base import CommonTableAttributes, UUIDPrimaryKey
67
from litestar.contrib.sqlalchemy.dto import SQLAlchemyDTO
78
from litestar.dto import DTOConfig
89
from litestar.pagination import ClassicPagination
910

10-
from .my_lib import Base
11+
12+
class Base(CommonTableAttributes, UUIDPrimaryKey, DeclarativeBase): ...
1113

1214

1315
class User(Base):

docs/usage/dto/1-abstract-dto.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,14 @@ Working with Litestar's Pagination Types
352352
Litestar offers paginated response wrapper types, and DTO Factory types can handle this out of the box.
353353

354354
.. literalinclude:: /examples/data_transfer_objects/factory/paginated_return_data.py
355-
:caption: Paginated Return Data
356355
:language: python
357-
:linenos:
356+
:lines: 9-11,26-40
357+
358+
.. dropdown:: Full code
359+
360+
.. literalinclude:: /examples/data_transfer_objects/factory/paginated_return_data.py
361+
:language: python
362+
:emphasize-lines: 9,26-40
358363

359364
The DTO is defined and configured, in our example, we're excluding ``password`` and ``created_at`` fields from the final
360365
representation of our users.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from litestar.status_codes import HTTP_200_OK
2+
from litestar.testing.client import TestClient
3+
4+
5+
def test_create_user() -> None:
6+
from docs.examples.data_transfer_objects.factory.paginated_return_data import app
7+
8+
with TestClient(app=app) as client:
9+
response = client.get("/users")
10+
11+
assert response.status_code == HTTP_200_OK
12+
assert response.json() == {
13+
"current_page": 1,
14+
"items": [{"id": 1, "name": "Litestar User"}],
15+
"page_size": 10,
16+
"total_pages": 1,
17+
}

0 commit comments

Comments
 (0)