~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1107
1107
        self.assertFalse(isinstance(dest_repo, RemoteRepository))
1108
1108
        self.assertTrue(isinstance(src_repo, RemoteRepository))
1109
1109
        src_repo.copy_content_into(dest_repo)
1110
 
 
1111
 
 
1112
 
class TestRepositoryStreamKnitData(TestRemoteRepository):
1113
 
 
1114
 
    def make_pack_file(self, records):
1115
 
        pack_file = StringIO()
1116
 
        pack_writer = pack.ContainerWriter(pack_file.write)
1117
 
        pack_writer.begin()
1118
 
        for bytes, names in records:
1119
 
            pack_writer.add_bytes_record(bytes, names)
1120
 
        pack_writer.end()
1121
 
        pack_file.seek(0)
1122
 
        return pack_file
1123
 
 
1124
 
    def make_pack_stream(self, records):
1125
 
        pack_serialiser = pack.ContainerSerialiser()
1126
 
        yield pack_serialiser.begin()
1127
 
        for bytes, names in records:
1128
 
            yield pack_serialiser.bytes_record(bytes, names)
1129
 
        yield pack_serialiser.end()
1130
 
 
1131
 
    def test_bad_pack_from_server(self):
1132
 
        """A response with invalid data (e.g. it has a record with multiple
1133
 
        names) triggers an exception.
1134
 
        
1135
 
        Not all possible errors will be caught at this stage, but obviously
1136
 
        malformed data should be.
1137
 
        """
1138
 
        record = ('bytes', [('name1',), ('name2',)])
1139
 
        pack_stream = self.make_pack_stream([record])
1140
 
        responses = [(('ok',), pack_stream), ]
1141
 
        transport_path = 'quack'
1142
 
        repo, client = self.setup_fake_client_and_repository(
1143
 
            responses, transport_path)
1144
 
        search = graph.SearchResult(set(['revid']), set(), 1, set(['revid']))
1145
 
        stream = repo.get_data_stream_for_search(search)
1146
 
        self.assertRaises(errors.SmartProtocolError, list, stream)
1147
 
    
1148
 
    def test_backwards_compatibility(self):
1149
 
        """If the server doesn't recognise this request, fallback to VFS."""
1150
 
        responses = [
1151
 
            (('unknown verb', 'Repository.stream_revisions_chunked'), '')]
1152
 
        repo, client = self.setup_fake_client_and_repository(
1153
 
            responses, 'path')
1154
 
        self.mock_called = False
1155
 
        repo._real_repository = MockRealRepository(self)
1156
 
        search = graph.SearchResult(set(['revid']), set(), 1, set(['revid']))
1157
 
        repo.get_data_stream_for_search(search)
1158
 
        self.assertTrue(self.mock_called)
1159
 
        self.failIf(client.expecting_body,
1160
 
            "The protocol has been left in an unclean state that will cause "
1161
 
            "TooManyConcurrentRequests errors.")
1162
 
 
1163
 
 
1164
 
class MockRealRepository(object):
1165
 
    """Helper class for TestRepositoryStreamKnitData.test_unknown_method."""
1166
 
 
1167
 
    def __init__(self, test):
1168
 
        self.test = test
1169
 
 
1170
 
    def get_data_stream_for_search(self, search):
1171
 
        self.test.assertEqual(set(['revid']), search.get_keys())
1172
 
        self.test.mock_called = True
1173
 
 
1174