Skip to content

Commit

Permalink
WIP - fix tests for largebinary schema, wrapped bytes fields fail in …
Browse files Browse the repository at this point in the history
…pydantic, will be fixed in pydantic-core, remaining is circural schema for related models, failing 6/442
  • Loading branch information
collerek committed Dec 19, 2023
1 parent b91bd49 commit 8c688b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ormar/models/helpers/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_pydantic_base_orm_config() -> pydantic.ConfigDict:
:rtype: pydantic Config
"""

return ConfigDict(validate_assignment=True)
return ConfigDict(validate_assignment=True, ser_json_bytes="base64")


def get_potential_fields(attrs: Union[Dict, MappingProxyType]) -> Dict:
Expand Down
10 changes: 2 additions & 8 deletions tests/test_fastapi/test_binary_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class BinaryThing(ormar.Model):

id: uuid.UUID = ormar.UUID(primary_key=True, default=uuid.uuid4)
name: str = ormar.Text(default="")
bt: str = ormar.Enum(enum_class=BinaryEnum, represent_as_base64_str=True,
)
bt: str = ormar.LargeBinary(represent_as_base64_str=True, max_length=100)


@app.get("/things", response_model=List[BinaryThing])
Expand Down Expand Up @@ -101,11 +100,6 @@ async def test_read_main():


def test_schema():
schema = BinaryThing.schema()
schema = BinaryThing.model_json_schema()
assert schema["properties"]["bt"]["format"] == "base64"
converted_choices = ["7g==", "/w==", "8CiMKA==", "wyg="]
assert len(schema["properties"]["bt"]["enum"]) == 4
assert all(
choice in schema["properties"]["bt"]["enum"] for choice in converted_choices
)
assert schema["example"]["bt"] == "string"
2 changes: 1 addition & 1 deletion tests/test_fastapi/test_fastapi_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ async def test_read_main():
assert response.json() == {
"category": {
"id": None,
"items": [{"id": 1, "name": "test"}],
"name": "test cat",
},
"id": 1,
"name": "test",
}
item = Item(**response.json())
assert item.id == 1
assert item.category.items[0].id == 1

0 comments on commit 8c688b8

Please sign in to comment.