~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-02-14 17:01:48 UTC
  • mto: (1185.79.1 bzr-jam-pending)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: john@arbash-meinel.com-20060214170148-2765fe23e7309b93
Updating bzr re-sign to allow multiple arguments, and updating tests

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 cat.
 
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 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):
 
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
 
 
54
        return wt
 
55
 
 
56
    def test_resign(self):
 
57
        #Test re signing of data.
 
58
        wt = self.setup_tree()
 
59
        repo = wt.branch.repository
 
60
 
 
61
        self.monkey_patch_gpg()
 
62
        self.run_bzr('re-sign', '-r', 'revid:A')
 
63
 
 
64
        self.assertEqual(
 
65
            Testament.from_revision(repo, 'A').as_short_text(),
 
66
            repo.revision_store.get('A', 'sig').read())
 
67
 
 
68
        self.run_bzr('re-sign', 'B')
 
69
        self.assertEqual(
 
70
            Testament.from_revision(repo, 'B').as_short_text(),
 
71
            repo.revision_store.get('B', 'sig').read())
 
72
            
 
73
    def test_resign_range(self):
 
74
        wt = self.setup_tree()
 
75
        repo = wt.branch.repository
 
76
 
 
77
        self.monkey_patch_gpg()
 
78
        self.run_bzr('re-sign', '-r', '1..')
 
79
        self.assertEqual(
 
80
            Testament.from_revision(repo, 'A').as_short_text(),
 
81
            repo.revision_store.get('A', 'sig').read())
 
82
        self.assertEqual(
 
83
            Testament.from_revision(repo, 'B').as_short_text(),
 
84
            repo.revision_store.get('B', 'sig').read())
 
85
        self.assertEqual(
 
86
            Testament.from_revision(repo, 'C').as_short_text(),
 
87
            repo.revision_store.get('C', 'sig').read())
 
88
 
 
89
    def test_resign_multiple(self):
 
90
        wt = self.setup_tree()
 
91
        repo = wt.branch.repository
 
92
 
 
93
        self.monkey_patch_gpg()
 
94
        self.run_bzr('re-sign', 'A', 'B', 'C')
 
95
        self.assertEqual(
 
96
            Testament.from_revision(repo, 'A').as_short_text(),
 
97
            repo.revision_store.get('A', 'sig').read())
 
98
        self.assertEqual(
 
99
            Testament.from_revision(repo, 'B').as_short_text(),
 
100
            repo.revision_store.get('B', 'sig').read())
 
101
        self.assertEqual(
 
102
            Testament.from_revision(repo, 'C').as_short_text(),
 
103
            repo.revision_store.get('C', 'sig').read())
 
104
 
 
105