Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sanic-org/sanic-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Dec 31, 2024
2 parents 16e632f + fd85ada commit e52f380
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools<60.0", "wheel"]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.ruff]
Expand Down
2 changes: 2 additions & 0 deletions sanic_ext/extras/validation/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def coerce(self, value):
try:
if isinstance(value, list):
value = [coerce_type(item) for item in value]
elif value is None and self.nullable:
value = None
else:
value = coerce_type(value)
except (ValueError, TypeError):
Expand Down
5 changes: 5 additions & 0 deletions tests/extra/test_validation_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def test_validate_form(app):
class Pet:
name: str
alter_ego: List[str]
description: Optional[str] = None

@app.post("/function")
@validate(form=Pet)
Expand All @@ -342,6 +343,7 @@ async def handler(_, body: Pet):
{
"is_pet": isinstance(body, Pet),
"pet": {"name": body.name, "alter_ego": body.alter_ego},
"description": body.description if body.description else "",
}
)

Expand All @@ -353,18 +355,21 @@ async def post(self, _, body: Pet):
{
"is_pet": isinstance(body, Pet),
"pet": {"name": body.name, "alter_ego": body.alter_ego},
"description": body.description if body.description else "",
}
)

_, response = app.test_client.post("/function", data=SNOOPY_DATA)
assert response.status == 200
assert response.json["is_pet"]
assert response.json["pet"] == SNOOPY_DATA
assert response.json["description"] == ""

_, response = app.test_client.post("/method", data=SNOOPY_DATA)
assert response.status == 200
assert response.json["is_pet"]
assert response.json["pet"] == SNOOPY_DATA
assert response.json["description"] == ""


def test_validate_query(app):
Expand Down

0 comments on commit e52f380

Please sign in to comment.