Skip to content

Commit

Permalink
Add tests for fixtures and encoders
Browse files Browse the repository at this point in the history
  • Loading branch information
codello committed Apr 13, 2020
1 parent 3dbb807 commit 4769c76
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def list_requirements(file):
"flake8-black",
"mypy",
"invoke",
"fastapi",
],
"typing": ["fastapi"],
},
Expand Down
26 changes: 26 additions & 0 deletions tests/test_encoders.py
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
18 changes: 18 additions & 0 deletions tests/test_fixtures.py
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) == {}

0 comments on commit 4769c76

Please sign in to comment.