1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
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
"""Black-box tests for bzr sign-my-commits."""
23
from bzrlib.testament import Testament
24
from bzrlib.tests import TestCaseWithTransport
25
from bzrlib.workingtree import WorkingTree
28
class SignMyCommits(TestCaseWithTransport):
30
def monkey_patch_gpg(self):
31
"""Monkey patch the gpg signing strategy to be a loopback.
33
This also registers the cleanup, so that we will revert to
34
the original gpg strategy when done.
36
self._oldstrategy = bzrlib.gpg.GPGStrategy
38
# monkey patch gpg signing mechanism
39
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
41
self.addCleanup(self._fix_gpg_strategy)
43
def _fix_gpg_strategy(self):
44
bzrlib.gpg.GPGStrategy = self._oldstrategy
46
def setup_tree(self, location='.'):
47
wt = self.make_branch_and_tree(location)
48
wt.commit("base A", allow_pointless=True, rev_id='A')
49
wt.commit("base B", allow_pointless=True, rev_id='B')
50
wt.commit("base C", allow_pointless=True, rev_id='C')
51
wt.commit("base D", allow_pointless=True, rev_id='D',
52
committer='Alternate <alt@foo.com>')
56
def test_sign_my_commits(self):
57
#Test re signing of data.
58
wt = self.setup_tree()
59
repo = wt.branch.repository
61
self.monkey_patch_gpg()
63
self.assertFalse(repo.revision_store.has_id('A', 'sig'))
64
self.assertFalse(repo.revision_store.has_id('B', 'sig'))
65
self.assertFalse(repo.revision_store.has_id('C', 'sig'))
66
self.assertFalse(repo.revision_store.has_id('D', 'sig'))
68
self.run_bzr('sign-my-commits')
70
self.assertTrue(repo.revision_store.has_id('A', 'sig'))
71
self.assertTrue(repo.revision_store.has_id('B', 'sig'))
72
self.assertTrue(repo.revision_store.has_id('C', 'sig'))
73
self.assertFalse(repo.revision_store.has_id('D', 'sig'))
75
def test_sign_my_commits_location(self):
76
wt = self.setup_tree('other')
77
repo = wt.branch.repository
79
self.monkey_patch_gpg()
81
self.run_bzr('sign-my-commits', 'other')
83
self.assertTrue(repo.revision_store.has_id('A', 'sig'))
84
self.assertTrue(repo.revision_store.has_id('B', 'sig'))
85
self.assertTrue(repo.revision_store.has_id('C', 'sig'))
86
self.assertFalse(repo.revision_store.has_id('D', 'sig'))
88
def test_sign_diff_committer(self):
89
wt = self.setup_tree()
90
repo = wt.branch.repository
92
self.monkey_patch_gpg()
94
self.run_bzr('sign-my-commits', '.', 'Alternate <alt@foo.com>')
96
self.assertFalse(repo.revision_store.has_id('A', 'sig'))
97
self.assertFalse(repo.revision_store.has_id('B', 'sig'))
98
self.assertFalse(repo.revision_store.has_id('C', 'sig'))
99
self.assertTrue(repo.revision_store.has_id('D', 'sig'))
101
def test_sign_dry_run(self):
102
wt = self.setup_tree()
103
repo = wt.branch.repository
105
self.monkey_patch_gpg()
107
out = self.run_bzr('sign-my-commits', '--dry-run')[0]
109
self.assertEquals('A\nB\nC\nSigned 3 revisions\n', out)
110
self.assertFalse(repo.revision_store.has_id('A', 'sig'))
111
self.assertFalse(repo.revision_store.has_id('B', 'sig'))
112
self.assertFalse(repo.revision_store.has_id('C', 'sig'))
113
self.assertFalse(repo.revision_store.has_id('D', 'sig'))