~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005 Canonical Ltd
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
2
# -*- coding: utf-8 -*-
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
3
#
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
8
#
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
13
#
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
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
1185.78.5 by John Arbash Meinel
Fix doc bug
19
"""Black-box tests for bzr re-sign.
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
20
"""
21
22
import os
23
24
import bzrlib.gpg
1558.1.3 by Aaron Bentley
Fixed deprecated op use in test suite
25
from bzrlib.bzrdir import BzrDir
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
26
from bzrlib.testament import Testament
27
from bzrlib.tests import TestCaseInTempDir
28
29
30
class ReSign(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):
1558.1.3 by Aaron Bentley
Fixed deprecated op use in test suite
49
        wt = BzrDir.create_standalone_workingtree('.')
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
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
54
        return wt
55
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
56
    def assertEqualSignature(self, repo, revision_id):
57
        """Assert a signature is stored correctly in repository."""
58
        self.assertEqual(
1551.12.36 by Aaron Bentley
Fix failing tests
59
            '-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
60
            Testament.from_revision(repo, revision_id).as_short_text() +
1551.12.52 by Aaron Bentley
speling fix
61
            '-----END PSEUDO-SIGNED CONTENT-----\n',
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
62
            repo.get_signature_text(revision_id))
63
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
64
    def test_resign(self):
65
        #Test re signing of data.
66
        wt = self.setup_tree()
67
        repo = wt.branch.repository
68
69
        self.monkey_patch_gpg()
70
        self.run_bzr('re-sign', '-r', 'revid:A')
71
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
72
        self.assertEqualSignature(repo, 'A')
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
73
74
        self.run_bzr('re-sign', 'B')
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
75
        self.assertEqualSignature(repo, 'B')
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
76
            
77
    def test_resign_range(self):
78
        wt = self.setup_tree()
79
        repo = wt.branch.repository
80
81
        self.monkey_patch_gpg()
82
        self.run_bzr('re-sign', '-r', '1..')
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
83
        self.assertEqualSignature(repo, 'A')
84
        self.assertEqualSignature(repo, 'B')
85
        self.assertEqualSignature(repo, 'C')
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
86
87
    def test_resign_multiple(self):
88
        wt = self.setup_tree()
89
        repo = wt.branch.repository
90
91
        self.monkey_patch_gpg()
92
        self.run_bzr('re-sign', 'A', 'B', 'C')
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
93
        self.assertEqualSignature(repo, 'A')
94
        self.assertEqualSignature(repo, 'B')
95
        self.assertEqualSignature(repo, 'C')