File: test_pydantic_extras.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 (34 lines) | stat: -rw-r--r-- 813 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytest

from tests.odm.models import (
    DocumentWithExtras,
    DocumentWithExtrasKw,
    DocumentWithPydanticConfig,
)


async def test_pydantic_extras():
    doc = DocumentWithExtras(num_1=2)
    doc.extra_value = "foo"
    await doc.save()

    loaded_doc = await DocumentWithExtras.get(doc.id)

    assert loaded_doc.extra_value == "foo"


@pytest.mark.skip(reason="setting extra to allow via class kwargs not working")
async def test_pydantic_extras_kw():
    doc = DocumentWithExtrasKw(num_1=2)
    doc.extra_value = "foo"
    await doc.save()

    loaded_doc = await DocumentWithExtras.get(doc.id)

    assert loaded_doc.extra_value == "foo"


async def test_fail_with_no_extras():
    doc = DocumentWithPydanticConfig(num_1=2)
    with pytest.raises(ValueError):
        doc.extra_value = "foo"