/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.155.3 by James Westby
Add some tests for the hook, rename the option to "upload_auto"
1
# Copyright (C) 2008 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
17
import os
18
19
from bzrlib.branch import Branch
20
from bzrlib.tests import TestCaseWithTransport
21
22
from bzrlib.plugins.upload import set_upload_location, set_upload_auto
23
from bzrlib.plugins.upload.auto_upload_hook import auto_upload_hook
24
25
# Hooks are disabled during tests, so that they don't cause havoc
26
# with a users system. What we will test is that the hook was
27
# correctly registered, and then set up the scenarios and trigger
28
# it manually
29
30
class AutoPushHookTests(TestCaseWithTransport):
31
32
    def make_start_branch(self, location=True, auto=True):
33
        self.wt = self.make_branch_and_tree('.')
34
        self.build_tree(['a'])
35
        self.wt.add(['a'])
36
        self.wt.commit("one")
37
        if location:
38
            set_upload_location(self.wt.branch, self.target_location())
39
        if auto:
40
            set_upload_auto(self.wt.branch, True)
41
42
    def target_location(self):
43
        return self.get_url('target')
44
45
    def get_params(self):
46
        class FakeParams(object):
47
            def __init__(self, branch):
48
                self.branch = branch
49
        return FakeParams(self.wt.branch)
50
51
    def test_hook_is_registered(self):
52
        # Hooks are stored in self._preserved_hooks
53
        self.assertTrue(auto_upload_hook in 
54
                self._preserved_hooks[Branch]['post_change_branch_tip'])
55
56
    def test_auto_push_on_commit(self):
57
        self.make_start_branch()
58
        self.failIfExists('target')
59
        self.build_tree(['b'])
60
        self.wt.add(['b'])
61
        self.wt.commit("two")
62
        auto_upload_hook(self.get_params(), quiet=True)
63
        self.failUnlessExists('target')
64
        self.failUnlessExists(os.path.join('target', 'a'))
65
        self.failUnlessExists(os.path.join('target', 'b'))
66
67
    def test_disable_auto_push(self):
68
        self.make_start_branch()
69
        self.failIfExists('target')
70
        self.build_tree(['b'])
71
        self.wt.add(['b'])
72
        self.wt.commit("two")
73
        auto_upload_hook(self.get_params(), quiet=True)
74
        set_upload_auto(self.wt.branch, False)
75
        self.build_tree(['c'])
76
        self.wt.add(['c'])
77
        self.wt.commit("three")
78
        auto_upload_hook(self.get_params(), quiet=True)
79
        self.failIfExists(os.path.join('target', 'c'))
80
81
    def test_dont_push_if_no_location(self):
82
        self.make_start_branch(location=False)
83
        self.failIfExists('target')
84
        self.build_tree(['b'])
85
        self.wt.add(['b'])
86
        self.wt.commit("two")
87
        auto_upload_hook(self.get_params(), quiet=True)
88
        self.failIfExists('target')
89