Skip to content

Commit bdc133b

Browse files
committed
fix init params test
1 parent e966803 commit bdc133b

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

python/tests/test_transaction.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import pytest
66

77
from psqlpy import Cursor, IsolationLevel, PSQLPool, ReadVariant
8-
from psqlpy.exceptions import DBTransactionError
8+
from psqlpy.exceptions import DBTransactionError, RustPSQLDriverPyBaseError
99

1010

1111
@pytest.mark.anyio()
12-
async def test_transaction_init_parameters(psql_pool: PSQLPool) -> None:
12+
async def test_transaction_init_parameters(
13+
psql_pool: PSQLPool,
14+
table_name: str,
15+
) -> None:
1316
connection = await psql_pool.connection()
1417

1518
test_init_parameters: typing.Final[list[dict[str, typing.Any]]] = [
@@ -35,13 +38,26 @@ async def test_transaction_init_parameters(psql_pool: PSQLPool) -> None:
3538
"read_variant": ReadVariant.ReadWrite,
3639
},
3740
]
38-
3941
for init_parameters in test_init_parameters:
40-
connection.transaction(
42+
insert_exception = None
43+
async with connection.transaction(
4144
isolation_level=init_parameters.get("isolation_level"),
4245
deferrable=init_parameters.get("deferrable"),
4346
read_variant=init_parameters.get("read_variant"),
44-
)
47+
) as transaction:
48+
await transaction.execute("SELECT 1")
49+
try:
50+
await transaction.execute(
51+
f"INSERT INTO {table_name} VALUES ($1, $2)",
52+
parameters=[100, "test_name"],
53+
)
54+
except RustPSQLDriverPyBaseError as exception:
55+
insert_exception = exception
56+
57+
assert (
58+
insert_exception is None
59+
or init_parameters.get("read_variant") is ReadVariant.ReadOnly
60+
)
4561

4662

4763
@pytest.mark.anyio()

src/driver/transaction.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct RustTransaction {
2727

2828
isolation_level: Option<IsolationLevel>,
2929
read_variant: Option<ReadVariant>,
30-
deferrable: Option<bool>,
30+
deferable: Option<bool>,
3131
cursor_num: usize,
3232
}
3333

@@ -40,7 +40,7 @@ impl RustTransaction {
4040
rollback_savepoint: Arc<tokio::sync::RwLock<HashSet<String>>>,
4141
isolation_level: Option<IsolationLevel>,
4242
read_variant: Option<ReadVariant>,
43-
deferrable: Option<bool>,
43+
deferable: Option<bool>,
4444
cursor_num: usize,
4545
) -> Self {
4646
Self {
@@ -50,7 +50,7 @@ impl RustTransaction {
5050
rollback_savepoint,
5151
isolation_level,
5252
read_variant,
53-
deferrable,
53+
deferable,
5454
cursor_num,
5555
}
5656
}
@@ -108,7 +108,7 @@ impl RustTransaction {
108108

109109
/// Start transaction
110110
/// Set up isolation level if specified
111-
/// Set up deferrable if specified
111+
/// Set up deferable if specified
112112
///
113113
/// # Errors
114114
/// May return Err Result if cannot execute querystring.
@@ -124,7 +124,7 @@ impl RustTransaction {
124124
querystring.push_str(format!(" {}", &read_var.to_str_option()).as_str());
125125
}
126126

127-
if self.deferrable.is_some() {
127+
if self.deferable.is_some() {
128128
querystring.push_str(" DEFERRABLE");
129129
} else {
130130
querystring.push_str(" NOT DEFERRABLE");

0 commit comments

Comments
 (0)