~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-16 23:53:02 UTC
  • mto: This revision was merged to the branch mainline in revision 1459.
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051016235302-818de607403e1c6e
test that the presence of a signature does not make a missing base file magically appear present

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from bzrlib.selftest import TestCaseInTempDir
21
21
from bzrlib.branch import Branch
22
 
from bzrlib.workingtree import WorkingTree
23
22
from bzrlib.commit import Commit
24
 
from bzrlib.config import BranchConfig
25
 
from bzrlib.errors import PointlessCommit, BzrError, SigningFailed
 
23
from bzrlib.errors import PointlessCommit, BzrError
26
24
 
27
25
 
28
26
# TODO: Test commit with some added, and added-but-missing files
29
27
 
30
 
class MustSignConfig(BranchConfig):
31
 
 
32
 
    def signature_needed(self):
33
 
        return True
34
 
 
35
 
    def gpg_signing_command(self):
36
 
        return ['cat', '-']
37
 
 
38
 
 
39
28
class TestCommit(TestCaseInTempDir):
40
29
 
41
30
    def test_simple_commit(self):
214
203
 
215
204
        
216
205
    def test_removed_commit(self):
217
 
        """Commit with a removed file"""
 
206
        """Test a commit with a removed file"""
218
207
        b = Branch.initialize('.')
219
 
        wt = b.working_tree()
220
208
        file('hello', 'w').write('hello world')
221
209
        b.add(['hello'], ['hello-id'])
222
210
        b.commit(message='add hello')
223
211
 
224
 
        wt = b.working_tree()  # FIXME: kludge for aliasing of working inventory
225
 
        wt.remove('hello')
 
212
        b.remove('hello')
226
213
        b.commit('removed hello', rev_id='rev2')
227
214
 
228
215
        tree = b.revision_tree('rev2')
258
245
        self.assertEqual('1', inv['file1id'].revision)
259
246
        # FIXME: This should raise a KeyError I think, rbc20051006
260
247
        self.assertRaises(BzrError, inv.__getitem__, 'file2id')
261
 
 
262
 
    def test_strict_commit(self):
263
 
        """Try and commit with unknown files and strict = True, should fail."""
264
 
        from bzrlib.errors import StrictCommitFailed
265
 
        b = Branch.initialize('.')
266
 
        file('hello', 'w').write('hello world')
267
 
        b.add('hello')
268
 
        file('goodbye', 'w').write('goodbye cruel world!')
269
 
        self.assertRaises(StrictCommitFailed, b.commit,
270
 
            message='add hello but not goodbye', strict=True)
271
 
 
272
 
    def test_nonstrict_commit(self):
273
 
        """Try and commit with unknown files and strict = False, should work."""
274
 
        b = Branch.initialize('.')
275
 
        file('hello', 'w').write('hello world')
276
 
        b.add('hello')
277
 
        file('goodbye', 'w').write('goodbye cruel world!')
278
 
        b.commit(message='add hello but not goodbye', strict=False)
279
 
 
280
 
    def test_signed_commit(self):
281
 
        import bzrlib.gpg
282
 
        import bzrlib.commit as commit
283
 
        oldstrategy = bzrlib.gpg.GPGStrategy
284
 
        branch = Branch.initialize('.')
285
 
        branch.commit("base", allow_pointless=True, rev_id='A')
286
 
        self.failIf(branch.revision_store.has_id('A', 'sig'))
287
 
        try:
288
 
            from bzrlib.testament import Testament
289
 
            # monkey patch gpg signing mechanism
290
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
291
 
            commit.Commit(config=MustSignConfig(branch)).commit(branch, "base",
292
 
                                                      allow_pointless=True,
293
 
                                                      rev_id='B')
294
 
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
295
 
                             branch.revision_store.get('B', 'sig').read())
296
 
        finally:
297
 
            bzrlib.gpg.GPGStrategy = oldstrategy
298
 
 
299
 
    def test_commit_failed_signature(self):
300
 
        import bzrlib.gpg
301
 
        import bzrlib.commit as commit
302
 
        oldstrategy = bzrlib.gpg.GPGStrategy
303
 
        branch = Branch.initialize('.')
304
 
        branch.commit("base", allow_pointless=True, rev_id='A')
305
 
        self.failIf(branch.revision_store.has_id('A', 'sig'))
306
 
        try:
307
 
            from bzrlib.testament import Testament
308
 
            # monkey patch gpg signing mechanism
309
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
310
 
            config = MustSignConfig(branch)
311
 
            self.assertRaises(SigningFailed,
312
 
                              commit.Commit(config=config).commit,
313
 
                              branch, "base",
314
 
                              allow_pointless=True,
315
 
                              rev_id='B')
316
 
            branch = Branch.open('.')
317
 
            self.assertEqual(branch.revision_history(), ['A'])
318
 
            self.failIf(branch.revision_store.has_id('B'))
319
 
        finally:
320
 
            bzrlib.gpg.GPGStrategy = oldstrategy