/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3408.3.1 by Martin Pool
Remove erroneous handling of branch.conf for RemoteBranch
1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for remote bzrdir/branch/repo/etc
18
19
These are proxy objects which act on remote objects by sending messages
20
through a smart client.  The proxies are to be created when attempting to open
21
the object given a transport that supports smartserver rpc operations. 
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
22
23
These tests correspond to tests.test_smart, which exercises the server side.
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
24
"""
25
3211.5.2 by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression.
26
import bz2
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
27
from cStringIO import StringIO
28
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
29
from bzrlib import (
30
    errors,
3184.1.9 by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of
31
    graph,
2535.3.39 by Andrew Bennetts
Tidy some XXXs.
32
    pack,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
33
    remote,
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
34
    repository,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
35
    tests,
36
    )
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
37
from bzrlib.branch import Branch
38
from bzrlib.bzrdir import BzrDir, BzrDirFormat
39
from bzrlib.remote import (
40
    RemoteBranch,
41
    RemoteBzrDir,
42
    RemoteBzrDirFormat,
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
43
    RemoteRepository,
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
44
    )
45
from bzrlib.revision import NULL_REVISION
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
46
from bzrlib.smart import server, medium
2018.5.159 by Andrew Bennetts
Rename SmartClient to _SmartClient.
47
from bzrlib.smart.client import _SmartClient
3287.6.4 by Robert Collins
Fix up deprecation warnings for get_revision_graph.
48
from bzrlib.symbol_versioning import one_four
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
49
from bzrlib.transport import get_transport, http
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
50
from bzrlib.transport.memory import MemoryTransport
3431.3.1 by Andrew Bennetts
First rough cut of a fix for bug #230550, by adding .base to SmartClientMedia rather than relying on other objects to track this accurately while reusing client media.
51
from bzrlib.transport.remote import RemoteTransport, RemoteTCPTransport
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
52
2018.5.24 by Andrew Bennetts
Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts)
53
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
54
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
55
56
    def setUp(self):
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
57
        self.transport_server = server.SmartTCPServer_for_testing
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
58
        super(BasicRemoteObjectTests, self).setUp()
59
        self.transport = self.get_transport()
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
60
        # make a branch that can be opened over the smart transport
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
61
        self.local_wt = BzrDir.create_standalone_workingtree('.')
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
62
2018.5.171 by Andrew Bennetts
Disconnect RemoteTransports in some tests to avoid tripping up test_strace with leftover threads from previous tests.
63
    def tearDown(self):
64
        self.transport.disconnect()
65
        tests.TestCaseWithTransport.tearDown(self)
66
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
67
    def test_create_remote_bzrdir(self):
68
        b = remote.RemoteBzrDir(self.transport)
69
        self.assertIsInstance(b, BzrDir)
70
71
    def test_open_remote_branch(self):
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
72
        # open a standalone branch in the working directory
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
73
        b = remote.RemoteBzrDir(self.transport)
74
        branch = b.open_branch()
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
75
        self.assertIsInstance(branch, Branch)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
76
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
77
    def test_remote_repository(self):
78
        b = BzrDir.open_from_transport(self.transport)
79
        repo = b.open_repository()
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
80
        revid = u'\xc823123123'.encode('utf8')
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
81
        self.assertFalse(repo.has_revision(revid))
82
        self.local_wt.commit(message='test commit', rev_id=revid)
83
        self.assertTrue(repo.has_revision(revid))
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
84
85
    def test_remote_branch_revision_history(self):
86
        b = BzrDir.open_from_transport(self.transport).open_branch()
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
87
        self.assertEqual([], b.revision_history())
88
        r1 = self.local_wt.commit('1st commit')
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
89
        r2 = self.local_wt.commit('1st commit', rev_id=u'\xc8'.encode('utf8'))
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
90
        self.assertEqual([r1, r2], b.revision_history())
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
91
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
92
    def test_find_correct_format(self):
2018.5.20 by Andrew Bennetts
Move bzrlib/transport/smart/_smart.py to bzrlib/transport/remote.py and rename SmartTransport to RemoteTransport (Robert Collins, Andrew Bennetts)
93
        """Should open a RemoteBzrDir over a RemoteTransport"""
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
94
        fmt = BzrDirFormat.find_format(self.transport)
2018.5.169 by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property.
95
        self.assertTrue(RemoteBzrDirFormat
96
                        in BzrDirFormat._control_server_formats)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
97
        self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
98
99
    def test_open_detected_smart_format(self):
100
        fmt = BzrDirFormat.find_format(self.transport)
101
        d = fmt.open(self.transport)
102
        self.assertIsInstance(d, BzrDir)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
103
2477.1.1 by Martin Pool
Add RemoteBranch repr
104
    def test_remote_branch_repr(self):
105
        b = BzrDir.open_from_transport(self.transport).open_branch()
106
        self.assertStartsWith(str(b), 'RemoteBranch(')
107
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
108
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
109
class FakeProtocol(object):
110
    """Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
111
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
112
    def __init__(self, body, fake_client):
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
113
        self.body = body
114
        self._body_buffer = None
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
115
        self._fake_client = fake_client
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
116
117
    def read_body_bytes(self, count=-1):
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
118
        if self._body_buffer is None:
119
            self._body_buffer = StringIO(self.body)
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
120
        bytes = self._body_buffer.read(count)
121
        if self._body_buffer.tell() == len(self._body_buffer.getvalue()):
122
            self._fake_client.expecting_body = False
123
        return bytes
124
125
    def cancel_read_body(self):
126
        self._fake_client.expecting_body = False
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
127
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
128
    def read_streamed_body(self):
129
        return self.body
130
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
131
2018.5.159 by Andrew Bennetts
Rename SmartClient to _SmartClient.
132
class FakeClient(_SmartClient):
133
    """Lookalike for _SmartClient allowing testing."""
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
134
    
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
135
    def __init__(self, fake_medium_base='fake base'):
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
136
        """Create a FakeClient.
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
137
3104.4.2 by Andrew Bennetts
All tests passing.
138
        :param responses: A list of response-tuple, body-data pairs to be sent
3297.3.3 by Andrew Bennetts
SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.
139
            back to callers.  A special case is if the response-tuple is
140
            'unknown verb', then a UnknownSmartMethod will be raised for that
141
            call, using the second element of the tuple as the verb in the
142
            exception.
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
143
        """
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
144
        self.responses = []
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
145
        self._calls = []
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
146
        self.expecting_body = False
3431.3.2 by Andrew Bennetts
Remove 'base' from _SmartClient entirely, now that the medium has it.
147
        _SmartClient.__init__(self, FakeMedium(self._calls, fake_medium_base))
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
148
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
149
    def add_success_response(self, *args):
150
        self.responses.append(('success', args, None))
151
152
    def add_success_response_with_body(self, body, *args):
153
        self.responses.append(('success', args, body))
154
155
    def add_error_response(self, *args):
156
        self.responses.append(('error', args))
157
158
    def add_unknown_method_response(self, verb):
159
        self.responses.append(('unknown', verb))
160
3297.3.3 by Andrew Bennetts
SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.
161
    def _get_next_response(self):
162
        response_tuple = self.responses.pop(0)
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
163
        if response_tuple[0] == 'unknown':
164
            raise errors.UnknownSmartMethod(response_tuple[1])
165
        elif response_tuple[0] == 'error':
166
            raise errors.ErrorFromSmartServer(response_tuple[1])
3297.3.3 by Andrew Bennetts
SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.
167
        return response_tuple
168
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
169
    def call(self, method, *args):
170
        self._calls.append(('call', method, args))
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
171
        return self._get_next_response()[1]
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
172
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
173
    def call_expecting_body(self, method, *args):
174
        self._calls.append(('call_expecting_body', method, args))
3297.3.3 by Andrew Bennetts
SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.
175
        result = self._get_next_response()
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
176
        self.expecting_body = True
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
177
        return result[1], FakeProtocol(result[2], self)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
178
3184.1.10 by Robert Collins
Change the smart server verb for Repository.stream_revisions_chunked to use SearchResults as the request mechanism for downloads.
179
    def call_with_body_bytes_expecting_body(self, method, args, body):
180
        self._calls.append(('call_with_body_bytes_expecting_body', method,
181
            args, body))
3297.3.3 by Andrew Bennetts
SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.
182
        result = self._get_next_response()
3184.1.10 by Robert Collins
Change the smart server verb for Repository.stream_revisions_chunked to use SearchResults as the request mechanism for downloads.
183
        self.expecting_body = True
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
184
        return result[1], FakeProtocol(result[2], self)
3184.1.10 by Robert Collins
Change the smart server verb for Repository.stream_revisions_chunked to use SearchResults as the request mechanism for downloads.
185
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
186
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
187
class FakeMedium(medium.SmartClientMedium):
3104.4.2 by Andrew Bennetts
All tests passing.
188
3431.3.1 by Andrew Bennetts
First rough cut of a fix for bug #230550, by adding .base to SmartClientMedia rather than relying on other objects to track this accurately while reusing client media.
189
    def __init__(self, client_calls, base):
3213.1.1 by Andrew Bennetts
Recover (by reconnecting) if the server turns out not to understand the new requests in 1.2 that send bodies.
190
        self._remote_is_at_least_1_2 = True
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
191
        self._client_calls = client_calls
3431.3.1 by Andrew Bennetts
First rough cut of a fix for bug #230550, by adding .base to SmartClientMedia rather than relying on other objects to track this accurately while reusing client media.
192
        self.base = base
3213.1.1 by Andrew Bennetts
Recover (by reconnecting) if the server turns out not to understand the new requests in 1.2 that send bodies.
193
194
    def disconnect(self):
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
195
        self._client_calls.append(('disconnect medium',))
3104.4.2 by Andrew Bennetts
All tests passing.
196
197
3192.2.1 by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier.
198
class TestVfsHas(tests.TestCase):
199
200
    def test_unicode_path(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
201
        client = FakeClient('/')
202
        client.add_success_response('yes',)
3192.2.1 by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier.
203
        transport = RemoteTransport('bzr://localhost/', _client=client)
204
        filename = u'/hell\u00d8'.encode('utf8')
205
        result = transport.has(filename)
206
        self.assertEqual(
207
            [('call', 'has', (filename,))],
208
            client._calls)
209
        self.assertTrue(result)
210
211
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
212
class Test_ClientMedium_remote_path_from_transport(tests.TestCase):
213
    """Tests for the behaviour of client_medium.remote_path_from_transport."""
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
214
215
    def assertRemotePath(self, expected, client_base, transport_base):
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
216
        """Assert that the result of
217
        SmartClientMedium.remote_path_from_transport is the expected value for
218
        a given client_base and transport_base.
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
219
        """
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
220
        client_medium = medium.SmartClientMedium(client_base)
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
221
        transport = get_transport(transport_base)
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
222
        result = client_medium.remote_path_from_transport(transport)
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
223
        self.assertEqual(expected, result)
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
224
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
225
    def test_remote_path_from_transport(self):
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
226
        """SmartClientMedium.remote_path_from_transport calculates a URL for
227
        the given transport relative to the root of the client base URL.
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
228
        """
229
        self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')
230
        self.assertRemotePath(
231
            'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz')
232
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
233
    def assertRemotePathHTTP(self, expected, transport_base, relpath):
234
        """Assert that the result of
235
        HttpTransportBase.remote_path_from_transport is the expected value for
236
        a given transport_base and relpath of that transport.  (Note that
237
        HttpTransportBase is a subclass of SmartClientMedium)
238
        """
239
        base_transport = get_transport(transport_base)
240
        client_medium = base_transport.get_smart_medium()
241
        cloned_transport = base_transport.clone(relpath)
242
        result = client_medium.remote_path_from_transport(cloned_transport)
243
        self.assertEqual(expected, result)
244
        
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
245
    def test_remote_path_from_transport_http(self):
246
        """Remote paths for HTTP transports are calculated differently to other
247
        transports.  They are just relative to the client base, not the root
248
        directory of the host.
249
        """
250
        for scheme in ['http:', 'https:', 'bzr+http:', 'bzr+https:']:
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
251
            self.assertRemotePathHTTP(
252
                '../xyz/', scheme + '//host/path', '../xyz/')
253
            self.assertRemotePathHTTP(
254
                'xyz/', scheme + '//host/path', 'xyz/')
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
255
256
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
257
class TestBzrDirOpenBranch(tests.TestCase):
258
259
    def test_branch_present(self):
260
        transport = MemoryTransport()
261
        transport.mkdir('quack')
262
        transport = transport.clone('quack')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
263
        client = FakeClient(transport.base)
264
        client.add_success_response('ok', '')
265
        client.add_success_response('ok', '', 'no', 'no', 'no')
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
266
        bzrdir = RemoteBzrDir(transport, _client=client)
267
        result = bzrdir.open_branch()
268
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
269
            [('call', 'BzrDir.open_branch', ('quack/',)),
3221.3.3 by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so
270
             ('call', 'BzrDir.find_repositoryV2', ('quack/',))],
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
271
            client._calls)
272
        self.assertIsInstance(result, RemoteBranch)
273
        self.assertEqual(bzrdir, result.bzrdir)
274
275
    def test_branch_missing(self):
276
        transport = MemoryTransport()
277
        transport.mkdir('quack')
278
        transport = transport.clone('quack')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
279
        client = FakeClient(transport.base)
280
        client.add_error_response('nobranch')
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
281
        bzrdir = RemoteBzrDir(transport, _client=client)
282
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
283
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
284
            [('call', 'BzrDir.open_branch', ('quack/',))],
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
285
            client._calls)
286
3211.4.1 by Robert Collins
* ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,
287
    def test__get_tree_branch(self):
288
        # _get_tree_branch is a form of open_branch, but it should only ask for
289
        # branch opening, not any other network requests.
290
        calls = []
291
        def open_branch():
292
            calls.append("Called")
293
            return "a-branch"
294
        transport = MemoryTransport()
295
        # no requests on the network - catches other api calls being made.
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
296
        client = FakeClient(transport.base)
3211.4.1 by Robert Collins
* ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,
297
        bzrdir = RemoteBzrDir(transport, _client=client)
298
        # patch the open_branch call to record that it was called.
299
        bzrdir.open_branch = open_branch
300
        self.assertEqual((None, "a-branch"), bzrdir._get_tree_branch())
301
        self.assertEqual(["Called"], calls)
302
        self.assertEqual([], client._calls)
303
3192.2.1 by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier.
304
    def test_url_quoting_of_path(self):
305
        # Relpaths on the wire should not be URL-escaped.  So "~" should be
306
        # transmitted as "~", not "%7E".
3431.3.1 by Andrew Bennetts
First rough cut of a fix for bug #230550, by adding .base to SmartClientMedia rather than relying on other objects to track this accurately while reusing client media.
307
        transport = RemoteTCPTransport('bzr://localhost/~hello/')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
308
        client = FakeClient(transport.base)
309
        client.add_success_response('ok', '')
310
        client.add_success_response('ok', '', 'no', 'no', 'no')
3192.2.1 by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier.
311
        bzrdir = RemoteBzrDir(transport, _client=client)
312
        result = bzrdir.open_branch()
313
        self.assertEqual(
314
            [('call', 'BzrDir.open_branch', ('~hello/',)),
3221.3.3 by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so
315
             ('call', 'BzrDir.find_repositoryV2', ('~hello/',))],
3192.2.1 by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier.
316
            client._calls)
317
3221.3.3 by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so
318
    def check_open_repository(self, rich_root, subtrees, external_lookup='no'):
3104.4.2 by Andrew Bennetts
All tests passing.
319
        transport = MemoryTransport()
320
        transport.mkdir('quack')
321
        transport = transport.clone('quack')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
322
        if rich_root:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
323
            rich_response = 'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
324
        else:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
325
            rich_response = 'no'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
326
        if subtrees:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
327
            subtree_response = 'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
328
        else:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
329
            subtree_response = 'no'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
330
        client = FakeClient(transport.base)
331
        client.add_success_response(
332
            'ok', '', rich_response, subtree_response, external_lookup)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
333
        bzrdir = RemoteBzrDir(transport, _client=client)
334
        result = bzrdir.open_repository()
335
        self.assertEqual(
3221.3.3 by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so
336
            [('call', 'BzrDir.find_repositoryV2', ('quack/',))],
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
337
            client._calls)
338
        self.assertIsInstance(result, RemoteRepository)
339
        self.assertEqual(bzrdir, result.bzrdir)
340
        self.assertEqual(rich_root, result._format.rich_root_data)
2018.5.138 by Robert Collins
Merge bzr.dev.
341
        self.assertEqual(subtrees, result._format.supports_tree_reference)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
342
343
    def test_open_repository_sets_format_attributes(self):
344
        self.check_open_repository(True, True)
345
        self.check_open_repository(False, True)
346
        self.check_open_repository(True, False)
347
        self.check_open_repository(False, False)
3221.3.3 by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so
348
        self.check_open_repository(False, False, 'yes')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
349
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
350
    def test_old_server(self):
351
        """RemoteBzrDirFormat should fail to probe if the server version is too
352
        old.
353
        """
354
        self.assertRaises(errors.NotBranchError,
355
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
356
357
3297.3.3 by Andrew Bennetts
SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.
358
class TestBzrDirOpenRepository(tests.TestCase):
359
360
    def test_backwards_compat_1_2(self):
361
        transport = MemoryTransport()
362
        transport.mkdir('quack')
363
        transport = transport.clone('quack')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
364
        client = FakeClient(transport.base)
365
        client.add_unknown_method_response('RemoteRepository.find_repositoryV2')
366
        client.add_success_response('ok', '', 'no', 'no')
3297.3.3 by Andrew Bennetts
SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.
367
        bzrdir = RemoteBzrDir(transport, _client=client)
368
        repo = bzrdir.open_repository()
369
        self.assertEqual(
370
            [('call', 'BzrDir.find_repositoryV2', ('quack/',)),
371
             ('call', 'BzrDir.find_repository', ('quack/',))],
372
            client._calls)
373
374
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
375
class OldSmartClient(object):
376
    """A fake smart client for test_old_version that just returns a version one
377
    response to the 'hello' (query version) command.
378
    """
379
380
    def get_request(self):
381
        input_file = StringIO('ok\x011\n')
382
        output_file = StringIO()
383
        client_medium = medium.SmartSimplePipesClientMedium(
384
            input_file, output_file)
385
        return medium.SmartClientStreamMediumRequest(client_medium)
386
3241.1.1 by Andrew Bennetts
Shift protocol version querying from RemoteBzrDirFormat into SmartClientMedium.
387
    def protocol_version(self):
388
        return 1
389
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
390
391
class OldServerTransport(object):
392
    """A fake transport for test_old_server that reports it's smart server
393
    protocol version as version one.
394
    """
395
396
    def __init__(self):
397
        self.base = 'fake:'
398
399
    def get_smart_client(self):
400
        return OldSmartClient()
401
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
402
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
403
class TestBranchLastRevisionInfo(tests.TestCase):
404
405
    def test_empty_branch(self):
406
        # in an empty branch we decode the response properly
407
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
408
        client = FakeClient(transport.base)
409
        client.add_success_response('ok', '0', 'null:')
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
410
        transport.mkdir('quack')
411
        transport = transport.clone('quack')
412
        # we do not want bzrdir to make any remote calls
413
        bzrdir = RemoteBzrDir(transport, _client=False)
414
        branch = RemoteBranch(bzrdir, None, _client=client)
415
        result = branch.last_revision_info()
416
417
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
418
            [('call', 'Branch.last_revision_info', ('quack/',))],
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
419
            client._calls)
420
        self.assertEqual((0, NULL_REVISION), result)
421
422
    def test_non_empty_branch(self):
423
        # in a non-empty branch we also decode the response properly
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
424
        revid = u'\xc8'.encode('utf8')
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
425
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
426
        client = FakeClient(transport.base)
427
        client.add_success_response('ok', '2', revid)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
428
        transport.mkdir('kwaak')
429
        transport = transport.clone('kwaak')
430
        # we do not want bzrdir to make any remote calls
431
        bzrdir = RemoteBzrDir(transport, _client=False)
432
        branch = RemoteBranch(bzrdir, None, _client=client)
433
        result = branch.last_revision_info()
434
435
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
436
            [('call', 'Branch.last_revision_info', ('kwaak/',))],
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
437
            client._calls)
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
438
        self.assertEqual((2, revid), result)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
439
440
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
441
class TestBranchSetLastRevision(tests.TestCase):
442
443
    def test_set_empty(self):
444
        # set_revision_history([]) is translated to calling
445
        # Branch.set_last_revision(path, '') on the wire.
3104.4.2 by Andrew Bennetts
All tests passing.
446
        transport = MemoryTransport()
447
        transport.mkdir('branch')
448
        transport = transport.clone('branch')
449
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
450
        client = FakeClient(transport.base)
451
        # lock_write
452
        client.add_success_response('ok', 'branch token', 'repo token')
453
        # set_last_revision
454
        client.add_success_response('ok')
455
        # unlock
456
        client.add_success_response('ok')
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
457
        bzrdir = RemoteBzrDir(transport, _client=False)
458
        branch = RemoteBranch(bzrdir, None, _client=client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
459
        # This is a hack to work around the problem that RemoteBranch currently
460
        # unnecessarily invokes _ensure_real upon a call to lock_write.
461
        branch._ensure_real = lambda: None
462
        branch.lock_write()
463
        client._calls = []
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
464
        result = branch.set_revision_history([])
465
        self.assertEqual(
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
466
            [('call', 'Branch.set_last_revision',
3104.4.2 by Andrew Bennetts
All tests passing.
467
                ('branch/', 'branch token', 'repo token', 'null:'))],
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
468
            client._calls)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
469
        branch.unlock()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
470
        self.assertEqual(None, result)
471
472
    def test_set_nonempty(self):
473
        # set_revision_history([rev-id1, ..., rev-idN]) is translated to calling
474
        # Branch.set_last_revision(path, rev-idN) on the wire.
3104.4.2 by Andrew Bennetts
All tests passing.
475
        transport = MemoryTransport()
476
        transport.mkdir('branch')
477
        transport = transport.clone('branch')
478
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
479
        client = FakeClient(transport.base)
480
        # lock_write
481
        client.add_success_response('ok', 'branch token', 'repo token')
482
        # set_last_revision
483
        client.add_success_response('ok')
484
        # unlock
485
        client.add_success_response('ok')
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
486
        bzrdir = RemoteBzrDir(transport, _client=False)
487
        branch = RemoteBranch(bzrdir, None, _client=client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
488
        # This is a hack to work around the problem that RemoteBranch currently
489
        # unnecessarily invokes _ensure_real upon a call to lock_write.
490
        branch._ensure_real = lambda: None
491
        # Lock the branch, reset the record of remote calls.
492
        branch.lock_write()
493
        client._calls = []
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
494
495
        result = branch.set_revision_history(['rev-id1', 'rev-id2'])
496
        self.assertEqual(
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
497
            [('call', 'Branch.set_last_revision',
3104.4.2 by Andrew Bennetts
All tests passing.
498
                ('branch/', 'branch token', 'repo token', 'rev-id2'))],
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
499
            client._calls)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
500
        branch.unlock()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
501
        self.assertEqual(None, result)
502
503
    def test_no_such_revision(self):
504
        transport = MemoryTransport()
505
        transport.mkdir('branch')
506
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
507
        # A response of 'NoSuchRevision' is translated into an exception.
508
        client = FakeClient(transport.base)
509
        # lock_write
510
        client.add_success_response('ok', 'branch token', 'repo token')
511
        # set_last_revision
512
        client.add_error_response('NoSuchRevision', 'rev-id')
513
        # unlock
514
        client.add_success_response('ok')
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
515
516
        bzrdir = RemoteBzrDir(transport, _client=False)
517
        branch = RemoteBranch(bzrdir, None, _client=client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
518
        branch._ensure_real = lambda: None
519
        branch.lock_write()
520
        client._calls = []
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
521
522
        self.assertRaises(
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
523
            errors.NoSuchRevision, branch.set_revision_history, ['rev-id'])
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
524
        branch.unlock()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
525
526
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
527
class TestBranchSetLastRevisionInfo(tests.TestCase):
528
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
529
    def test_set_last_revision_info(self):
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
530
        # set_last_revision_info(num, 'rev-id') is translated to calling
531
        # Branch.set_last_revision_info(num, 'rev-id') on the wire.
3297.4.1 by Andrew Bennetts
Merge 'Add Branch.set_last_revision_info smart method'.
532
        transport = MemoryTransport()
533
        transport.mkdir('branch')
534
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
535
        client = FakeClient(transport.base)
536
        # lock_write
537
        client.add_success_response('ok', 'branch token', 'repo token')
538
        # set_last_revision
539
        client.add_success_response('ok')
540
        # unlock
541
        client.add_success_response('ok')
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
542
543
        bzrdir = RemoteBzrDir(transport, _client=False)
544
        branch = RemoteBranch(bzrdir, None, _client=client)
545
        # This is a hack to work around the problem that RemoteBranch currently
546
        # unnecessarily invokes _ensure_real upon a call to lock_write.
547
        branch._ensure_real = lambda: None
548
        # Lock the branch, reset the record of remote calls.
549
        branch.lock_write()
550
        client._calls = []
551
        result = branch.set_last_revision_info(1234, 'a-revision-id')
552
        self.assertEqual(
553
            [('call', 'Branch.set_last_revision_info',
3297.4.1 by Andrew Bennetts
Merge 'Add Branch.set_last_revision_info smart method'.
554
                ('branch/', 'branch token', 'repo token',
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
555
                 '1234', 'a-revision-id'))],
556
            client._calls)
557
        self.assertEqual(None, result)
558
559
    def test_no_such_revision(self):
560
        # A response of 'NoSuchRevision' is translated into an exception.
561
        transport = MemoryTransport()
562
        transport.mkdir('branch')
563
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
564
        client = FakeClient(transport.base)
565
        # lock_write
566
        client.add_success_response('ok', 'branch token', 'repo token')
567
        # set_last_revision
568
        client.add_error_response('NoSuchRevision', 'revid')
569
        # unlock
570
        client.add_success_response('ok')
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
571
572
        bzrdir = RemoteBzrDir(transport, _client=False)
573
        branch = RemoteBranch(bzrdir, None, _client=client)
574
        # This is a hack to work around the problem that RemoteBranch currently
575
        # unnecessarily invokes _ensure_real upon a call to lock_write.
576
        branch._ensure_real = lambda: None
577
        # Lock the branch, reset the record of remote calls.
578
        branch.lock_write()
579
        client._calls = []
580
581
        self.assertRaises(
582
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
583
        branch.unlock()
584
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
585
    def lock_remote_branch(self, branch):
586
        """Trick a RemoteBranch into thinking it is locked."""
587
        branch._lock_mode = 'w'
588
        branch._lock_count = 2
589
        branch._lock_token = 'branch token'
590
        branch._repo_lock_token = 'repo token'
591
592
    def test_backwards_compatibility(self):
593
        """If the server does not support the Branch.set_last_revision_info
594
        verb (which is new in 1.4), then the client falls back to VFS methods.
595
        """
596
        # This test is a little messy.  Unlike most tests in this file, it
597
        # doesn't purely test what a Remote* object sends over the wire, and
598
        # how it reacts to responses from the wire.  It instead relies partly
599
        # on asserting that the RemoteBranch will call
600
        # self._real_branch.set_last_revision_info(...).
601
602
        # First, set up our RemoteBranch with a FakeClient that raises
603
        # UnknownSmartMethod, and a StubRealBranch that logs how it is called.
604
        transport = MemoryTransport()
605
        transport.mkdir('branch')
606
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
607
        client = FakeClient(transport.base)
608
        client.add_unknown_method_response('Branch.set_last_revision_info')
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
609
        bzrdir = RemoteBzrDir(transport, _client=False)
610
        branch = RemoteBranch(bzrdir, None, _client=client)
611
        class StubRealBranch(object):
612
            def __init__(self):
613
                self.calls = []
614
            def set_last_revision_info(self, revno, revision_id):
615
                self.calls.append(
616
                    ('set_last_revision_info', revno, revision_id))
3441.5.5 by Andrew Bennetts
Some small tweaks and comments.
617
            def _clear_cached_state(self):
618
                pass
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
619
        real_branch = StubRealBranch()
620
        branch._real_branch = real_branch
621
        self.lock_remote_branch(branch)
622
623
        # Call set_last_revision_info, and verify it behaved as expected.
624
        result = branch.set_last_revision_info(1234, 'a-revision-id')
625
        self.assertEqual(
626
            [('call', 'Branch.set_last_revision_info',
627
                ('branch/', 'branch token', 'repo token',
628
                 '1234', 'a-revision-id')),],
629
            client._calls)
630
        self.assertEqual(
631
            [('set_last_revision_info', 1234, 'a-revision-id')],
632
            real_branch.calls)
633
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
634
    def test_unexpected_error(self):
635
        # A response of 'NoSuchRevision' is translated into an exception.
636
        transport = MemoryTransport()
637
        transport.mkdir('branch')
638
        transport = transport.clone('branch')
639
        client = FakeClient(transport.base)
640
        # lock_write
641
        client.add_success_response('ok', 'branch token', 'repo token')
642
        # set_last_revision
643
        client.add_error_response('UnexpectedError')
644
        # unlock
645
        client.add_success_response('ok')
646
647
        bzrdir = RemoteBzrDir(transport, _client=False)
648
        branch = RemoteBranch(bzrdir, None, _client=client)
649
        # This is a hack to work around the problem that RemoteBranch currently
650
        # unnecessarily invokes _ensure_real upon a call to lock_write.
651
        branch._ensure_real = lambda: None
652
        # Lock the branch, reset the record of remote calls.
653
        branch.lock_write()
654
        client._calls = []
655
656
        err = self.assertRaises(
657
            errors.ErrorFromSmartServer,
658
            branch.set_last_revision_info, 123, 'revid')
659
        self.assertEqual(('UnexpectedError',), err.error_tuple)
660
        branch.unlock()
661
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
662
2018.5.169 by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property.
663
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
3408.3.1 by Martin Pool
Remove erroneous handling of branch.conf for RemoteBranch
664
    """Getting the branch configuration should use an abstract method not vfs.
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
665
    """
666
667
    def test_get_branch_conf(self):
3408.3.1 by Martin Pool
Remove erroneous handling of branch.conf for RemoteBranch
668
        raise tests.KnownFailure('branch.conf is not retrieved by get_config_file')
669
        # We should see that branch.get_config() does a single rpc to get the
670
        # remote configuration file, abstracting away where that is stored on
671
        # the server.  However at the moment it always falls back to using the
672
        # vfs, and this would need some changes in config.py.
673
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
674
        # in an empty branch we decode the response properly
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
675
        client = FakeClient(self.get_url())
3245.6.1 by Andrew Bennetts
Merge from bzr.dev.
676
        client.add_success_response_with_body('# config file body', 'ok')
2018.5.169 by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property.
677
        # we need to make a real branch because the remote_branch.control_files
678
        # will trigger _ensure_real.
679
        branch = self.make_branch('quack')
680
        transport = branch.bzrdir.root_transport
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
681
        # we do not want bzrdir to make any remote calls
682
        bzrdir = RemoteBzrDir(transport, _client=False)
683
        branch = RemoteBranch(bzrdir, None, _client=client)
3408.3.1 by Martin Pool
Remove erroneous handling of branch.conf for RemoteBranch
684
        config = branch.get_config()
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
685
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
686
            [('call_expecting_body', 'Branch.get_config_file', ('quack/',))],
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
687
            client._calls)
688
689
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
690
class TestBranchLockWrite(tests.TestCase):
691
692
    def test_lock_write_unlockable(self):
693
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
694
        client = FakeClient(transport.base)
695
        client.add_error_response('UnlockableTransport')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
696
        transport.mkdir('quack')
697
        transport = transport.clone('quack')
698
        # we do not want bzrdir to make any remote calls
699
        bzrdir = RemoteBzrDir(transport, _client=False)
700
        branch = RemoteBranch(bzrdir, None, _client=client)
701
        self.assertRaises(errors.UnlockableTransport, branch.lock_write)
702
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
703
            [('call', 'Branch.lock_write', ('quack/', '', ''))],
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
704
            client._calls)
705
706
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
707
class TestTransportIsReadonly(tests.TestCase):
708
709
    def test_true(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
710
        client = FakeClient()
711
        client.add_success_response('yes')
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
712
        transport = RemoteTransport('bzr://example.com/', medium=False,
713
                                    _client=client)
714
        self.assertEqual(True, transport.is_readonly())
715
        self.assertEqual(
716
            [('call', 'Transport.is_readonly', ())],
717
            client._calls)
718
719
    def test_false(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
720
        client = FakeClient()
721
        client.add_success_response('no')
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
722
        transport = RemoteTransport('bzr://example.com/', medium=False,
723
                                    _client=client)
724
        self.assertEqual(False, transport.is_readonly())
725
        self.assertEqual(
726
            [('call', 'Transport.is_readonly', ())],
727
            client._calls)
728
729
    def test_error_from_old_server(self):
730
        """bzr 0.15 and earlier servers don't recognise the is_readonly verb.
731
        
732
        Clients should treat it as a "no" response, because is_readonly is only
733
        advisory anyway (a transport could be read-write, but then the
734
        underlying filesystem could be readonly anyway).
735
        """
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
736
        client = FakeClient()
737
        client.add_unknown_method_response('Transport.is_readonly')
2471.2.1 by Andrew Bennetts
Fix trivial incompatibility with bzr 0.11 servers, which give a slightly different error to bzr 0.15 servers.
738
        transport = RemoteTransport('bzr://example.com/', medium=False,
739
                                    _client=client)
740
        self.assertEqual(False, transport.is_readonly())
741
        self.assertEqual(
742
            [('call', 'Transport.is_readonly', ())],
743
            client._calls)
744
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
745
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
746
class TestRemoteRepository(tests.TestCase):
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
747
    """Base for testing RemoteRepository protocol usage.
748
    
749
    These tests contain frozen requests and responses.  We want any changes to 
750
    what is sent or expected to be require a thoughtful update to these tests
751
    because they might break compatibility with different-versioned servers.
752
    """
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
753
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
754
    def setup_fake_client_and_repository(self, transport_path):
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
755
        """Create the fake client and repository for testing with.
756
        
757
        There's no real server here; we just have canned responses sent
758
        back one by one.
759
        
760
        :param transport_path: Path below the root of the MemoryTransport
761
            where the repository will be created.
762
        """
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
763
        transport = MemoryTransport()
764
        transport.mkdir(transport_path)
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
765
        client = FakeClient(transport.base)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
766
        transport = transport.clone(transport_path)
767
        # we do not want bzrdir to make any remote calls
768
        bzrdir = RemoteBzrDir(transport, _client=False)
769
        repo = RemoteRepository(bzrdir, None, _client=client)
770
        return repo, client
771
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
772
2018.12.2 by Andrew Bennetts
Remove some duplicate code in test_remote
773
class TestRepositoryGatherStats(TestRemoteRepository):
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
774
775
    def test_revid_none(self):
776
        # ('ok',), body with revisions and size
777
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
778
        repo, client = self.setup_fake_client_and_repository(transport_path)
779
        client.add_success_response_with_body(
780
            'revisions: 2\nsize: 18\n', 'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
781
        result = repo.gather_stats(None)
782
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
783
            [('call_expecting_body', 'Repository.gather_stats',
3104.4.2 by Andrew Bennetts
All tests passing.
784
             ('quack/','','no'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
785
            client._calls)
786
        self.assertEqual({'revisions': 2, 'size': 18}, result)
787
788
    def test_revid_no_committers(self):
789
        # ('ok',), body without committers
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
790
        body = ('firstrev: 123456.300 3600\n'
791
                'latestrev: 654231.400 0\n'
792
                'revisions: 2\n'
793
                'size: 18\n')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
794
        transport_path = 'quick'
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
795
        revid = u'\xc8'.encode('utf8')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
796
        repo, client = self.setup_fake_client_and_repository(transport_path)
797
        client.add_success_response_with_body(body, 'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
798
        result = repo.gather_stats(revid)
799
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
800
            [('call_expecting_body', 'Repository.gather_stats',
3104.4.2 by Andrew Bennetts
All tests passing.
801
              ('quick/', revid, 'no'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
802
            client._calls)
803
        self.assertEqual({'revisions': 2, 'size': 18,
804
                          'firstrev': (123456.300, 3600),
805
                          'latestrev': (654231.400, 0),},
806
                         result)
807
808
    def test_revid_with_committers(self):
809
        # ('ok',), body with committers
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
810
        body = ('committers: 128\n'
811
                'firstrev: 123456.300 3600\n'
812
                'latestrev: 654231.400 0\n'
813
                'revisions: 2\n'
814
                'size: 18\n')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
815
        transport_path = 'buick'
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
816
        revid = u'\xc8'.encode('utf8')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
817
        repo, client = self.setup_fake_client_and_repository(transport_path)
818
        client.add_success_response_with_body(body, 'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
819
        result = repo.gather_stats(revid, True)
820
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
821
            [('call_expecting_body', 'Repository.gather_stats',
3104.4.2 by Andrew Bennetts
All tests passing.
822
              ('buick/', revid, 'yes'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
823
            client._calls)
824
        self.assertEqual({'revisions': 2, 'size': 18,
825
                          'committers': 128,
826
                          'firstrev': (123456.300, 3600),
827
                          'latestrev': (654231.400, 0),},
828
                         result)
829
830
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
831
class TestRepositoryGetGraph(TestRemoteRepository):
832
833
    def test_get_graph(self):
3172.5.8 by Robert Collins
Review feedback.
834
        # get_graph returns a graph with the repository as the
835
        # parents_provider.
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
836
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
837
        repo, client = self.setup_fake_client_and_repository(transport_path)
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
838
        graph = repo.get_graph()
3441.5.4 by Andrew Bennetts
Fix test failures, and add some tests for the remote graph heads RPC.
839
        self.assertEqual(graph._real_graph._parents_provider, repo)
840
841
    def test_heads(self):
842
        transport_path = 'quack'
843
        repo, client = self.setup_fake_client_and_repository(transport_path)
844
        graph = repo.get_graph()
845
        client.add_success_response('revision-a', 'revision-b')
846
        heads = graph.heads(['revision-a', 'revision-b', 'revision-c'])
847
        self.assertEqual(
848
            [('call', 'Repository.graph_heads',
849
              ('quack/', 'revision-a', 'revision-b', 'revision-c'))],
850
            client._calls)
851
        self.assertEqual(set(['revision-a', 'revision-b']), heads)
852
853
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
854
855
856
class TestRepositoryGetParentMap(TestRemoteRepository):
857
858
    def test_get_parent_map_caching(self):
859
        # get_parent_map returns from cache until unlock()
860
        # setup a reponse with two revisions
861
        r1 = u'\u0e33'.encode('utf8')
862
        r2 = u'\u0dab'.encode('utf8')
863
        lines = [' '.join([r2, r1]), r1]
3211.5.2 by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression.
864
        encoded_body = bz2.compress('\n'.join(lines))
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
865
866
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
867
        repo, client = self.setup_fake_client_and_repository(transport_path)
868
        client.add_success_response_with_body(encoded_body, 'ok')
869
        client.add_success_response_with_body(encoded_body, 'ok')
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
870
        repo.lock_read()
871
        graph = repo.get_graph()
872
        parents = graph.get_parent_map([r2])
873
        self.assertEqual({r2: (r1,)}, parents)
874
        # locking and unlocking deeper should not reset
875
        repo.lock_read()
876
        repo.unlock()
877
        parents = graph.get_parent_map([r1])
3172.5.6 by Robert Collins
Create new smart server verb Repository.get_parent_map.
878
        self.assertEqual({r1: (NULL_REVISION,)}, parents)
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
879
        self.assertEqual(
3211.5.1 by Robert Collins
Change the smart server get_parents method to take a graph search to exclude already recieved parents from. This prevents history shortcuts causing huge numbers of duplicates.
880
            [('call_with_body_bytes_expecting_body',
881
              'Repository.get_parent_map', ('quack/', r2), '\n\n0')],
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
882
            client._calls)
883
        repo.unlock()
884
        # now we call again, and it should use the second response.
885
        repo.lock_read()
886
        graph = repo.get_graph()
3172.5.6 by Robert Collins
Create new smart server verb Repository.get_parent_map.
887
        parents = graph.get_parent_map([r1])
888
        self.assertEqual({r1: (NULL_REVISION,)}, parents)
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
889
        self.assertEqual(
3211.5.1 by Robert Collins
Change the smart server get_parents method to take a graph search to exclude already recieved parents from. This prevents history shortcuts causing huge numbers of duplicates.
890
            [('call_with_body_bytes_expecting_body',
891
              'Repository.get_parent_map', ('quack/', r2), '\n\n0'),
892
             ('call_with_body_bytes_expecting_body',
893
              'Repository.get_parent_map', ('quack/', r1), '\n\n0'),
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
894
            ],
895
            client._calls)
896
        repo.unlock()
897
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
898
    def test_get_parent_map_reconnects_if_unknown_method(self):
899
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
900
        repo, client = self.setup_fake_client_and_repository(transport_path)
901
        client.add_unknown_method_response('Repository,get_parent_map')
902
        client.add_success_response_with_body('', 'ok')
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
903
        self.assertTrue(client._medium._remote_is_at_least_1_2)
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
904
        rev_id = 'revision-id'
3297.3.5 by Andrew Bennetts
Suppress a deprecation warning.
905
        expected_deprecations = [
906
            'bzrlib.remote.RemoteRepository.get_revision_graph was deprecated '
907
            'in version 1.4.']
908
        parents = self.callDeprecated(
909
            expected_deprecations, repo.get_parent_map, [rev_id])
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
910
        self.assertEqual(
3213.1.8 by Andrew Bennetts
Merge from bzr.dev.
911
            [('call_with_body_bytes_expecting_body',
912
              'Repository.get_parent_map', ('quack/', rev_id), '\n\n0'),
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
913
             ('disconnect medium',),
914
             ('call_expecting_body', 'Repository.get_revision_graph',
915
              ('quack/', ''))],
916
            client._calls)
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
917
        # The medium is now marked as being connected to an older server
918
        self.assertFalse(client._medium._remote_is_at_least_1_2)
919
920
    def test_get_parent_map_fallback_parentless_node(self):
921
        """get_parent_map falls back to get_revision_graph on old servers.  The
922
        results from get_revision_graph are tweaked to match the get_parent_map
923
        API.
924
3389.1.3 by Andrew Bennetts
Remove XXX from test description.
925
        Specifically, a {key: ()} result from get_revision_graph means "no
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
926
        parents" for that key, which in get_parent_map results should be
3389.1.3 by Andrew Bennetts
Remove XXX from test description.
927
        represented as {key: ('null:',)}.
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
928
929
        This is the test for https://bugs.launchpad.net/bzr/+bug/214894
930
        """
931
        rev_id = 'revision-id'
932
        transport_path = 'quack'
3245.4.40 by Andrew Bennetts
Merge from bzr.dev.
933
        repo, client = self.setup_fake_client_and_repository(transport_path)
934
        client.add_success_response_with_body(rev_id, 'ok')
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
935
        client._medium._remote_is_at_least_1_2 = False
936
        expected_deprecations = [
937
            'bzrlib.remote.RemoteRepository.get_revision_graph was deprecated '
938
            'in version 1.4.']
939
        parents = self.callDeprecated(
940
            expected_deprecations, repo.get_parent_map, [rev_id])
941
        self.assertEqual(
942
            [('call_expecting_body', 'Repository.get_revision_graph',
943
             ('quack/', ''))],
944
            client._calls)
945
        self.assertEqual({rev_id: ('null:',)}, parents)
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
946
3297.2.3 by Andrew Bennetts
Test the code path that the typo is on.
947
    def test_get_parent_map_unexpected_response(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
948
        repo, client = self.setup_fake_client_and_repository('path')
949
        client.add_success_response('something unexpected!')
3297.2.3 by Andrew Bennetts
Test the code path that the typo is on.
950
        self.assertRaises(
951
            errors.UnexpectedSmartServerResponse,
952
            repo.get_parent_map, ['a-revision-id'])
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
953
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
954
2018.5.68 by Wouter van Heyst
Merge RemoteRepository.gather_stats.
955
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
956
    
957
    def test_null_revision(self):
958
        # a null revision has the predictable result {}, we should have no wire
959
        # traffic when calling it with this argument
960
        transport_path = 'empty'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
961
        repo, client = self.setup_fake_client_and_repository(transport_path)
962
        client.add_success_response('notused')
3287.6.4 by Robert Collins
Fix up deprecation warnings for get_revision_graph.
963
        result = self.applyDeprecated(one_four, repo.get_revision_graph,
964
            NULL_REVISION)
2018.5.68 by Wouter van Heyst
Merge RemoteRepository.gather_stats.
965
        self.assertEqual([], client._calls)
966
        self.assertEqual({}, result)
967
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
968
    def test_none_revision(self):
969
        # with none we want the entire graph
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
970
        r1 = u'\u0e33'.encode('utf8')
971
        r2 = u'\u0dab'.encode('utf8')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
972
        lines = [' '.join([r2, r1]), r1]
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
973
        encoded_body = '\n'.join(lines)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
974
975
        transport_path = 'sinhala'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
976
        repo, client = self.setup_fake_client_and_repository(transport_path)
977
        client.add_success_response_with_body(encoded_body, 'ok')
3287.6.4 by Robert Collins
Fix up deprecation warnings for get_revision_graph.
978
        result = self.applyDeprecated(one_four, repo.get_revision_graph)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
979
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
980
            [('call_expecting_body', 'Repository.get_revision_graph',
3104.4.2 by Andrew Bennetts
All tests passing.
981
             ('sinhala/', ''))],
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
982
            client._calls)
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
983
        self.assertEqual({r1: (), r2: (r1, )}, result)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
984
985
    def test_specific_revision(self):
986
        # with a specific revision we want the graph for that
987
        # with none we want the entire graph
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
988
        r11 = u'\u0e33'.encode('utf8')
989
        r12 = u'\xc9'.encode('utf8')
990
        r2 = u'\u0dab'.encode('utf8')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
991
        lines = [' '.join([r2, r11, r12]), r11, r12]
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
992
        encoded_body = '\n'.join(lines)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
993
994
        transport_path = 'sinhala'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
995
        repo, client = self.setup_fake_client_and_repository(transport_path)
996
        client.add_success_response_with_body(encoded_body, 'ok')
3287.6.4 by Robert Collins
Fix up deprecation warnings for get_revision_graph.
997
        result = self.applyDeprecated(one_four, repo.get_revision_graph, r2)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
998
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
999
            [('call_expecting_body', 'Repository.get_revision_graph',
3104.4.2 by Andrew Bennetts
All tests passing.
1000
             ('sinhala/', r2))],
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1001
            client._calls)
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
1002
        self.assertEqual({r11: (), r12: (), r2: (r11, r12), }, result)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1003
1004
    def test_no_such_revision(self):
1005
        revid = '123'
1006
        transport_path = 'sinhala'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1007
        repo, client = self.setup_fake_client_and_repository(transport_path)
1008
        client.add_error_response('nosuchrevision', revid)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1009
        # also check that the right revision is reported in the error
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1010
        self.assertRaises(errors.NoSuchRevision,
3287.6.4 by Robert Collins
Fix up deprecation warnings for get_revision_graph.
1011
            self.applyDeprecated, one_four, repo.get_revision_graph, revid)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1012
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
1013
            [('call_expecting_body', 'Repository.get_revision_graph',
3104.4.2 by Andrew Bennetts
All tests passing.
1014
             ('sinhala/', revid))],
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1015
            client._calls)
1016
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1017
    def test_unexpected_error(self):
1018
        revid = '123'
1019
        transport_path = 'sinhala'
1020
        repo, client = self.setup_fake_client_and_repository(transport_path)
1021
        client.add_error_response('AnUnexpectedError')
1022
        e = self.assertRaises(errors.ErrorFromSmartServer,
1023
            self.applyDeprecated, one_four, repo.get_revision_graph, revid)
1024
        self.assertEqual(('AnUnexpectedError',), e.error_tuple)
1025
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1026
        
1027
class TestRepositoryIsShared(TestRemoteRepository):
1028
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1029
    def test_is_shared(self):
1030
        # ('yes', ) for Repository.is_shared -> 'True'.
1031
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1032
        repo, client = self.setup_fake_client_and_repository(transport_path)
1033
        client.add_success_response('yes')
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1034
        result = repo.is_shared()
1035
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1036
            [('call', 'Repository.is_shared', ('quack/',))],
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1037
            client._calls)
1038
        self.assertEqual(True, result)
1039
1040
    def test_is_not_shared(self):
1041
        # ('no', ) for Repository.is_shared -> 'False'.
1042
        transport_path = 'qwack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1043
        repo, client = self.setup_fake_client_and_repository(transport_path)
1044
        client.add_success_response('no')
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1045
        result = repo.is_shared()
1046
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1047
            [('call', 'Repository.is_shared', ('qwack/',))],
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1048
            client._calls)
1049
        self.assertEqual(False, result)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1050
1051
1052
class TestRepositoryLockWrite(TestRemoteRepository):
1053
1054
    def test_lock_write(self):
1055
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1056
        repo, client = self.setup_fake_client_and_repository(transport_path)
1057
        client.add_success_response('ok', 'a token')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1058
        result = repo.lock_write()
1059
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1060
            [('call', 'Repository.lock_write', ('quack/', ''))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1061
            client._calls)
1062
        self.assertEqual('a token', result)
1063
1064
    def test_lock_write_already_locked(self):
1065
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1066
        repo, client = self.setup_fake_client_and_repository(transport_path)
1067
        client.add_error_response('LockContention')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1068
        self.assertRaises(errors.LockContention, repo.lock_write)
1069
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1070
            [('call', 'Repository.lock_write', ('quack/', ''))],
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
1071
            client._calls)
1072
1073
    def test_lock_write_unlockable(self):
1074
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1075
        repo, client = self.setup_fake_client_and_repository(transport_path)
1076
        client.add_error_response('UnlockableTransport')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
1077
        self.assertRaises(errors.UnlockableTransport, repo.lock_write)
1078
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1079
            [('call', 'Repository.lock_write', ('quack/', ''))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1080
            client._calls)
1081
1082
1083
class TestRepositoryUnlock(TestRemoteRepository):
1084
1085
    def test_unlock(self):
1086
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1087
        repo, client = self.setup_fake_client_and_repository(transport_path)
1088
        client.add_success_response('ok', 'a token')
1089
        client.add_success_response('ok')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1090
        repo.lock_write()
1091
        repo.unlock()
1092
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1093
            [('call', 'Repository.lock_write', ('quack/', '')),
1094
             ('call', 'Repository.unlock', ('quack/', 'a token'))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1095
            client._calls)
1096
1097
    def test_unlock_wrong_token(self):
1098
        # If somehow the token is wrong, unlock will raise TokenMismatch.
1099
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1100
        repo, client = self.setup_fake_client_and_repository(transport_path)
1101
        client.add_success_response('ok', 'a token')
1102
        client.add_error_response('TokenMismatch')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1103
        repo.lock_write()
1104
        self.assertRaises(errors.TokenMismatch, repo.unlock)
1105
1106
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1107
class TestRepositoryHasRevision(TestRemoteRepository):
1108
1109
    def test_none(self):
1110
        # repo.has_revision(None) should not cause any traffic.
1111
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1112
        repo, client = self.setup_fake_client_and_repository(transport_path)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1113
1114
        # The null revision is always there, so has_revision(None) == True.
3172.3.3 by Robert Collins
Missed one occurence of None -> NULL_REVISION.
1115
        self.assertEqual(True, repo.has_revision(NULL_REVISION))
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1116
1117
        # The remote repo shouldn't be accessed.
1118
        self.assertEqual([], client._calls)
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1119
1120
1121
class TestRepositoryTarball(TestRemoteRepository):
1122
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1123
    # This is a canned tarball reponse we can validate against
2018.18.18 by Martin Pool
reformat
1124
    tarball_content = (
2018.18.23 by Martin Pool
review cleanups
1125
        'QlpoOTFBWSZTWdGkj3wAAWF/k8aQACBIB//A9+8cIX/v33AACEAYABAECEACNz'
1126
        'JqsgJJFPTSnk1A3qh6mTQAAAANPUHkagkSTEkaA09QaNAAAGgAAAcwCYCZGAEY'
1127
        'mJhMJghpiaYBUkKammSHqNMZQ0NABkNAeo0AGneAevnlwQoGzEzNVzaYxp/1Uk'
1128
        'xXzA1CQX0BJMZZLcPBrluJir5SQyijWHYZ6ZUtVqqlYDdB2QoCwa9GyWwGYDMA'
1129
        'OQYhkpLt/OKFnnlT8E0PmO8+ZNSo2WWqeCzGB5fBXZ3IvV7uNJVE7DYnWj6qwB'
1130
        'k5DJDIrQ5OQHHIjkS9KqwG3mc3t+F1+iujb89ufyBNIKCgeZBWrl5cXxbMGoMs'
1131
        'c9JuUkg5YsiVcaZJurc6KLi6yKOkgCUOlIlOpOoXyrTJjK8ZgbklReDdwGmFgt'
1132
        'dkVsAIslSVCd4AtACSLbyhLHryfb14PKegrVDba+U8OL6KQtzdM5HLjAc8/p6n'
1133
        '0lgaWU8skgO7xupPTkyuwheSckejFLK5T4ZOo0Gda9viaIhpD1Qn7JqqlKAJqC'
1134
        'QplPKp2nqBWAfwBGaOwVrz3y1T+UZZNismXHsb2Jq18T+VaD9k4P8DqE3g70qV'
1135
        'JLurpnDI6VS5oqDDPVbtVjMxMxMg4rzQVipn2Bv1fVNK0iq3Gl0hhnnHKm/egy'
1136
        'nWQ7QH/F3JFOFCQ0aSPfA='
1137
        ).decode('base64')
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1138
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1139
    def test_repository_tarball(self):
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1140
        # Test that Repository.tarball generates the right operations
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1141
        transport_path = 'repo'
2018.18.14 by Martin Pool
merge hpss again; restore incorrectly removed RemoteRepository.break_lock
1142
        expected_calls = [('call_expecting_body', 'Repository.tarball',
3104.4.2 by Andrew Bennetts
All tests passing.
1143
                           ('repo/', 'bz2',),),
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1144
            ]
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1145
        repo, client = self.setup_fake_client_and_repository(transport_path)
1146
        client.add_success_response_with_body(self.tarball_content, 'ok')
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1147
        # Now actually ask for the tarball
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1148
        tarball_file = repo._get_tarball('bz2')
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
1149
        try:
1150
            self.assertEqual(expected_calls, client._calls)
1151
            self.assertEqual(self.tarball_content, tarball_file.read())
1152
        finally:
1153
            tarball_file.close()
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1154
1155
1156
class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):
1157
    """RemoteRepository.copy_content_into optimizations"""
1158
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
1159
    def test_copy_content_remote_to_local(self):
1160
        self.transport_server = server.SmartTCPServer_for_testing
1161
        src_repo = self.make_repository('repo1')
1162
        src_repo = repository.Repository.open(self.get_url('repo1'))
1163
        # At the moment the tarball-based copy_content_into can't write back
1164
        # into a smart server.  It would be good if it could upload the
1165
        # tarball; once that works we'd have to create repositories of
1166
        # different formats. -- mbp 20070410
1167
        dest_url = self.get_vfs_only_url('repo2')
1168
        dest_bzrdir = BzrDir.create(dest_url)
1169
        dest_repo = dest_bzrdir.create_repository()
1170
        self.assertFalse(isinstance(dest_repo, RemoteRepository))
1171
        self.assertTrue(isinstance(src_repo, RemoteRepository))
1172
        src_repo.copy_content_into(dest_repo)
2535.3.39 by Andrew Bennetts
Tidy some XXXs.
1173
1174
2535.3.49 by Andrew Bennetts
Rename 'Repository.fetch_revisions' smart request to 'Repository.stream_knit_data_for_revisions'.
1175
class TestRepositoryStreamKnitData(TestRemoteRepository):
2535.3.39 by Andrew Bennetts
Tidy some XXXs.
1176
1177
    def make_pack_file(self, records):
1178
        pack_file = StringIO()
1179
        pack_writer = pack.ContainerWriter(pack_file.write)
1180
        pack_writer.begin()
1181
        for bytes, names in records:
1182
            pack_writer.add_bytes_record(bytes, names)
1183
        pack_writer.end()
1184
        pack_file.seek(0)
1185
        return pack_file
1186
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
1187
    def make_pack_stream(self, records):
2535.4.18 by Andrew Bennetts
Use pack.ContainerSerialiser to remove some nasty cruft.
1188
        pack_serialiser = pack.ContainerSerialiser()
1189
        yield pack_serialiser.begin()
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
1190
        for bytes, names in records:
2535.4.18 by Andrew Bennetts
Use pack.ContainerSerialiser to remove some nasty cruft.
1191
            yield pack_serialiser.bytes_record(bytes, names)
1192
        yield pack_serialiser.end()
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
1193
2535.3.39 by Andrew Bennetts
Tidy some XXXs.
1194
    def test_bad_pack_from_server(self):
2535.3.50 by Andrew Bennetts
Use tuple names in data streams rather than concatenated strings.
1195
        """A response with invalid data (e.g. it has a record with multiple
1196
        names) triggers an exception.
1197
        
1198
        Not all possible errors will be caught at this stage, but obviously
1199
        malformed data should be.
1200
        """
1201
        record = ('bytes', [('name1',), ('name2',)])
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
1202
        pack_stream = self.make_pack_stream([record])
2535.3.39 by Andrew Bennetts
Tidy some XXXs.
1203
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1204
        repo, client = self.setup_fake_client_and_repository(transport_path)
1205
        client.add_success_response_with_body(pack_stream, 'ok')
3184.1.9 by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of
1206
        search = graph.SearchResult(set(['revid']), set(), 1, set(['revid']))
1207
        stream = repo.get_data_stream_for_search(search)
2535.3.39 by Andrew Bennetts
Tidy some XXXs.
1208
        self.assertRaises(errors.SmartProtocolError, list, stream)
1209
    
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
1210
    def test_backwards_compatibility(self):
1211
        """If the server doesn't recognise this request, fallback to VFS."""
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1212
        repo, client = self.setup_fake_client_and_repository('path')
1213
        client.add_unknown_method_response(
1214
            'Repository.stream_revisions_chunked')
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
1215
        self.mock_called = False
1216
        repo._real_repository = MockRealRepository(self)
3184.1.9 by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of
1217
        search = graph.SearchResult(set(['revid']), set(), 1, set(['revid']))
1218
        repo.get_data_stream_for_search(search)
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
1219
        self.assertTrue(self.mock_called)
1220
        self.failIf(client.expecting_body,
1221
            "The protocol has been left in an unclean state that will cause "
1222
            "TooManyConcurrentRequests errors.")
1223
1224
1225
class MockRealRepository(object):
1226
    """Helper class for TestRepositoryStreamKnitData.test_unknown_method."""
1227
1228
    def __init__(self, test):
1229
        self.test = test
1230
3184.1.9 by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of
1231
    def get_data_stream_for_search(self, search):
1232
        self.test.assertEqual(set(['revid']), search.get_keys())
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
1233
        self.test.mock_called = True
1234
1235