Skip to content

Commit

Permalink
adding tests for committing nesting transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfunley committed Mar 13, 2022
1 parent 5c16c6a commit d43de3a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/sql/postgres/upsert_foo.sql
@@ -0,0 +1,4 @@
-- :name upsert_foo :affected
insert into test.test (id, foo)
values (:id, :foo)
on conflict (id) do update set foo = excluded.foo
24 changes: 24 additions & 0 deletions tests/test_postgres.py
Expand Up @@ -36,3 +36,27 @@ def test_where_in(self):

ids = [r['id'] for r in self.fixtures.where_in(foo=('abcd', '99999',))]
self.assertEqual({ 1, 2 }, set(ids))

def test_transaction(self):
with self.fixtures.transaction():
self.fixtures.upsert_foo(id=1, foo='abcd')
self.assertEqual('abcd', self.fixtures.get_foo(id=1))

def test_nested_transactions(self):
with self.fixtures.transaction():
self.fixtures.upsert_foo(id=1, foo='abcd')

with self.fixtures.transaction():
self.fixtures.upsert_foo(id=1, foo='bar')

self.assertEqual('bar', self.fixtures.get_foo(id=1))

def test_rolling_back_nested_transactions(self):
with self.fixtures.transaction():
self.fixtures.upsert_foo(id=1, foo='abcd')

with self.fixtures.transaction() as t:
self.fixtures.upsert_foo(id=1, foo='bar')
t.rollback()

self.assertEqual('abcd', self.fixtures.get_foo(id=1))

0 comments on commit d43de3a

Please sign in to comment.