-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Type | ||
|
||
import pytest | ||
from bson import CodecOptions | ||
from bson.codec_options import TypeEncoder, TypeRegistry | ||
from motor.motor_asyncio import AsyncIOMotorDatabase | ||
|
||
from motor_odm import Document, encoders | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
@pytest.mark.parametrize("encoder", [encoders.SetEncoder, encoders.FrozensetEncoder]) | ||
async def test_encoder(encoder: Type[TypeEncoder], db: AsyncIOMotorDatabase): | ||
class Doc(Document): | ||
class Mongo: | ||
collection = "test" | ||
codec_options = CodecOptions(type_registry=TypeRegistry([encoder()])) | ||
|
||
val: encoder.python_type | ||
|
||
doc = Doc(val={"A", "B", "C"}) | ||
await doc.save() | ||
one = await Doc.find_one() | ||
assert one.val == {"A", "B", "C"} | ||
assert type(one.val) is encoder.python_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import fastapi | ||
from pydantic import BaseModel | ||
|
||
from motor_odm import Document, fixtures # noqa: F401,F403 | ||
|
||
|
||
def test_fastapi_fix(): | ||
class SomeModel(BaseModel): | ||
pass | ||
|
||
class SomeDoc(Document): | ||
class Mongo: | ||
collection = "test" | ||
|
||
model = SomeModel() | ||
doc = SomeDoc() | ||
assert fastapi.routing._prepare_response_content(doc, exclude_unset=False) is doc | ||
assert fastapi.routing._prepare_response_content(model, exclude_unset=False) == {} |