11from __future__ import annotations
22
3+ import typing
4+
35import pytest
6+ from tests .helpers import count_rows_in_test_table
47
58from psqlpy import Cursor , IsolationLevel , PSQLPool , ReadVariant
69from psqlpy .exceptions import DBTransactionError , RustPSQLDriverPyBaseError
710
11+ pytestmark = pytest .mark .anyio
12+
813
9- @pytest .mark .anyio ()
1014@pytest .mark .parametrize (
1115 ("isolation_level" , "deferrable" , "read_variant" ),
1216 [
@@ -42,7 +46,6 @@ async def test_transaction_init_parameters(
4246 assert read_variant is not ReadVariant .ReadOnly
4347
4448
45- @pytest .mark .anyio ()
4649async def test_transaction_begin (
4750 psql_pool : PSQLPool ,
4851 table_name : str ,
@@ -66,7 +69,6 @@ async def test_transaction_begin(
6669 assert len (result .result ()) == number_database_records
6770
6871
69- @pytest .mark .anyio ()
7072async def test_transaction_commit (
7173 psql_pool : PSQLPool ,
7274 table_name : str ,
@@ -100,7 +102,6 @@ async def test_transaction_commit(
100102 assert len (result .result ())
101103
102104
103- @pytest .mark .anyio ()
104105async def test_transaction_savepoint (
105106 psql_pool : PSQLPool ,
106107 table_name : str ,
@@ -133,7 +134,6 @@ async def test_transaction_savepoint(
133134 await transaction .commit ()
134135
135136
136- @pytest .mark .anyio ()
137137async def test_transaction_rollback (
138138 psql_pool : PSQLPool ,
139139 table_name : str ,
@@ -171,7 +171,6 @@ async def test_transaction_rollback(
171171 assert not (result_from_conn .result ())
172172
173173
174- @pytest .mark .anyio ()
175174async def test_transaction_release_savepoint (
176175 psql_pool : PSQLPool ,
177176) -> None :
@@ -194,7 +193,6 @@ async def test_transaction_release_savepoint(
194193 await transaction .savepoint (sp_name_1 )
195194
196195
197- @pytest .mark .anyio ()
198196async def test_transaction_cursor (
199197 psql_pool : PSQLPool ,
200198 table_name : str ,
@@ -205,3 +203,29 @@ async def test_transaction_cursor(
205203 cursor = await transaction .cursor (f"SELECT * FROM { table_name } " )
206204
207205 assert isinstance (cursor , Cursor )
206+
207+
208+ @pytest .mark .parametrize (
209+ ("insert_values" ),
210+ [
211+ [[1 , "name1" ], [2 , "name2" ]],
212+ [[10 , "name1" ], [20 , "name2" ], [30 , "name3" ]],
213+ [[1 , "name1" ]],
214+ ],
215+ )
216+ async def test_transaction_execute_many (
217+ psql_pool : PSQLPool ,
218+ table_name : str ,
219+ number_database_records : int ,
220+ insert_values : list [list [typing .Any ]],
221+ ) -> None :
222+ connection = await psql_pool .connection ()
223+ async with connection .transaction () as transaction :
224+ await transaction .execute_many (
225+ f"INSERT INTO { table_name } VALUES ($1, $2)" ,
226+ insert_values ,
227+ )
228+ assert await count_rows_in_test_table (
229+ table_name ,
230+ transaction ,
231+ ) - number_database_records == len (insert_values )
0 commit comments