-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
2 changed files
with
37 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,36 @@ | ||
from typing import List | ||
|
||
import pytest | ||
|
||
import mongoz | ||
from mongoz import Document, EmbeddedDocument | ||
from tests.conftest import client | ||
|
||
pytestmark = pytest.mark.anyio | ||
|
||
|
||
class Actor(EmbeddedDocument): | ||
name: str = mongoz.String() | ||
price: float = mongoz.Decimal(max_digits=5, decimal_places=2, null=True) | ||
|
||
|
||
class Movie(Document): | ||
actors: List[Actor] = mongoz.Array(Actor) | ||
|
||
class Meta: | ||
registry = client | ||
database = "test_db" | ||
|
||
|
||
async def test_embedded_model() -> None: | ||
actor = Actor(name="Tom Hanks", price=100.00) | ||
|
||
await Movie( | ||
actors=[actor], | ||
name="Saving Private Ryan", | ||
).create() | ||
|
||
movie = await Movie.objects.last() | ||
|
||
assert movie.actors[0].name == "Tom Hanks" | ||
assert float(str(movie.actors[0].price)) == 100.00 |