~bzr-pqm/bzr/bzr.dev

5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
1
# Copyright (C) 2005-2010 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
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
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
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
24
from bzrlib import (
25
    gpg,
26
    tests,
27
    )
1558.1.3 by Aaron Bentley
Fixed deprecated op use in test suite
28
from bzrlib.bzrdir import BzrDir
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
29
from bzrlib.testament import Testament
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
30
31
32
class ReSign(tests.TestCaseInTempDir):
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
33
34
    def monkey_patch_gpg(self):
35
        """Monkey patch the gpg signing strategy to be a loopback.
36
37
        This also registers the cleanup, so that we will revert to
38
        the original gpg strategy when done.
39
        """
40
        # monkey patch gpg signing mechanism
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
41
        self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
42
43
    def setup_tree(self):
1558.1.3 by Aaron Bentley
Fixed deprecated op use in test suite
44
        wt = BzrDir.create_standalone_workingtree('.')
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
45
        wt.commit("base A", allow_pointless=True, rev_id='A')
46
        wt.commit("base B", allow_pointless=True, rev_id='B')
47
        wt.commit("base C", allow_pointless=True, rev_id='C')
48
49
        return wt
50
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
51
    def assertEqualSignature(self, repo, revision_id):
52
        """Assert a signature is stored correctly in repository."""
53
        self.assertEqual(
1551.12.36 by Aaron Bentley
Fix failing tests
54
            '-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
55
            Testament.from_revision(repo, revision_id).as_short_text() +
1551.12.52 by Aaron Bentley
speling fix
56
            '-----END PSEUDO-SIGNED CONTENT-----\n',
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
57
            repo.get_signature_text(revision_id))
58
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
59
    def test_resign(self):
60
        #Test re signing of data.
61
        wt = self.setup_tree()
62
        repo = wt.branch.repository
63
64
        self.monkey_patch_gpg()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
65
        self.run_bzr('re-sign -r revid:A')
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
66
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
67
        self.assertEqualSignature(repo, 'A')
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
68
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
69
        self.run_bzr('re-sign B')
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
70
        self.assertEqualSignature(repo, 'B')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
71
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
72
    def test_resign_range(self):
73
        wt = self.setup_tree()
74
        repo = wt.branch.repository
75
76
        self.monkey_patch_gpg()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
77
        self.run_bzr('re-sign -r 1..')
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
78
        self.assertEqualSignature(repo, 'A')
79
        self.assertEqualSignature(repo, 'B')
80
        self.assertEqualSignature(repo, 'C')
1185.78.1 by John Arbash Meinel
Updating bzr re-sign to allow multiple arguments, and updating tests
81
82
    def test_resign_multiple(self):
83
        wt = self.setup_tree()
84
        repo = wt.branch.repository
85
86
        self.monkey_patch_gpg()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
87
        self.run_bzr('re-sign A B C')
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
88
        self.assertEqualSignature(repo, 'A')
89
        self.assertEqualSignature(repo, 'B')
90
        self.assertEqualSignature(repo, 'C')
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
91
92
    def test_resign_directory(self):
93
        """Test --directory option"""
94
        wt = BzrDir.create_standalone_workingtree('a')
95
        wt.commit("base A", allow_pointless=True, rev_id='A')
96
        wt.commit("base B", allow_pointless=True, rev_id='B')
97
        wt.commit("base C", allow_pointless=True, rev_id='C')
98
        repo = wt.branch.repository
99
        self.monkey_patch_gpg()
100
        self.run_bzr('re-sign --directory=a -r revid:A')
101
        self.assertEqualSignature(repo, 'A')
102
        self.run_bzr('re-sign -d a B')
103
        self.assertEqualSignature(repo, 'B')