1
# Copyright (C) 2005 by Canonical Ltd
 
 
2
#   Authors: Robert Collins <robert.collins@canonical.com>
 
 
4
# This program is free software; you can redistribute it and/or modify
 
 
5
# it under the terms of the GNU General Public License as published by
 
 
6
# the Free Software Foundation; either version 2 of the License, or
 
 
7
# (at your option) any later version.
 
 
9
# This program is distributed in the hope that it will be useful,
 
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 
12
# GNU General Public License for more details.
 
 
14
# You should have received a copy of the GNU General Public License
 
 
15
# along with this program; if not, write to the Free Software
 
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
18
"""Tests for the behaviour of the Transaction concept in bzr."""
 
 
20
# import system imports here
 
 
24
#import bzrlib specific imports here
 
 
25
import bzrlib.errors as errors
 
 
26
from bzrlib.selftest import TestCase, TestCaseInTempDir
 
 
27
import bzrlib.transactions as transactions
 
 
30
class TestReadOnlyTransaction(TestCase):
 
 
32
    def test_symbols(self):
 
 
33
        from bzrlib.transactions import ReadOnlyTransaction
 
 
35
    def test_construct(self):
 
 
36
        transactions.ReadOnlyTransaction()
 
 
38
    def test_register_clean(self):
 
 
39
        transaction = transactions.ReadOnlyTransaction()
 
 
40
        transaction.register_clean("anobject")
 
 
42
    def test_register_dirty_raises(self):
 
 
43
        transaction = transactions.ReadOnlyTransaction()
 
 
44
        self.assertRaises(errors.ReadOnlyError, 
 
 
45
                          transaction.register_dirty,"anobject")
 
 
47
    def test_commit_raises(self):
 
 
48
        transaction = transactions.ReadOnlyTransaction()
 
 
49
        self.assertRaises(errors.CommitNotPossible, transaction.commit)
 
 
52
        transaction = transactions.ReadOnlyTransaction()
 
 
53
        self.assertNotEqual(None, getattr(transaction, "map", None))
 
 
55
    def test_add_and_get(self):
 
 
56
        transaction = transactions.ReadOnlyTransaction()
 
 
58
        transaction.map.add_weave("id", weave)
 
 
59
        self.assertEqual(weave, transaction.map.find_weave("id"))
 
 
61
    def test_rollback_returns(self):
 
 
62
        transaction = transactions.ReadOnlyTransaction()
 
 
63
        transaction.rollback()
 
 
65
    def test_finish_returns(self):
 
 
66
        transaction = transactions.ReadOnlyTransaction()
 
 
70
class TestPassThroughTransaction(TestCase):
 
 
72
    def test_symbols(self):
 
 
73
        from bzrlib.transactions import PassThroughTransaction
 
 
75
    def test_construct(self):
 
 
76
        transactions.PassThroughTransaction()
 
 
78
    def test_register_clean(self):
 
 
79
        transaction = transactions.PassThroughTransaction()
 
 
80
        transaction.register_clean("anobject")
 
 
82
    def test_register_dirty(self):
 
 
83
        transaction = transactions.PassThroughTransaction()
 
 
84
        transaction.register_dirty("anobject")
 
 
86
    def test_commit_nothing_returns(self):
 
 
87
        transaction = transactions.PassThroughTransaction()
 
 
91
        transaction = transactions.PassThroughTransaction()
 
 
92
        self.assertNotEqual(None, getattr(transaction, "map", None))
 
 
94
    def test_add_and_get(self):
 
 
95
        transaction = transactions.PassThroughTransaction()
 
 
97
        transaction.map.add_weave("id", weave)
 
 
98
        self.assertEqual(None, transaction.map.find_weave("id"))
 
 
100
    def test_rollback_asserts(self):
 
 
101
        transaction = transactions.PassThroughTransaction()
 
 
102
        self.assertRaises(errors.AlreadyCommitted, transaction.rollback)
 
 
104
    def test_finish_returns(self):
 
 
105
        transaction = transactions.PassThroughTransaction()