/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
1
# Copyright (C) 2007 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
2245.1.2 by Robert Collins
Remove the static DefaultHooks method from Branch, replacing it with a derived dict BranchHooks object, which is easier to use and provides a place to put the policy-checking add method discussed on list.
17
"""Tests that branch classes implement hook callouts correctly."""
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
18
19
from bzrlib.branch import Branch
20
from bzrlib.tests import TestCaseWithMemoryTransport
21
22
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
23
class TestSetRevisionHistoryHook(TestCaseWithMemoryTransport):
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
24
25
    def setUp(self):
26
        self.hook_calls = []
27
        TestCaseWithMemoryTransport.setUp(self)
28
29
    def capture_set_rh_hook(self, branch, rev_history):
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
30
        """Capture post set-rh hook calls to self.hook_calls.
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
31
        
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
32
        The call is logged, as is some state of the branch.
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
33
        """
34
        self.hook_calls.append(
35
            ('set_rh', branch, rev_history, branch.is_locked()))
36
37
    def test_set_rh_empty_history(self):
38
        branch = self.make_branch('source')
3256.2.15 by Daniel Watkins
Updated uses of Hooks.install_hook to Hooks.install_named_hook in tests.branch_implementation.test_hooks.
39
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
40
                                        None)
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
41
        branch.set_revision_history([])
42
        self.assertEqual(self.hook_calls,
43
            [('set_rh', branch, [], True)])
44
45
    def test_set_rh_nonempty_history(self):
2230.3.20 by Aaron Bentley
Add hooking for set_revision_history
46
        tree = self.make_branch_and_memory_tree('source')
47
        tree.lock_write()
48
        tree.add('')
2696.3.7 by Martin Pool
Update hook test to cope with branches that can't set their last revision to one that's not present
49
        tree.commit('another commit', rev_id='f\xc2\xb5')
2230.3.20 by Aaron Bentley
Add hooking for set_revision_history
50
        tree.commit('empty commit', rev_id='foo')
51
        tree.unlock()
52
        branch = tree.branch
3256.2.15 by Daniel Watkins
Updated uses of Hooks.install_hook to Hooks.install_named_hook in tests.branch_implementation.test_hooks.
53
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
54
                                        None)
2696.3.7 by Martin Pool
Update hook test to cope with branches that can't set their last revision to one that's not present
55
        # some branches require that their history be set to a revision in the
56
        # repository
2309.4.10 by John Arbash Meinel
(fixed) Fix the last few tests that were explicitly passing around unicode ids
57
        branch.set_revision_history(['f\xc2\xb5'])
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
58
        self.assertEqual(self.hook_calls,
2309.4.10 by John Arbash Meinel
(fixed) Fix the last few tests that were explicitly passing around unicode ids
59
            [('set_rh', branch, ['f\xc2\xb5'], True)])
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
60
61
    def test_set_rh_branch_is_locked(self):
62
        branch = self.make_branch('source')
3256.2.15 by Daniel Watkins
Updated uses of Hooks.install_hook to Hooks.install_named_hook in tests.branch_implementation.test_hooks.
63
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
64
                                        None)
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
65
        branch.set_revision_history([])
66
        self.assertEqual(self.hook_calls,
67
            [('set_rh', branch, [], True)])
68
69
    def test_set_rh_calls_all_hooks_no_errors(self):
70
        branch = self.make_branch('source')
3256.2.15 by Daniel Watkins
Updated uses of Hooks.install_hook to Hooks.install_named_hook in tests.branch_implementation.test_hooks.
71
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
72
                                        None)
73
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
74
                                        None)
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
75
        branch.set_revision_history([])
76
        self.assertEqual(self.hook_calls,
77
            [('set_rh', branch, [], True),
78
             ('set_rh', branch, [], True),
79
            ])