~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-03-08 14:31:23 UTC
  • mfrom: (1598 +trunk)
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060308143123-448308b0db4de410
[merge] bzr.dev 1573, lots of updates

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