~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Robert Collins
  • Date: 2009-08-04 04:36:34 UTC
  • mfrom: (4583 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4593.
  • Revision ID: robertc@robertcollins.net-20090804043634-2iu9wpcgs273i97s
Merge bzr.dev.

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')
1161
1198
            request.execute('', 'missingrevision'))
1162
1199
 
1163
1200
 
 
1201
class TestSmartServerRepositoryGetRevIdForRevno(tests.TestCaseWithMemoryTransport):
 
1202
 
 
1203
    def test_revno_found(self):
 
1204
        backing = self.get_transport()
 
1205
        request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
 
1206
        tree = self.make_branch_and_memory_tree('.')
 
1207
        tree.lock_write()
 
1208
        tree.add('')
 
1209
        rev1_id_utf8 = u'\xc8'.encode('utf-8')
 
1210
        rev2_id_utf8 = u'\xc9'.encode('utf-8')
 
1211
        tree.commit('1st commit', rev_id=rev1_id_utf8)
 
1212
        tree.commit('2nd commit', rev_id=rev2_id_utf8)
 
1213
        tree.unlock()
 
1214
 
 
1215
        self.assertEqual(SmartServerResponse(('ok', rev1_id_utf8)),
 
1216
            request.execute('', 1, (2, rev2_id_utf8)))
 
1217
 
 
1218
    def test_known_revid_missing(self):
 
1219
        backing = self.get_transport()
 
1220
        request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
 
1221
        repo = self.make_repository('.')
 
1222
        self.assertEqual(
 
1223
            FailedSmartServerResponse(('nosuchrevision', 'ghost')),
 
1224
            request.execute('', 1, (2, 'ghost')))
 
1225
 
 
1226
    def test_history_incomplete(self):
 
1227
        backing = self.get_transport()
 
1228
        request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
 
1229
        parent = self.make_branch_and_memory_tree('parent', format='1.9')
 
1230
        parent.lock_write()
 
1231
        parent.add([''], ['TREE_ROOT'])
 
1232
        r1 = parent.commit(message='first commit')
 
1233
        r2 = parent.commit(message='second commit')
 
1234
        parent.unlock()
 
1235
        local = self.make_branch_and_memory_tree('local', format='1.9')
 
1236
        local.branch.pull(parent.branch)
 
1237
        local.set_parent_ids([r2])
 
1238
        r3 = local.commit(message='local commit')
 
1239
        local.branch.create_clone_on_transport(
 
1240
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
 
1241
        self.assertEqual(
 
1242
            SmartServerResponse(('history-incomplete', 2, r2)),
 
1243
            request.execute('stacked', 1, (3, r3)))
 
1244
 
1164
1245
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
1165
1246
 
1166
1247
    def make_two_commit_repo(self):
1576
1657
            smart.repository.SmartServerRepositoryGatherStats)
1577
1658
        self.assertHandlerEqual('Repository.get_parent_map',
1578
1659
            smart.repository.SmartServerRepositoryGetParentMap)
 
1660
        self.assertHandlerEqual('Repository.get_rev_id_for_revno',
 
1661
            smart.repository.SmartServerRepositoryGetRevIdForRevno)
1579
1662
        self.assertHandlerEqual('Repository.get_revision_graph',
1580
1663
            smart.repository.SmartServerRepositoryGetRevisionGraph)
1581
1664
        self.assertHandlerEqual('Repository.get_stream',