File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 33from typing import AsyncGenerator
44
55import pytest
6+ from pydantic import BaseModel
67
78from psqlpy import Cursor , PSQLPool
89
910
11+ class DefaultPydanticModel (BaseModel ):
12+ """Validation model for test data based on Pydantic."""
13+
14+ id : int
15+ name : str
16+
17+
18+ class DefaultPythonModelClass :
19+ """Validation model for test data based on default Python class."""
20+
21+ def __init__ (self , id : int , name : str ) -> None :
22+ self .id = id
23+ self .name = name
24+
25+
1026@pytest .fixture ()
1127def anyio_backend () -> str :
1228 """
Original file line number Diff line number Diff line change 1+ import pytest
2+ from tests .conftest import DefaultPydanticModel , DefaultPythonModelClass
3+
4+ from psqlpy import PSQLPool
5+
6+ pytestmark = pytest .mark .anyio
7+
8+
9+ async def test_as_class (
10+ psql_pool : PSQLPool ,
11+ table_name : str ,
12+ number_database_records : int ,
13+ ) -> None :
14+ """Test `as_class()` method."""
15+ select_result = await psql_pool .execute (
16+ f"SELECT * FROM { table_name } " ,
17+ )
18+
19+ as_pydantic = select_result .as_class (
20+ as_class = DefaultPydanticModel ,
21+ )
22+ assert len (as_pydantic ) == number_database_records
23+
24+ for single_record in as_pydantic :
25+ assert isinstance (single_record , DefaultPydanticModel )
26+
27+ as_py_class = select_result .as_class (
28+ as_class = DefaultPythonModelClass ,
29+ )
30+
31+ assert len (as_py_class ) == number_database_records
32+
33+ for single_py_record in as_py_class :
34+ assert isinstance (single_py_record , DefaultPythonModelClass )
You can’t perform that action at this time.
0 commit comments