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 3
3
from typing import AsyncGenerator
4
4
5
5
import pytest
6
+ from pydantic import BaseModel
6
7
7
8
from psqlpy import Cursor , PSQLPool
8
9
9
10
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
+
10
26
@pytest .fixture ()
11
27
def anyio_backend () -> str :
12
28
"""
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