Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Sep 5, 2019
1 parent 0a04f5a commit aa8a5b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/nti/transactions/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ def handler():

assert_that(calling(TransactionLoop(handler)), raises(ForeignTransactionError))

def test_setup_teardown(self):

class Loop(TransactionLoop):
setupcalled = teardowncalled = False
def setUp(self):
assert_that(transaction.manager, has_property('explicit', is_true()))
self.setupcalled = True
def tearDown(self):
self.teardowncalled = True

def handler():
raise Exception

loop = Loop(handler)
assert_that(calling(loop), raises(Exception))

assert_that(loop, has_property('setupcalled', is_true()))
assert_that(loop, has_property('teardowncalled', is_true()))

def test_retriable(self, loop_class=TransactionLoop, exc_type=TransientError):

calls = []
Expand Down
1 change: 1 addition & 0 deletions src/nti/transactions/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ def __call__(self, *args, **kwargs):
return self.__loop(txm, note, args, kwargs)
finally:
txm.explicit = was_explicit
self.tearDown()

def __loop(self, txm, note, args, kwargs):
number = self.attempts
Expand Down

0 comments on commit aa8a5b9

Please sign in to comment.