~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
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009-2013, 2016 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
"""Black-box tests for bzr sign-my-commits."""
19
19
 
20
 
from bzrlib import (
21
 
    gpg,
22
 
    tests,
23
 
    )
24
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
25
 
 
26
 
 
27
 
class SignMyCommits(tests.TestCaseWithTransport):
 
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):
28
29
 
29
30
    def monkey_patch_gpg(self):
30
31
        """Monkey patch the gpg signing strategy to be a loopback.
32
33
        This also registers the cleanup, so that we will revert to
33
34
        the original gpg strategy when done.
34
35
        """
 
36
        self._oldstrategy = bzrlib.gpg.GPGStrategy
 
37
 
35
38
        # monkey patch gpg signing mechanism
36
 
        self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
 
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
37
45
 
38
46
    def setup_tree(self, location='.'):
39
47
        wt = self.make_branch_and_tree(location)
42
50
        wt.commit("base C", allow_pointless=True, rev_id='C')
43
51
        wt.commit("base D", allow_pointless=True, rev_id='D',
44
52
                committer='Alternate <alt@foo.com>')
45
 
        wt.add_parent_tree_id("aghost")
46
 
        wt.commit("base E", allow_pointless=True, rev_id='E')
 
53
 
47
54
        return wt
48
55
 
49
56
    def assertUnsigned(self, repo, revision_id):
72
79
        self.assertSigned(repo, 'B')
73
80
        self.assertSigned(repo, 'C')
74
81
        self.assertUnsigned(repo, 'D')
75
 
 
 
82
            
76
83
    def test_sign_my_commits_location(self):
77
84
        wt = self.setup_tree('other')
78
85
        repo = wt.branch.repository
107
114
 
108
115
        out = self.run_bzr('sign-my-commits --dry-run')[0]
109
116
 
110
 
        outlines = out.splitlines()
111
 
        self.assertEqual(5, len(outlines))
112
 
        self.assertEqual('Signed 4 revisions.', outlines[-1])
 
117
        self.assertEquals('A\nB\nC\nSigned 3 revisions\n', out)
113
118
        self.assertUnsigned(repo, 'A')
114
119
        self.assertUnsigned(repo, 'B')
115
120
        self.assertUnsigned(repo, 'C')
116
121
        self.assertUnsigned(repo, 'D')
117
 
        self.assertUnsigned(repo, 'E')
118
 
 
119
 
 
120
 
class TestSmartServerSignMyCommits(tests.TestCaseWithTransport):
121
 
 
122
 
    def monkey_patch_gpg(self):
123
 
        """Monkey patch the gpg signing strategy to be a loopback.
124
 
 
125
 
        This also registers the cleanup, so that we will revert to
126
 
        the original gpg strategy when done.
127
 
        """
128
 
        # monkey patch gpg signing mechanism
129
 
        self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
130
 
 
131
 
    def test_sign_single_commit(self):
132
 
        self.setup_smart_server_with_call_log()
133
 
        t = self.make_branch_and_tree('branch')
134
 
        self.build_tree_contents([('branch/foo', 'thecontents')])
135
 
        t.add("foo")
136
 
        t.commit("message")
137
 
        self.reset_smart_call_log()
138
 
        self.monkey_patch_gpg()
139
 
        out, err = self.run_bzr(['sign-my-commits', self.get_url('branch')])
140
 
        # This figure represent the amount of work to perform this use case. It
141
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
142
 
        # being too low. If rpc_count increases, more network roundtrips have
143
 
        # become necessary for this use case. Please do not adjust this number
144
 
        # upwards without agreement from bzr's network support maintainers.
145
 
        self.assertLength(15, self.hpss_calls)
146
 
        self.assertLength(1, self.hpss_connections)
147
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)