/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3948.3.7 by Martin Pool
Updated tests for RemoteRepository.get_parent_map on old servers.
1
# Copyright (C) 2006, 2007, 2008, 2009 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
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
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 (
3834.3.2 by Andrew Bennetts
Preserve BzrBranch5's _synchronize_history code without affecting Branch or BzrBranch7; add effort test for RemoteBranch.copy_content_into.
30
    bzrdir,
3777.1.3 by Aaron Bentley
Use SSH default username from authentication.conf
31
    config,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
32
    errors,
3184.1.9 by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of
33
    graph,
2535.3.39 by Andrew Bennetts
Tidy some XXXs.
34
    pack,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
35
    remote,
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
36
    repository,
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
37
    smart,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
38
    tests,
3691.2.4 by Martin Pool
Add FakeRemoteTransport to clarify test_remote
39
    urlutils,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
40
    )
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
41
from bzrlib.branch import Branch
42
from bzrlib.bzrdir import BzrDir, BzrDirFormat
43
from bzrlib.remote import (
44
    RemoteBranch,
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
45
    RemoteBranchFormat,
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
46
    RemoteBzrDir,
47
    RemoteBzrDirFormat,
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
48
    RemoteRepository,
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
49
    )
50
from bzrlib.revision import NULL_REVISION
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
51
from bzrlib.smart import server, medium
2018.5.159 by Andrew Bennetts
Rename SmartClient to _SmartClient.
52
from bzrlib.smart.client import _SmartClient
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
53
from bzrlib.tests import (
54
    condition_isinstance,
55
    split_suite_by_condition,
56
    multiply_tests,
57
    )
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
58
from bzrlib.transport import get_transport, http
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
59
from bzrlib.transport.memory import MemoryTransport
3777.1.3 by Aaron Bentley
Use SSH default username from authentication.conf
60
from bzrlib.transport.remote import (
61
    RemoteTransport,
62
    RemoteSSHTransport,
63
    RemoteTCPTransport,
64
)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
65
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
66
def load_tests(standard_tests, module, loader):
67
    to_adapt, result = split_suite_by_condition(
68
        standard_tests, condition_isinstance(BasicRemoteObjectTests))
69
    smart_server_version_scenarios = [
4104.4.2 by Robert Collins
Fix test_source for 1.13 landing.
70
        ('HPSS-v2',
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
71
            {'transport_server': server.SmartTCPServer_for_testing_v2_only}),
4104.4.2 by Robert Collins
Fix test_source for 1.13 landing.
72
        ('HPSS-v3',
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
73
            {'transport_server': server.SmartTCPServer_for_testing})]
74
    return multiply_tests(to_adapt, smart_server_version_scenarios, result)
75
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)
76
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
77
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
78
79
    def setUp(self):
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
80
        super(BasicRemoteObjectTests, self).setUp()
81
        self.transport = self.get_transport()
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
82
        # 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
83
        self.local_wt = BzrDir.create_standalone_workingtree('.')
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
84
2018.5.171 by Andrew Bennetts
Disconnect RemoteTransports in some tests to avoid tripping up test_strace with leftover threads from previous tests.
85
    def tearDown(self):
86
        self.transport.disconnect()
87
        tests.TestCaseWithTransport.tearDown(self)
88
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
89
    def test_create_remote_bzrdir(self):
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
90
        b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
91
        self.assertIsInstance(b, BzrDir)
92
93
    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.
94
        # open a standalone branch in the working directory
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
95
        b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
96
        branch = b.open_branch()
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
97
        self.assertIsInstance(branch, Branch)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
98
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
99
    def test_remote_repository(self):
100
        b = BzrDir.open_from_transport(self.transport)
101
        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.
102
        revid = u'\xc823123123'.encode('utf8')
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
103
        self.assertFalse(repo.has_revision(revid))
104
        self.local_wt.commit(message='test commit', rev_id=revid)
105
        self.assertTrue(repo.has_revision(revid))
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
106
107
    def test_remote_branch_revision_history(self):
108
        b = BzrDir.open_from_transport(self.transport).open_branch()
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
109
        self.assertEqual([], b.revision_history())
110
        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.
111
        r2 = self.local_wt.commit('1st commit', rev_id=u'\xc8'.encode('utf8'))
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
112
        self.assertEqual([r1, r2], b.revision_history())
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
113
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
114
    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)
115
        """Should open a RemoteBzrDir over a RemoteTransport"""
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
116
        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.
117
        self.assertTrue(RemoteBzrDirFormat
118
                        in BzrDirFormat._control_server_formats)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
119
        self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
120
121
    def test_open_detected_smart_format(self):
122
        fmt = BzrDirFormat.find_format(self.transport)
123
        d = fmt.open(self.transport)
124
        self.assertIsInstance(d, BzrDir)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
125
2477.1.1 by Martin Pool
Add RemoteBranch repr
126
    def test_remote_branch_repr(self):
127
        b = BzrDir.open_from_transport(self.transport).open_branch()
128
        self.assertStartsWith(str(b), 'RemoteBranch(')
129
4103.2.2 by Andrew Bennetts
Fix RemoteBranchFormat.supports_stacking()
130
    def test_remote_branch_format_supports_stacking(self):
131
        t = self.transport
132
        self.make_branch('unstackable', format='pack-0.92')
133
        b = BzrDir.open_from_transport(t.clone('unstackable')).open_branch()
134
        self.assertFalse(b._format.supports_stacking())
135
        self.make_branch('stackable', format='1.9')
136
        b = BzrDir.open_from_transport(t.clone('stackable')).open_branch()
137
        self.assertTrue(b._format.supports_stacking())
138
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
139
    def test_remote_repo_format_supports_external_references(self):
140
        t = self.transport
141
        bd = self.make_bzrdir('unstackable', format='pack-0.92')
142
        r = bd.create_repository()
143
        self.assertFalse(r._format.supports_external_lookups)
144
        r = BzrDir.open_from_transport(t.clone('unstackable')).open_repository()
145
        self.assertFalse(r._format.supports_external_lookups)
146
        bd = self.make_bzrdir('stackable', format='1.9')
147
        r = bd.create_repository()
148
        self.assertTrue(r._format.supports_external_lookups)
149
        r = BzrDir.open_from_transport(t.clone('stackable')).open_repository()
150
        self.assertTrue(r._format.supports_external_lookups)
151
3691.2.4 by Martin Pool
Add FakeRemoteTransport to clarify test_remote
152
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
153
class FakeProtocol(object):
154
    """Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
155
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
156
    def __init__(self, body, fake_client):
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
157
        self.body = body
158
        self._body_buffer = None
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
159
        self._fake_client = fake_client
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
160
161
    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.
162
        if self._body_buffer is None:
163
            self._body_buffer = StringIO(self.body)
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
164
        bytes = self._body_buffer.read(count)
165
        if self._body_buffer.tell() == len(self._body_buffer.getvalue()):
166
            self._fake_client.expecting_body = False
167
        return bytes
168
169
    def cancel_read_body(self):
170
        self._fake_client.expecting_body = False
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
171
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
172
    def read_streamed_body(self):
173
        return self.body
174
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
175
2018.5.159 by Andrew Bennetts
Rename SmartClient to _SmartClient.
176
class FakeClient(_SmartClient):
177
    """Lookalike for _SmartClient allowing testing."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
178
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
179
    def __init__(self, fake_medium_base='fake base'):
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
180
        """Create a FakeClient."""
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
181
        self.responses = []
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
182
        self._calls = []
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
183
        self.expecting_body = False
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
184
        # if non-None, this is the list of expected calls, with only the
185
        # method name and arguments included.  the body might be hard to
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
186
        # compute so is not included. If a call is None, that call can
187
        # be anything.
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
188
        self._expected_calls = None
3431.3.2 by Andrew Bennetts
Remove 'base' from _SmartClient entirely, now that the medium has it.
189
        _SmartClient.__init__(self, FakeMedium(self._calls, fake_medium_base))
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
190
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
191
    def add_expected_call(self, call_name, call_args, response_type,
192
        response_args, response_body=None):
193
        if self._expected_calls is None:
194
            self._expected_calls = []
195
        self._expected_calls.append((call_name, call_args))
3691.2.8 by Martin Pool
Update some test_remote tests for Branch.get_stacked_on_url and with clearer assertions
196
        self.responses.append((response_type, response_args, response_body))
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
197
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
198
    def add_success_response(self, *args):
199
        self.responses.append(('success', args, None))
200
201
    def add_success_response_with_body(self, body, *args):
202
        self.responses.append(('success', args, body))
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
203
        if self._expected_calls is not None:
204
            self._expected_calls.append(None)
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
205
206
    def add_error_response(self, *args):
207
        self.responses.append(('error', args))
208
209
    def add_unknown_method_response(self, verb):
210
        self.responses.append(('unknown', verb))
211
3691.2.8 by Martin Pool
Update some test_remote tests for Branch.get_stacked_on_url and with clearer assertions
212
    def finished_test(self):
213
        if self._expected_calls:
214
            raise AssertionError("%r finished but was still expecting %r"
215
                % (self, self._expected_calls[0]))
216
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.
217
    def _get_next_response(self):
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
218
        try:
219
            response_tuple = self.responses.pop(0)
220
        except IndexError, e:
221
            raise AssertionError("%r didn't expect any more calls"
222
                % (self,))
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
223
        if response_tuple[0] == 'unknown':
224
            raise errors.UnknownSmartMethod(response_tuple[1])
225
        elif response_tuple[0] == 'error':
226
            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.
227
        return response_tuple
228
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
229
    def _check_call(self, method, args):
230
        if self._expected_calls is None:
231
            # the test should be updated to say what it expects
232
            return
233
        try:
234
            next_call = self._expected_calls.pop(0)
235
        except IndexError:
236
            raise AssertionError("%r didn't expect any more calls "
237
                "but got %r%r"
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
238
                % (self, method, args,))
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
239
        if next_call is None:
240
            return
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
241
        if method != next_call[0] or args != next_call[1]:
242
            raise AssertionError("%r expected %r%r "
243
                "but got %r%r"
3691.2.8 by Martin Pool
Update some test_remote tests for Branch.get_stacked_on_url and with clearer assertions
244
                % (self, next_call[0], next_call[1], method, args,))
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
245
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
246
    def call(self, method, *args):
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
247
        self._check_call(method, args)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
248
        self._calls.append(('call', method, args))
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
249
        return self._get_next_response()[1]
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
250
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
251
    def call_expecting_body(self, method, *args):
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
252
        self._check_call(method, args)
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
253
        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.
254
        result = self._get_next_response()
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
255
        self.expecting_body = True
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
256
        return result[1], FakeProtocol(result[2], self)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
257
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.
258
    def call_with_body_bytes_expecting_body(self, method, args, body):
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
259
        self._check_call(method, args)
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.
260
        self._calls.append(('call_with_body_bytes_expecting_body', method,
261
            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.
262
        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.
263
        self.expecting_body = True
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
264
        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.
265
3842.3.9 by Andrew Bennetts
Backing up the stream so that we can fallback correctly.
266
    def call_with_body_stream(self, args, stream):
267
        # Explicitly consume the stream before checking for an error, because
268
        # that's what happens a real medium.
269
        stream = list(stream)
270
        self._check_call(args[0], args[1:])
271
        self._calls.append(('call_with_body_stream', args[0], args[1:], stream))
4144.3.2 by Andrew Bennetts
Use Repository.insert_stream_locked if there is a lock_token for the remote repo.
272
        result = self._get_next_response()
4144.3.3 by Andrew Bennetts
Tweaks based on review from Robert.
273
        # The second value returned from call_with_body_stream is supposed to
274
        # be a response_handler object, but so far no tests depend on that.
275
        response_handler = None 
276
        return result[1], response_handler
3842.3.9 by Andrew Bennetts
Backing up the stream so that we can fallback correctly.
277
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
278
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
279
class FakeMedium(medium.SmartClientMedium):
3104.4.2 by Andrew Bennetts
All tests passing.
280
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.
281
    def __init__(self, client_calls, base):
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
282
        medium.SmartClientMedium.__init__(self, base)
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
283
        self._client_calls = client_calls
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.
284
285
    def disconnect(self):
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
286
        self._client_calls.append(('disconnect medium',))
3104.4.2 by Andrew Bennetts
All tests passing.
287
288
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.
289
class TestVfsHas(tests.TestCase):
290
291
    def test_unicode_path(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
292
        client = FakeClient('/')
293
        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.
294
        transport = RemoteTransport('bzr://localhost/', _client=client)
295
        filename = u'/hell\u00d8'.encode('utf8')
296
        result = transport.has(filename)
297
        self.assertEqual(
298
            [('call', 'has', (filename,))],
299
            client._calls)
300
        self.assertTrue(result)
301
302
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
303
class TestRemote(tests.TestCaseWithMemoryTransport):
4032.1.1 by John Arbash Meinel
Merge the removal of all trailing whitespace, and resolve conflicts.
304
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
305
    def get_branch_format(self):
306
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
307
        return reference_bzrdir_format.get_branch_format()
308
4053.1.2 by Robert Collins
Actually make this branch work.
309
    def get_repo_format(self):
310
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
311
        return reference_bzrdir_format.repository_format
312
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
313
    def disable_verb(self, verb):
314
        """Disable a verb for one test."""
315
        request_handlers = smart.request.request_handlers
316
        orig_method = request_handlers.get(verb)
317
        request_handlers.remove(verb)
318
        def restoreVerb():
319
            request_handlers.register(verb, orig_method)
320
        self.addCleanup(restoreVerb)
321
322
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
323
class Test_ClientMedium_remote_path_from_transport(tests.TestCase):
324
    """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.
325
326
    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.
327
        """Assert that the result of
328
        SmartClientMedium.remote_path_from_transport is the expected value for
329
        a given client_base and transport_base.
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
330
        """
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
331
        client_medium = medium.SmartClientMedium(client_base)
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
332
        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.
333
        result = client_medium.remote_path_from_transport(transport)
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
334
        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.
335
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
336
    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.
337
        """SmartClientMedium.remote_path_from_transport calculates a URL for
338
        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.
339
        """
340
        self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')
341
        self.assertRemotePath(
342
            'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz')
343
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
344
    def assertRemotePathHTTP(self, expected, transport_base, relpath):
345
        """Assert that the result of
346
        HttpTransportBase.remote_path_from_transport is the expected value for
347
        a given transport_base and relpath of that transport.  (Note that
348
        HttpTransportBase is a subclass of SmartClientMedium)
349
        """
350
        base_transport = get_transport(transport_base)
351
        client_medium = base_transport.get_smart_medium()
352
        cloned_transport = base_transport.clone(relpath)
353
        result = client_medium.remote_path_from_transport(cloned_transport)
354
        self.assertEqual(expected, result)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
355
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
356
    def test_remote_path_from_transport_http(self):
357
        """Remote paths for HTTP transports are calculated differently to other
358
        transports.  They are just relative to the client base, not the root
359
        directory of the host.
360
        """
361
        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.
362
            self.assertRemotePathHTTP(
363
                '../xyz/', scheme + '//host/path', '../xyz/')
364
            self.assertRemotePathHTTP(
365
                'xyz/', scheme + '//host/path', 'xyz/')
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
366
367
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
368
class Test_ClientMedium_remote_is_at_least(tests.TestCase):
369
    """Tests for the behaviour of client_medium.remote_is_at_least."""
370
371
    def test_initially_unlimited(self):
372
        """A fresh medium assumes that the remote side supports all
373
        versions.
374
        """
375
        client_medium = medium.SmartClientMedium('dummy base')
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
376
        self.assertFalse(client_medium._is_remote_before((99, 99)))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
377
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
378
    def test__remember_remote_is_before(self):
379
        """Calling _remember_remote_is_before ratchets down the known remote
380
        version.
381
        """
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
382
        client_medium = medium.SmartClientMedium('dummy base')
383
        # Mark the remote side as being less than 1.6.  The remote side may
384
        # still be 1.5.
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
385
        client_medium._remember_remote_is_before((1, 6))
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
386
        self.assertTrue(client_medium._is_remote_before((1, 6)))
387
        self.assertFalse(client_medium._is_remote_before((1, 5)))
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
388
        # Calling _remember_remote_is_before again with a lower value works.
389
        client_medium._remember_remote_is_before((1, 5))
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
390
        self.assertTrue(client_medium._is_remote_before((1, 5)))
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
391
        # You cannot call _remember_remote_is_before with a larger value.
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
392
        self.assertRaises(
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
393
            AssertionError, client_medium._remember_remote_is_before, (1, 9))
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
394
395
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
396
class TestBzrDirCloningMetaDir(TestRemote):
397
398
    def test_backwards_compat(self):
399
        self.setup_smart_server_with_call_log()
400
        a_dir = self.make_bzrdir('.')
401
        self.reset_smart_call_log()
402
        verb = 'BzrDir.cloning_metadir'
403
        self.disable_verb(verb)
404
        format = a_dir.cloning_metadir()
405
        call_count = len([call for call in self.hpss_calls if
4070.3.1 by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips.
406
            call.call.method == verb])
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
407
        self.assertEqual(1, call_count)
408
409
    def test_current_server(self):
410
        transport = self.get_transport('.')
411
        transport = transport.clone('quack')
412
        self.make_bzrdir('quack')
413
        client = FakeClient(transport.base)
414
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
415
        control_name = reference_bzrdir_format.network_name()
416
        client.add_expected_call(
417
            'BzrDir.cloning_metadir', ('quack/', 'False'),
4084.2.2 by Robert Collins
Review feedback.
418
            'success', (control_name, '', ('branch', ''))),
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
419
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
420
            _client=client)
421
        result = a_bzrdir.cloning_metadir()
422
        # We should have got a reference control dir with default branch and
423
        # repository formats.
424
        # This pokes a little, just to be sure.
425
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
4070.2.8 by Robert Collins
Really test the current BzrDir.cloning_metadir contract.
426
        self.assertEqual(None, result._repository_format)
427
        self.assertEqual(None, result._branch_format)
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
428
        client.finished_test()
429
430
4053.1.2 by Robert Collins
Actually make this branch work.
431
class TestBzrDirOpenBranch(TestRemote):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
432
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
433
    def test_backwards_compat(self):
434
        self.setup_smart_server_with_call_log()
435
        self.make_branch('.')
436
        a_dir = BzrDir.open(self.get_url('.'))
437
        self.reset_smart_call_log()
438
        verb = 'BzrDir.open_branchV2'
439
        self.disable_verb(verb)
440
        format = a_dir.open_branch()
441
        call_count = len([call for call in self.hpss_calls if
442
            call.call.method == verb])
443
        self.assertEqual(1, call_count)
444
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
445
    def test_branch_present(self):
4053.1.2 by Robert Collins
Actually make this branch work.
446
        reference_format = self.get_repo_format()
447
        network_name = reference_format.network_name()
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
448
        branch_network_name = self.get_branch_format().network_name()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
449
        transport = MemoryTransport()
450
        transport.mkdir('quack')
451
        transport = transport.clone('quack')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
452
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
453
        client.add_expected_call(
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
454
            'BzrDir.open_branchV2', ('quack/',),
455
            'success', ('branch', branch_network_name))
3691.2.10 by Martin Pool
Update more test_remote tests
456
        client.add_expected_call(
4053.1.2 by Robert Collins
Actually make this branch work.
457
            'BzrDir.find_repositoryV3', ('quack/',),
458
            'success', ('ok', '', 'no', 'no', 'no', network_name))
3691.2.10 by Martin Pool
Update more test_remote tests
459
        client.add_expected_call(
460
            'Branch.get_stacked_on_url', ('quack/',),
461
            'error', ('NotStacked',))
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
462
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
463
            _client=client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
464
        result = bzrdir.open_branch()
465
        self.assertIsInstance(result, RemoteBranch)
466
        self.assertEqual(bzrdir, result.bzrdir)
3691.2.10 by Martin Pool
Update more test_remote tests
467
        client.finished_test()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
468
469
    def test_branch_missing(self):
470
        transport = MemoryTransport()
471
        transport.mkdir('quack')
472
        transport = transport.clone('quack')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
473
        client = FakeClient(transport.base)
474
        client.add_error_response('nobranch')
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
475
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
476
            _client=client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
477
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
478
        self.assertEqual(
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
479
            [('call', 'BzrDir.open_branchV2', ('quack/',))],
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
480
            client._calls)
481
3211.4.1 by Robert Collins
* ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,
482
    def test__get_tree_branch(self):
483
        # _get_tree_branch is a form of open_branch, but it should only ask for
484
        # branch opening, not any other network requests.
485
        calls = []
486
        def open_branch():
487
            calls.append("Called")
488
            return "a-branch"
489
        transport = MemoryTransport()
490
        # 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.
491
        client = FakeClient(transport.base)
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
492
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
493
            _client=client)
3211.4.1 by Robert Collins
* ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,
494
        # patch the open_branch call to record that it was called.
495
        bzrdir.open_branch = open_branch
496
        self.assertEqual((None, "a-branch"), bzrdir._get_tree_branch())
497
        self.assertEqual(["Called"], calls)
498
        self.assertEqual([], client._calls)
499
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.
500
    def test_url_quoting_of_path(self):
501
        # Relpaths on the wire should not be URL-escaped.  So "~" should be
502
        # 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.
503
        transport = RemoteTCPTransport('bzr://localhost/~hello/')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
504
        client = FakeClient(transport.base)
4053.1.2 by Robert Collins
Actually make this branch work.
505
        reference_format = self.get_repo_format()
506
        network_name = reference_format.network_name()
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
507
        branch_network_name = self.get_branch_format().network_name()
3691.2.10 by Martin Pool
Update more test_remote tests
508
        client.add_expected_call(
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
509
            'BzrDir.open_branchV2', ('~hello/',),
510
            'success', ('branch', branch_network_name))
3691.2.10 by Martin Pool
Update more test_remote tests
511
        client.add_expected_call(
4053.1.2 by Robert Collins
Actually make this branch work.
512
            'BzrDir.find_repositoryV3', ('~hello/',),
513
            'success', ('ok', '', 'no', 'no', 'no', network_name))
3691.2.10 by Martin Pool
Update more test_remote tests
514
        client.add_expected_call(
515
            'Branch.get_stacked_on_url', ('~hello/',),
516
            'error', ('NotStacked',))
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
517
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
518
            _client=client)
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.
519
        result = bzrdir.open_branch()
3691.2.10 by Martin Pool
Update more test_remote tests
520
        client.finished_test()
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.
521
3221.3.3 by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so
522
    def check_open_repository(self, rich_root, subtrees, external_lookup='no'):
4053.1.2 by Robert Collins
Actually make this branch work.
523
        reference_format = self.get_repo_format()
524
        network_name = reference_format.network_name()
3104.4.2 by Andrew Bennetts
All tests passing.
525
        transport = MemoryTransport()
526
        transport.mkdir('quack')
527
        transport = transport.clone('quack')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
528
        if rich_root:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
529
            rich_response = 'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
530
        else:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
531
            rich_response = 'no'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
532
        if subtrees:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
533
            subtree_response = 'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
534
        else:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
535
            subtree_response = 'no'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
536
        client = FakeClient(transport.base)
537
        client.add_success_response(
4053.1.2 by Robert Collins
Actually make this branch work.
538
            'ok', '', rich_response, subtree_response, external_lookup,
539
            network_name)
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
540
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
541
            _client=client)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
542
        result = bzrdir.open_repository()
543
        self.assertEqual(
4053.1.2 by Robert Collins
Actually make this branch work.
544
            [('call', 'BzrDir.find_repositoryV3', ('quack/',))],
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
545
            client._calls)
546
        self.assertIsInstance(result, RemoteRepository)
547
        self.assertEqual(bzrdir, result.bzrdir)
548
        self.assertEqual(rich_root, result._format.rich_root_data)
2018.5.138 by Robert Collins
Merge bzr.dev.
549
        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.
550
551
    def test_open_repository_sets_format_attributes(self):
552
        self.check_open_repository(True, True)
553
        self.check_open_repository(False, True)
554
        self.check_open_repository(True, False)
555
        self.check_open_repository(False, False)
3221.3.3 by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so
556
        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.
557
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
558
    def test_old_server(self):
559
        """RemoteBzrDirFormat should fail to probe if the server version is too
560
        old.
561
        """
562
        self.assertRaises(errors.NotBranchError,
563
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
564
565
4032.3.2 by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.
566
class TestBzrDirCreateBranch(TestRemote):
567
568
    def test_backwards_compat(self):
569
        self.setup_smart_server_with_call_log()
570
        repo = self.make_repository('.')
571
        self.reset_smart_call_log()
572
        self.disable_verb('BzrDir.create_branch')
573
        branch = repo.bzrdir.create_branch()
574
        create_branch_call_count = len([call for call in self.hpss_calls if
4070.3.1 by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips.
575
            call.call.method == 'BzrDir.create_branch'])
4032.3.2 by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.
576
        self.assertEqual(1, create_branch_call_count)
577
578
    def test_current_server(self):
579
        transport = self.get_transport('.')
580
        transport = transport.clone('quack')
581
        self.make_repository('quack')
582
        client = FakeClient(transport.base)
583
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
584
        reference_format = reference_bzrdir_format.get_branch_format()
585
        network_name = reference_format.network_name()
586
        reference_repo_fmt = reference_bzrdir_format.repository_format
587
        reference_repo_name = reference_repo_fmt.network_name()
588
        client.add_expected_call(
589
            'BzrDir.create_branch', ('quack/', network_name),
590
            'success', ('ok', network_name, '', 'no', 'no', 'yes',
591
            reference_repo_name))
592
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
593
            _client=client)
594
        branch = a_bzrdir.create_branch()
595
        # We should have got a remote branch
596
        self.assertIsInstance(branch, remote.RemoteBranch)
597
        # its format should have the settings from the response
598
        format = branch._format
599
        self.assertEqual(network_name, format.network_name())
600
601
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
602
class TestBzrDirCreateRepository(TestRemote):
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
603
604
    def test_backwards_compat(self):
605
        self.setup_smart_server_with_call_log()
606
        bzrdir = self.make_bzrdir('.')
607
        self.reset_smart_call_log()
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
608
        self.disable_verb('BzrDir.create_repository')
609
        repo = bzrdir.create_repository()
610
        create_repo_call_count = len([call for call in self.hpss_calls if
4070.3.1 by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips.
611
            call.call.method == 'BzrDir.create_repository'])
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
612
        self.assertEqual(1, create_repo_call_count)
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
613
614
    def test_current_server(self):
615
        transport = self.get_transport('.')
616
        transport = transport.clone('quack')
617
        self.make_bzrdir('quack')
618
        client = FakeClient(transport.base)
619
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
620
        reference_format = reference_bzrdir_format.repository_format
621
        network_name = reference_format.network_name()
622
        client.add_expected_call(
623
            'BzrDir.create_repository', ('quack/',
624
                'Bazaar pack repository format 1 (needs bzr 0.92)\n', 'False'),
625
            'success', ('ok', 'no', 'no', 'no', network_name))
626
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
627
            _client=client)
628
        repo = a_bzrdir.create_repository()
629
        # We should have got a remote repository
630
        self.assertIsInstance(repo, remote.RemoteRepository)
631
        # its format should have the settings from the response
632
        format = repo._format
633
        self.assertFalse(format.rich_root_data)
634
        self.assertFalse(format.supports_tree_reference)
635
        self.assertFalse(format.supports_external_lookups)
636
        self.assertEqual(network_name, format.network_name())
637
638
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
639
class TestBzrDirOpenRepository(TestRemote):
640
641
    def test_backwards_compat_1_2_3(self):
642
        # fallback all the way to the first version.
643
        reference_format = self.get_repo_format()
644
        network_name = reference_format.network_name()
645
        client = FakeClient('bzr://example.com/')
646
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
647
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
648
        client.add_success_response('ok', '', 'no', 'no')
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
649
        # A real repository instance will be created to determine the network
650
        # name.
651
        client.add_success_response_with_body(
652
            "Bazaar-NG meta directory, format 1\n", 'ok')
653
        client.add_success_response_with_body(
654
            reference_format.get_format_string(), 'ok')
655
        # PackRepository wants to do a stat
656
        client.add_success_response('stat', '0', '65535')
657
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
658
            _client=client)
659
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
660
            _client=client)
661
        repo = bzrdir.open_repository()
662
        self.assertEqual(
663
            [('call', 'BzrDir.find_repositoryV3', ('quack/',)),
664
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
665
             ('call', 'BzrDir.find_repository', ('quack/',)),
666
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
667
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
668
             ('call', 'stat', ('/quack/.bzr/repository',)),
669
             ],
670
            client._calls)
671
        self.assertEqual(network_name, repo._format.network_name())
672
673
    def test_backwards_compat_2(self):
674
        # fallback to find_repositoryV2
675
        reference_format = self.get_repo_format()
676
        network_name = reference_format.network_name()
677
        client = FakeClient('bzr://example.com/')
678
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
679
        client.add_success_response('ok', '', 'no', 'no', 'no')
680
        # A real repository instance will be created to determine the network
681
        # name.
682
        client.add_success_response_with_body(
683
            "Bazaar-NG meta directory, format 1\n", 'ok')
684
        client.add_success_response_with_body(
685
            reference_format.get_format_string(), 'ok')
686
        # PackRepository wants to do a stat
687
        client.add_success_response('stat', '0', '65535')
688
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
689
            _client=client)
690
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
691
            _client=client)
692
        repo = bzrdir.open_repository()
693
        self.assertEqual(
694
            [('call', 'BzrDir.find_repositoryV3', ('quack/',)),
695
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
696
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
697
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
698
             ('call', 'stat', ('/quack/.bzr/repository',)),
699
             ],
700
            client._calls)
701
        self.assertEqual(network_name, repo._format.network_name())
702
703
    def test_current_server(self):
704
        reference_format = self.get_repo_format()
705
        network_name = reference_format.network_name()
706
        transport = MemoryTransport()
707
        transport.mkdir('quack')
708
        transport = transport.clone('quack')
709
        client = FakeClient(transport.base)
710
        client.add_success_response('ok', '', 'no', 'no', 'no', network_name)
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
711
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
712
            _client=client)
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.
713
        repo = bzrdir.open_repository()
714
        self.assertEqual(
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
715
            [('call', 'BzrDir.find_repositoryV3', ('quack/',))],
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.
716
            client._calls)
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
717
        self.assertEqual(network_name, repo._format.network_name())
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.
718
719
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
720
class OldSmartClient(object):
721
    """A fake smart client for test_old_version that just returns a version one
722
    response to the 'hello' (query version) command.
723
    """
724
725
    def get_request(self):
726
        input_file = StringIO('ok\x011\n')
727
        output_file = StringIO()
728
        client_medium = medium.SmartSimplePipesClientMedium(
729
            input_file, output_file)
730
        return medium.SmartClientStreamMediumRequest(client_medium)
731
3241.1.1 by Andrew Bennetts
Shift protocol version querying from RemoteBzrDirFormat into SmartClientMedium.
732
    def protocol_version(self):
733
        return 1
734
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
735
736
class OldServerTransport(object):
737
    """A fake transport for test_old_server that reports it's smart server
738
    protocol version as version one.
739
    """
740
741
    def __init__(self):
742
        self.base = 'fake:'
743
744
    def get_smart_client(self):
745
        return OldSmartClient()
746
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
747
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
748
class RemoteBranchTestCase(TestRemote):
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
749
750
    def make_remote_branch(self, transport, client):
751
        """Make a RemoteBranch using 'client' as its _SmartClient.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
752
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
753
        A RemoteBzrDir and RemoteRepository will also be created to fill out
754
        the RemoteBranch, albeit with stub values for some of their attributes.
755
        """
756
        # we do not want bzrdir to make any remote calls, so use False as its
757
        # _client.  If it tries to make a remote call, this will fail
758
        # immediately.
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
759
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
760
            _client=False)
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
761
        repo = RemoteRepository(bzrdir, None, _client=client)
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
762
        branch_format = self.get_branch_format()
763
        format = RemoteBranchFormat(network_name=branch_format.network_name())
764
        return RemoteBranch(bzrdir, repo, _client=client, format=format)
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
765
766
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
767
class TestBranchGetParent(RemoteBranchTestCase):
768
769
    def test_no_parent(self):
770
        # in an empty branch we decode the response properly
771
        transport = MemoryTransport()
772
        client = FakeClient(transport.base)
773
        client.add_expected_call(
774
            'Branch.get_stacked_on_url', ('quack/',),
775
            'error', ('NotStacked',))
776
        client.add_expected_call(
777
            'Branch.get_parent', ('quack/',),
4083.1.7 by Andrew Bennetts
Fix same trivial bug [(x) != (x,)] in test_remote and test_smart.
778
            'success', ('',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
779
        transport.mkdir('quack')
780
        transport = transport.clone('quack')
781
        branch = self.make_remote_branch(transport, client)
782
        result = branch.get_parent()
783
        client.finished_test()
784
        self.assertEqual(None, result)
785
786
    def test_parent_relative(self):
787
        transport = MemoryTransport()
788
        client = FakeClient(transport.base)
789
        client.add_expected_call(
790
            'Branch.get_stacked_on_url', ('kwaak/',),
791
            'error', ('NotStacked',))
792
        client.add_expected_call(
793
            'Branch.get_parent', ('kwaak/',),
4083.1.7 by Andrew Bennetts
Fix same trivial bug [(x) != (x,)] in test_remote and test_smart.
794
            'success', ('../foo/',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
795
        transport.mkdir('kwaak')
796
        transport = transport.clone('kwaak')
797
        branch = self.make_remote_branch(transport, client)
798
        result = branch.get_parent()
799
        self.assertEqual(transport.clone('../foo').base, result)
800
801
    def test_parent_absolute(self):
802
        transport = MemoryTransport()
803
        client = FakeClient(transport.base)
804
        client.add_expected_call(
805
            'Branch.get_stacked_on_url', ('kwaak/',),
806
            'error', ('NotStacked',))
807
        client.add_expected_call(
808
            'Branch.get_parent', ('kwaak/',),
4083.1.7 by Andrew Bennetts
Fix same trivial bug [(x) != (x,)] in test_remote and test_smart.
809
            'success', ('http://foo/',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
810
        transport.mkdir('kwaak')
811
        transport = transport.clone('kwaak')
812
        branch = self.make_remote_branch(transport, client)
813
        result = branch.get_parent()
814
        self.assertEqual('http://foo/', result)
815
816
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
817
class TestBranchGetTagsBytes(RemoteBranchTestCase):
818
819
    def test_backwards_compat(self):
820
        self.setup_smart_server_with_call_log()
821
        branch = self.make_branch('.')
822
        self.reset_smart_call_log()
823
        verb = 'Branch.get_tags_bytes'
824
        self.disable_verb(verb)
825
        branch.tags.get_tag_dict()
826
        call_count = len([call for call in self.hpss_calls if
827
            call.call.method == verb])
828
        self.assertEqual(1, call_count)
829
830
    def test_trivial(self):
831
        transport = MemoryTransport()
832
        client = FakeClient(transport.base)
833
        client.add_expected_call(
834
            'Branch.get_stacked_on_url', ('quack/',),
835
            'error', ('NotStacked',))
836
        client.add_expected_call(
837
            'Branch.get_tags_bytes', ('quack/',),
838
            'success', ('',))
839
        transport.mkdir('quack')
840
        transport = transport.clone('quack')
841
        branch = self.make_remote_branch(transport, client)
842
        result = branch.tags.get_tag_dict()
843
        client.finished_test()
844
        self.assertEqual({}, result)
845
846
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
847
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
848
849
    def test_empty_branch(self):
850
        # in an empty branch we decode the response properly
851
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
852
        client = FakeClient(transport.base)
3691.2.8 by Martin Pool
Update some test_remote tests for Branch.get_stacked_on_url and with clearer assertions
853
        client.add_expected_call(
854
            'Branch.get_stacked_on_url', ('quack/',),
855
            'error', ('NotStacked',))
856
        client.add_expected_call(
857
            'Branch.last_revision_info', ('quack/',),
858
            'success', ('ok', '0', 'null:'))
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
859
        transport.mkdir('quack')
860
        transport = transport.clone('quack')
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
861
        branch = self.make_remote_branch(transport, client)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
862
        result = branch.last_revision_info()
3691.2.8 by Martin Pool
Update some test_remote tests for Branch.get_stacked_on_url and with clearer assertions
863
        client.finished_test()
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
864
        self.assertEqual((0, NULL_REVISION), result)
865
866
    def test_non_empty_branch(self):
867
        # 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.
868
        revid = u'\xc8'.encode('utf8')
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
869
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
870
        client = FakeClient(transport.base)
3691.2.8 by Martin Pool
Update some test_remote tests for Branch.get_stacked_on_url and with clearer assertions
871
        client.add_expected_call(
872
            'Branch.get_stacked_on_url', ('kwaak/',),
873
            'error', ('NotStacked',))
874
        client.add_expected_call(
875
            'Branch.last_revision_info', ('kwaak/',),
876
            'success', ('ok', '2', revid))
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
877
        transport.mkdir('kwaak')
878
        transport = transport.clone('kwaak')
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
879
        branch = self.make_remote_branch(transport, client)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
880
        result = branch.last_revision_info()
2018.5.106 by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings.
881
        self.assertEqual((2, revid), result)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
882
883
4053.1.2 by Robert Collins
Actually make this branch work.
884
class TestBranch_get_stacked_on_url(TestRemote):
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
885
    """Test Branch._get_stacked_on_url rpc"""
886
3691.2.10 by Martin Pool
Update more test_remote tests
887
    def test_get_stacked_on_invalid_url(self):
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
888
        # test that asking for a stacked on url the server can't access works.
889
        # This isn't perfect, but then as we're in the same process there
890
        # really isn't anything we can do to be 100% sure that the server
891
        # doesn't just open in - this test probably needs to be rewritten using
892
        # a spawn()ed server.
893
        stacked_branch = self.make_branch('stacked', format='1.9')
894
        memory_branch = self.make_branch('base', format='1.9')
895
        vfs_url = self.get_vfs_only_url('base')
896
        stacked_branch.set_stacked_on_url(vfs_url)
897
        transport = stacked_branch.bzrdir.root_transport
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
898
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
899
        client.add_expected_call(
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
900
            'Branch.get_stacked_on_url', ('stacked/',),
901
            'success', ('ok', vfs_url))
902
        # XXX: Multiple calls are bad, this second call documents what is
903
        # today.
904
        client.add_expected_call(
905
            'Branch.get_stacked_on_url', ('stacked/',),
906
            'success', ('ok', vfs_url))
907
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
908
            _client=client)
4118.1.5 by Andrew Bennetts
Fix test_remote tests.
909
        repo_fmt = remote.RemoteRepositoryFormat()
910
        repo_fmt._custom_format = stacked_branch.repository._format
911
        branch = RemoteBranch(bzrdir, RemoteRepository(bzrdir, repo_fmt),
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
912
            _client=client)
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
913
        result = branch.get_stacked_on_url()
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
914
        self.assertEqual(vfs_url, result)
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
915
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
916
    def test_backwards_compatible(self):
917
        # like with bzr1.6 with no Branch.get_stacked_on_url rpc
918
        base_branch = self.make_branch('base', format='1.6')
919
        stacked_branch = self.make_branch('stacked', format='1.6')
920
        stacked_branch.set_stacked_on_url('../base')
921
        client = FakeClient(self.get_url())
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
922
        branch_network_name = self.get_branch_format().network_name()
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
923
        client.add_expected_call(
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
924
            'BzrDir.open_branchV2', ('stacked/',),
925
            'success', ('branch', branch_network_name))
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
926
        client.add_expected_call(
4053.1.2 by Robert Collins
Actually make this branch work.
927
            'BzrDir.find_repositoryV3', ('stacked/',),
4118.1.5 by Andrew Bennetts
Fix test_remote tests.
928
            'success', ('ok', '', 'no', 'no', 'yes',
4053.1.2 by Robert Collins
Actually make this branch work.
929
                stacked_branch.repository._format.network_name()))
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
930
        # called twice, once from constructor and then again by us
931
        client.add_expected_call(
932
            'Branch.get_stacked_on_url', ('stacked/',),
933
            'unknown', ('Branch.get_stacked_on_url',))
934
        client.add_expected_call(
935
            'Branch.get_stacked_on_url', ('stacked/',),
936
            'unknown', ('Branch.get_stacked_on_url',))
937
        # this will also do vfs access, but that goes direct to the transport
938
        # and isn't seen by the FakeClient.
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
939
        bzrdir = RemoteBzrDir(self.get_transport('stacked'),
940
            remote.RemoteBzrDirFormat(), _client=client)
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
941
        branch = bzrdir.open_branch()
942
        result = branch.get_stacked_on_url()
943
        self.assertEqual('../base', result)
944
        client.finished_test()
945
        # it's in the fallback list both for the RemoteRepository and its vfs
946
        # repository
947
        self.assertEqual(1, len(branch.repository._fallback_repositories))
948
        self.assertEqual(1,
949
            len(branch.repository._real_repository._fallback_repositories))
950
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
951
    def test_get_stacked_on_real_branch(self):
952
        base_branch = self.make_branch('base', format='1.6')
953
        stacked_branch = self.make_branch('stacked', format='1.6')
954
        stacked_branch.set_stacked_on_url('../base')
4053.1.2 by Robert Collins
Actually make this branch work.
955
        reference_format = self.get_repo_format()
956
        network_name = reference_format.network_name()
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
957
        client = FakeClient(self.get_url())
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
958
        branch_network_name = self.get_branch_format().network_name()
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
959
        client.add_expected_call(
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
960
            'BzrDir.open_branchV2', ('stacked/',),
961
            'success', ('branch', branch_network_name))
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
962
        client.add_expected_call(
4053.1.2 by Robert Collins
Actually make this branch work.
963
            'BzrDir.find_repositoryV3', ('stacked/',),
4118.1.5 by Andrew Bennetts
Fix test_remote tests.
964
            'success', ('ok', '', 'no', 'no', 'yes', network_name))
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
965
        # called twice, once from constructor and then again by us
966
        client.add_expected_call(
967
            'Branch.get_stacked_on_url', ('stacked/',),
968
            'success', ('ok', '../base'))
969
        client.add_expected_call(
970
            'Branch.get_stacked_on_url', ('stacked/',),
971
            'success', ('ok', '../base'))
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
972
        bzrdir = RemoteBzrDir(self.get_transport('stacked'),
973
            remote.RemoteBzrDirFormat(), _client=client)
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
974
        branch = bzrdir.open_branch()
975
        result = branch.get_stacked_on_url()
976
        self.assertEqual('../base', result)
977
        client.finished_test()
978
        # it's in the fallback list both for the RemoteRepository and its vfs
979
        # repository
980
        self.assertEqual(1, len(branch.repository._fallback_repositories))
981
        self.assertEqual(1,
982
            len(branch.repository._real_repository._fallback_repositories))
983
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
984
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
985
class TestBranchSetLastRevision(RemoteBranchTestCase):
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
986
987
    def test_set_empty(self):
988
        # set_revision_history([]) is translated to calling
989
        # Branch.set_last_revision(path, '') on the wire.
3104.4.2 by Andrew Bennetts
All tests passing.
990
        transport = MemoryTransport()
991
        transport.mkdir('branch')
992
        transport = transport.clone('branch')
993
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
994
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
995
        client.add_expected_call(
996
            'Branch.get_stacked_on_url', ('branch/',),
997
            'error', ('NotStacked',))
998
        client.add_expected_call(
999
            'Branch.lock_write', ('branch/', '', ''),
1000
            'success', ('ok', 'branch token', 'repo token'))
1001
        client.add_expected_call(
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1002
            'Branch.last_revision_info',
1003
            ('branch/',),
1004
            'success', ('ok', '0', 'null:'))
1005
        client.add_expected_call(
3691.2.10 by Martin Pool
Update more test_remote tests
1006
            'Branch.set_last_revision', ('branch/', 'branch token', 'repo token', 'null:',),
1007
            'success', ('ok',))
1008
        client.add_expected_call(
1009
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1010
            'success', ('ok',))
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1011
        branch = self.make_remote_branch(transport, client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1012
        # This is a hack to work around the problem that RemoteBranch currently
1013
        # unnecessarily invokes _ensure_real upon a call to lock_write.
1014
        branch._ensure_real = lambda: None
1015
        branch.lock_write()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1016
        result = branch.set_revision_history([])
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1017
        branch.unlock()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1018
        self.assertEqual(None, result)
3691.2.10 by Martin Pool
Update more test_remote tests
1019
        client.finished_test()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1020
1021
    def test_set_nonempty(self):
1022
        # set_revision_history([rev-id1, ..., rev-idN]) is translated to calling
1023
        # Branch.set_last_revision(path, rev-idN) on the wire.
3104.4.2 by Andrew Bennetts
All tests passing.
1024
        transport = MemoryTransport()
1025
        transport.mkdir('branch')
1026
        transport = transport.clone('branch')
1027
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1028
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1029
        client.add_expected_call(
1030
            'Branch.get_stacked_on_url', ('branch/',),
1031
            'error', ('NotStacked',))
1032
        client.add_expected_call(
1033
            'Branch.lock_write', ('branch/', '', ''),
1034
            'success', ('ok', 'branch token', 'repo token'))
1035
        client.add_expected_call(
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1036
            'Branch.last_revision_info',
1037
            ('branch/',),
1038
            'success', ('ok', '0', 'null:'))
1039
        lines = ['rev-id2']
1040
        encoded_body = bz2.compress('\n'.join(lines))
1041
        client.add_success_response_with_body(encoded_body, 'ok')
1042
        client.add_expected_call(
3691.2.10 by Martin Pool
Update more test_remote tests
1043
            'Branch.set_last_revision', ('branch/', 'branch token', 'repo token', 'rev-id2',),
1044
            'success', ('ok',))
1045
        client.add_expected_call(
1046
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1047
            'success', ('ok',))
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1048
        branch = self.make_remote_branch(transport, client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1049
        # This is a hack to work around the problem that RemoteBranch currently
1050
        # unnecessarily invokes _ensure_real upon a call to lock_write.
1051
        branch._ensure_real = lambda: None
1052
        # Lock the branch, reset the record of remote calls.
1053
        branch.lock_write()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1054
        result = branch.set_revision_history(['rev-id1', 'rev-id2'])
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1055
        branch.unlock()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1056
        self.assertEqual(None, result)
3691.2.10 by Martin Pool
Update more test_remote tests
1057
        client.finished_test()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1058
1059
    def test_no_such_revision(self):
1060
        transport = MemoryTransport()
1061
        transport.mkdir('branch')
1062
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1063
        # A response of 'NoSuchRevision' is translated into an exception.
1064
        client = FakeClient(transport.base)
3691.2.9 by Martin Pool
Convert and update more test_remote tests
1065
        client.add_expected_call(
1066
            'Branch.get_stacked_on_url', ('branch/',),
1067
            'error', ('NotStacked',))
1068
        client.add_expected_call(
1069
            'Branch.lock_write', ('branch/', '', ''),
1070
            'success', ('ok', 'branch token', 'repo token'))
1071
        client.add_expected_call(
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1072
            'Branch.last_revision_info',
1073
            ('branch/',),
1074
            'success', ('ok', '0', 'null:'))
1075
        # get_graph calls to construct the revision history, for the set_rh
1076
        # hook
1077
        lines = ['rev-id']
1078
        encoded_body = bz2.compress('\n'.join(lines))
1079
        client.add_success_response_with_body(encoded_body, 'ok')
1080
        client.add_expected_call(
3691.2.9 by Martin Pool
Convert and update more test_remote tests
1081
            'Branch.set_last_revision', ('branch/', 'branch token', 'repo token', 'rev-id',),
1082
            'error', ('NoSuchRevision', 'rev-id'))
1083
        client.add_expected_call(
1084
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1085
            'success', ('ok',))
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1086
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1087
        branch = self.make_remote_branch(transport, client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1088
        branch.lock_write()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1089
        self.assertRaises(
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1090
            errors.NoSuchRevision, branch.set_revision_history, ['rev-id'])
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1091
        branch.unlock()
3691.2.9 by Martin Pool
Convert and update more test_remote tests
1092
        client.finished_test()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1093
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1094
    def test_tip_change_rejected(self):
1095
        """TipChangeRejected responses cause a TipChangeRejected exception to
1096
        be raised.
1097
        """
1098
        transport = MemoryTransport()
1099
        transport.mkdir('branch')
1100
        transport = transport.clone('branch')
1101
        client = FakeClient(transport.base)
1102
        rejection_msg_unicode = u'rejection message\N{INTERROBANG}'
1103
        rejection_msg_utf8 = rejection_msg_unicode.encode('utf8')
3691.2.10 by Martin Pool
Update more test_remote tests
1104
        client.add_expected_call(
1105
            'Branch.get_stacked_on_url', ('branch/',),
1106
            'error', ('NotStacked',))
1107
        client.add_expected_call(
1108
            'Branch.lock_write', ('branch/', '', ''),
1109
            'success', ('ok', 'branch token', 'repo token'))
1110
        client.add_expected_call(
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1111
            'Branch.last_revision_info',
1112
            ('branch/',),
1113
            'success', ('ok', '0', 'null:'))
1114
        lines = ['rev-id']
1115
        encoded_body = bz2.compress('\n'.join(lines))
1116
        client.add_success_response_with_body(encoded_body, 'ok')
1117
        client.add_expected_call(
3691.2.10 by Martin Pool
Update more test_remote tests
1118
            'Branch.set_last_revision', ('branch/', 'branch token', 'repo token', 'rev-id',),
1119
            'error', ('TipChangeRejected', rejection_msg_utf8))
1120
        client.add_expected_call(
1121
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1122
            'success', ('ok',))
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1123
        branch = self.make_remote_branch(transport, client)
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1124
        branch._ensure_real = lambda: None
1125
        branch.lock_write()
1126
        # The 'TipChangeRejected' error response triggered by calling
1127
        # set_revision_history causes a TipChangeRejected exception.
1128
        err = self.assertRaises(
1129
            errors.TipChangeRejected, branch.set_revision_history, ['rev-id'])
1130
        # The UTF-8 message from the response has been decoded into a unicode
1131
        # object.
1132
        self.assertIsInstance(err.msg, unicode)
1133
        self.assertEqual(rejection_msg_unicode, err.msg)
3691.2.10 by Martin Pool
Update more test_remote tests
1134
        branch.unlock()
1135
        client.finished_test()
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1136
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1137
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1138
class TestBranchSetLastRevisionInfo(RemoteBranchTestCase):
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1139
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1140
    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.
1141
        # set_last_revision_info(num, 'rev-id') is translated to calling
1142
        # 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'.
1143
        transport = MemoryTransport()
1144
        transport.mkdir('branch')
1145
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1146
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1147
        # get_stacked_on_url
1148
        client.add_error_response('NotStacked')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1149
        # lock_write
1150
        client.add_success_response('ok', 'branch token', 'repo token')
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1151
        # query the current revision
1152
        client.add_success_response('ok', '0', 'null:')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1153
        # set_last_revision
1154
        client.add_success_response('ok')
1155
        # unlock
1156
        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.
1157
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1158
        branch = self.make_remote_branch(transport, client)
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1159
        # Lock the branch, reset the record of remote calls.
1160
        branch.lock_write()
1161
        client._calls = []
1162
        result = branch.set_last_revision_info(1234, 'a-revision-id')
1163
        self.assertEqual(
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1164
            [('call', 'Branch.last_revision_info', ('branch/',)),
1165
             ('call', 'Branch.set_last_revision_info',
3297.4.1 by Andrew Bennetts
Merge 'Add Branch.set_last_revision_info smart method'.
1166
                ('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.
1167
                 '1234', 'a-revision-id'))],
1168
            client._calls)
1169
        self.assertEqual(None, result)
1170
1171
    def test_no_such_revision(self):
1172
        # A response of 'NoSuchRevision' is translated into an exception.
1173
        transport = MemoryTransport()
1174
        transport.mkdir('branch')
1175
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1176
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1177
        # get_stacked_on_url
1178
        client.add_error_response('NotStacked')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1179
        # lock_write
1180
        client.add_success_response('ok', 'branch token', 'repo token')
1181
        # set_last_revision
1182
        client.add_error_response('NoSuchRevision', 'revid')
1183
        # unlock
1184
        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.
1185
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1186
        branch = self.make_remote_branch(transport, client)
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1187
        # Lock the branch, reset the record of remote calls.
1188
        branch.lock_write()
1189
        client._calls = []
1190
1191
        self.assertRaises(
1192
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1193
        branch.unlock()
1194
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1195
    def lock_remote_branch(self, branch):
1196
        """Trick a RemoteBranch into thinking it is locked."""
1197
        branch._lock_mode = 'w'
1198
        branch._lock_count = 2
1199
        branch._lock_token = 'branch token'
1200
        branch._repo_lock_token = 'repo token'
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1201
        branch.repository._lock_mode = 'w'
1202
        branch.repository._lock_count = 2
1203
        branch.repository._lock_token = 'repo token'
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1204
1205
    def test_backwards_compatibility(self):
1206
        """If the server does not support the Branch.set_last_revision_info
1207
        verb (which is new in 1.4), then the client falls back to VFS methods.
1208
        """
1209
        # This test is a little messy.  Unlike most tests in this file, it
1210
        # doesn't purely test what a Remote* object sends over the wire, and
1211
        # how it reacts to responses from the wire.  It instead relies partly
1212
        # on asserting that the RemoteBranch will call
1213
        # self._real_branch.set_last_revision_info(...).
1214
1215
        # First, set up our RemoteBranch with a FakeClient that raises
1216
        # UnknownSmartMethod, and a StubRealBranch that logs how it is called.
1217
        transport = MemoryTransport()
1218
        transport.mkdir('branch')
1219
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1220
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1221
        client.add_expected_call(
1222
            'Branch.get_stacked_on_url', ('branch/',),
1223
            'error', ('NotStacked',))
1224
        client.add_expected_call(
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1225
            'Branch.last_revision_info',
1226
            ('branch/',),
1227
            'success', ('ok', '0', 'null:'))
1228
        client.add_expected_call(
3691.2.10 by Martin Pool
Update more test_remote tests
1229
            'Branch.set_last_revision_info',
1230
            ('branch/', 'branch token', 'repo token', '1234', 'a-revision-id',),
1231
            'unknown', 'Branch.set_last_revision_info')
1232
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1233
        branch = self.make_remote_branch(transport, client)
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1234
        class StubRealBranch(object):
1235
            def __init__(self):
1236
                self.calls = []
1237
            def set_last_revision_info(self, revno, revision_id):
1238
                self.calls.append(
1239
                    ('set_last_revision_info', revno, revision_id))
3441.5.5 by Andrew Bennetts
Some small tweaks and comments.
1240
            def _clear_cached_state(self):
1241
                pass
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1242
        real_branch = StubRealBranch()
1243
        branch._real_branch = real_branch
1244
        self.lock_remote_branch(branch)
1245
1246
        # Call set_last_revision_info, and verify it behaved as expected.
1247
        result = branch.set_last_revision_info(1234, 'a-revision-id')
1248
        self.assertEqual(
1249
            [('set_last_revision_info', 1234, 'a-revision-id')],
1250
            real_branch.calls)
3691.2.10 by Martin Pool
Update more test_remote tests
1251
        client.finished_test()
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1252
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1253
    def test_unexpected_error(self):
3697.2.6 by Martin Pool
Merge 261315 fix into 1.7 branch
1254
        # If the server sends an error the client doesn't understand, it gets
1255
        # turned into an UnknownErrorFromSmartServer, which is presented as a
1256
        # non-internal error to the user.
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1257
        transport = MemoryTransport()
1258
        transport.mkdir('branch')
1259
        transport = transport.clone('branch')
1260
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1261
        # get_stacked_on_url
1262
        client.add_error_response('NotStacked')
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1263
        # lock_write
1264
        client.add_success_response('ok', 'branch token', 'repo token')
1265
        # set_last_revision
1266
        client.add_error_response('UnexpectedError')
1267
        # unlock
1268
        client.add_success_response('ok')
1269
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1270
        branch = self.make_remote_branch(transport, client)
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1271
        # Lock the branch, reset the record of remote calls.
1272
        branch.lock_write()
1273
        client._calls = []
1274
1275
        err = self.assertRaises(
3690.1.2 by Andrew Bennetts
Rename UntranslateableErrorFromSmartServer -> UnknownErrorFromSmartServer.
1276
            errors.UnknownErrorFromSmartServer,
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1277
            branch.set_last_revision_info, 123, 'revid')
1278
        self.assertEqual(('UnexpectedError',), err.error_tuple)
1279
        branch.unlock()
1280
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1281
    def test_tip_change_rejected(self):
1282
        """TipChangeRejected responses cause a TipChangeRejected exception to
1283
        be raised.
1284
        """
1285
        transport = MemoryTransport()
1286
        transport.mkdir('branch')
1287
        transport = transport.clone('branch')
1288
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1289
        # get_stacked_on_url
1290
        client.add_error_response('NotStacked')
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1291
        # lock_write
1292
        client.add_success_response('ok', 'branch token', 'repo token')
1293
        # set_last_revision
1294
        client.add_error_response('TipChangeRejected', 'rejection message')
1295
        # unlock
1296
        client.add_success_response('ok')
1297
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1298
        branch = self.make_remote_branch(transport, client)
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1299
        # Lock the branch, reset the record of remote calls.
1300
        branch.lock_write()
1301
        self.addCleanup(branch.unlock)
1302
        client._calls = []
1303
1304
        # The 'TipChangeRejected' error response triggered by calling
1305
        # set_last_revision_info causes a TipChangeRejected exception.
1306
        err = self.assertRaises(
1307
            errors.TipChangeRejected,
1308
            branch.set_last_revision_info, 123, 'revid')
1309
        self.assertEqual('rejection message', err.msg)
1310
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1311
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.
1312
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
3408.3.1 by Martin Pool
Remove erroneous handling of branch.conf for RemoteBranch
1313
    """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).
1314
    """
1315
1316
    def test_get_branch_conf(self):
3408.3.1 by Martin Pool
Remove erroneous handling of branch.conf for RemoteBranch
1317
        raise tests.KnownFailure('branch.conf is not retrieved by get_config_file')
3407.2.10 by Martin Pool
Merge trunk
1318
        ## # We should see that branch.get_config() does a single rpc to get the
1319
        ## # remote configuration file, abstracting away where that is stored on
1320
        ## # the server.  However at the moment it always falls back to using the
1321
        ## # vfs, and this would need some changes in config.py.
3408.3.1 by Martin Pool
Remove erroneous handling of branch.conf for RemoteBranch
1322
3407.2.10 by Martin Pool
Merge trunk
1323
        ## # in an empty branch we decode the response properly
1324
        ## client = FakeClient([(('ok', ), '# config file body')], self.get_url())
1325
        ## # we need to make a real branch because the remote_branch.control_files
1326
        ## # will trigger _ensure_real.
1327
        ## branch = self.make_branch('quack')
1328
        ## transport = branch.bzrdir.root_transport
1329
        ## # we do not want bzrdir to make any remote calls
1330
        ## bzrdir = RemoteBzrDir(transport, _client=False)
1331
        ## branch = RemoteBranch(bzrdir, None, _client=client)
1332
        ## config = branch.get_config()
1333
        ## self.assertEqual(
1334
        ##     [('call_expecting_body', 'Branch.get_config_file', ('quack/',))],
1335
        ##     client._calls)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
1336
1337
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1338
class TestBranchLockWrite(RemoteBranchTestCase):
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.
1339
1340
    def test_lock_write_unlockable(self):
1341
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1342
        client = FakeClient(transport.base)
3691.2.9 by Martin Pool
Convert and update more test_remote tests
1343
        client.add_expected_call(
1344
            'Branch.get_stacked_on_url', ('quack/',),
1345
            'error', ('NotStacked',),)
1346
        client.add_expected_call(
1347
            'Branch.lock_write', ('quack/', '', ''),
1348
            'error', ('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.
1349
        transport.mkdir('quack')
1350
        transport = transport.clone('quack')
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1351
        branch = self.make_remote_branch(transport, client)
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.
1352
        self.assertRaises(errors.UnlockableTransport, branch.lock_write)
3691.2.9 by Martin Pool
Convert and update more test_remote tests
1353
        client.finished_test()
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.
1354
1355
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
1356
class TestTransportIsReadonly(tests.TestCase):
1357
1358
    def test_true(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1359
        client = FakeClient()
1360
        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.
1361
        transport = RemoteTransport('bzr://example.com/', medium=False,
1362
                                    _client=client)
1363
        self.assertEqual(True, transport.is_readonly())
1364
        self.assertEqual(
1365
            [('call', 'Transport.is_readonly', ())],
1366
            client._calls)
1367
1368
    def test_false(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1369
        client = FakeClient()
1370
        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.
1371
        transport = RemoteTransport('bzr://example.com/', medium=False,
1372
                                    _client=client)
1373
        self.assertEqual(False, transport.is_readonly())
1374
        self.assertEqual(
1375
            [('call', 'Transport.is_readonly', ())],
1376
            client._calls)
1377
1378
    def test_error_from_old_server(self):
1379
        """bzr 0.15 and earlier servers don't recognise the is_readonly verb.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1380
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
1381
        Clients should treat it as a "no" response, because is_readonly is only
1382
        advisory anyway (a transport could be read-write, but then the
1383
        underlying filesystem could be readonly anyway).
1384
        """
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1385
        client = FakeClient()
1386
        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.
1387
        transport = RemoteTransport('bzr://example.com/', medium=False,
1388
                                    _client=client)
1389
        self.assertEqual(False, transport.is_readonly())
1390
        self.assertEqual(
1391
            [('call', 'Transport.is_readonly', ())],
1392
            client._calls)
1393
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
1394
3840.1.1 by Andrew Bennetts
Fix RemoteTransport's translation of errors involving paths; it wasn't passing orig_path to _translate_error.
1395
class TestTransportMkdir(tests.TestCase):
1396
1397
    def test_permissiondenied(self):
1398
        client = FakeClient()
1399
        client.add_error_response('PermissionDenied', 'remote path', 'extra')
1400
        transport = RemoteTransport('bzr://example.com/', medium=False,
1401
                                    _client=client)
1402
        exc = self.assertRaises(
1403
            errors.PermissionDenied, transport.mkdir, 'client path')
1404
        expected_error = errors.PermissionDenied('/client path', 'extra')
1405
        self.assertEqual(expected_error, exc)
1406
1407
3777.1.3 by Aaron Bentley
Use SSH default username from authentication.conf
1408
class TestRemoteSSHTransportAuthentication(tests.TestCaseInTempDir):
1409
1410
    def test_defaults_to_none(self):
1411
        t = RemoteSSHTransport('bzr+ssh://example.com')
1412
        self.assertIs(None, t._get_credentials()[0])
1413
1414
    def test_uses_authentication_config(self):
1415
        conf = config.AuthenticationConfig()
1416
        conf._get_config().update(
1417
            {'bzr+sshtest': {'scheme': 'ssh', 'user': 'bar', 'host':
1418
            'example.com'}})
1419
        conf._save()
1420
        t = RemoteSSHTransport('bzr+ssh://example.com')
1421
        self.assertEqual('bar', t._get_credentials()[0])
1422
1423
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1424
class TestRemoteRepository(TestRemote):
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1425
    """Base for testing RemoteRepository protocol usage.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1426
1427
    These tests contain frozen requests and responses.  We want any changes to
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1428
    what is sent or expected to be require a thoughtful update to these tests
1429
    because they might break compatibility with different-versioned servers.
1430
    """
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1431
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1432
    def setup_fake_client_and_repository(self, transport_path):
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1433
        """Create the fake client and repository for testing with.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1434
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1435
        There's no real server here; we just have canned responses sent
1436
        back one by one.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1437
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1438
        :param transport_path: Path below the root of the MemoryTransport
1439
            where the repository will be created.
1440
        """
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1441
        transport = MemoryTransport()
1442
        transport.mkdir(transport_path)
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1443
        client = FakeClient(transport.base)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1444
        transport = transport.clone(transport_path)
1445
        # we do not want bzrdir to make any remote calls
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1446
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
1447
            _client=False)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1448
        repo = RemoteRepository(bzrdir, None, _client=client)
1449
        return repo, client
1450
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1451
2018.12.2 by Andrew Bennetts
Remove some duplicate code in test_remote
1452
class TestRepositoryGatherStats(TestRemoteRepository):
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1453
1454
    def test_revid_none(self):
1455
        # ('ok',), body with revisions and size
1456
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1457
        repo, client = self.setup_fake_client_and_repository(transport_path)
1458
        client.add_success_response_with_body(
1459
            'revisions: 2\nsize: 18\n', 'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1460
        result = repo.gather_stats(None)
1461
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
1462
            [('call_expecting_body', 'Repository.gather_stats',
3104.4.2 by Andrew Bennetts
All tests passing.
1463
             ('quack/','','no'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1464
            client._calls)
1465
        self.assertEqual({'revisions': 2, 'size': 18}, result)
1466
1467
    def test_revid_no_committers(self):
1468
        # ('ok',), body without committers
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1469
        body = ('firstrev: 123456.300 3600\n'
1470
                'latestrev: 654231.400 0\n'
1471
                'revisions: 2\n'
1472
                'size: 18\n')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1473
        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.
1474
        revid = u'\xc8'.encode('utf8')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1475
        repo, client = self.setup_fake_client_and_repository(transport_path)
1476
        client.add_success_response_with_body(body, 'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1477
        result = repo.gather_stats(revid)
1478
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
1479
            [('call_expecting_body', 'Repository.gather_stats',
3104.4.2 by Andrew Bennetts
All tests passing.
1480
              ('quick/', revid, 'no'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1481
            client._calls)
1482
        self.assertEqual({'revisions': 2, 'size': 18,
1483
                          'firstrev': (123456.300, 3600),
1484
                          'latestrev': (654231.400, 0),},
1485
                         result)
1486
1487
    def test_revid_with_committers(self):
1488
        # ('ok',), body with committers
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1489
        body = ('committers: 128\n'
1490
                'firstrev: 123456.300 3600\n'
1491
                'latestrev: 654231.400 0\n'
1492
                'revisions: 2\n'
1493
                'size: 18\n')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1494
        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.
1495
        revid = u'\xc8'.encode('utf8')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1496
        repo, client = self.setup_fake_client_and_repository(transport_path)
1497
        client.add_success_response_with_body(body, 'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1498
        result = repo.gather_stats(revid, True)
1499
        self.assertEqual(
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
1500
            [('call_expecting_body', 'Repository.gather_stats',
3104.4.2 by Andrew Bennetts
All tests passing.
1501
              ('buick/', revid, 'yes'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
1502
            client._calls)
1503
        self.assertEqual({'revisions': 2, 'size': 18,
1504
                          'committers': 128,
1505
                          'firstrev': (123456.300, 3600),
1506
                          'latestrev': (654231.400, 0),},
1507
                         result)
1508
1509
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
1510
class TestRepositoryGetGraph(TestRemoteRepository):
1511
1512
    def test_get_graph(self):
3835.1.6 by Aaron Bentley
Reduce inefficiency when doing make_parents_provider frequently
1513
        # get_graph returns a graph with a custom parents provider.
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
1514
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1515
        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.
1516
        graph = repo.get_graph()
3835.1.6 by Aaron Bentley
Reduce inefficiency when doing make_parents_provider frequently
1517
        self.assertNotEqual(graph._parents_provider, repo)
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
1518
1519
1520
class TestRepositoryGetParentMap(TestRemoteRepository):
1521
1522
    def test_get_parent_map_caching(self):
1523
        # get_parent_map returns from cache until unlock()
1524
        # setup a reponse with two revisions
1525
        r1 = u'\u0e33'.encode('utf8')
1526
        r2 = u'\u0dab'.encode('utf8')
1527
        lines = [' '.join([r2, r1]), r1]
3211.5.2 by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression.
1528
        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.
1529
1530
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1531
        repo, client = self.setup_fake_client_and_repository(transport_path)
1532
        client.add_success_response_with_body(encoded_body, 'ok')
1533
        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.
1534
        repo.lock_read()
1535
        graph = repo.get_graph()
1536
        parents = graph.get_parent_map([r2])
1537
        self.assertEqual({r2: (r1,)}, parents)
1538
        # locking and unlocking deeper should not reset
1539
        repo.lock_read()
1540
        repo.unlock()
1541
        parents = graph.get_parent_map([r1])
3172.5.6 by Robert Collins
Create new smart server verb Repository.get_parent_map.
1542
        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.
1543
        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.
1544
            [('call_with_body_bytes_expecting_body',
1545
              '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.
1546
            client._calls)
1547
        repo.unlock()
1548
        # now we call again, and it should use the second response.
1549
        repo.lock_read()
1550
        graph = repo.get_graph()
3172.5.6 by Robert Collins
Create new smart server verb Repository.get_parent_map.
1551
        parents = graph.get_parent_map([r1])
1552
        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.
1553
        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.
1554
            [('call_with_body_bytes_expecting_body',
1555
              'Repository.get_parent_map', ('quack/', r2), '\n\n0'),
1556
             ('call_with_body_bytes_expecting_body',
1557
              '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.
1558
            ],
1559
            client._calls)
1560
        repo.unlock()
1561
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
1562
    def test_get_parent_map_reconnects_if_unknown_method(self):
1563
        transport_path = 'quack'
3948.3.7 by Martin Pool
Updated tests for RemoteRepository.get_parent_map on old servers.
1564
        rev_id = 'revision-id'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1565
        repo, client = self.setup_fake_client_and_repository(transport_path)
3948.3.7 by Martin Pool
Updated tests for RemoteRepository.get_parent_map on old servers.
1566
        client.add_unknown_method_response('Repository.get_parent_map')
1567
        client.add_success_response_with_body(rev_id, 'ok')
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
1568
        self.assertFalse(client._medium._is_remote_before((1, 2)))
3948.3.7 by Martin Pool
Updated tests for RemoteRepository.get_parent_map on old servers.
1569
        parents = 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.
1570
        self.assertEqual(
3213.1.8 by Andrew Bennetts
Merge from bzr.dev.
1571
            [('call_with_body_bytes_expecting_body',
1572
              '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.
1573
             ('disconnect medium',),
1574
             ('call_expecting_body', 'Repository.get_revision_graph',
1575
              ('quack/', ''))],
1576
            client._calls)
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
1577
        # The medium is now marked as being connected to an older server
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
1578
        self.assertTrue(client._medium._is_remote_before((1, 2)))
3948.3.7 by Martin Pool
Updated tests for RemoteRepository.get_parent_map on old servers.
1579
        self.assertEqual({rev_id: ('null:',)}, parents)
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
1580
1581
    def test_get_parent_map_fallback_parentless_node(self):
1582
        """get_parent_map falls back to get_revision_graph on old servers.  The
1583
        results from get_revision_graph are tweaked to match the get_parent_map
1584
        API.
1585
3389.1.3 by Andrew Bennetts
Remove XXX from test description.
1586
        Specifically, a {key: ()} result from get_revision_graph means "no
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
1587
        parents" for that key, which in get_parent_map results should be
3389.1.3 by Andrew Bennetts
Remove XXX from test description.
1588
        represented as {key: ('null:',)}.
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
1589
1590
        This is the test for https://bugs.launchpad.net/bzr/+bug/214894
1591
        """
1592
        rev_id = 'revision-id'
1593
        transport_path = 'quack'
3245.4.40 by Andrew Bennetts
Merge from bzr.dev.
1594
        repo, client = self.setup_fake_client_and_repository(transport_path)
1595
        client.add_success_response_with_body(rev_id, 'ok')
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
1596
        client._medium._remember_remote_is_before((1, 2))
3948.3.7 by Martin Pool
Updated tests for RemoteRepository.get_parent_map on old servers.
1597
        parents = repo.get_parent_map([rev_id])
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
1598
        self.assertEqual(
1599
            [('call_expecting_body', 'Repository.get_revision_graph',
1600
             ('quack/', ''))],
1601
            client._calls)
1602
        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.
1603
3297.2.3 by Andrew Bennetts
Test the code path that the typo is on.
1604
    def test_get_parent_map_unexpected_response(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1605
        repo, client = self.setup_fake_client_and_repository('path')
1606
        client.add_success_response('something unexpected!')
3297.2.3 by Andrew Bennetts
Test the code path that the typo is on.
1607
        self.assertRaises(
1608
            errors.UnexpectedSmartServerResponse,
1609
            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.
1610
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
1611
3835.1.15 by Aaron Bentley
Allow miss caching to be disabled.
1612
class TestGetParentMapAllowsNew(tests.TestCaseWithTransport):
1613
1614
    def test_allows_new_revisions(self):
1615
        """get_parent_map's results can be updated by commit."""
1616
        smart_server = server.SmartTCPServer_for_testing()
1617
        smart_server.setUp()
1618
        self.addCleanup(smart_server.tearDown)
1619
        self.make_branch('branch')
1620
        branch = Branch.open(smart_server.get_url() + '/branch')
1621
        tree = branch.create_checkout('tree', lightweight=True)
1622
        tree.lock_write()
1623
        self.addCleanup(tree.unlock)
1624
        graph = tree.branch.repository.get_graph()
1625
        # This provides an opportunity for the missing rev-id to be cached.
1626
        self.assertEqual({}, graph.get_parent_map(['rev1']))
1627
        tree.commit('message', rev_id='rev1')
1628
        graph = tree.branch.repository.get_graph()
1629
        self.assertEqual({'rev1': ('null:',)}, graph.get_parent_map(['rev1']))
1630
1631
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1632
class TestRepositoryIsShared(TestRemoteRepository):
1633
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1634
    def test_is_shared(self):
1635
        # ('yes', ) for Repository.is_shared -> 'True'.
1636
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1637
        repo, client = self.setup_fake_client_and_repository(transport_path)
1638
        client.add_success_response('yes')
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1639
        result = repo.is_shared()
1640
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1641
            [('call', 'Repository.is_shared', ('quack/',))],
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1642
            client._calls)
1643
        self.assertEqual(True, result)
1644
1645
    def test_is_not_shared(self):
1646
        # ('no', ) for Repository.is_shared -> 'False'.
1647
        transport_path = 'qwack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1648
        repo, client = self.setup_fake_client_and_repository(transport_path)
1649
        client.add_success_response('no')
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1650
        result = repo.is_shared()
1651
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1652
            [('call', 'Repository.is_shared', ('qwack/',))],
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1653
            client._calls)
1654
        self.assertEqual(False, result)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1655
1656
1657
class TestRepositoryLockWrite(TestRemoteRepository):
1658
1659
    def test_lock_write(self):
1660
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1661
        repo, client = self.setup_fake_client_and_repository(transport_path)
1662
        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
1663
        result = repo.lock_write()
1664
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1665
            [('call', 'Repository.lock_write', ('quack/', ''))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1666
            client._calls)
1667
        self.assertEqual('a token', result)
1668
1669
    def test_lock_write_already_locked(self):
1670
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1671
        repo, client = self.setup_fake_client_and_repository(transport_path)
1672
        client.add_error_response('LockContention')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1673
        self.assertRaises(errors.LockContention, repo.lock_write)
1674
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1675
            [('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.
1676
            client._calls)
1677
1678
    def test_lock_write_unlockable(self):
1679
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1680
        repo, client = self.setup_fake_client_and_repository(transport_path)
1681
        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.
1682
        self.assertRaises(errors.UnlockableTransport, repo.lock_write)
1683
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1684
            [('call', 'Repository.lock_write', ('quack/', ''))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1685
            client._calls)
1686
1687
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1688
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
1689
1690
    def test_backwards_compat(self):
1691
        self.setup_smart_server_with_call_log()
1692
        repo = self.make_repository('.')
1693
        self.reset_smart_call_log()
1694
        verb = 'Repository.set_make_working_trees'
1695
        self.disable_verb(verb)
1696
        repo.set_make_working_trees(True)
1697
        call_count = len([call for call in self.hpss_calls if
4070.3.1 by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips.
1698
            call.call.method == verb])
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1699
        self.assertEqual(1, call_count)
1700
1701
    def test_current(self):
1702
        transport_path = 'quack'
1703
        repo, client = self.setup_fake_client_and_repository(transport_path)
1704
        client.add_expected_call(
1705
            'Repository.set_make_working_trees', ('quack/', 'True'),
1706
            'success', ('ok',))
1707
        client.add_expected_call(
1708
            'Repository.set_make_working_trees', ('quack/', 'False'),
1709
            'success', ('ok',))
1710
        repo.set_make_working_trees(True)
1711
        repo.set_make_working_trees(False)
1712
1713
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1714
class TestRepositoryUnlock(TestRemoteRepository):
1715
1716
    def test_unlock(self):
1717
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1718
        repo, client = self.setup_fake_client_and_repository(transport_path)
1719
        client.add_success_response('ok', 'a token')
1720
        client.add_success_response('ok')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1721
        repo.lock_write()
1722
        repo.unlock()
1723
        self.assertEqual(
3104.4.2 by Andrew Bennetts
All tests passing.
1724
            [('call', 'Repository.lock_write', ('quack/', '')),
1725
             ('call', 'Repository.unlock', ('quack/', 'a token'))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1726
            client._calls)
1727
1728
    def test_unlock_wrong_token(self):
1729
        # If somehow the token is wrong, unlock will raise TokenMismatch.
1730
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1731
        repo, client = self.setup_fake_client_and_repository(transport_path)
1732
        client.add_success_response('ok', 'a token')
1733
        client.add_error_response('TokenMismatch')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1734
        repo.lock_write()
1735
        self.assertRaises(errors.TokenMismatch, repo.unlock)
1736
1737
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1738
class TestRepositoryHasRevision(TestRemoteRepository):
1739
1740
    def test_none(self):
1741
        # repo.has_revision(None) should not cause any traffic.
1742
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1743
        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.
1744
1745
        # The null revision is always there, so has_revision(None) == True.
3172.3.3 by Robert Collins
Missed one occurence of None -> NULL_REVISION.
1746
        self.assertEqual(True, repo.has_revision(NULL_REVISION))
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1747
1748
        # The remote repo shouldn't be accessed.
1749
        self.assertEqual([], client._calls)
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1750
1751
4144.3.2 by Andrew Bennetts
Use Repository.insert_stream_locked if there is a lock_token for the remote repo.
1752
class TestRepositoryInsertStream(TestRemoteRepository):
1753
1754
    def test_unlocked_repo(self):
1755
        transport_path = 'quack'
1756
        repo, client = self.setup_fake_client_and_repository(transport_path)
1757
        client.add_expected_call(
1758
            'Repository.insert_stream', ('quack/', ''),
1759
            'success', ('ok',))
1760
        client.add_expected_call(
1761
            'Repository.insert_stream', ('quack/', ''),
1762
            'success', ('ok',))
1763
        sink = repo._get_sink()
1764
        fmt = repository.RepositoryFormat.get_default_format()
1765
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
1766
        self.assertEqual([], resume_tokens)
1767
        self.assertEqual(set(), missing_keys)
1768
        client.finished_test()
1769
1770
    def test_locked_repo_with_no_lock_token(self):
1771
        transport_path = 'quack'
1772
        repo, client = self.setup_fake_client_and_repository(transport_path)
1773
        client.add_expected_call(
1774
            'Repository.lock_write', ('quack/', ''),
1775
            'success', ('ok', ''))
1776
        client.add_expected_call(
1777
            'Repository.insert_stream', ('quack/', ''),
1778
            'success', ('ok',))
1779
        client.add_expected_call(
1780
            'Repository.insert_stream', ('quack/', ''),
1781
            'success', ('ok',))
1782
        repo.lock_write()
1783
        sink = repo._get_sink()
1784
        fmt = repository.RepositoryFormat.get_default_format()
1785
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
1786
        self.assertEqual([], resume_tokens)
1787
        self.assertEqual(set(), missing_keys)
1788
        client.finished_test()
1789
1790
    def test_locked_repo_with_lock_token(self):
1791
        transport_path = 'quack'
1792
        repo, client = self.setup_fake_client_and_repository(transport_path)
1793
        client.add_expected_call(
1794
            'Repository.lock_write', ('quack/', ''),
1795
            'success', ('ok', 'a token'))
1796
        client.add_expected_call(
1797
            'Repository.insert_stream_locked', ('quack/', '', 'a token'),
1798
            'success', ('ok',))
1799
        client.add_expected_call(
1800
            'Repository.insert_stream_locked', ('quack/', '', 'a token'),
1801
            'success', ('ok',))
1802
        repo.lock_write()
1803
        sink = repo._get_sink()
1804
        fmt = repository.RepositoryFormat.get_default_format()
1805
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
1806
        self.assertEqual([], resume_tokens)
1807
        self.assertEqual(set(), missing_keys)
1808
        client.finished_test()
1809
1810
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1811
class TestRepositoryTarball(TestRemoteRepository):
1812
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1813
    # This is a canned tarball reponse we can validate against
2018.18.18 by Martin Pool
reformat
1814
    tarball_content = (
2018.18.23 by Martin Pool
review cleanups
1815
        'QlpoOTFBWSZTWdGkj3wAAWF/k8aQACBIB//A9+8cIX/v33AACEAYABAECEACNz'
1816
        'JqsgJJFPTSnk1A3qh6mTQAAAANPUHkagkSTEkaA09QaNAAAGgAAAcwCYCZGAEY'
1817
        'mJhMJghpiaYBUkKammSHqNMZQ0NABkNAeo0AGneAevnlwQoGzEzNVzaYxp/1Uk'
1818
        'xXzA1CQX0BJMZZLcPBrluJir5SQyijWHYZ6ZUtVqqlYDdB2QoCwa9GyWwGYDMA'
1819
        'OQYhkpLt/OKFnnlT8E0PmO8+ZNSo2WWqeCzGB5fBXZ3IvV7uNJVE7DYnWj6qwB'
1820
        'k5DJDIrQ5OQHHIjkS9KqwG3mc3t+F1+iujb89ufyBNIKCgeZBWrl5cXxbMGoMs'
1821
        'c9JuUkg5YsiVcaZJurc6KLi6yKOkgCUOlIlOpOoXyrTJjK8ZgbklReDdwGmFgt'
1822
        'dkVsAIslSVCd4AtACSLbyhLHryfb14PKegrVDba+U8OL6KQtzdM5HLjAc8/p6n'
1823
        '0lgaWU8skgO7xupPTkyuwheSckejFLK5T4ZOo0Gda9viaIhpD1Qn7JqqlKAJqC'
1824
        'QplPKp2nqBWAfwBGaOwVrz3y1T+UZZNismXHsb2Jq18T+VaD9k4P8DqE3g70qV'
1825
        'JLurpnDI6VS5oqDDPVbtVjMxMxMg4rzQVipn2Bv1fVNK0iq3Gl0hhnnHKm/egy'
1826
        'nWQ7QH/F3JFOFCQ0aSPfA='
1827
        ).decode('base64')
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1828
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1829
    def test_repository_tarball(self):
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1830
        # Test that Repository.tarball generates the right operations
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1831
        transport_path = 'repo'
2018.18.14 by Martin Pool
merge hpss again; restore incorrectly removed RemoteRepository.break_lock
1832
        expected_calls = [('call_expecting_body', 'Repository.tarball',
3104.4.2 by Andrew Bennetts
All tests passing.
1833
                           ('repo/', 'bz2',),),
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
1834
            ]
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1835
        repo, client = self.setup_fake_client_and_repository(transport_path)
1836
        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
1837
        # Now actually ask for the tarball
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1838
        tarball_file = repo._get_tarball('bz2')
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
1839
        try:
1840
            self.assertEqual(expected_calls, client._calls)
1841
            self.assertEqual(self.tarball_content, tarball_file.read())
1842
        finally:
1843
            tarball_file.close()
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
1844
1845
1846
class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):
1847
    """RemoteRepository.copy_content_into optimizations"""
1848
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
1849
    def test_copy_content_remote_to_local(self):
1850
        self.transport_server = server.SmartTCPServer_for_testing
1851
        src_repo = self.make_repository('repo1')
1852
        src_repo = repository.Repository.open(self.get_url('repo1'))
1853
        # At the moment the tarball-based copy_content_into can't write back
1854
        # into a smart server.  It would be good if it could upload the
1855
        # tarball; once that works we'd have to create repositories of
1856
        # different formats. -- mbp 20070410
1857
        dest_url = self.get_vfs_only_url('repo2')
1858
        dest_bzrdir = BzrDir.create(dest_url)
1859
        dest_repo = dest_bzrdir.create_repository()
1860
        self.assertFalse(isinstance(dest_repo, RemoteRepository))
1861
        self.assertTrue(isinstance(src_repo, RemoteRepository))
1862
        src_repo.copy_content_into(dest_repo)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
1863
1864
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1865
class _StubRealPackRepository(object):
1866
1867
    def __init__(self, calls):
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1868
        self.calls = calls
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1869
        self._pack_collection = _StubPackCollection(calls)
1870
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1871
    def is_in_write_group(self):
1872
        return False
1873
1874
    def refresh_data(self):
1875
        self.calls.append(('pack collection reload_pack_names',))
1876
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1877
1878
class _StubPackCollection(object):
1879
1880
    def __init__(self, calls):
1881
        self.calls = calls
1882
1883
    def autopack(self):
1884
        self.calls.append(('pack collection autopack',))
1885
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1886
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1887
class TestRemotePackRepositoryAutoPack(TestRemoteRepository):
1888
    """Tests for RemoteRepository.autopack implementation."""
1889
1890
    def test_ok(self):
1891
        """When the server returns 'ok' and there's no _real_repository, then
1892
        nothing else happens: the autopack method is done.
1893
        """
1894
        transport_path = 'quack'
1895
        repo, client = self.setup_fake_client_and_repository(transport_path)
1896
        client.add_expected_call(
3801.1.13 by Andrew Bennetts
Revert returning of pack-names from the RPC.
1897
            'PackRepository.autopack', ('quack/',), 'success', ('ok',))
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1898
        repo.autopack()
1899
        client.finished_test()
1900
1901
    def test_ok_with_real_repo(self):
1902
        """When the server returns 'ok' and there is a _real_repository, then
1903
        the _real_repository's reload_pack_name's method will be called.
1904
        """
1905
        transport_path = 'quack'
1906
        repo, client = self.setup_fake_client_and_repository(transport_path)
1907
        client.add_expected_call(
1908
            'PackRepository.autopack', ('quack/',),
3801.1.13 by Andrew Bennetts
Revert returning of pack-names from the RPC.
1909
            'success', ('ok',))
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1910
        repo._real_repository = _StubRealPackRepository(client._calls)
1911
        repo.autopack()
1912
        self.assertEqual(
1913
            [('call', 'PackRepository.autopack', ('quack/',)),
3801.1.13 by Andrew Bennetts
Revert returning of pack-names from the RPC.
1914
             ('pack collection reload_pack_names',)],
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1915
            client._calls)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1916
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1917
    def test_backwards_compatibility(self):
1918
        """If the server does not recognise the PackRepository.autopack verb,
1919
        fallback to the real_repository's implementation.
1920
        """
1921
        transport_path = 'quack'
1922
        repo, client = self.setup_fake_client_and_repository(transport_path)
1923
        client.add_unknown_method_response('PackRepository.autopack')
1924
        def stub_ensure_real():
1925
            client._calls.append(('_ensure_real',))
1926
            repo._real_repository = _StubRealPackRepository(client._calls)
1927
        repo._ensure_real = stub_ensure_real
1928
        repo.autopack()
1929
        self.assertEqual(
1930
            [('call', 'PackRepository.autopack', ('quack/',)),
1931
             ('_ensure_real',),
1932
             ('pack collection autopack',)],
1933
            client._calls)
1934
1935
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
1936
class TestErrorTranslationBase(tests.TestCaseWithMemoryTransport):
1937
    """Base class for unit tests for bzrlib.remote._translate_error."""
1938
1939
    def translateTuple(self, error_tuple, **context):
1940
        """Call _translate_error with an ErrorFromSmartServer built from the
1941
        given error_tuple.
1942
1943
        :param error_tuple: A tuple of a smart server response, as would be
1944
            passed to an ErrorFromSmartServer.
1945
        :kwargs context: context items to call _translate_error with.
1946
1947
        :returns: The error raised by _translate_error.
1948
        """
1949
        # Raise the ErrorFromSmartServer before passing it as an argument,
1950
        # because _translate_error may need to re-raise it with a bare 'raise'
1951
        # statement.
1952
        server_error = errors.ErrorFromSmartServer(error_tuple)
1953
        translated_error = self.translateErrorFromSmartServer(
1954
            server_error, **context)
1955
        return translated_error
1956
1957
    def translateErrorFromSmartServer(self, error_object, **context):
1958
        """Like translateTuple, but takes an already constructed
1959
        ErrorFromSmartServer rather than a tuple.
1960
        """
1961
        try:
1962
            raise error_object
1963
        except errors.ErrorFromSmartServer, server_error:
1964
            translated_error = self.assertRaises(
1965
                errors.BzrError, remote._translate_error, server_error,
1966
                **context)
1967
        return translated_error
1968
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1969
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
1970
class TestErrorTranslationSuccess(TestErrorTranslationBase):
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
1971
    """Unit tests for bzrlib.remote._translate_error.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1972
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
1973
    Given an ErrorFromSmartServer (which has an error tuple from a smart
1974
    server) and some context, _translate_error raises more specific errors from
1975
    bzrlib.errors.
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
1976
1977
    This test case covers the cases where _translate_error succeeds in
1978
    translating an ErrorFromSmartServer to something better.  See
1979
    TestErrorTranslationRobustness for other cases.
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
1980
    """
1981
1982
    def test_NoSuchRevision(self):
1983
        branch = self.make_branch('')
1984
        revid = 'revid'
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
1985
        translated_error = self.translateTuple(
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
1986
            ('NoSuchRevision', revid), branch=branch)
1987
        expected_error = errors.NoSuchRevision(branch, revid)
1988
        self.assertEqual(expected_error, translated_error)
1989
1990
    def test_nosuchrevision(self):
1991
        repository = self.make_repository('')
1992
        revid = 'revid'
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
1993
        translated_error = self.translateTuple(
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
1994
            ('nosuchrevision', revid), repository=repository)
1995
        expected_error = errors.NoSuchRevision(repository, revid)
1996
        self.assertEqual(expected_error, translated_error)
1997
1998
    def test_nobranch(self):
1999
        bzrdir = self.make_bzrdir('')
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2000
        translated_error = self.translateTuple(('nobranch',), bzrdir=bzrdir)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
2001
        expected_error = errors.NotBranchError(path=bzrdir.root_transport.base)
2002
        self.assertEqual(expected_error, translated_error)
2003
2004
    def test_LockContention(self):
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2005
        translated_error = self.translateTuple(('LockContention',))
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
2006
        expected_error = errors.LockContention('(remote lock)')
2007
        self.assertEqual(expected_error, translated_error)
2008
2009
    def test_UnlockableTransport(self):
2010
        bzrdir = self.make_bzrdir('')
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2011
        translated_error = self.translateTuple(
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
2012
            ('UnlockableTransport',), bzrdir=bzrdir)
2013
        expected_error = errors.UnlockableTransport(bzrdir.root_transport)
2014
        self.assertEqual(expected_error, translated_error)
2015
2016
    def test_LockFailed(self):
2017
        lock = 'str() of a server lock'
2018
        why = 'str() of why'
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2019
        translated_error = self.translateTuple(('LockFailed', lock, why))
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
2020
        expected_error = errors.LockFailed(lock, why)
2021
        self.assertEqual(expected_error, translated_error)
2022
2023
    def test_TokenMismatch(self):
2024
        token = 'a lock token'
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2025
        translated_error = self.translateTuple(('TokenMismatch',), token=token)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
2026
        expected_error = errors.TokenMismatch(token, '(remote token)')
2027
        self.assertEqual(expected_error, translated_error)
2028
2029
    def test_Diverged(self):
2030
        branch = self.make_branch('a')
2031
        other_branch = self.make_branch('b')
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2032
        translated_error = self.translateTuple(
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
2033
            ('Diverged',), branch=branch, other_branch=other_branch)
2034
        expected_error = errors.DivergedBranches(branch, other_branch)
2035
        self.assertEqual(expected_error, translated_error)
2036
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
2037
    def test_ReadError_no_args(self):
2038
        path = 'a path'
2039
        translated_error = self.translateTuple(('ReadError',), path=path)
2040
        expected_error = errors.ReadError(path)
2041
        self.assertEqual(expected_error, translated_error)
2042
2043
    def test_ReadError(self):
2044
        path = 'a path'
2045
        translated_error = self.translateTuple(('ReadError', path))
2046
        expected_error = errors.ReadError(path)
2047
        self.assertEqual(expected_error, translated_error)
2048
2049
    def test_PermissionDenied_no_args(self):
2050
        path = 'a path'
2051
        translated_error = self.translateTuple(('PermissionDenied',), path=path)
2052
        expected_error = errors.PermissionDenied(path)
2053
        self.assertEqual(expected_error, translated_error)
2054
2055
    def test_PermissionDenied_one_arg(self):
2056
        path = 'a path'
2057
        translated_error = self.translateTuple(('PermissionDenied', path))
2058
        expected_error = errors.PermissionDenied(path)
2059
        self.assertEqual(expected_error, translated_error)
2060
2061
    def test_PermissionDenied_one_arg_and_context(self):
2062
        """Given a choice between a path from the local context and a path on
2063
        the wire, _translate_error prefers the path from the local context.
2064
        """
2065
        local_path = 'local path'
2066
        remote_path = 'remote path'
2067
        translated_error = self.translateTuple(
2068
            ('PermissionDenied', remote_path), path=local_path)
2069
        expected_error = errors.PermissionDenied(local_path)
2070
        self.assertEqual(expected_error, translated_error)
2071
2072
    def test_PermissionDenied_two_args(self):
2073
        path = 'a path'
2074
        extra = 'a string with extra info'
2075
        translated_error = self.translateTuple(
2076
            ('PermissionDenied', path, extra))
2077
        expected_error = errors.PermissionDenied(path, extra)
2078
        self.assertEqual(expected_error, translated_error)
2079
2080
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2081
class TestErrorTranslationRobustness(TestErrorTranslationBase):
2082
    """Unit tests for bzrlib.remote._translate_error's robustness.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2083
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2084
    TestErrorTranslationSuccess is for cases where _translate_error can
2085
    translate successfully.  This class about how _translate_err behaves when
2086
    it fails to translate: it re-raises the original error.
2087
    """
2088
2089
    def test_unrecognised_server_error(self):
2090
        """If the error code from the server is not recognised, the original
2091
        ErrorFromSmartServer is propagated unmodified.
2092
        """
2093
        error_tuple = ('An unknown error tuple',)
3690.1.2 by Andrew Bennetts
Rename UntranslateableErrorFromSmartServer -> UnknownErrorFromSmartServer.
2094
        server_error = errors.ErrorFromSmartServer(error_tuple)
2095
        translated_error = self.translateErrorFromSmartServer(server_error)
2096
        expected_error = errors.UnknownErrorFromSmartServer(server_error)
3690.1.1 by Andrew Bennetts
Unexpected error responses from a smart server no longer cause the client to traceback.
2097
        self.assertEqual(expected_error, translated_error)
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
2098
2099
    def test_context_missing_a_key(self):
2100
        """In case of a bug in the client, or perhaps an unexpected response
2101
        from a server, _translate_error returns the original error tuple from
2102
        the server and mutters a warning.
2103
        """
2104
        # To translate a NoSuchRevision error _translate_error needs a 'branch'
2105
        # in the context dict.  So let's give it an empty context dict instead
2106
        # to exercise its error recovery.
2107
        empty_context = {}
2108
        error_tuple = ('NoSuchRevision', 'revid')
2109
        server_error = errors.ErrorFromSmartServer(error_tuple)
2110
        translated_error = self.translateErrorFromSmartServer(server_error)
2111
        self.assertEqual(server_error, translated_error)
2112
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2113
        # been muttered to the log file for developer to look at.
2114
        self.assertContainsRe(
2115
            self._get_log(keep_log_file=True),
2116
            "Missing key 'branch' in context")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2117
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
2118
    def test_path_missing(self):
2119
        """Some translations (PermissionDenied, ReadError) can determine the
2120
        'path' variable from either the wire or the local context.  If neither
2121
        has it, then an error is raised.
2122
        """
2123
        error_tuple = ('ReadError',)
2124
        server_error = errors.ErrorFromSmartServer(error_tuple)
2125
        translated_error = self.translateErrorFromSmartServer(server_error)
2126
        self.assertEqual(server_error, translated_error)
2127
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2128
        # been muttered to the log file for developer to look at.
2129
        self.assertContainsRe(
2130
            self._get_log(keep_log_file=True), "Missing key 'path' in context")
2131
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
2132
2133
class TestStacking(tests.TestCaseWithTransport):
2134
    """Tests for operations on stacked remote repositories.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2135
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
2136
    The underlying format type must support stacking.
2137
    """
2138
2139
    def test_access_stacked_remote(self):
2140
        # based on <http://launchpad.net/bugs/261315>
2141
        # make a branch stacked on another repository containing an empty
2142
        # revision, then open it over hpss - we should be able to see that
2143
        # revision.
2144
        base_transport = self.get_transport()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2145
        base_builder = self.make_branch_builder('base', format='1.9')
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
2146
        base_builder.start_series()
2147
        base_revid = base_builder.build_snapshot('rev-id', None,
2148
            [('add', ('', None, 'directory', None))],
2149
            'message')
2150
        base_builder.finish_series()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2151
        stacked_branch = self.make_branch('stacked', format='1.9')
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
2152
        stacked_branch.set_stacked_on_url('../base')
2153
        # start a server looking at this
2154
        smart_server = server.SmartTCPServer_for_testing()
2155
        smart_server.setUp()
2156
        self.addCleanup(smart_server.tearDown)
2157
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
2158
        # can get its branch and repository
2159
        remote_branch = remote_bzrdir.open_branch()
2160
        remote_repo = remote_branch.repository
3691.2.6 by Martin Pool
Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions
2161
        remote_repo.lock_read()
2162
        try:
2163
            # it should have an appropriate fallback repository, which should also
2164
            # be a RemoteRepository
2165
            self.assertEquals(len(remote_repo._fallback_repositories), 1)
2166
            self.assertIsInstance(remote_repo._fallback_repositories[0],
2167
                RemoteRepository)
2168
            # and it has the revision committed to the underlying repository;
2169
            # these have varying implementations so we try several of them
2170
            self.assertTrue(remote_repo.has_revisions([base_revid]))
2171
            self.assertTrue(remote_repo.has_revision(base_revid))
2172
            self.assertEqual(remote_repo.get_revision(base_revid).message,
2173
                'message')
2174
        finally:
2175
            remote_repo.unlock()
3835.1.2 by Aaron Bentley
Add tests for get_parent_map
2176
3835.1.7 by Aaron Bentley
Updates from review
2177
    def prepare_stacked_remote_branch(self):
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2178
        """Get stacked_upon and stacked branches with content in each."""
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
2179
        self.setup_smart_server_with_call_log()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2180
        tree1 = self.make_branch_and_tree('tree1', format='1.9')
3835.1.2 by Aaron Bentley
Add tests for get_parent_map
2181
        tree1.commit('rev1', rev_id='rev1')
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2182
        tree2 = tree1.branch.bzrdir.sprout('tree2', stacked=True
2183
            ).open_workingtree()
2184
        tree2.commit('local changes make me feel good.')
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
2185
        branch2 = Branch.open(self.get_url('tree2'))
3835.1.2 by Aaron Bentley
Add tests for get_parent_map
2186
        branch2.lock_read()
2187
        self.addCleanup(branch2.unlock)
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2188
        return tree1.branch, branch2
3835.1.7 by Aaron Bentley
Updates from review
2189
2190
    def test_stacked_get_parent_map(self):
2191
        # the public implementation of get_parent_map obeys stacking
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2192
        _, branch = self.prepare_stacked_remote_branch()
3835.1.7 by Aaron Bentley
Updates from review
2193
        repo = branch.repository
3835.1.2 by Aaron Bentley
Add tests for get_parent_map
2194
        self.assertEqual(['rev1'], repo.get_parent_map(['rev1']).keys())
3835.1.7 by Aaron Bentley
Updates from review
2195
3835.1.10 by Aaron Bentley
Move CachingExtraParentsProvider to Graph
2196
    def test_unstacked_get_parent_map(self):
2197
        # _unstacked_provider.get_parent_map ignores stacking
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2198
        _, branch = self.prepare_stacked_remote_branch()
3835.1.10 by Aaron Bentley
Move CachingExtraParentsProvider to Graph
2199
        provider = branch.repository._unstacked_provider
3835.1.8 by Aaron Bentley
Make UnstackedParentsProvider manage the cache
2200
        self.assertEqual([], provider.get_parent_map(['rev1']).keys())
3834.3.3 by John Arbash Meinel
Merge bzr.dev, resolve conflict in tests.
2201
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2202
    def fetch_stream_to_rev_order(self, stream):
2203
        result = []
2204
        for kind, substream in stream:
2205
            if not kind == 'revisions':
2206
                list(substream)
2207
            else:
2208
                for content in substream:
2209
                    result.append(content.key[-1])
2210
        return result
2211
2212
    def get_ordered_revs(self, format, order):
2213
        """Get a list of the revisions in a stream to format format.
2214
2215
        :param format: The format of the target.
2216
        :param order: the order that target should have requested.
2217
        :result: The revision ids in the stream, in the order seen,
2218
            the topological order of revisions in the source.
2219
        """
2220
        unordered_format = bzrdir.format_registry.get(format)()
2221
        target_repository_format = unordered_format.repository_format
2222
        # Cross check
2223
        self.assertEqual(order, target_repository_format._fetch_order)
2224
        trunk, stacked = self.prepare_stacked_remote_branch()
2225
        source = stacked.repository._get_source(target_repository_format)
2226
        tip = stacked.last_revision()
2227
        revs = stacked.repository.get_ancestry(tip)
2228
        search = graph.PendingAncestryResult([tip], stacked.repository)
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
2229
        self.reset_smart_call_log()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2230
        stream = source.get_stream(search)
2231
        if None in revs:
2232
            revs.remove(None)
2233
        # We trust that if a revision is in the stream the rest of the new
2234
        # content for it is too, as per our main fetch tests; here we are
2235
        # checking that the revisions are actually included at all, and their
2236
        # order.
2237
        return self.fetch_stream_to_rev_order(stream), revs
2238
2239
    def test_stacked_get_stream_unordered(self):
2240
        # Repository._get_source.get_stream() from a stacked repository with
2241
        # unordered yields the full data from both stacked and stacked upon
2242
        # sources.
2243
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered')
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
2244
        self.assertEqual(set(expected_revs), set(rev_ord))
2245
        # Getting unordered results should have made a streaming data request
2246
        # from the server, then one from the backing branch.
2247
        self.assertLength(2, self.hpss_calls)
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2248
2249
    def test_stacked_get_stream_topological(self):
2250
        # Repository._get_source.get_stream() from a stacked repository with
2251
        # topological sorting yields the full data from both stacked and
2252
        # stacked upon sources in topological order.
2253
        rev_ord, expected_revs = self.get_ordered_revs('knit', 'topological')
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
2254
        self.assertEqual(expected_revs, rev_ord)
2255
        # Getting topological sort requires VFS calls still
2256
        self.assertLength(14, self.hpss_calls)
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2257
2258
    def test_stacked_get_stream_groupcompress(self):
2259
        # Repository._get_source.get_stream() from a stacked repository with
2260
        # groupcompress sorting yields the full data from both stacked and
2261
        # stacked upon sources in groupcompress order.
2262
        raise tests.TestSkipped('No groupcompress ordered format available')
2263
        rev_ord, expected_revs = self.get_ordered_revs('dev5', 'groupcompress')
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
2264
        self.assertEqual(expected_revs, reversed(rev_ord))
2265
        # Getting unordered results should have made a streaming data request
2266
        # from the backing branch, and one from the stacked on branch.
2267
        self.assertLength(2, self.hpss_calls)
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
2268
3834.3.2 by Andrew Bennetts
Preserve BzrBranch5's _synchronize_history code without affecting Branch or BzrBranch7; add effort test for RemoteBranch.copy_content_into.
2269
2270
class TestRemoteBranchEffort(tests.TestCaseWithTransport):
2271
2272
    def setUp(self):
2273
        super(TestRemoteBranchEffort, self).setUp()
2274
        # Create a smart server that publishes whatever the backing VFS server
2275
        # does.
2276
        self.smart_server = server.SmartTCPServer_for_testing()
2277
        self.smart_server.setUp(self.get_server())
2278
        self.addCleanup(self.smart_server.tearDown)
2279
        # Log all HPSS calls into self.hpss_calls.
2280
        _SmartClient.hooks.install_named_hook(
2281
            'call', self.capture_hpss_call, None)
2282
        self.hpss_calls = []
2283
2284
    def capture_hpss_call(self, params):
2285
        self.hpss_calls.append(params.method)
2286
2287
    def test_copy_content_into_avoids_revision_history(self):
2288
        local = self.make_branch('local')
2289
        remote_backing_tree = self.make_branch_and_tree('remote')
2290
        remote_backing_tree.commit("Commit.")
2291
        remote_branch_url = self.smart_server.get_url() + 'remote'
2292
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
2293
        local.repository.fetch(remote_branch.repository)
2294
        self.hpss_calls = []
2295
        remote_branch.copy_content_into(local)
3834.3.3 by John Arbash Meinel
Merge bzr.dev, resolve conflict in tests.
2296
        self.assertFalse('Branch.revision_history' in self.hpss_calls)