~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-08-07 00:25:38 UTC
  • mfrom: (3612 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3613.
  • Revision ID: andrew.bennetts@canonical.com-20080807002538-mtl1fcgy2fdabha4
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
551
551
            errors.NoSuchRevision, branch.set_revision_history, ['rev-id'])
552
552
        branch.unlock()
553
553
 
 
554
    def test_tip_change_rejected(self):
 
555
        """TipChangeRejected responses cause a TipChangeRejected exception to
 
556
        be raised.
 
557
        """
 
558
        transport = MemoryTransport()
 
559
        transport.mkdir('branch')
 
560
        transport = transport.clone('branch')
 
561
        client = FakeClient(transport.base)
 
562
        # lock_write
 
563
        client.add_success_response('ok', 'branch token', 'repo token')
 
564
        # set_last_revision
 
565
        rejection_msg_unicode = u'rejection message\N{INTERROBANG}'
 
566
        rejection_msg_utf8 = rejection_msg_unicode.encode('utf8')
 
567
        client.add_error_response('TipChangeRejected', rejection_msg_utf8)
 
568
        # unlock
 
569
        client.add_success_response('ok')
 
570
 
 
571
        bzrdir = RemoteBzrDir(transport, _client=False)
 
572
        repo = RemoteRepository(bzrdir, None, _client=client)
 
573
        branch = RemoteBranch(bzrdir, repo, _client=client)
 
574
        branch._ensure_real = lambda: None
 
575
        branch.lock_write()
 
576
        self.addCleanup(branch.unlock)
 
577
        client._calls = []
 
578
 
 
579
        # The 'TipChangeRejected' error response triggered by calling
 
580
        # set_revision_history causes a TipChangeRejected exception.
 
581
        err = self.assertRaises(
 
582
            errors.TipChangeRejected, branch.set_revision_history, ['rev-id'])
 
583
        # The UTF-8 message from the response has been decoded into a unicode
 
584
        # object.
 
585
        self.assertIsInstance(err.msg, unicode)
 
586
        self.assertEqual(rejection_msg_unicode, err.msg)
 
587
 
554
588
 
555
589
class TestBranchSetLastRevisionInfo(tests.TestCase):
556
590
 
689
723
        self.assertEqual(('UnexpectedError',), err.error_tuple)
690
724
        branch.unlock()
691
725
 
 
726
    def test_tip_change_rejected(self):
 
727
        """TipChangeRejected responses cause a TipChangeRejected exception to
 
728
        be raised.
 
729
        """
 
730
        transport = MemoryTransport()
 
731
        transport.mkdir('branch')
 
732
        transport = transport.clone('branch')
 
733
        client = FakeClient(transport.base)
 
734
        # lock_write
 
735
        client.add_success_response('ok', 'branch token', 'repo token')
 
736
        # set_last_revision
 
737
        client.add_error_response('TipChangeRejected', 'rejection message')
 
738
        # unlock
 
739
        client.add_success_response('ok')
 
740
 
 
741
        bzrdir = RemoteBzrDir(transport, _client=False)
 
742
        repo = RemoteRepository(bzrdir, None, _client=client)
 
743
        branch = RemoteBranch(bzrdir, repo, _client=client)
 
744
        # This is a hack to work around the problem that RemoteBranch currently
 
745
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 
746
        branch._ensure_real = lambda: None
 
747
        # Lock the branch, reset the record of remote calls.
 
748
        branch.lock_write()
 
749
        self.addCleanup(branch.unlock)
 
750
        client._calls = []
 
751
 
 
752
        # The 'TipChangeRejected' error response triggered by calling
 
753
        # set_last_revision_info causes a TipChangeRejected exception.
 
754
        err = self.assertRaises(
 
755
            errors.TipChangeRejected,
 
756
            branch.set_last_revision_info, 123, 'revid')
 
757
        self.assertEqual('rejection message', err.msg)
 
758
 
692
759
 
693
760
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
694
761
    """Getting the branch configuration should use an abstract method not vfs.