Skip to content

Commit

Permalink
Merge aa8a5b9 into 464c32e
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Sep 5, 2019
2 parents 464c32e + aa8a5b9 commit e7a4687
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 133 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Expand Up @@ -16,6 +16,12 @@
retried. Previously, an error there would probably be raised
*anyway* and not retried, unless a subclass had made customizations.

- Add ``setUp`` and ``tearDown`` methods to TransactionLoop to give
subclasses a place to hook into the inners of the transaction loop.
This is particularly helpful if they need to do something after the
transaction manager has been put in explicit mode. See `issue 22
<https://github.com/NextThought/nti.transactions/issues/22>`_.

2.0.1 (2019-09-03)
==================

Expand Down
29 changes: 24 additions & 5 deletions src/nti/transactions/tests/test_transaction.py
Expand Up @@ -40,7 +40,7 @@ class RaisingCommit(object):
def __init__(self, t=Exception):
self.t = t

def commit(self):
def nti_commit(self):
if self.t:
raise self.t

Expand Down 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 Expand Up @@ -186,7 +205,7 @@ def test_note(self, fake_begin, fake_get):
fake_tx = fudge.Fake()
(fake_tx
.expects('note').with_args(u'Hi')
.expects('abort')
.expects('nti_abort')
.provides('isDoomed').returns(True))
fake_begin.expects_call().returns(fake_tx)
fake_get.expects_call().returns(fake_tx)
Expand All @@ -202,7 +221,7 @@ def describe_transaction(self, *args, **kwargs):
'transaction._manager.TransactionManager.get')
def test_abort_no_side_effect(self, fake_begin, fake_get):
fake_tx = fudge.Fake()
fake_tx.expects('abort')
fake_tx.expects('nti_abort')

fake_begin.expects_call().returns(fake_tx)
fake_get.expects_call().returns(fake_tx)
Expand All @@ -214,7 +233,7 @@ class Loop(TransactionLoop):
result = Loop(lambda: 42)()
assert_that(result, is_(42))

@fudge.patch('transaction._transaction.Transaction.abort')
@fudge.patch('transaction._transaction.Transaction.nti_abort')
def test_abort_doomed(self, fake_abort):
fake_abort.expects_call()

Expand All @@ -230,7 +249,7 @@ def handler():
'transaction._manager.TransactionManager.get')
def test_abort_veto(self, fake_begin, fake_get):
fake_tx = fudge.Fake()
fake_tx.expects('abort')
fake_tx.expects('nti_abort')
fake_tx.provides('isDoomed').returns(False)

fake_begin.expects_call().returns(fake_tx)
Expand Down

0 comments on commit e7a4687

Please sign in to comment.