File: test_options_validation.py

package info (click to toggle)
python-polyfactory 2.22.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,892 kB
  • sloc: python: 11,338; makefile: 103; sh: 37
file content (46 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
import pytest

from polyfactory import ConfigurationException
from polyfactory.factories.pydantic_factory import ModelFactory
from tests.models import Person


def test_validates_model_is_set_on_definition_of_factory() -> None:
    with pytest.raises(ConfigurationException):

        class MyFactory(ModelFactory):
            pass


def test_validates_connection_in_create_sync() -> None:
    class MyFactory(ModelFactory):
        __model__ = Person

    with pytest.raises(ConfigurationException):
        MyFactory.create_sync()


def test_validates_connection_in_create_batch_sync() -> None:
    class MyFactory(ModelFactory):
        __model__ = Person

    with pytest.raises(ConfigurationException):
        MyFactory.create_batch_sync(2)


@pytest.mark.asyncio()
async def test_validates_connection_in_create_async() -> None:
    class MyFactory(ModelFactory):
        __model__ = Person

    with pytest.raises(ConfigurationException):
        await MyFactory.create_async()


@pytest.mark.asyncio()
async def test_validates_connection_in_create_batch_async() -> None:
    class MyFactory(ModelFactory):
        __model__ = Person

    with pytest.raises(ConfigurationException):
        await MyFactory.create_batch_async(2)