Skip to content

Commit

Permalink
fix builds and removed some pydantic 2.7 refs
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjunk committed Oct 18, 2024
1 parent d21659a commit 6072ae2
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pydantic_forms/exception_handlers/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from fastapi.requests import Request
from fastapi.responses import JSONResponse

from pydantic_forms.exceptions import FormException, FormNotCompleteError, FormValidationError, show_ex
from pydantic_forms.exceptions import FormException, FormNotCompleteError, FormValidationError
from pydantic_forms.utils.json import json_dumps, json_loads


Expand Down
4 changes: 3 additions & 1 deletion pydantic_forms/validators/components/migration_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class _MigrationSummary(BaseModel):

def create_json_extra_schema(data: SummaryData, schema: dict[str, Any]) -> None:
schema.update({"format": "summary", "type": "string", "uniforms": {"data": data}})
schema.pop("allOf") # This is needed, because otherwise Uniforms (3.8.1) is unable to render this schema
# TODO: check if Frontend renders MigrationSummary ok
# Error: no "allOf" anymore in pydantic JSON scheme
# schema.pop("allOf") # This is needed, because otherwise Uniforms (3.8.1) is unable to render this schema


def migration_summary(data: SummaryData) -> type[MigrationSummary]:
Expand Down
12 changes: 12 additions & 0 deletions tests/unit_tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def assert_equal_ignore_key(expected, actual, ignore_keys):
def deep_remove_keys(d, keys_to_ignore):
if isinstance(d, dict):
return {k: deep_remove_keys(v, keys_to_ignore) for k, v in d.items() if k not in keys_to_ignore}
elif isinstance(d, list):
return [deep_remove_keys(i, keys_to_ignore) for i in d]
return d

stripped_expected = deep_remove_keys(expected, ignore_keys)
stripped_actual = deep_remove_keys(actual, ignore_keys)

assert stripped_expected == stripped_actual, f"Expected {stripped_expected}, but got {stripped_actual}"
3 changes: 2 additions & 1 deletion tests/unit_tests/test_accept.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pydantic_forms.core import FormPage
from pydantic_forms.utils.json import json_loads
from pydantic_forms.validators import Accept, AcceptValues
from tests.unit_tests.helpers import assert_equal_ignore_key


def test_accept_ok():
Expand Down Expand Up @@ -96,4 +97,4 @@ class Form(FormPage):
"url": "https://errors.pydantic.dev/2.7/v/enum",
}
]
assert error_info.value.errors() == expected
assert_equal_ignore_key(expected, error_info.value.errors(), ["url"])
2 changes: 1 addition & 1 deletion tests/unit_tests/test_choice_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_choice_list_constraint_at_least_one_item(Form):
{
"input": [],
"loc": ("choice",),
"msg": "List should have at least 1 item after validation, not 0",
"msg": "Value should have at least 1 item after validation, not 0",
"type": "too_short",
# "ctx": {"limit_value": 1},
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_constrained_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_constrained_list_too_short():
# "ctx": {"error": ListMinLengthError(limit_value=1)},
"input": [],
"loc": ("v",),
"msg": "List should have at least 1 item after validation, not 0",
"msg": "Value should have at least 1 item after validation, not 0",
"type": "too_short",
}
]
Expand Down Expand Up @@ -115,7 +115,7 @@ class UniqueConListModel(FormPage):
{
"input": [],
"loc": ("v",),
"msg": "List should have at least 1 item after validation, not 0",
"msg": "Value should have at least 1 item after validation, not 0",
"type": "too_short",
# "ctx": {"limit_value": 1},
}
Expand Down
4 changes: 3 additions & 1 deletion tests/unit_tests/test_display_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Form(FormPage):
summary: Summary

expected = {
"$defs": {"MigrationSummaryValue": {"properties": {}, "title": "MigrationSummaryValue", "type": "object"}},
"additionalProperties": False,
"properties": {
"display_sub": {
Expand All @@ -52,8 +53,9 @@ class Form(FormPage):
"type": "string",
},
"summary": {
"format": "summary",
"$ref": "#/$defs/MigrationSummaryValue",
"default": None,
"format": "summary",
"type": "string",
"uniforms": {"data": {"headers": ["one"]}},
},
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_list_of_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_list_of_two_min_items(Form):
{
"input": [1],
"loc": ("two",),
"msg": "List should have at least 2 items after validation, not 1",
"msg": "Value should have at least 2 items after validation, not 1",
"type": "too_short",
}
]
Expand All @@ -42,7 +42,7 @@ def test_list_of_two_max_items(Form):
{
"input": [1, 2, 3],
"loc": ("two",),
"msg": "List should have at most 2 items after validation, not 3",
"msg": "Value should have at most 2 items after validation, not 3",
"type": "too_long",
},
]
Expand Down
4 changes: 3 additions & 1 deletion tests/unit_tests/test_migration_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ class Form(FormPage):
ms: Summary

expected = {
"$defs": {"MigrationSummaryValue": {"properties": {}, "title": "MigrationSummaryValue", "type": "object"}},
"additionalProperties": False,
"properties": {
"ms": {
"format": "summary",
"$ref": "#/$defs/MigrationSummaryValue",
"default": None,
"format": "summary",
"type": "string",
"uniforms": {
"data": {"headers": ["one"]},
Expand Down

0 comments on commit 6072ae2

Please sign in to comment.