~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_commit.py

  • Committer: Robert Collins
  • Date: 2005-10-17 11:41:07 UTC
  • mfrom: (1442.1.60)
  • Revision ID: robertc@robertcollins.net-20051017114107-f5586285d825c105
Merge in first part of GPG support.

This adds check_signatures config support, triams back the transport api
to be leaner and easier to hook in suffixes - non primary streams in the store
associated with the fileid that primary data is stored in, a gpg module which
will encapsulate all signing and checking operations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib.selftest import TestCaseInTempDir
21
21
from bzrlib.branch import Branch
22
22
from bzrlib.commit import Commit
 
23
from bzrlib.config import BranchConfig
23
24
from bzrlib.errors import PointlessCommit, BzrError
24
25
 
25
26
 
26
27
# TODO: Test commit with some added, and added-but-missing files
27
28
 
 
29
class MustSignConfig(BranchConfig):
 
30
 
 
31
    def signature_needed(self):
 
32
        return True
 
33
 
 
34
    def gpg_signing_command(self):
 
35
        return ['cat', '-']
 
36
 
 
37
 
28
38
class TestCommit(TestCaseInTempDir):
29
39
 
30
40
    def test_simple_commit(self):
51
61
        tree2 = b.revision_tree(rh[1])
52
62
        eq(tree2.get_file_text(file_id), 'version 2')
53
63
 
54
 
 
55
64
    def test_delete_commit(self):
56
65
        """Test a commit with a deleted file"""
57
66
        b = Branch.initialize('.')
246
255
        self.assertEqual('1', inv['file1id'].revision)
247
256
        # FIXME: This should raise a KeyError I think, rbc20051006
248
257
        self.assertRaises(BzrError, inv.__getitem__, 'file2id')
 
258
 
 
259
    def test_signed_commit(self):
 
260
        import bzrlib.gpg
 
261
        import bzrlib.commit as commit
 
262
        oldstrategy = bzrlib.gpg.GPGStrategy
 
263
        branch = Branch.initialize('.')
 
264
        branch.commit("base", allow_pointless=True, rev_id='A')
 
265
        self.failIf(branch.revision_store.has_id('A', 'sig'))
 
266
        try:
 
267
            from bzrlib.testament import Testament
 
268
            # monkey patch gpg signing mechanism
 
269
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
 
270
            commit.Commit(config=MustSignConfig(branch)).commit(branch, "base",
 
271
                                                      allow_pointless=True,
 
272
                                                      rev_id='B')
 
273
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
 
274
                             branch.revision_store.get('B', 'sig').read())
 
275
        finally:
 
276
            bzrlib.gpg.GPGStrategy = oldstrategy