Skip to content

Commit a37268b

Browse files
committed
Add tests.
1 parent 6b662fc commit a37268b

File tree

5 files changed

+119
-3
lines changed

5 files changed

+119
-3
lines changed

tests/test_edgeql_delete.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,3 +665,22 @@ async def test_edgeql_delete_where_order_dml(self):
665665
(DELETE DeleteTest filter .name = 't1')
666666
limit 1
667667
''')
668+
669+
async def test_edgeql_delete_read_only_tx_01(self):
670+
con = (
671+
edgedb.create_async_client(
672+
**self.get_connect_args(database=self.con.dbname)
673+
).with_transaction_options(
674+
edgedb.TransactionOptions(readonly=True)
675+
)
676+
)
677+
try:
678+
with self.assertRaisesRegex(
679+
edgedb.TransactionError,
680+
r'Modifications not allowed in a read-only transaction'
681+
):
682+
async for tx in con.transaction():
683+
async with tx:
684+
await tx.execute("delete DeleteTest")
685+
finally:
686+
await con.aclose()

tests/test_edgeql_functions_inline.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11576,3 +11576,34 @@ async def reset_data():
1157611576
'select Bar.a',
1157711577
[3],
1157811578
)
11579+
11580+
11581+
class TestEdgeQLFunctionsInlineTransaction(tb.QueryTestCase):
11582+
11583+
SETUP = [
11584+
'''
11585+
create type Bar;
11586+
create function foo() -> Bar {
11587+
using ((insert Bar));
11588+
};
11589+
'''
11590+
]
11591+
11592+
async def test_edgeql_functions_inline_transaction_dml_01(self):
11593+
con = (
11594+
edgedb.create_async_client(
11595+
**self.get_connect_args(database=self.con.dbname)
11596+
).with_transaction_options(
11597+
edgedb.TransactionOptions(readonly=True)
11598+
)
11599+
)
11600+
try:
11601+
with self.assertRaisesRegex(
11602+
edgedb.TransactionError,
11603+
r'Modifications not allowed in a read-only transaction'
11604+
):
11605+
async for tx in con.transaction():
11606+
async with tx:
11607+
await tx.execute("select foo()")
11608+
finally:
11609+
await con.aclose()

tests/test_edgeql_insert.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7948,6 +7948,48 @@ async def test_edgeql_insert_empty_array_05(self):
79487948
[{'l2': 0, 'subordinates': [{'name': 'hi', '@comment': 'a'}]}],
79497949
)
79507950

7951+
async def test_edgeql_insert_read_only_tx_01(self):
7952+
con = (
7953+
edgedb.create_async_client(
7954+
**self.get_connect_args(database=self.con.dbname)
7955+
).with_transaction_options(
7956+
edgedb.TransactionOptions(readonly=True)
7957+
)
7958+
)
7959+
try:
7960+
with self.assertRaisesRegex(
7961+
edgedb.TransactionError,
7962+
r'Modifications not allowed in a read-only transaction'
7963+
):
7964+
async for tx in con.transaction():
7965+
async with tx:
7966+
await tx.execute("insert Subordinate { name := 'hi' }")
7967+
finally:
7968+
await con.aclose()
7969+
7970+
async def test_edgeql_insert_read_only_tx_02(self):
7971+
# Check that the error is raised if the query is cached.
7972+
7973+
await self.con.execute("insert Subordinate { name := 'hi' }")
7974+
7975+
con = (
7976+
edgedb.create_async_client(
7977+
**self.get_connect_args(database=self.con.dbname)
7978+
).with_transaction_options(
7979+
edgedb.TransactionOptions(readonly=True)
7980+
)
7981+
)
7982+
try:
7983+
with self.assertRaisesRegex(
7984+
edgedb.TransactionError,
7985+
r'Modifications not allowed in a read-only transaction'
7986+
):
7987+
async for tx in con.transaction():
7988+
async with tx:
7989+
await tx.execute("insert Subordinate { name := 'hi' }")
7990+
finally:
7991+
await con.aclose()
7992+
79517993

79527994
class TestRepeatableReadInsert(tb.QueryTestCase):
79537995
'''The scope of the tests is testing various modes of Object creation.'''

tests/test_edgeql_update.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4007,3 +4007,24 @@ async def test_edgeql_update_empty_array_05(self):
40074007
},
40084008
],
40094009
)
4010+
4011+
async def test_edgeql_update_read_only_tx_01(self):
4012+
con = (
4013+
edgedb.create_async_client(
4014+
**self.get_connect_args(database=self.con.dbname)
4015+
).with_transaction_options(
4016+
edgedb.TransactionOptions(readonly=True)
4017+
)
4018+
)
4019+
try:
4020+
with self.assertRaisesRegex(
4021+
edgedb.TransactionError,
4022+
r'Modifications not allowed in a read-only transaction'
4023+
):
4024+
async for tx in con.transaction():
4025+
async with tx:
4026+
await tx.execute(
4027+
"update UpdateTest set { comment := 'hi' }"
4028+
)
4029+
finally:
4030+
await con.aclose()

tests/test_server_proto.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,8 +1568,9 @@ async def test_server_proto_tx_07(self):
15681568
''')
15691569

15701570
with self.assertRaisesRegex(
1571-
edgedb.TransactionError,
1572-
'read-only transaction'):
1571+
edgedb.TransactionError,
1572+
'Modifications not allowed in a read-only transaction'
1573+
):
15731574

15741575
await self.con.query('''
15751576
INSERT Tmp {
@@ -2344,7 +2345,9 @@ async def test_server_proto_tx_31(self):
23442345
await self.assert_tx_isolation_and_default(
23452346
'RepeatableRead', default='Serializable'
23462347
)
2347-
await self.assert_read_only_and_default('read-only transaction')
2348+
await self.assert_read_only_and_default(
2349+
'Modifications not allowed in a read-only transaction'
2350+
)
23482351
finally:
23492352
await self.con.query(f'''
23502353
ROLLBACK;

0 commit comments

Comments
 (0)