File: test_root_models.py

package info (click to toggle)
python-beanie 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,480 kB
  • sloc: python: 14,427; makefile: 7; sh: 6
file content (16 lines) | stat: -rw-r--r-- 645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from beanie.odm.utils.pydantic import IS_PYDANTIC_V2
from tests.odm.models import DocumentWithRootModelAsAField

if IS_PYDANTIC_V2:

    class TestRootModels:
        async def test_insert(self):
            doc = DocumentWithRootModelAsAField(pets=["dog", "cat", "fish"])
            await doc.insert()

            new_doc = await DocumentWithRootModelAsAField.get(doc.id)
            assert new_doc.pets.root == ["dog", "cat", "fish"]

            collection = DocumentWithRootModelAsAField.get_pymongo_collection()
            raw_doc = await collection.find_one({"_id": doc.id})
            assert raw_doc["pets"] == ["dog", "cat", "fish"]