13003.1.1
by Aaron Bentley
Ensure that branch upgrade does not hold a database transaction. |
1 |
# Copyright 2011 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Test the helpers."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
from testtools.testcase import ExpectedException |
|
9 |
import transaction |
|
10 |
||
11 |
from lp.testing import TestCase |
|
12 |
from lp.scripts.helpers import TransactionFreeOperation |
|
13 |
||
14 |
||
15 |
class TestTransactionFreeOperation(TestCase): |
|
16 |
||
17 |
def setUp(self): |
|
18 |
"""We can ignore transactions in general, but this test case cares."""
|
|
19 |
super(TestTransactionFreeOperation, self).setUp() |
|
20 |
transaction.abort() |
|
21 |
||
22 |
def test_pending_transaction(self): |
|
23 |
"""When a transaction is pending before the operation, raise."""
|
|
24 |
transaction.begin() |
|
25 |
with ExpectedException( |
|
26 |
AssertionError, 'Transaction open before operation'): |
|
27 |
with TransactionFreeOperation: |
|
28 |
pass
|
|
29 |
||
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: |
|
35 |
transaction.begin() |
|
36 |
||
37 |
def test_transaction_free(self): |
|
38 |
"""When there are no transactions, do not raise."""
|
|
39 |
with TransactionFreeOperation: |
|
40 |
pass
|
|
41 |
||
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(): |
|
47 |
pass
|
|
48 |
||
49 |
def test_require_with_TransactionFreeOperation(self): |
|
50 |
"""If TransactionFreeOperation is used, do not raise."""
|
|
51 |
with TransactionFreeOperation.require(): |
|
52 |
with TransactionFreeOperation: |
|
53 |
pass
|