~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-03-25 07:21:21 UTC
  • mto: (3297.4.1 smart-set-revision-info)
  • mto: This revision was merged to the branch mainline in revision 3355.
  • Revision ID: andrew.bennetts@canonical.com-20080325072121-67qctpl7mxhr3onc
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
356
356
        branch.unlock()
357
357
 
358
358
 
 
359
class TestBranchSetLastRevisionInfo(tests.TestCase):
 
360
 
 
361
    def test_set_empty(self):
 
362
        # set_last_revision_info(num, 'rev-id') is translated to calling
 
363
        # Branch.set_last_revision_info(num, 'rev-id') on the wire.
 
364
        client = FakeClient([
 
365
            # lock_write
 
366
            (('ok', 'branch token', 'repo token'), ),
 
367
            # set_last_revision_info
 
368
            (('ok',), ),
 
369
            # unlock
 
370
            (('ok',), )])
 
371
        transport = MemoryTransport()
 
372
        transport.mkdir('branch')
 
373
        transport = transport.clone('branch')
 
374
 
 
375
        bzrdir = RemoteBzrDir(transport, _client=False)
 
376
        branch = RemoteBranch(bzrdir, None, _client=client)
 
377
        # This is a hack to work around the problem that RemoteBranch currently
 
378
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 
379
        branch._ensure_real = lambda: None
 
380
        # Lock the branch, reset the record of remote calls.
 
381
        branch.lock_write()
 
382
        client._calls = []
 
383
        result = branch.set_last_revision_info(1234, 'a-revision-id')
 
384
        self.assertEqual(
 
385
            [('call', 'Branch.set_last_revision_info',
 
386
                ('///branch/', 'branch token', 'repo token',
 
387
                 '1234', 'a-revision-id'))],
 
388
            client._calls)
 
389
        self.assertEqual(None, result)
 
390
 
 
391
    def test_no_such_revision(self):
 
392
        # A response of 'NoSuchRevision' is translated into an exception.
 
393
        client = FakeClient([
 
394
            # lock_write
 
395
            (('ok', 'branch token', 'repo token'), ),
 
396
            # set_last_revision_info
 
397
            (('NoSuchRevision', 'revid'), ),
 
398
            # unlock
 
399
            (('ok',), ),
 
400
            ])
 
401
        transport = MemoryTransport()
 
402
        transport.mkdir('branch')
 
403
        transport = transport.clone('branch')
 
404
 
 
405
        bzrdir = RemoteBzrDir(transport, _client=False)
 
406
        branch = RemoteBranch(bzrdir, None, _client=client)
 
407
        # This is a hack to work around the problem that RemoteBranch currently
 
408
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 
409
        branch._ensure_real = lambda: None
 
410
        # Lock the branch, reset the record of remote calls.
 
411
        branch.lock_write()
 
412
        client._calls = []
 
413
 
 
414
        self.assertRaises(
 
415
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
 
416
        branch.unlock()
 
417
 
 
418
 
359
419
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
360
420
    """Test branch.control_files api munging...
361
421