1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Test the helpers."""
8
from testtools.testcase import ExpectedException
11
from lp.testing import TestCase
12
from lp.scripts.helpers import TransactionFreeOperation
15
class TestTransactionFreeOperation(TestCase):
18
"""We can ignore transactions in general, but this test case cares."""
19
super(TestTransactionFreeOperation, self).setUp()
22
def test_pending_transaction(self):
23
"""When a transaction is pending before the operation, raise."""
25
with ExpectedException(
26
AssertionError, 'Transaction open before operation'):
27
with TransactionFreeOperation:
30
def test_transaction_during_operation(self):
31
"""When the operation creates a transaction, raise."""
32
with ExpectedException(
33
AssertionError, 'Operation opened transaction!'):
34
with TransactionFreeOperation:
37
def test_transaction_free(self):
38
"""When there are no transactions, do not raise."""
39
with TransactionFreeOperation:
42
def test_require_no_TransactionFreeOperation(self):
43
"""If TransactionFreeOperation is not used, raise."""
44
with ExpectedException(
45
AssertionError, 'TransactionFreeOperation was not used.'):
46
with TransactionFreeOperation.require():
49
def test_require_with_TransactionFreeOperation(self):
50
"""If TransactionFreeOperation is used, do not raise."""
51
with TransactionFreeOperation.require():
52
with TransactionFreeOperation: