You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
769 B
Python
26 lines
769 B
Python
from iti.responses import fail, ok, page, pagination
|
|
from iti.schemas import ItiModel
|
|
|
|
|
|
class UserOut(ItiModel):
|
|
user_id: str
|
|
created_at: str
|
|
|
|
|
|
def test_envelope_helpers():
|
|
assert ok({"id": "1"}) == {"data": {"id": "1"}, "code": 200, "message": "成功"}
|
|
assert fail("x", code=400) == {"data": None, "code": 400, "message": "x"}
|
|
|
|
|
|
def test_page_helper():
|
|
result = page([{"id": 1}], pagination(page=2, size=10, total=11))
|
|
|
|
assert result["data"]["items"] == [{"id": 1}]
|
|
assert result["data"]["page"] == {"page": 2, "size": 10, "pages": 2, "total": 11}
|
|
|
|
|
|
def test_model_outputs_camel_case():
|
|
result = UserOut(user_id="u1", created_at="2026-01-01").model_dump(by_alias=True)
|
|
|
|
assert result == {"userId": "u1", "createdAt": "2026-01-01"}
|