Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_transaction_readonly_oldstyle(engine):
with (await engine) as cur:
tr = Transaction(cur, IsolationLevel.serializable, readonly=True)
await tr.begin()
resp = await cur.execute('select * from tbl where id = 22')
row = await resp.fetchone()
assert row.id == 22
assert row.name == 'read only'
await tr.commit()
async def two_commit(cur):
tr = Transaction(cur, IsolationLevel.read_committed)
await tr.begin()
await tr.commit()
await tr.commit()
async def two_begin(cur):
tr = Transaction(cur, IsolationLevel.read_committed)
await tr.begin()
await tr.begin()
async def e_savepoint(cur):
tr = Transaction(cur, IsolationLevel.read_committed)
await tr.savepoint()
async def two_rollback(cur):
tr = Transaction(cur, IsolationLevel.read_committed)
await tr.begin()
await tr.rollback()
await tr.rollback()
def test_transaction_value_error():
with pytest.raises(ValueError):
Transaction(None, IsolationLevel.read_committed, readonly=True)
async def e_rollback_savepoint(cur):
tr = Transaction(cur, IsolationLevel.read_committed)
await tr.rollback_savepoint()
async def test_transaction_rollback(engine):
async with engine.cursor() as cur:
with pytest.raises(psycopg2.DataError):
async with Transaction(cur, IsolationLevel.read_committed):
await cur.execute("insert into tbl values(1/0, 'no data')")
await cur.execute('select * from tbl')
row = await cur.fetchall()
assert row == [(22, 'read only'), ]
async def test_transaction_point_oldstyle(engine):
with (await engine) as cur:
tr = Transaction(cur, IsolationLevel.read_committed)
await tr.begin()
await cur.execute("insert into tbl values(1, 'data')")
try:
await tr.savepoint()
await cur.execute("insert into tbl values(1/0, 'no data')")
except psycopg2.DataError:
await tr.rollback_savepoint()
await tr.savepoint()
await cur.execute("insert into tbl values(2, 'data')")
await tr.release_savepoint()
await cur.execute("insert into tbl values(3, 'data')")
async def e_release_savepoint(cur):
tr = Transaction(cur, IsolationLevel.read_committed)
await tr.release_savepoint()