~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_sign_my_commits.py

[merge] bump up sign-my-commits

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
 
 
19
"""Black-box tests for bzr sign-my-commits.
 
20
"""
 
21
 
 
22
import os
 
23
 
 
24
import bzrlib.gpg
 
25
from bzrlib.testament import Testament
 
26
from bzrlib.tests import TestCaseInTempDir
 
27
from bzrlib.workingtree import WorkingTree
 
28
 
 
29
 
 
30
class SignMyCommits(TestCaseInTempDir):
 
31
 
 
32
    def monkey_patch_gpg(self):
 
33
        """Monkey patch the gpg signing strategy to be a loopback.
 
34
 
 
35
        This also registers the cleanup, so that we will revert to
 
36
        the original gpg strategy when done.
 
37
        """
 
38
        self._oldstrategy = bzrlib.gpg.GPGStrategy
 
39
 
 
40
        # monkey patch gpg signing mechanism
 
41
        bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
 
42
 
 
43
        self.addCleanup(self._fix_gpg_strategy)
 
44
 
 
45
    def _fix_gpg_strategy(self):
 
46
        bzrlib.gpg.GPGStrategy = self._oldstrategy
 
47
 
 
48
    def setup_tree(self):
 
49
        wt = WorkingTree.create_standalone('.')
 
50
        wt.commit("base A", allow_pointless=True, rev_id='A')
 
51
        wt.commit("base B", allow_pointless=True, rev_id='B')
 
52
        wt.commit("base C", allow_pointless=True, rev_id='C')
 
53
        wt.commit("base D", allow_pointless=True, rev_id='D',
 
54
                committer='Alternate <alt@foo.com>')
 
55
 
 
56
        return wt
 
57
 
 
58
    def test_sign_my_commits(self):
 
59
        #Test re signing of data.
 
60
        wt = self.setup_tree()
 
61
        repo = wt.branch.repository
 
62
 
 
63
        self.monkey_patch_gpg()
 
64
 
 
65
        self.assertFalse(repo.revision_store.has_id('A', 'sig'))
 
66
        self.assertFalse(repo.revision_store.has_id('B', 'sig'))
 
67
        self.assertFalse(repo.revision_store.has_id('C', 'sig'))
 
68
        self.assertFalse(repo.revision_store.has_id('D', 'sig'))
 
69
 
 
70
        self.run_bzr('sign-my-commits')
 
71
 
 
72
        self.assertTrue(repo.revision_store.has_id('A', 'sig'))
 
73
        self.assertTrue(repo.revision_store.has_id('B', 'sig'))
 
74
        self.assertTrue(repo.revision_store.has_id('C', 'sig'))
 
75
        self.assertFalse(repo.revision_store.has_id('D', 'sig'))
 
76
            
 
77
    def test_sign_my_commits_location(self):
 
78
        os.mkdir('other')
 
79
        os.chdir('other')
 
80
        wt = self.setup_tree()
 
81
        repo = wt.branch.repository
 
82
        os.chdir('..')
 
83
 
 
84
        self.monkey_patch_gpg()
 
85
 
 
86
        self.run_bzr('sign-my-commits', 'other')
 
87
 
 
88
        self.assertTrue(repo.revision_store.has_id('A', 'sig'))
 
89
        self.assertTrue(repo.revision_store.has_id('B', 'sig'))
 
90
        self.assertTrue(repo.revision_store.has_id('C', 'sig'))
 
91
        self.assertFalse(repo.revision_store.has_id('D', 'sig'))
 
92
 
 
93
    def test_sign_diff_committer(self):
 
94
        wt = self.setup_tree()
 
95
        repo = wt.branch.repository
 
96
 
 
97
        self.monkey_patch_gpg()
 
98
 
 
99
        self.run_bzr('sign-my-commits', '.', 'Alternate <alt@foo.com>')
 
100
 
 
101
        self.assertFalse(repo.revision_store.has_id('A', 'sig'))
 
102
        self.assertFalse(repo.revision_store.has_id('B', 'sig'))
 
103
        self.assertFalse(repo.revision_store.has_id('C', 'sig'))
 
104
        self.assertTrue(repo.revision_store.has_id('D', 'sig'))
 
105
 
 
106
    def test_sign_dry_run(self):
 
107
        wt = self.setup_tree()
 
108
        repo = wt.branch.repository
 
109
 
 
110
        self.monkey_patch_gpg()
 
111
 
 
112
        out = self.run_bzr('sign-my-commits', '--dry-run')[0]
 
113
 
 
114
        self.assertEquals('A\nB\nC\nSigned 3 revisions\n', out)
 
115
        self.assertFalse(repo.revision_store.has_id('A', 'sig'))
 
116
        self.assertFalse(repo.revision_store.has_id('B', 'sig'))
 
117
        self.assertFalse(repo.revision_store.has_id('C', 'sig'))
 
118
        self.assertFalse(repo.revision_store.has_id('D', 'sig'))
 
119