~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-23 07:37:05 UTC
  • mto: This revision was merged to the branch mainline in revision 4573.
  • Revision ID: andrew.bennetts@canonical.com-20090723073705-l9shzmc4ix74zv18
Handle failures more gracefully.

Show diffs side-by-side

added added

removed removed

Lines of Context:
603
603
        branch.unlock()
604
604
 
605
605
 
 
606
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
 
607
    # Only called when the branch format and tags match [yay factory
 
608
    # methods] so only need to test straight forward cases.
 
609
 
 
610
    def test_set_bytes(self):
 
611
        base_branch = self.make_branch('base')
 
612
        tag_bytes = base_branch._get_tags_bytes()
 
613
        # get_lock_tokens takes out a lock.
 
614
        branch_token, repo_token = self.get_lock_tokens(base_branch)
 
615
        request = smart.branch.SmartServerBranchSetTagsBytes(
 
616
            self.get_transport())
 
617
        response = request.execute('base', branch_token, repo_token)
 
618
        self.assertEqual(None, response)
 
619
        response = request.do_chunk(tag_bytes)
 
620
        self.assertEqual(None, response)
 
621
        response = request.do_end()
 
622
        self.assertEquals(
 
623
            SuccessfulSmartServerResponse(()), response)
 
624
        base_branch.unlock()
 
625
 
 
626
    def test_lock_failed(self):
 
627
        base_branch = self.make_branch('base')
 
628
        base_branch.lock_write()
 
629
        tag_bytes = base_branch._get_tags_bytes()
 
630
        request = smart.branch.SmartServerBranchSetTagsBytes(
 
631
            self.get_transport())
 
632
        self.assertRaises(errors.TokenMismatch, request.execute,
 
633
            'base', 'wrong token', 'wrong token')
 
634
        # The request handler will keep processing the message parts, so even
 
635
        # if the request fails immediately do_chunk and do_end are still
 
636
        # called.
 
637
        request.do_chunk(tag_bytes)
 
638
        request.do_end()
 
639
        base_branch.unlock()
 
640
 
 
641
 
 
642
 
606
643
class SetLastRevisionTestBase(TestLockedBranch):
607
644
    """Base test case for verbs that implement set_last_revision."""
608
645
 
872
909
 
873
910
 
874
911
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
875
 
# Only called when the branch format and tags match [yay factory
876
 
# methods] so only need to test straight forward cases.
 
912
    # Only called when the branch format and tags match [yay factory
 
913
    # methods] so only need to test straight forward cases.
877
914
 
878
915
    def test_get_bytes(self):
879
916
        base_branch = self.make_branch('base')