/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2013, 2016 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
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
6791.2.3 by Jelmer Vernooij
Fix more imports.
26
import base64
3211.5.2 by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression.
27
import bz2
6968.5.7 by Jelmer Vernooij
Add client side test.
28
import tarfile
6280.9.4 by Jelmer Vernooij
use zlib instead.
29
import zlib
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
30
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
31
from .. import (
6436.3.1 by Jelmer Vernooij
Add remote get_branches call.
32
    bencode,
4792.1.1 by Andrew Bennetts
Show real branch/repo format description in 'info -v' over HPSS.
33
    branch,
3777.1.3 by Aaron Bentley
Use SSH default username from authentication.conf
34
    config,
5363.2.9 by Jelmer Vernooij
Fix some tests.
35
    controldir,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
36
    errors,
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
37
    repository,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
38
    tests,
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
39
    transport,
4190.1.4 by Robert Collins
Cache ghosts when we can get them from a RemoteRepository in get_parent_map.
40
    treebuilder,
6670.4.1 by Jelmer Vernooij
Update imports.
41
    )
42
from ..branch import Branch
43
from ..bzr import (
44
    bzrdir,
45
    inventory,
46
    inventory_delta,
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
47
    remote,
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
48
    versionedfile,
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
49
    vf_search,
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
50
    )
6670.4.1 by Jelmer Vernooij
Update imports.
51
from ..bzr.bzrdir import (
5363.2.9 by Jelmer Vernooij
Fix some tests.
52
    BzrDir,
53
    BzrDirFormat,
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
54
    )
55
from ..bzr import (
5363.2.9 by Jelmer Vernooij
Fix some tests.
56
    RemoteBzrProber,
57
    )
6670.4.1 by Jelmer Vernooij
Update imports.
58
from ..bzr.chk_serializer import chk_bencode_serializer
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
59
from ..bzr.remote import (
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
60
    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.
61
    RemoteBranchFormat,
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
62
    RemoteBzrDir,
5712.3.17 by Jelmer Vernooij
more fixes.
63
    RemoteBzrDirFormat,
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
64
    RemoteRepository,
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
65
    RemoteRepositoryFormat,
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
66
    )
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
67
from ..bzr import groupcompress_repo, knitpack_repo
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
68
from ..revision import (
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
69
    NULL_REVISION,
70
    Revision,
71
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
72
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
73
    BytesIO,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
74
    text_type,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
75
    )
6670.4.16 by Jelmer Vernooij
Move smart to breezy.bzr.
76
from ..bzr.smart import medium, request
77
from ..bzr.smart.client import _SmartClient
78
from ..bzr.smart.repository import (
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
79
    SmartServerRepositoryGetParentMap,
80
    SmartServerRepositoryGetStream_1_19,
6282.6.37 by Jelmer Vernooij
Cope with empty results.
81
    _stream_to_byte_stream,
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
82
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
83
from . import (
5017.3.28 by Vincent Ladeuil
selftest -s bt.test_remote passing
84
    test_server,
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
85
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
86
from .scenarios import load_tests_apply_scenarios
87
from ..transport.memory import MemoryTransport
88
from ..transport.remote import (
3777.1.3 by Aaron Bentley
Use SSH default username from authentication.conf
89
    RemoteTransport,
90
    RemoteSSHTransport,
91
    RemoteTCPTransport,
5579.3.1 by Jelmer Vernooij
Remove unused imports.
92
    )
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
93
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
94
95
load_tests = load_tests_apply_scenarios
96
97
98
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
99
100
    scenarios = [
4104.4.2 by Robert Collins
Fix test_source for 1.13 landing.
101
        ('HPSS-v2',
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
102
            {'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
4104.4.2 by Robert Collins
Fix test_source for 1.13 landing.
103
        ('HPSS-v3',
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
104
            {'transport_server': test_server.SmartTCPServer_for_testing})]
105
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
106
107
    def setUp(self):
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
108
        super(BasicRemoteObjectTests, self).setUp()
109
        self.transport = self.get_transport()
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
110
        # 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
111
        self.local_wt = BzrDir.create_standalone_workingtree('.')
4986.2.1 by Martin Pool
Remove tearDown in tests in favor of addCleanup
112
        self.addCleanup(self.transport.disconnect)
2018.5.171 by Andrew Bennetts
Disconnect RemoteTransports in some tests to avoid tripping up test_strace with leftover threads from previous tests.
113
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
114
    def test_create_remote_bzrdir(self):
5712.3.17 by Jelmer Vernooij
more fixes.
115
        b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
116
        self.assertIsInstance(b, BzrDir)
117
118
    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.
119
        # open a standalone branch in the working directory
5712.3.17 by Jelmer Vernooij
more fixes.
120
        b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
121
        branch = b.open_branch()
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
122
        self.assertIsInstance(branch, Branch)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
123
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
124
    def test_remote_repository(self):
125
        b = BzrDir.open_from_transport(self.transport)
126
        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.
127
        revid = u'\xc823123123'.encode('utf8')
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
128
        self.assertFalse(repo.has_revision(revid))
129
        self.local_wt.commit(message='test commit', rev_id=revid)
130
        self.assertTrue(repo.has_revision(revid))
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
131
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
132
    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)
133
        """Should open a RemoteBzrDir over a RemoteTransport"""
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
134
        fmt = BzrDirFormat.find_format(self.transport)
6695.5.3 by Jelmer Vernooij
Fix last reference to bzrdir.RemoteBzrProber.
135
        self.assertTrue(RemoteBzrProber
5363.2.9 by Jelmer Vernooij
Fix some tests.
136
                        in controldir.ControlDirFormat._server_probers)
5712.3.17 by Jelmer Vernooij
more fixes.
137
        self.assertIsInstance(fmt, RemoteBzrDirFormat)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
138
139
    def test_open_detected_smart_format(self):
140
        fmt = BzrDirFormat.find_format(self.transport)
141
        d = fmt.open(self.transport)
142
        self.assertIsInstance(d, BzrDir)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
143
2477.1.1 by Martin Pool
Add RemoteBranch repr
144
    def test_remote_branch_repr(self):
145
        b = BzrDir.open_from_transport(self.transport).open_branch()
146
        self.assertStartsWith(str(b), 'RemoteBranch(')
147
4964.2.1 by Martin Pool
Add RemoteBzrDir repr
148
    def test_remote_bzrdir_repr(self):
149
        b = BzrDir.open_from_transport(self.transport)
150
        self.assertStartsWith(str(b), 'RemoteBzrDir(')
151
4103.2.2 by Andrew Bennetts
Fix RemoteBranchFormat.supports_stacking()
152
    def test_remote_branch_format_supports_stacking(self):
153
        t = self.transport
154
        self.make_branch('unstackable', format='pack-0.92')
155
        b = BzrDir.open_from_transport(t.clone('unstackable')).open_branch()
156
        self.assertFalse(b._format.supports_stacking())
157
        self.make_branch('stackable', format='1.9')
158
        b = BzrDir.open_from_transport(t.clone('stackable')).open_branch()
159
        self.assertTrue(b._format.supports_stacking())
160
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
161
    def test_remote_repo_format_supports_external_references(self):
162
        t = self.transport
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
163
        bd = self.make_controldir('unstackable', format='pack-0.92')
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
164
        r = bd.create_repository()
165
        self.assertFalse(r._format.supports_external_lookups)
166
        r = BzrDir.open_from_transport(t.clone('unstackable')).open_repository()
167
        self.assertFalse(r._format.supports_external_lookups)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
168
        bd = self.make_controldir('stackable', format='1.9')
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
169
        r = bd.create_repository()
170
        self.assertTrue(r._format.supports_external_lookups)
171
        r = BzrDir.open_from_transport(t.clone('stackable')).open_repository()
172
        self.assertTrue(r._format.supports_external_lookups)
173
4301.3.1 by Andrew Bennetts
Implement RemoteBranch.set_append_revisions_only.
174
    def test_remote_branch_set_append_revisions_only(self):
175
        # Make a format 1.9 branch, which supports append_revisions_only
176
        branch = self.make_branch('branch', format='1.9')
177
        branch.set_append_revisions_only(True)
6372.4.2 by Jelmer Vernooij
Fix remaining tests.
178
        config = branch.get_config_stack()
4301.3.1 by Andrew Bennetts
Implement RemoteBranch.set_append_revisions_only.
179
        self.assertEqual(
6372.4.1 by Jelmer Vernooij
Convert 'append_revisions_only' over to config stacks.
180
            True, config.get('append_revisions_only'))
4301.3.1 by Andrew Bennetts
Implement RemoteBranch.set_append_revisions_only.
181
        branch.set_append_revisions_only(False)
6372.4.2 by Jelmer Vernooij
Fix remaining tests.
182
        config = branch.get_config_stack()
4301.3.1 by Andrew Bennetts
Implement RemoteBranch.set_append_revisions_only.
183
        self.assertEqual(
6372.4.1 by Jelmer Vernooij
Convert 'append_revisions_only' over to config stacks.
184
            False, config.get('append_revisions_only'))
4301.3.1 by Andrew Bennetts
Implement RemoteBranch.set_append_revisions_only.
185
186
    def test_remote_branch_set_append_revisions_only_upgrade_reqd(self):
187
        branch = self.make_branch('branch', format='knit')
188
        self.assertRaises(
4301.3.3 by Andrew Bennetts
Move check onto base Branch class, and add a supports_set_append_revisions_only method to BranchFormat, as suggested by Robert.
189
            errors.UpgradeRequired, branch.set_append_revisions_only, True)
4301.3.1 by Andrew Bennetts
Implement RemoteBranch.set_append_revisions_only.
190
3691.2.4 by Martin Pool
Add FakeRemoteTransport to clarify test_remote
191
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
192
class FakeProtocol(object):
193
    """Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
194
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
195
    def __init__(self, body, fake_client):
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
196
        self.body = body
197
        self._body_buffer = None
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
198
        self._fake_client = fake_client
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
199
200
    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.
201
        if self._body_buffer is None:
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
202
            self._body_buffer = BytesIO(self.body)
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
203
        bytes = self._body_buffer.read(count)
204
        if self._body_buffer.tell() == len(self._body_buffer.getvalue()):
205
            self._fake_client.expecting_body = False
206
        return bytes
207
208
    def cancel_read_body(self):
209
        self._fake_client.expecting_body = False
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
210
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
211
    def read_streamed_body(self):
212
        return self.body
213
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
214
2018.5.159 by Andrew Bennetts
Rename SmartClient to _SmartClient.
215
class FakeClient(_SmartClient):
216
    """Lookalike for _SmartClient allowing testing."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
217
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
218
    def __init__(self, fake_medium_base='fake base'):
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
219
        """Create a FakeClient."""
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
220
        self.responses = []
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
221
        self._calls = []
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
222
        self.expecting_body = False
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
223
        # if non-None, this is the list of expected calls, with only the
224
        # 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.
225
        # compute so is not included. If a call is None, that call can
226
        # be anything.
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
227
        self._expected_calls = None
3431.3.2 by Andrew Bennetts
Remove 'base' from _SmartClient entirely, now that the medium has it.
228
        _SmartClient.__init__(self, FakeMedium(self._calls, fake_medium_base))
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
229
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
230
    def add_expected_call(self, call_name, call_args, response_type,
231
        response_args, response_body=None):
232
        if self._expected_calls is None:
233
            self._expected_calls = []
234
        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
235
        self.responses.append((response_type, response_args, response_body))
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
236
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
237
    def add_success_response(self, *args):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
238
        self.responses.append((b'success', args, None))
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
239
240
    def add_success_response_with_body(self, body, *args):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
241
        self.responses.append((b'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.
242
        if self._expected_calls is not None:
243
            self._expected_calls.append(None)
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
244
245
    def add_error_response(self, *args):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
246
        self.responses.append((b'error', args))
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
247
248
    def add_unknown_method_response(self, verb):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
249
        self.responses.append((b'unknown', verb))
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
250
4523.3.2 by Andrew Bennetts
Adjust according to Robert's review.
251
    def finished_test(self):
252
        if self._expected_calls:
253
            raise AssertionError("%r finished but was still expecting %r"
254
                % (self, self._expected_calls[0]))
255
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.
256
    def _get_next_response(self):
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
257
        try:
258
            response_tuple = self.responses.pop(0)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
259
        except IndexError as e:
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
260
            raise AssertionError("%r didn't expect any more calls"
261
                % (self,))
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
262
        if response_tuple[0] == b'unknown':
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
263
            raise errors.UnknownSmartMethod(response_tuple[1])
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
264
        elif response_tuple[0] == b'error':
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
265
            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.
266
        return response_tuple
267
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
268
    def _check_call(self, method, args):
269
        if self._expected_calls is None:
270
            # the test should be updated to say what it expects
271
            return
272
        try:
273
            next_call = self._expected_calls.pop(0)
274
        except IndexError:
275
            raise AssertionError("%r didn't expect any more calls "
276
                "but got %r%r"
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
277
                % (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.
278
        if next_call is None:
279
            return
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
280
        if method != next_call[0] or args != next_call[1]:
281
            raise AssertionError("%r expected %r%r "
282
                "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
283
                % (self, next_call[0], next_call[1], method, args,))
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
284
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
285
    def call(self, method, *args):
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
286
        self._check_call(method, args)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
287
        self._calls.append(('call', method, args))
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
288
        return self._get_next_response()[1]
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
289
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
290
    def call_expecting_body(self, method, *args):
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
291
        self._check_call(method, args)
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
292
        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.
293
        result = self._get_next_response()
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
294
        self.expecting_body = True
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
295
        return result[1], FakeProtocol(result[2], self)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
296
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
297
    def call_with_body_bytes(self, method, args, body):
298
        self._check_call(method, args)
299
        self._calls.append(('call_with_body_bytes', method, args, body))
300
        result = self._get_next_response()
301
        return result[1], FakeProtocol(result[2], self)
302
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.
303
    def call_with_body_bytes_expecting_body(self, method, args, body):
3691.2.7 by Martin Pool
FakeClient can know what calls to expect
304
        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.
305
        self._calls.append(('call_with_body_bytes_expecting_body', method,
306
            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.
307
        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.
308
        self.expecting_body = True
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
309
        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.
310
3842.3.9 by Andrew Bennetts
Backing up the stream so that we can fallback correctly.
311
    def call_with_body_stream(self, args, stream):
312
        # Explicitly consume the stream before checking for an error, because
313
        # that's what happens a real medium.
314
        stream = list(stream)
315
        self._check_call(args[0], args[1:])
316
        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.
317
        result = self._get_next_response()
4144.3.3 by Andrew Bennetts
Tweaks based on review from Robert.
318
        # The second value returned from call_with_body_stream is supposed to
319
        # be a response_handler object, but so far no tests depend on that.
320
        response_handler = None 
321
        return result[1], response_handler
3842.3.9 by Andrew Bennetts
Backing up the stream so that we can fallback correctly.
322
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
323
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
324
class FakeMedium(medium.SmartClientMedium):
3104.4.2 by Andrew Bennetts
All tests passing.
325
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.
326
    def __init__(self, client_calls, base):
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
327
        medium.SmartClientMedium.__init__(self, base)
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
328
        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.
329
330
    def disconnect(self):
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
331
        self._client_calls.append(('disconnect medium',))
3104.4.2 by Andrew Bennetts
All tests passing.
332
333
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.
334
class TestVfsHas(tests.TestCase):
335
336
    def test_unicode_path(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
337
        client = FakeClient('/')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
338
        client.add_success_response(b'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.
339
        transport = RemoteTransport('bzr://localhost/', _client=client)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
340
        filename = u'/hell\u00d8'.encode('utf-8')
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.
341
        result = transport.has(filename)
342
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
343
            [('call', b'has', (filename,))],
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.
344
            client._calls)
345
        self.assertTrue(result)
346
347
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
348
class TestRemote(tests.TestCaseWithMemoryTransport):
4032.1.1 by John Arbash Meinel
Merge the removal of all trailing whitespace, and resolve conflicts.
349
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.
350
    def get_branch_format(self):
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
351
        reference_bzrdir_format = controldir.format_registry.get('default')()
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.
352
        return reference_bzrdir_format.get_branch_format()
353
4053.1.2 by Robert Collins
Actually make this branch work.
354
    def get_repo_format(self):
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
355
        reference_bzrdir_format = controldir.format_registry.get('default')()
4053.1.2 by Robert Collins
Actually make this branch work.
356
        return reference_bzrdir_format.repository_format
357
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
358
    def assertFinished(self, fake_client):
359
        """Assert that all of a FakeClient's expected calls have occurred."""
4523.3.2 by Andrew Bennetts
Adjust according to Robert's review.
360
        fake_client.finished_test()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
361
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
362
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
363
class Test_ClientMedium_remote_path_from_transport(tests.TestCase):
364
    """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.
365
366
    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.
367
        """Assert that the result of
368
        SmartClientMedium.remote_path_from_transport is the expected value for
369
        a given client_base and transport_base.
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
370
        """
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
371
        client_medium = medium.SmartClientMedium(client_base)
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
372
        t = transport.get_transport(transport_base)
373
        result = client_medium.remote_path_from_transport(t)
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
374
        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.
375
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
376
    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.
377
        """SmartClientMedium.remote_path_from_transport calculates a URL for
378
        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.
379
        """
380
        self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')
381
        self.assertRemotePath(
382
            'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz')
383
3431.3.11 by Andrew Bennetts
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.
384
    def assertRemotePathHTTP(self, expected, transport_base, relpath):
385
        """Assert that the result of
386
        HttpTransportBase.remote_path_from_transport is the expected value for
387
        a given transport_base and relpath of that transport.  (Note that
388
        HttpTransportBase is a subclass of SmartClientMedium)
389
        """
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
390
        base_transport = 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.
391
        client_medium = base_transport.get_smart_medium()
392
        cloned_transport = base_transport.clone(relpath)
393
        result = client_medium.remote_path_from_transport(cloned_transport)
394
        self.assertEqual(expected, result)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
395
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
396
    def test_remote_path_from_transport_http(self):
397
        """Remote paths for HTTP transports are calculated differently to other
398
        transports.  They are just relative to the client base, not the root
399
        directory of the host.
400
        """
401
        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.
402
            self.assertRemotePathHTTP(
403
                '../xyz/', scheme + '//host/path', '../xyz/')
404
            self.assertRemotePathHTTP(
405
                'xyz/', scheme + '//host/path', 'xyz/')
3313.3.3 by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport.
406
407
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
408
class Test_ClientMedium_remote_is_at_least(tests.TestCase):
409
    """Tests for the behaviour of client_medium.remote_is_at_least."""
410
411
    def test_initially_unlimited(self):
412
        """A fresh medium assumes that the remote side supports all
413
        versions.
414
        """
415
        client_medium = medium.SmartClientMedium('dummy base')
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
416
        self.assertFalse(client_medium._is_remote_before((99, 99)))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
417
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
418
    def test__remember_remote_is_before(self):
419
        """Calling _remember_remote_is_before ratchets down the known remote
420
        version.
421
        """
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
422
        client_medium = medium.SmartClientMedium('dummy base')
423
        # Mark the remote side as being less than 1.6.  The remote side may
424
        # still be 1.5.
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
425
        client_medium._remember_remote_is_before((1, 6))
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
426
        self.assertTrue(client_medium._is_remote_before((1, 6)))
427
        self.assertFalse(client_medium._is_remote_before((1, 5)))
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
428
        # Calling _remember_remote_is_before again with a lower value works.
429
        client_medium._remember_remote_is_before((1, 5))
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
430
        self.assertTrue(client_medium._is_remote_before((1, 5)))
4797.49.4 by Andrew Bennetts
Expand test a little further, and use consistent terminology in its comments.
431
        # If you call _remember_remote_is_before with a higher value it logs a
432
        # warning, and continues to remember the lower value.
4797.49.1 by Andrew Bennetts
First, fix _remember_remote_is_before to never raise AssertionError for what is a very minor bug.
433
        self.assertNotContainsRe(self.get_log(), '_remember_remote_is_before')
434
        client_medium._remember_remote_is_before((1, 9))
435
        self.assertContainsRe(self.get_log(), '_remember_remote_is_before')
4797.49.4 by Andrew Bennetts
Expand test a little further, and use consistent terminology in its comments.
436
        self.assertTrue(client_medium._is_remote_before((1, 5)))
3453.4.1 by Andrew Bennetts
Better infrastructure on SmartClientMedium for tracking the remote version.
437
438
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
439
class TestBzrDirCloningMetaDir(TestRemote):
440
441
    def test_backwards_compat(self):
442
        self.setup_smart_server_with_call_log()
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
443
        a_dir = self.make_controldir('.')
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
444
        self.reset_smart_call_log()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
445
        verb = b'BzrDir.cloning_metadir'
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
446
        self.disable_verb(verb)
447
        format = a_dir.cloning_metadir()
448
        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.
449
            call.call.method == verb])
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
450
        self.assertEqual(1, call_count)
451
4160.2.9 by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make
452
    def test_branch_reference(self):
453
        transport = self.get_transport('quack')
454
        referenced = self.make_branch('referenced')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
455
        expected = referenced.controldir.cloning_metadir()
4160.2.9 by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make
456
        client = FakeClient(transport.base)
457
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
458
            b'BzrDir.cloning_metadir', (b'quack/', b'False'),
459
            b'error', (b'BranchReference',)),
4160.2.9 by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make
460
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
461
            b'BzrDir.open_branchV3', (b'quack/',),
462
            b'success', (b'ref', self.get_url('referenced'))),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
463
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
4160.2.9 by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make
464
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
465
        result = a_controldir.cloning_metadir()
4160.2.9 by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make
466
        # We should have got a control dir matching the referenced branch.
467
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
468
        self.assertEqual(expected._repository_format, result._repository_format)
469
        self.assertEqual(expected._branch_format, result._branch_format)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
470
        self.assertFinished(client)
4160.2.9 by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make
471
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
472
    def test_current_server(self):
473
        transport = self.get_transport('.')
474
        transport = transport.clone('quack')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
475
        self.make_controldir('quack')
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
476
        client = FakeClient(transport.base)
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
477
        reference_bzrdir_format = controldir.format_registry.get('default')()
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
478
        control_name = reference_bzrdir_format.network_name()
479
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
480
            b'BzrDir.cloning_metadir', (b'quack/', b'False'),
481
            b'success', (control_name, b'', (b'branch', b''))),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
482
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
483
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
484
        result = a_controldir.cloning_metadir()
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
485
        # We should have got a reference control dir with default branch and
486
        # repository formats.
487
        # This pokes a little, just to be sure.
488
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
4070.2.8 by Robert Collins
Really test the current BzrDir.cloning_metadir contract.
489
        self.assertEqual(None, result._repository_format)
490
        self.assertEqual(None, result._branch_format)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
491
        self.assertFinished(client)
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
492
6305.4.1 by Jelmer Vernooij
Print sensible error message when remote format is unknown.
493
    def test_unknown(self):
494
        transport = self.get_transport('quack')
495
        referenced = self.make_branch('referenced')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
496
        expected = referenced.controldir.cloning_metadir()
6305.4.1 by Jelmer Vernooij
Print sensible error message when remote format is unknown.
497
        client = FakeClient(transport.base)
498
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
499
            b'BzrDir.cloning_metadir', (b'quack/', b'False'),
500
            b'success', (b'unknown', b'unknown', (b'branch', b''))),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
501
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
6305.4.1 by Jelmer Vernooij
Print sensible error message when remote format is unknown.
502
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
503
        self.assertRaises(errors.UnknownFormatError, a_controldir.cloning_metadir)
6305.4.1 by Jelmer Vernooij
Print sensible error message when remote format is unknown.
504
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
505
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
506
class TestBzrDirCheckoutMetaDir(TestRemote):
507
508
    def test__get_checkout_format(self):
509
        transport = MemoryTransport()
510
        client = FakeClient(transport.base)
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
511
        reference_bzrdir_format = controldir.format_registry.get('default')()
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
512
        control_name = reference_bzrdir_format.network_name()
513
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
514
            b'BzrDir.checkout_metadir', (b'quack/', ),
515
            b'success', (control_name, b'', b''))
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
516
        transport.mkdir('quack')
517
        transport = transport.clone('quack')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
518
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
519
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
520
        result = a_controldir.checkout_metadir()
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
521
        # We should have got a reference control dir with default branch and
522
        # repository formats.
523
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
524
        self.assertEqual(None, result._repository_format)
525
        self.assertEqual(None, result._branch_format)
526
        self.assertFinished(client)
527
528
    def test_unknown_format(self):
529
        transport = MemoryTransport()
530
        client = FakeClient(transport.base)
531
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
532
            b'BzrDir.checkout_metadir', (b'quack/',),
533
            b'success', (b'dontknow', b'', b''))
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
534
        transport.mkdir('quack')
535
        transport = transport.clone('quack')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
536
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
537
            _client=client)
538
        self.assertRaises(errors.UnknownFormatError,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
539
            a_controldir.checkout_metadir)
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
540
        self.assertFinished(client)
541
542
6436.3.1 by Jelmer Vernooij
Add remote get_branches call.
543
class TestBzrDirGetBranches(TestRemote):
544
545
    def test_get_branches(self):
546
        transport = MemoryTransport()
547
        client = FakeClient(transport.base)
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
548
        reference_bzrdir_format = controldir.format_registry.get('default')()
6436.3.2 by Jelmer Vernooij
Add HPSS call for BzrDir.get_branches.
549
        branch_name = reference_bzrdir_format.get_branch_format().network_name()
6436.3.1 by Jelmer Vernooij
Add remote get_branches call.
550
        client.add_success_response_with_body(
551
            bencode.bencode({
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
552
                b"foo": (b"branch", branch_name),
553
                b"": (b"branch", branch_name)}), b"success")
554
        client.add_success_response(
555
            b'ok', b'', b'no', b'no', b'no',
556
                reference_bzrdir_format.repository_format.network_name())
557
        client.add_error_response(b'NotStacked')
558
        client.add_success_response(
559
            b'ok', b'', b'no', b'no', b'no',
560
                reference_bzrdir_format.repository_format.network_name())
561
        client.add_error_response(b'NotStacked')
6436.3.1 by Jelmer Vernooij
Add remote get_branches call.
562
        transport.mkdir('quack')
563
        transport = transport.clone('quack')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
564
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
6436.3.1 by Jelmer Vernooij
Add remote get_branches call.
565
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
566
        result = a_controldir.get_branches()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
567
        self.assertEqual({b"", b"foo"}, set(result.keys()))
6436.3.1 by Jelmer Vernooij
Add remote get_branches call.
568
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
569
            [('call_expecting_body', b'BzrDir.get_branches', (b'quack/',)),
570
             ('call', b'BzrDir.find_repositoryV3', (b'quack/', )),
571
             ('call', b'Branch.get_stacked_on_url', (b'quack/', )),
572
             ('call', b'BzrDir.find_repositoryV3', (b'quack/', )),
573
             ('call', b'Branch.get_stacked_on_url', (b'quack/', ))],
6436.3.1 by Jelmer Vernooij
Add remote get_branches call.
574
            client._calls)
575
576
6266.4.1 by Jelmer Vernooij
HPSS call 'BzrDir.destroy_branch'.
577
class TestBzrDirDestroyBranch(TestRemote):
578
579
    def test_destroy_default(self):
580
        transport = self.get_transport('quack')
581
        referenced = self.make_branch('referenced')
582
        client = FakeClient(transport.base)
583
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
584
            b'BzrDir.destroy_branch', (b'quack/', ),
585
            b'success', (b'ok',)),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
586
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
6266.4.1 by Jelmer Vernooij
HPSS call 'BzrDir.destroy_branch'.
587
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
588
        a_controldir.destroy_branch()
6266.4.1 by Jelmer Vernooij
HPSS call 'BzrDir.destroy_branch'.
589
        self.assertFinished(client)
590
591
6266.3.1 by Jelmer Vernooij
Add HPSS call for BzrDir.has_workingtree.
592
class TestBzrDirHasWorkingTree(TestRemote):
593
594
    def test_has_workingtree(self):
595
        transport = self.get_transport('quack')
596
        client = FakeClient(transport.base)
597
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
598
            b'BzrDir.has_workingtree', (b'quack/',),
599
            b'success', (b'yes',)),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
600
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
6266.3.1 by Jelmer Vernooij
Add HPSS call for BzrDir.has_workingtree.
601
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
602
        self.assertTrue(a_controldir.has_workingtree())
6266.3.1 by Jelmer Vernooij
Add HPSS call for BzrDir.has_workingtree.
603
        self.assertFinished(client)
604
605
    def test_no_workingtree(self):
606
        transport = self.get_transport('quack')
607
        client = FakeClient(transport.base)
608
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
609
            b'BzrDir.has_workingtree', (b'quack/',),
610
            b'success', (b'no',)),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
611
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
6266.3.1 by Jelmer Vernooij
Add HPSS call for BzrDir.has_workingtree.
612
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
613
        self.assertFalse(a_controldir.has_workingtree())
6266.3.1 by Jelmer Vernooij
Add HPSS call for BzrDir.has_workingtree.
614
        self.assertFinished(client)
615
616
6266.2.1 by Jelmer Vernooij
New HPSS call BzrDir.destroy_repository.
617
class TestBzrDirDestroyRepository(TestRemote):
618
619
    def test_destroy_repository(self):
620
        transport = self.get_transport('quack')
621
        client = FakeClient(transport.base)
622
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
623
            b'BzrDir.destroy_repository', (b'quack/',),
624
            b'success', (b'ok',)),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
625
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
6266.2.1 by Jelmer Vernooij
New HPSS call BzrDir.destroy_repository.
626
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
627
        a_controldir.destroy_repository()
6266.2.1 by Jelmer Vernooij
New HPSS call BzrDir.destroy_repository.
628
        self.assertFinished(client)
629
630
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
631
class TestBzrDirOpen(TestRemote):
632
633
    def make_fake_client_and_transport(self, path='quack'):
634
        transport = MemoryTransport()
635
        transport.mkdir(path)
636
        transport = transport.clone(path)
637
        client = FakeClient(transport.base)
638
        return client, transport
639
640
    def test_absent(self):
641
        client, transport = self.make_fake_client_and_transport()
642
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
643
            b'BzrDir.open_2.1', (b'quack/',), b'success', (b'no',))
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
644
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
5712.3.17 by Jelmer Vernooij
more fixes.
645
                RemoteBzrDirFormat(), _client=client, _force_probe=True)
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
646
        self.assertFinished(client)
647
648
    def test_present_without_workingtree(self):
649
        client, transport = self.make_fake_client_and_transport()
650
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
651
            b'BzrDir.open_2.1', (b'quack/',), b'success', (b'yes', b'no'))
5712.3.17 by Jelmer Vernooij
more fixes.
652
        bd = RemoteBzrDir(transport, RemoteBzrDirFormat(),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
653
            _client=client, _force_probe=True)
654
        self.assertIsInstance(bd, RemoteBzrDir)
655
        self.assertFalse(bd.has_workingtree())
656
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
657
        self.assertFinished(client)
658
659
    def test_present_with_workingtree(self):
660
        client, transport = self.make_fake_client_and_transport()
661
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
662
            b'BzrDir.open_2.1', (b'quack/',), b'success', (b'yes', b'yes'))
5712.3.17 by Jelmer Vernooij
more fixes.
663
        bd = RemoteBzrDir(transport, RemoteBzrDirFormat(),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
664
            _client=client, _force_probe=True)
665
        self.assertIsInstance(bd, RemoteBzrDir)
666
        self.assertTrue(bd.has_workingtree())
667
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
668
        self.assertFinished(client)
669
670
    def test_backwards_compat(self):
671
        client, transport = self.make_fake_client_and_transport()
672
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
673
            b'BzrDir.open_2.1', (b'quack/',), b'unknown', (b'BzrDir.open_2.1',))
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
674
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
675
            b'BzrDir.open', (b'quack/',), b'success', (b'yes',))
5712.3.17 by Jelmer Vernooij
more fixes.
676
        bd = RemoteBzrDir(transport, RemoteBzrDirFormat(),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
677
            _client=client, _force_probe=True)
678
        self.assertIsInstance(bd, RemoteBzrDir)
679
        self.assertFinished(client)
680
4797.49.2 by Andrew Bennetts
Add test that demonstrates bug #528041.
681
    def test_backwards_compat_hpss_v2(self):
682
        client, transport = self.make_fake_client_and_transport()
683
        # Monkey-patch fake client to simulate real-world behaviour with v2
684
        # server: upon first RPC call detect the protocol version, and because
685
        # the version is 2 also do _remember_remote_is_before((1, 6)) before
686
        # continuing with the RPC.
687
        orig_check_call = client._check_call
688
        def check_call(method, args):
689
            client._medium._protocol_version = 2
690
            client._medium._remember_remote_is_before((1, 6))
691
            client._check_call = orig_check_call
692
            client._check_call(method, args)
693
        client._check_call = check_call
694
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
695
            b'BzrDir.open_2.1', (b'quack/',), b'unknown', (b'BzrDir.open_2.1',))
4797.49.2 by Andrew Bennetts
Add test that demonstrates bug #528041.
696
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
697
            b'BzrDir.open', (b'quack/',), b'success', (b'yes',))
5712.3.17 by Jelmer Vernooij
more fixes.
698
        bd = RemoteBzrDir(transport, RemoteBzrDirFormat(),
4797.49.2 by Andrew Bennetts
Add test that demonstrates bug #528041.
699
            _client=client, _force_probe=True)
700
        self.assertIsInstance(bd, RemoteBzrDir)
701
        self.assertFinished(client)
702
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
703
4053.1.2 by Robert Collins
Actually make this branch work.
704
class TestBzrDirOpenBranch(TestRemote):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
705
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.
706
    def test_backwards_compat(self):
707
        self.setup_smart_server_with_call_log()
708
        self.make_branch('.')
709
        a_dir = BzrDir.open(self.get_url('.'))
710
        self.reset_smart_call_log()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
711
        verb = b'BzrDir.open_branchV3'
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.
712
        self.disable_verb(verb)
713
        format = a_dir.open_branch()
714
        call_count = len([call for call in self.hpss_calls if
715
            call.call.method == verb])
716
        self.assertEqual(1, call_count)
717
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
718
    def test_branch_present(self):
4053.1.2 by Robert Collins
Actually make this branch work.
719
        reference_format = self.get_repo_format()
720
        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.
721
        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.
722
        transport = MemoryTransport()
723
        transport.mkdir('quack')
724
        transport = transport.clone('quack')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
725
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
726
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
727
            b'BzrDir.open_branchV3', (b'quack/',),
728
            b'success', (b'branch', branch_network_name))
729
        client.add_expected_call(
730
            b'BzrDir.find_repositoryV3', (b'quack/',),
731
            b'success', (b'ok', b'', b'no', b'no', b'no', network_name))
732
        client.add_expected_call(
733
            b'Branch.get_stacked_on_url', (b'quack/',),
734
            b'error', (b'NotStacked',))
5712.3.17 by Jelmer Vernooij
more fixes.
735
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
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.
736
            _client=client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
737
        result = bzrdir.open_branch()
738
        self.assertIsInstance(result, RemoteBranch)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
739
        self.assertEqual(bzrdir, result.controldir)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
740
        self.assertFinished(client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
741
742
    def test_branch_missing(self):
743
        transport = MemoryTransport()
744
        transport.mkdir('quack')
745
        transport = transport.clone('quack')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
746
        client = FakeClient(transport.base)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
747
        client.add_error_response(b'nobranch')
5712.3.17 by Jelmer Vernooij
more fixes.
748
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
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.
749
            _client=client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
750
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
751
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
752
            [('call', b'BzrDir.open_branchV3', (b'quack/',))],
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
753
            client._calls)
754
3211.4.1 by Robert Collins
* ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,
755
    def test__get_tree_branch(self):
756
        # _get_tree_branch is a form of open_branch, but it should only ask for
757
        # branch opening, not any other network requests.
758
        calls = []
6305.3.4 by Jelmer Vernooij
Add possible_transports in a couple more places.
759
        def open_branch(name=None, possible_transports=None):
3211.4.1 by Robert Collins
* ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,
760
            calls.append("Called")
761
            return "a-branch"
762
        transport = MemoryTransport()
763
        # 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.
764
        client = FakeClient(transport.base)
5712.3.17 by Jelmer Vernooij
more fixes.
765
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
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.
766
            _client=client)
3211.4.1 by Robert Collins
* ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,
767
        # patch the open_branch call to record that it was called.
768
        bzrdir.open_branch = open_branch
769
        self.assertEqual((None, "a-branch"), bzrdir._get_tree_branch())
770
        self.assertEqual(["Called"], calls)
771
        self.assertEqual([], client._calls)
772
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.
773
    def test_url_quoting_of_path(self):
774
        # Relpaths on the wire should not be URL-escaped.  So "~" should be
775
        # 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.
776
        transport = RemoteTCPTransport('bzr://localhost/~hello/')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
777
        client = FakeClient(transport.base)
4053.1.2 by Robert Collins
Actually make this branch work.
778
        reference_format = self.get_repo_format()
779
        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.
780
        branch_network_name = self.get_branch_format().network_name()
3691.2.10 by Martin Pool
Update more test_remote tests
781
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
782
            b'BzrDir.open_branchV3', (b'~hello/',),
783
            b'success', (b'branch', branch_network_name))
784
        client.add_expected_call(
785
            b'BzrDir.find_repositoryV3', (b'~hello/',),
786
            b'success', (b'ok', b'', b'no', b'no', b'no', network_name))
787
        client.add_expected_call(
788
            b'Branch.get_stacked_on_url', (b'~hello/',),
789
            b'error', (b'NotStacked',))
5712.3.17 by Jelmer Vernooij
more fixes.
790
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
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.
791
            _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.
792
        result = bzrdir.open_branch()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
793
        self.assertFinished(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.
794
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
795
    def check_open_repository(self, rich_root, subtrees, external_lookup=b'no'):
4053.1.2 by Robert Collins
Actually make this branch work.
796
        reference_format = self.get_repo_format()
797
        network_name = reference_format.network_name()
3104.4.2 by Andrew Bennetts
All tests passing.
798
        transport = MemoryTransport()
799
        transport.mkdir('quack')
800
        transport = transport.clone('quack')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
801
        if rich_root:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
802
            rich_response = b'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
803
        else:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
804
            rich_response = b'no'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
805
        if subtrees:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
806
            subtree_response = b'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
807
        else:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
808
            subtree_response = b'no'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
809
        client = FakeClient(transport.base)
810
        client.add_success_response(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
811
            b'ok', b'', rich_response, subtree_response, external_lookup,
4053.1.2 by Robert Collins
Actually make this branch work.
812
            network_name)
5712.3.17 by Jelmer Vernooij
more fixes.
813
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
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.
814
            _client=client)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
815
        result = bzrdir.open_repository()
816
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
817
            [('call', b'BzrDir.find_repositoryV3', (b'quack/',))],
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
818
            client._calls)
819
        self.assertIsInstance(result, RemoteRepository)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
820
        self.assertEqual(bzrdir, result.controldir)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
821
        self.assertEqual(rich_root, result._format.rich_root_data)
2018.5.138 by Robert Collins
Merge bzr.dev.
822
        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.
823
824
    def test_open_repository_sets_format_attributes(self):
825
        self.check_open_repository(True, True)
826
        self.check_open_repository(False, True)
827
        self.check_open_repository(True, False)
828
        self.check_open_repository(False, False)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
829
        self.check_open_repository(False, False, b'yes')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
830
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
831
    def test_old_server(self):
832
        """RemoteBzrDirFormat should fail to probe if the server version is too
833
        old.
834
        """
835
        self.assertRaises(errors.NotBranchError,
5363.2.9 by Jelmer Vernooij
Fix some tests.
836
            RemoteBzrProber.probe_transport, OldServerTransport())
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
837
838
4032.3.2 by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.
839
class TestBzrDirCreateBranch(TestRemote):
840
841
    def test_backwards_compat(self):
842
        self.setup_smart_server_with_call_log()
843
        repo = self.make_repository('.')
844
        self.reset_smart_call_log()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
845
        self.disable_verb(b'BzrDir.create_branch')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
846
        branch = repo.controldir.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.
847
        create_branch_call_count = len([call for call in self.hpss_calls if
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
848
            call.call.method == b'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.
849
        self.assertEqual(1, create_branch_call_count)
850
851
    def test_current_server(self):
852
        transport = self.get_transport('.')
853
        transport = transport.clone('quack')
854
        self.make_repository('quack')
855
        client = FakeClient(transport.base)
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
856
        reference_bzrdir_format = controldir.format_registry.get('default')()
4032.3.2 by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.
857
        reference_format = reference_bzrdir_format.get_branch_format()
858
        network_name = reference_format.network_name()
859
        reference_repo_fmt = reference_bzrdir_format.repository_format
860
        reference_repo_name = reference_repo_fmt.network_name()
861
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
862
            b'BzrDir.create_branch', (b'quack/', network_name),
863
            b'success', (b'ok', network_name, b'', b'no', b'no', b'yes',
4032.3.2 by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.
864
            reference_repo_name))
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
865
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
4032.3.2 by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.
866
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
867
        branch = a_controldir.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.
868
        # We should have got a remote branch
869
        self.assertIsInstance(branch, remote.RemoteBranch)
870
        # its format should have the settings from the response
871
        format = branch._format
872
        self.assertEqual(network_name, format.network_name())
873
5609.21.2 by Andrew Bennetts
Add test.
874
    def test_already_open_repo_and_reused_medium(self):
875
        """Bug 726584: create_branch(..., repository=repo) should work
876
        regardless of what the smart medium's base URL is.
877
        """
878
        self.transport_server = test_server.SmartTCPServer_for_testing
879
        transport = self.get_transport('.')
880
        repo = self.make_repository('quack')
881
        # Client's medium rooted a transport root (not at the bzrdir)
882
        client = FakeClient(transport.base)
883
        transport = transport.clone('quack')
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
884
        reference_bzrdir_format = controldir.format_registry.get('default')()
5609.21.2 by Andrew Bennetts
Add test.
885
        reference_format = reference_bzrdir_format.get_branch_format()
886
        network_name = reference_format.network_name()
887
        reference_repo_fmt = reference_bzrdir_format.repository_format
888
        reference_repo_name = reference_repo_fmt.network_name()
889
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
890
            b'BzrDir.create_branch', (b'extra/quack/', network_name),
891
            b'success', (b'ok', network_name, b'', b'no', b'no', b'yes',
5609.21.2 by Andrew Bennetts
Add test.
892
            reference_repo_name))
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
893
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
5609.21.2 by Andrew Bennetts
Add test.
894
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
895
        branch = a_controldir.create_branch(repository=repo)
5609.21.2 by Andrew Bennetts
Add test.
896
        # We should have got a remote branch
897
        self.assertIsInstance(branch, remote.RemoteBranch)
898
        # its format should have the settings from the response
899
        format = branch._format
900
        self.assertEqual(network_name, format.network_name())
901
4032.3.2 by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.
902
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
903
class TestBzrDirCreateRepository(TestRemote):
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
904
905
    def test_backwards_compat(self):
906
        self.setup_smart_server_with_call_log()
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
907
        bzrdir = self.make_controldir('.')
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
908
        self.reset_smart_call_log()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
909
        self.disable_verb(b'BzrDir.create_repository')
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
910
        repo = bzrdir.create_repository()
911
        create_repo_call_count = len([call for call in self.hpss_calls if
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
912
            call.call.method == b'BzrDir.create_repository'])
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
913
        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.
914
915
    def test_current_server(self):
916
        transport = self.get_transport('.')
917
        transport = transport.clone('quack')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
918
        self.make_controldir('quack')
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
919
        client = FakeClient(transport.base)
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
920
        reference_bzrdir_format = controldir.format_registry.get('default')()
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
921
        reference_format = reference_bzrdir_format.repository_format
922
        network_name = reference_format.network_name()
923
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
924
            b'BzrDir.create_repository', (b'quack/',
925
                b'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
926
                b'False'),
927
            b'success', (b'ok', b'yes', b'yes', b'yes', network_name))
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
928
        a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
929
            _client=client)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
930
        repo = a_controldir.create_repository()
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
931
        # We should have got a remote repository
932
        self.assertIsInstance(repo, remote.RemoteRepository)
933
        # its format should have the settings from the response
934
        format = repo._format
4599.4.20 by Robert Collins
Prep test_remote for 2a as default.
935
        self.assertTrue(format.rich_root_data)
936
        self.assertTrue(format.supports_tree_reference)
937
        self.assertTrue(format.supports_external_lookups)
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
938
        self.assertEqual(network_name, format.network_name())
939
940
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
941
class TestBzrDirOpenRepository(TestRemote):
942
943
    def test_backwards_compat_1_2_3(self):
944
        # fallback all the way to the first version.
945
        reference_format = self.get_repo_format()
946
        network_name = reference_format.network_name()
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
947
        server_url = 'bzr://example.com/'
948
        self.permit_url(server_url)
949
        client = FakeClient(server_url)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
950
        client.add_unknown_method_response(b'BzrDir.find_repositoryV3')
951
        client.add_unknown_method_response(b'BzrDir.find_repositoryV2')
952
        client.add_success_response(b'ok', b'', b'no', b'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.
953
        # A real repository instance will be created to determine the network
954
        # name.
955
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
956
            b"Bazaar-NG meta directory, format 1\n", b'ok')
957
        client.add_success_response(b'stat', b'0', b'65535')
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
958
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
959
            reference_format.get_format_string(), b'ok')
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
960
        # PackRepository wants to do a stat
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
961
        client.add_success_response(b'stat', b'0', b'65535')
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
962
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
963
            _client=client)
5712.3.17 by Jelmer Vernooij
more fixes.
964
        bzrdir = RemoteBzrDir(remote_transport, RemoteBzrDirFormat(),
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
965
            _client=client)
966
        repo = bzrdir.open_repository()
967
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
968
            [('call', b'BzrDir.find_repositoryV3', (b'quack/',)),
969
             ('call', b'BzrDir.find_repositoryV2', (b'quack/',)),
970
             ('call', b'BzrDir.find_repository', (b'quack/',)),
971
             ('call_expecting_body', b'get', (b'/quack/.bzr/branch-format',)),
972
             ('call', b'stat', (b'/quack/.bzr',)),
973
             ('call_expecting_body', b'get', (b'/quack/.bzr/repository/format',)),
974
             ('call', b'stat', (b'/quack/.bzr/repository',)),
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
975
             ],
976
            client._calls)
977
        self.assertEqual(network_name, repo._format.network_name())
978
979
    def test_backwards_compat_2(self):
980
        # fallback to find_repositoryV2
981
        reference_format = self.get_repo_format()
982
        network_name = reference_format.network_name()
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
983
        server_url = 'bzr://example.com/'
984
        self.permit_url(server_url)
985
        client = FakeClient(server_url)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
986
        client.add_unknown_method_response(b'BzrDir.find_repositoryV3')
987
        client.add_success_response(b'ok', b'', b'no', b'no', b'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.
988
        # A real repository instance will be created to determine the network
989
        # name.
990
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
991
            b"Bazaar-NG meta directory, format 1\n", b'ok')
992
        client.add_success_response(b'stat', b'0', b'65535')
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
993
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
994
            reference_format.get_format_string(), b'ok')
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
995
        # PackRepository wants to do a stat
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
996
        client.add_success_response(b'stat', b'0', b'65535')
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
997
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
998
            _client=client)
5712.3.17 by Jelmer Vernooij
more fixes.
999
        bzrdir = RemoteBzrDir(remote_transport, RemoteBzrDirFormat(),
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
1000
            _client=client)
1001
        repo = bzrdir.open_repository()
1002
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1003
            [('call', b'BzrDir.find_repositoryV3', (b'quack/',)),
1004
             ('call', b'BzrDir.find_repositoryV2', (b'quack/',)),
1005
             ('call_expecting_body', b'get', (b'/quack/.bzr/branch-format',)),
1006
             ('call', b'stat', (b'/quack/.bzr',)),
1007
             ('call_expecting_body', b'get', (b'/quack/.bzr/repository/format',)),
1008
             ('call', b'stat', (b'/quack/.bzr/repository',)),
4053.1.1 by Robert Collins
New version of the BzrDir.find_repository verb supporting _network_name to support removing more _ensure_real calls.
1009
             ],
1010
            client._calls)
1011
        self.assertEqual(network_name, repo._format.network_name())
1012
1013
    def test_current_server(self):
1014
        reference_format = self.get_repo_format()
1015
        network_name = reference_format.network_name()
1016
        transport = MemoryTransport()
1017
        transport.mkdir('quack')
1018
        transport = transport.clone('quack')
1019
        client = FakeClient(transport.base)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1020
        client.add_success_response(b'ok', b'', b'no', b'no', b'no', network_name)
5712.3.17 by Jelmer Vernooij
more fixes.
1021
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
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.
1022
            _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.
1023
        repo = bzrdir.open_repository()
1024
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1025
            [('call', b'BzrDir.find_repositoryV3', (b'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.
1026
            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.
1027
        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.
1028
1029
4384.1.1 by Andrew Bennetts
Translate ErrorFromSmartServer in RemoteBzrDirFormat.
1030
class TestBzrDirFormatInitializeEx(TestRemote):
1031
1032
    def test_success(self):
1033
        """Simple test for typical successful call."""
5712.3.17 by Jelmer Vernooij
more fixes.
1034
        fmt = RemoteBzrDirFormat()
4384.1.1 by Andrew Bennetts
Translate ErrorFromSmartServer in RemoteBzrDirFormat.
1035
        default_format_name = BzrDirFormat.get_default_format().network_name()
1036
        transport = self.get_transport()
1037
        client = FakeClient(transport.base)
1038
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1039
            b'BzrDirFormat.initialize_ex_1.16',
1040
                (default_format_name, b'path', b'False', b'False', b'False', b'',
1041
                 b'', b'', b'', b'False'),
1042
            b'success',
1043
                (b'.', b'no', b'no', b'yes', b'repo fmt', b'repo bzrdir fmt',
1044
                 b'bzrdir fmt', b'False', b'', b'', b'repo lock token'))
4384.1.1 by Andrew Bennetts
Translate ErrorFromSmartServer in RemoteBzrDirFormat.
1045
        # XXX: It would be better to call fmt.initialize_on_transport_ex, but
1046
        # it's currently hard to test that without supplying a real remote
1047
        # transport connected to a real server.
1048
        result = fmt._initialize_on_transport_ex_rpc(client, 'path',
1049
            transport, False, False, False, None, None, None, None, False)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1050
        self.assertFinished(client)
4384.1.1 by Andrew Bennetts
Translate ErrorFromSmartServer in RemoteBzrDirFormat.
1051
1052
    def test_error(self):
1053
        """Error responses are translated, e.g. 'PermissionDenied' raises the
1054
        corresponding error from the client.
1055
        """
5712.3.17 by Jelmer Vernooij
more fixes.
1056
        fmt = RemoteBzrDirFormat()
4384.1.1 by Andrew Bennetts
Translate ErrorFromSmartServer in RemoteBzrDirFormat.
1057
        default_format_name = BzrDirFormat.get_default_format().network_name()
1058
        transport = self.get_transport()
1059
        client = FakeClient(transport.base)
1060
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1061
            b'BzrDirFormat.initialize_ex_1.16',
1062
                (default_format_name, b'path', b'False', b'False', b'False', b'',
1063
                 b'', b'', b'', b'False'),
1064
            b'error',
1065
                (b'PermissionDenied', b'path', b'extra info'))
4384.1.1 by Andrew Bennetts
Translate ErrorFromSmartServer in RemoteBzrDirFormat.
1066
        # XXX: It would be better to call fmt.initialize_on_transport_ex, but
1067
        # it's currently hard to test that without supplying a real remote
1068
        # transport connected to a real server.
1069
        err = self.assertRaises(errors.PermissionDenied,
1070
            fmt._initialize_on_transport_ex_rpc, client, 'path', transport,
1071
            False, False, False, None, None, None, None, False)
1072
        self.assertEqual('path', err.path)
1073
        self.assertEqual(': extra info', err.extra)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1074
        self.assertFinished(client)
4384.1.1 by Andrew Bennetts
Translate ErrorFromSmartServer in RemoteBzrDirFormat.
1075
4384.1.3 by Andrew Bennetts
Add test suggested by John.
1076
    def test_error_from_real_server(self):
1077
        """Integration test for error translation."""
1078
        transport = self.make_smart_server('foo')
1079
        transport = transport.clone('no-such-path')
5712.3.17 by Jelmer Vernooij
more fixes.
1080
        fmt = RemoteBzrDirFormat()
4384.1.3 by Andrew Bennetts
Add test suggested by John.
1081
        err = self.assertRaises(errors.NoSuchFile,
1082
            fmt.initialize_on_transport_ex, transport, create_prefix=False)
1083
4384.1.1 by Andrew Bennetts
Translate ErrorFromSmartServer in RemoteBzrDirFormat.
1084
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
1085
class OldSmartClient(object):
1086
    """A fake smart client for test_old_version that just returns a version one
1087
    response to the 'hello' (query version) command.
1088
    """
1089
1090
    def get_request(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1091
        input_file = BytesIO(b'ok\x011\n')
1092
        output_file = BytesIO()
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
1093
        client_medium = medium.SmartSimplePipesClientMedium(
1094
            input_file, output_file)
1095
        return medium.SmartClientStreamMediumRequest(client_medium)
1096
3241.1.1 by Andrew Bennetts
Shift protocol version querying from RemoteBzrDirFormat into SmartClientMedium.
1097
    def protocol_version(self):
1098
        return 1
1099
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
1100
1101
class OldServerTransport(object):
1102
    """A fake transport for test_old_server that reports it's smart server
1103
    protocol version as version one.
1104
    """
1105
1106
    def __init__(self):
1107
        self.base = 'fake:'
1108
1109
    def get_smart_client(self):
1110
        return OldSmartClient()
1111
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1112
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
1113
class RemoteBzrDirTestCase(TestRemote):
1114
1115
    def make_remote_bzrdir(self, transport, client):
1116
        """Make a RemotebzrDir using 'client' as the _client."""
5712.3.17 by Jelmer Vernooij
more fixes.
1117
        return RemoteBzrDir(transport, RemoteBzrDirFormat(),
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
1118
            _client=client)
1119
1120
1121
class RemoteBranchTestCase(RemoteBzrDirTestCase):
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1122
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1123
    def lock_remote_branch(self, branch):
1124
        """Trick a RemoteBranch into thinking it is locked."""
1125
        branch._lock_mode = 'w'
1126
        branch._lock_count = 2
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1127
        branch._lock_token = b'branch token'
1128
        branch._repo_lock_token = b'repo token'
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1129
        branch.repository._lock_mode = 'w'
1130
        branch.repository._lock_count = 2
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1131
        branch.repository._lock_token = b'repo token'
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1132
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1133
    def make_remote_branch(self, transport, client):
1134
        """Make a RemoteBranch using 'client' as its _SmartClient.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1135
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1136
        A RemoteBzrDir and RemoteRepository will also be created to fill out
1137
        the RemoteBranch, albeit with stub values for some of their attributes.
1138
        """
1139
        # we do not want bzrdir to make any remote calls, so use False as its
1140
        # _client.  If it tries to make a remote call, this will fail
1141
        # immediately.
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
1142
        bzrdir = self.make_remote_bzrdir(transport, False)
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1143
        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.
1144
        branch_format = self.get_branch_format()
1145
        format = RemoteBranchFormat(network_name=branch_format.network_name())
1146
        return RemoteBranch(bzrdir, repo, _client=client, format=format)
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1147
1148
6280.4.3 by Jelmer Vernooij
add Branch.break_lock.
1149
class TestBranchBreakLock(RemoteBranchTestCase):
1150
1151
    def test_break_lock(self):
1152
        transport_path = 'quack'
1153
        transport = MemoryTransport()
1154
        client = FakeClient(transport.base)
1155
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1156
            b'Branch.get_stacked_on_url', (b'quack/',),
1157
            b'error', (b'NotStacked',))
6280.4.3 by Jelmer Vernooij
add Branch.break_lock.
1158
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1159
            b'Branch.break_lock', (b'quack/',),
1160
            b'success', (b'ok',))
6280.4.3 by Jelmer Vernooij
add Branch.break_lock.
1161
        transport.mkdir('quack')
1162
        transport = transport.clone('quack')
1163
        branch = self.make_remote_branch(transport, client)
1164
        branch.break_lock()
1165
        self.assertFinished(client)
1166
1167
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
1168
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
1169
1170
    def test_get_physical_lock_status_yes(self):
1171
        transport = MemoryTransport()
1172
        client = FakeClient(transport.base)
1173
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1174
            b'Branch.get_stacked_on_url', (b'quack/',),
1175
            b'error', (b'NotStacked',))
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
1176
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1177
            b'Branch.get_physical_lock_status', (b'quack/',),
1178
            b'success', (b'yes',))
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
1179
        transport.mkdir('quack')
1180
        transport = transport.clone('quack')
1181
        branch = self.make_remote_branch(transport, client)
1182
        result = branch.get_physical_lock_status()
1183
        self.assertFinished(client)
1184
        self.assertEqual(True, result)
1185
1186
    def test_get_physical_lock_status_no(self):
1187
        transport = MemoryTransport()
1188
        client = FakeClient(transport.base)
1189
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1190
            b'Branch.get_stacked_on_url', (b'quack/',),
1191
            b'error', (b'NotStacked',))
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
1192
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1193
            b'Branch.get_physical_lock_status', (b'quack/',),
1194
            b'success', (b'no',))
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
1195
        transport.mkdir('quack')
1196
        transport = transport.clone('quack')
1197
        branch = self.make_remote_branch(transport, client)
1198
        result = branch.get_physical_lock_status()
1199
        self.assertFinished(client)
1200
        self.assertEqual(False, result)
1201
1202
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1203
class TestBranchGetParent(RemoteBranchTestCase):
1204
1205
    def test_no_parent(self):
1206
        # in an empty branch we decode the response properly
1207
        transport = MemoryTransport()
1208
        client = FakeClient(transport.base)
1209
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1210
            b'Branch.get_stacked_on_url', (b'quack/',),
1211
            b'error', (b'NotStacked',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1212
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1213
            b'Branch.get_parent', (b'quack/',),
1214
            b'success', (b'',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1215
        transport.mkdir('quack')
1216
        transport = transport.clone('quack')
1217
        branch = self.make_remote_branch(transport, client)
1218
        result = branch.get_parent()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1219
        self.assertFinished(client)
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1220
        self.assertEqual(None, result)
1221
1222
    def test_parent_relative(self):
1223
        transport = MemoryTransport()
1224
        client = FakeClient(transport.base)
1225
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1226
            b'Branch.get_stacked_on_url', (b'kwaak/',),
1227
            b'error', (b'NotStacked',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1228
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1229
            b'Branch.get_parent', (b'kwaak/',),
1230
            b'success', (b'../foo/',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1231
        transport.mkdir('kwaak')
1232
        transport = transport.clone('kwaak')
1233
        branch = self.make_remote_branch(transport, client)
1234
        result = branch.get_parent()
1235
        self.assertEqual(transport.clone('../foo').base, result)
1236
1237
    def test_parent_absolute(self):
1238
        transport = MemoryTransport()
1239
        client = FakeClient(transport.base)
1240
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1241
            b'Branch.get_stacked_on_url', (b'kwaak/',),
1242
            b'error', (b'NotStacked',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1243
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1244
            b'Branch.get_parent', (b'kwaak/',),
1245
            b'success', (b'http://foo/',))
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1246
        transport.mkdir('kwaak')
1247
        transport = transport.clone('kwaak')
1248
        branch = self.make_remote_branch(transport, client)
1249
        result = branch.get_parent()
1250
        self.assertEqual('http://foo/', result)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1251
        self.assertFinished(client)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1252
1253
1254
class TestBranchSetParentLocation(RemoteBranchTestCase):
1255
1256
    def test_no_parent(self):
1257
        # We call the verb when setting parent to None
1258
        transport = MemoryTransport()
1259
        client = FakeClient(transport.base)
1260
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1261
            b'Branch.get_stacked_on_url', (b'quack/',),
1262
            b'error', (b'NotStacked',))
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1263
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1264
            b'Branch.set_parent_location', (b'quack/', b'b', b'r', b''),
1265
            b'success', ())
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1266
        transport.mkdir('quack')
1267
        transport = transport.clone('quack')
1268
        branch = self.make_remote_branch(transport, client)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1269
        branch._lock_token = b'b'
1270
        branch._repo_lock_token = b'r'
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1271
        branch._set_parent_location(None)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1272
        self.assertFinished(client)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1273
1274
    def test_parent(self):
1275
        transport = MemoryTransport()
1276
        client = FakeClient(transport.base)
1277
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1278
            b'Branch.get_stacked_on_url', (b'kwaak/',),
1279
            b'error', (b'NotStacked',))
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1280
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1281
            b'Branch.set_parent_location', (b'kwaak/', b'b', b'r', b'foo'),
1282
            b'success', ())
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1283
        transport.mkdir('kwaak')
1284
        transport = transport.clone('kwaak')
1285
        branch = self.make_remote_branch(transport, client)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1286
        branch._lock_token = b'b'
1287
        branch._repo_lock_token = b'r'
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1288
        branch._set_parent_location('foo')
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1289
        self.assertFinished(client)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1290
1291
    def test_backwards_compat(self):
1292
        self.setup_smart_server_with_call_log()
1293
        branch = self.make_branch('.')
1294
        self.reset_smart_call_log()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1295
        verb = b'Branch.set_parent_location'
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1296
        self.disable_verb(verb)
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
1297
        branch.set_parent('http://foo/')
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
1298
        self.assertLength(14, self.hpss_calls)
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1299
1300
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.
1301
class TestBranchGetTagsBytes(RemoteBranchTestCase):
1302
1303
    def test_backwards_compat(self):
1304
        self.setup_smart_server_with_call_log()
1305
        branch = self.make_branch('.')
1306
        self.reset_smart_call_log()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1307
        verb = b'Branch.get_tags_bytes'
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.
1308
        self.disable_verb(verb)
1309
        branch.tags.get_tag_dict()
1310
        call_count = len([call for call in self.hpss_calls if
1311
            call.call.method == verb])
1312
        self.assertEqual(1, call_count)
1313
1314
    def test_trivial(self):
1315
        transport = MemoryTransport()
1316
        client = FakeClient(transport.base)
1317
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1318
            b'Branch.get_stacked_on_url', (b'quack/',),
1319
            b'error', (b'NotStacked',))
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.
1320
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1321
            b'Branch.get_tags_bytes', (b'quack/',),
1322
            b'success', (b'',))
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.
1323
        transport.mkdir('quack')
1324
        transport = transport.clone('quack')
1325
        branch = self.make_remote_branch(transport, client)
1326
        result = branch.tags.get_tag_dict()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1327
        self.assertFinished(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.
1328
        self.assertEqual({}, result)
1329
1330
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1331
class TestBranchSetTagsBytes(RemoteBranchTestCase):
1332
1333
    def test_trivial(self):
1334
        transport = MemoryTransport()
1335
        client = FakeClient(transport.base)
1336
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1337
            b'Branch.get_stacked_on_url', (b'quack/',),
1338
            b'error', (b'NotStacked',))
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1339
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1340
            b'Branch.set_tags_bytes', (b'quack/', b'branch token', b'repo token'),
1341
            b'success', ('',))
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1342
        transport.mkdir('quack')
1343
        transport = transport.clone('quack')
1344
        branch = self.make_remote_branch(transport, client)
1345
        self.lock_remote_branch(branch)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1346
        branch._set_tags_bytes(b'tags bytes')
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1347
        self.assertFinished(client)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1348
        self.assertEqual(b'tags bytes', client._calls[-1][-1])
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1349
1350
    def test_backwards_compatible(self):
1351
        transport = MemoryTransport()
1352
        client = FakeClient(transport.base)
1353
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1354
            b'Branch.get_stacked_on_url', (b'quack/',),
1355
            b'error', (b'NotStacked',))
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1356
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1357
            b'Branch.set_tags_bytes', (b'quack/', b'branch token', b'repo token'),
1358
            b'unknown', (b'Branch.set_tags_bytes',))
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1359
        transport.mkdir('quack')
1360
        transport = transport.clone('quack')
1361
        branch = self.make_remote_branch(transport, client)
1362
        self.lock_remote_branch(branch)
1363
        class StubRealBranch(object):
1364
            def __init__(self):
1365
                self.calls = []
1366
            def _set_tags_bytes(self, bytes):
1367
                self.calls.append(('set_tags_bytes', bytes))
1368
        real_branch = StubRealBranch()
1369
        branch._real_branch = real_branch
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1370
        branch._set_tags_bytes(b'tags bytes')
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1371
        # Call a second time, to exercise the 'remote version already inferred'
1372
        # code path.
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1373
        branch._set_tags_bytes(b'tags bytes')
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1374
        self.assertFinished(client)
1375
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1376
            [('set_tags_bytes', b'tags bytes')] * 2, real_branch.calls)
4634.36.1 by Andrew Bennetts
Fix trivial bug in RemoteBranch._set_tags_bytes, and add some unit tests for it.
1377
1378
5672.1.5 by Andrew Bennetts
Add some tests for RemoteBranch.heads_to_fetch, and add release-note.
1379
class TestBranchHeadsToFetch(RemoteBranchTestCase):
1380
1381
    def test_uses_last_revision_info_and_tags_by_default(self):
1382
        transport = MemoryTransport()
1383
        client = FakeClient(transport.base)
1384
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1385
            b'Branch.get_stacked_on_url', (b'quack/',),
1386
            b'error', (b'NotStacked',))
1387
        client.add_expected_call(
1388
            b'Branch.last_revision_info', (b'quack/',),
1389
            b'success', (b'ok', b'1', b'rev-tip'))
1390
        client.add_expected_call(
1391
            b'Branch.get_config_file', (b'quack/',),
6973.14.12 by Jelmer Vernooij
Merge trunk.
1392
            b'success', (b'ok',), b'')
6015.15.4 by John Arbash Meinel
Catch a couple more cases that test tag fetching.
1393
        transport.mkdir('quack')
1394
        transport = transport.clone('quack')
1395
        branch = self.make_remote_branch(transport, client)
1396
        result = branch.heads_to_fetch()
1397
        self.assertFinished(client)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1398
        self.assertEqual(({b'rev-tip'}, set()), result)
6015.15.4 by John Arbash Meinel
Catch a couple more cases that test tag fetching.
1399
1400
    def test_uses_last_revision_info_and_tags_when_set(self):
1401
        transport = MemoryTransport()
1402
        client = FakeClient(transport.base)
1403
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1404
            b'Branch.get_stacked_on_url', (b'quack/',),
1405
            b'error', (b'NotStacked',))
1406
        client.add_expected_call(
1407
            b'Branch.last_revision_info', (b'quack/',),
1408
            b'success', (b'ok', b'1', b'rev-tip'))
1409
        client.add_expected_call(
1410
            b'Branch.get_config_file', (b'quack/',),
1411
            b'success', (b'ok',), b'branch.fetch_tags = True')
5672.1.5 by Andrew Bennetts
Add some tests for RemoteBranch.heads_to_fetch, and add release-note.
1412
        # XXX: this will break if the default format's serialization of tags
1413
        # changes, or if the RPC for fetching tags changes from get_tags_bytes.
1414
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1415
            b'Branch.get_tags_bytes', (b'quack/',),
1416
            b'success', (b'd5:tag-17:rev-foo5:tag-27:rev-bare',))
5672.1.5 by Andrew Bennetts
Add some tests for RemoteBranch.heads_to_fetch, and add release-note.
1417
        transport.mkdir('quack')
1418
        transport = transport.clone('quack')
1419
        branch = self.make_remote_branch(transport, client)
1420
        result = branch.heads_to_fetch()
1421
        self.assertFinished(client)
1422
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1423
            ({b'rev-tip'}, {b'rev-foo', b'rev-bar'}), result)
5672.1.5 by Andrew Bennetts
Add some tests for RemoteBranch.heads_to_fetch, and add release-note.
1424
1425
    def test_uses_rpc_for_formats_with_non_default_heads_to_fetch(self):
1426
        transport = MemoryTransport()
1427
        client = FakeClient(transport.base)
1428
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1429
            b'Branch.get_stacked_on_url', (b'quack/',),
1430
            b'error', (b'NotStacked',))
5672.1.5 by Andrew Bennetts
Add some tests for RemoteBranch.heads_to_fetch, and add release-note.
1431
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1432
            b'Branch.heads_to_fetch', (b'quack/',),
1433
            b'success', ([b'tip'], [b'tagged-1', b'tagged-2']))
5672.1.5 by Andrew Bennetts
Add some tests for RemoteBranch.heads_to_fetch, and add release-note.
1434
        transport.mkdir('quack')
1435
        transport = transport.clone('quack')
1436
        branch = self.make_remote_branch(transport, client)
5672.1.7 by Andrew Bennetts
Use a more explicit method name.
1437
        branch._format._use_default_local_heads_to_fetch = lambda: False
5672.1.5 by Andrew Bennetts
Add some tests for RemoteBranch.heads_to_fetch, and add release-note.
1438
        result = branch.heads_to_fetch()
1439
        self.assertFinished(client)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1440
        self.assertEqual(({b'tip'}, {b'tagged-1', b'tagged-2'}), result)
5672.1.6 by Andrew Bennetts
Add another test.
1441
6015.15.1 by John Arbash Meinel
Start working on a config entry for testing whether we should fetch tags or not.
1442
    def make_branch_with_tags(self):
5672.1.6 by Andrew Bennetts
Add another test.
1443
        self.setup_smart_server_with_call_log()
1444
        # Make a branch with a single revision.
1445
        builder = self.make_branch_builder('foo')
1446
        builder.start_series()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
1447
        builder.build_snapshot(None, [
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1448
            ('add', ('', b'root-id', 'directory', ''))],
1449
            revision_id=b'tip')
5672.1.6 by Andrew Bennetts
Add another test.
1450
        builder.finish_series()
1451
        branch = builder.get_branch()
1452
        # Add two tags to that branch
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1453
        branch.tags.set_tag('tag-1', b'rev-1')
1454
        branch.tags.set_tag('tag-2', b'rev-2')
6015.15.1 by John Arbash Meinel
Start working on a config entry for testing whether we should fetch tags or not.
1455
        return branch
1456
1457
    def test_backwards_compatible(self):
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
1458
        br = self.make_branch_with_tags()
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
1459
        br.get_config_stack().set('branch.fetch_tags', True)
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
1460
        self.addCleanup(br.lock_read().unlock)
5672.1.6 by Andrew Bennetts
Add another test.
1461
        # Disable the heads_to_fetch verb
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1462
        verb = b'Branch.heads_to_fetch'
5672.1.6 by Andrew Bennetts
Add another test.
1463
        self.disable_verb(verb)
1464
        self.reset_smart_call_log()
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
1465
        result = br.heads_to_fetch()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1466
        self.assertEqual(({b'tip'}, {b'rev-1', b'rev-2'}), result)
5672.1.6 by Andrew Bennetts
Add another test.
1467
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1468
            [b'Branch.last_revision_info', b'Branch.get_tags_bytes'],
6015.15.1 by John Arbash Meinel
Start working on a config entry for testing whether we should fetch tags or not.
1469
            [call.call.method for call in self.hpss_calls])
1470
1471
    def test_backwards_compatible_no_tags(self):
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
1472
        br = self.make_branch_with_tags()
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
1473
        br.get_config_stack().set('branch.fetch_tags', False)
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
1474
        self.addCleanup(br.lock_read().unlock)
6015.15.1 by John Arbash Meinel
Start working on a config entry for testing whether we should fetch tags or not.
1475
        # Disable the heads_to_fetch verb
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1476
        verb = b'Branch.heads_to_fetch'
6015.15.1 by John Arbash Meinel
Start working on a config entry for testing whether we should fetch tags or not.
1477
        self.disable_verb(verb)
1478
        self.reset_smart_call_log()
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
1479
        result = br.heads_to_fetch()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1480
        self.assertEqual(({b'tip'}, set()), result)
6015.15.1 by John Arbash Meinel
Start working on a config entry for testing whether we should fetch tags or not.
1481
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1482
            [b'Branch.last_revision_info'],
5672.1.6 by Andrew Bennetts
Add another test.
1483
            [call.call.method for call in self.hpss_calls])
5672.1.5 by Andrew Bennetts
Add some tests for RemoteBranch.heads_to_fetch, and add release-note.
1484
1485
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1486
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1487
1488
    def test_empty_branch(self):
1489
        # in an empty branch we decode the response properly
1490
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1491
        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
1492
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1493
            b'Branch.get_stacked_on_url', (b'quack/',),
1494
            b'error', (b'NotStacked',))
3691.2.8 by Martin Pool
Update some test_remote tests for Branch.get_stacked_on_url and with clearer assertions
1495
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1496
            b'Branch.last_revision_info', (b'quack/',),
1497
            b'success', (b'ok', b'0', b'null:'))
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1498
        transport.mkdir('quack')
1499
        transport = transport.clone('quack')
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1500
        branch = self.make_remote_branch(transport, client)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1501
        result = branch.last_revision_info()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1502
        self.assertFinished(client)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1503
        self.assertEqual((0, NULL_REVISION), result)
1504
1505
    def test_non_empty_branch(self):
1506
        # 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.
1507
        revid = u'\xc8'.encode('utf8')
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1508
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1509
        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
1510
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1511
            b'Branch.get_stacked_on_url', (b'kwaak/',),
1512
            b'error', (b'NotStacked',))
3691.2.8 by Martin Pool
Update some test_remote tests for Branch.get_stacked_on_url and with clearer assertions
1513
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1514
            b'Branch.last_revision_info', (b'kwaak/',),
1515
            b'success', (b'ok', b'2', revid))
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1516
        transport.mkdir('kwaak')
1517
        transport = transport.clone('kwaak')
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1518
        branch = self.make_remote_branch(transport, client)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1519
        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.
1520
        self.assertEqual((2, revid), result)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1521
1522
4053.1.2 by Robert Collins
Actually make this branch work.
1523
class TestBranch_get_stacked_on_url(TestRemote):
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1524
    """Test Branch._get_stacked_on_url rpc"""
1525
3691.2.10 by Martin Pool
Update more test_remote tests
1526
    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.
1527
        # test that asking for a stacked on url the server can't access works.
1528
        # This isn't perfect, but then as we're in the same process there
1529
        # really isn't anything we can do to be 100% sure that the server
1530
        # doesn't just open in - this test probably needs to be rewritten using
1531
        # a spawn()ed server.
1532
        stacked_branch = self.make_branch('stacked', format='1.9')
1533
        memory_branch = self.make_branch('base', format='1.9')
1534
        vfs_url = self.get_vfs_only_url('base')
1535
        stacked_branch.set_stacked_on_url(vfs_url)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1536
        transport = stacked_branch.controldir.root_transport
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1537
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1538
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1539
            b'Branch.get_stacked_on_url', (b'stacked/',),
7045.2.18 by Jelmer Vernooij
Some fixes.
1540
            b'success', (b'ok', vfs_url.encode('utf-8')))
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.
1541
        # XXX: Multiple calls are bad, this second call documents what is
1542
        # today.
1543
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1544
            b'Branch.get_stacked_on_url', (b'stacked/',),
7045.2.18 by Jelmer Vernooij
Some fixes.
1545
            b'success', (b'ok', vfs_url.encode('utf-8')))
5712.3.17 by Jelmer Vernooij
more fixes.
1546
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
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.
1547
            _client=client)
4118.1.5 by Andrew Bennetts
Fix test_remote tests.
1548
        repo_fmt = remote.RemoteRepositoryFormat()
1549
        repo_fmt._custom_format = stacked_branch.repository._format
1550
        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.
1551
            _client=client)
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1552
        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.
1553
        self.assertEqual(vfs_url, result)
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1554
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
1555
    def test_backwards_compatible(self):
1556
        # like with bzr1.6 with no Branch.get_stacked_on_url rpc
1557
        base_branch = self.make_branch('base', format='1.6')
1558
        stacked_branch = self.make_branch('stacked', format='1.6')
1559
        stacked_branch.set_stacked_on_url('../base')
1560
        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.
1561
        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
1562
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1563
            b'BzrDir.open_branchV3', (b'stacked/',),
1564
            b'success', (b'branch', branch_network_name))
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
1565
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1566
            b'BzrDir.find_repositoryV3', (b'stacked/',),
1567
            b'success', (b'ok', b'', b'no', b'no', b'yes',
4053.1.2 by Robert Collins
Actually make this branch work.
1568
                stacked_branch.repository._format.network_name()))
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
1569
        # called twice, once from constructor and then again by us
1570
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1571
            b'Branch.get_stacked_on_url', (b'stacked/',),
1572
            b'unknown', (b'Branch.get_stacked_on_url',))
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
1573
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1574
            b'Branch.get_stacked_on_url', (b'stacked/',),
1575
            b'unknown', (b'Branch.get_stacked_on_url',))
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
1576
        # this will also do vfs access, but that goes direct to the transport
1577
        # 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.
1578
        bzrdir = RemoteBzrDir(self.get_transport('stacked'),
5712.3.17 by Jelmer Vernooij
more fixes.
1579
            RemoteBzrDirFormat(), _client=client)
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
1580
        branch = bzrdir.open_branch()
1581
        result = branch.get_stacked_on_url()
1582
        self.assertEqual('../base', result)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1583
        self.assertFinished(client)
3691.2.12 by Martin Pool
Add test for coping without Branch.get_stacked_on_url
1584
        # it's in the fallback list both for the RemoteRepository and its vfs
1585
        # repository
1586
        self.assertEqual(1, len(branch.repository._fallback_repositories))
1587
        self.assertEqual(1,
1588
            len(branch.repository._real_repository._fallback_repositories))
1589
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1590
    def test_get_stacked_on_real_branch(self):
5158.4.3 by Andrew Bennetts
Fix test_remote tests that accidentally assumed it was ok to stack mismatched formats.
1591
        base_branch = self.make_branch('base')
1592
        stacked_branch = self.make_branch('stacked')
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1593
        stacked_branch.set_stacked_on_url('../base')
4053.1.2 by Robert Collins
Actually make this branch work.
1594
        reference_format = self.get_repo_format()
1595
        network_name = reference_format.network_name()
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1596
        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.
1597
        branch_network_name = self.get_branch_format().network_name()
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1598
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1599
            b'BzrDir.open_branchV3', ('stacked/',),
1600
            b'success', ('branch', branch_network_name))
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1601
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1602
            b'BzrDir.find_repositoryV3', (b'stacked/',),
1603
            b'success', (b'ok', b'', b'yes', b'no', b'yes', network_name))
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1604
        # called twice, once from constructor and then again by us
1605
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1606
            b'Branch.get_stacked_on_url', (b'stacked/',),
1607
            b'success', (b'ok', b'../base'))
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1608
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1609
            b'Branch.get_stacked_on_url', (b'stacked/',),
1610
            b'success', (b'ok', b'../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.
1611
        bzrdir = RemoteBzrDir(self.get_transport('stacked'),
5712.3.17 by Jelmer Vernooij
more fixes.
1612
            RemoteBzrDirFormat(), _client=client)
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1613
        branch = bzrdir.open_branch()
1614
        result = branch.get_stacked_on_url()
1615
        self.assertEqual('../base', result)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1616
        self.assertFinished(client)
4226.1.2 by Robert Collins
Fix test_remote failing because of less _real_repository objects.
1617
        # it's in the fallback list both for the RemoteRepository.
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1618
        self.assertEqual(1, len(branch.repository._fallback_repositories))
4226.1.2 by Robert Collins
Fix test_remote failing because of less _real_repository objects.
1619
        # And we haven't had to construct a real repository.
1620
        self.assertEqual(None, branch.repository._real_repository)
3691.2.11 by Martin Pool
More tests around RemoteBranch stacking.
1621
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1622
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1623
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.
1624
1625
    def test_set_empty(self):
5718.7.12 by Jelmer Vernooij
Fix use of _set_last_revision.
1626
        # _set_last_revision_info('null:') is translated to calling
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1627
        # Branch.set_last_revision(path, '') on the wire.
3104.4.2 by Andrew Bennetts
All tests passing.
1628
        transport = MemoryTransport()
1629
        transport.mkdir('branch')
1630
        transport = transport.clone('branch')
1631
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1632
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1633
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1634
            b'Branch.get_stacked_on_url', (b'branch/',),
1635
            b'error', (b'NotStacked',))
1636
        client.add_expected_call(
1637
            b'Branch.lock_write', (b'branch/', b'', b''),
1638
            b'success', (b'ok', b'branch token', b'repo token'))
1639
        client.add_expected_call(
1640
            b'Branch.last_revision_info',
1641
            (b'branch/',),
1642
            b'success', (b'ok', b'0', b'null:'))
1643
        client.add_expected_call(
1644
            b'Branch.set_last_revision', (b'branch/', b'branch token', b'repo token', b'null:',),
1645
            b'success', (b'ok',))
1646
        client.add_expected_call(
1647
            b'Branch.unlock', (b'branch/', b'branch token', b'repo token'),
1648
            b'success', (b'ok',))
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1649
        branch = self.make_remote_branch(transport, client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1650
        branch.lock_write()
5718.7.12 by Jelmer Vernooij
Fix use of _set_last_revision.
1651
        result = branch._set_last_revision(NULL_REVISION)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1652
        branch.unlock()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1653
        self.assertEqual(None, result)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1654
        self.assertFinished(client)
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1655
1656
    def test_set_nonempty(self):
5718.7.4 by Jelmer Vernooij
Branch.set_revision_history.
1657
        # set_last_revision_info(N, rev-idN) is translated to calling
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1658
        # Branch.set_last_revision(path, rev-idN) on the wire.
3104.4.2 by Andrew Bennetts
All tests passing.
1659
        transport = MemoryTransport()
1660
        transport.mkdir('branch')
1661
        transport = transport.clone('branch')
1662
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1663
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1664
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1665
            b'Branch.get_stacked_on_url', (b'branch/',),
1666
            b'error', (b'NotStacked',))
1667
        client.add_expected_call(
1668
            b'Branch.lock_write', (b'branch/', b'', b''),
1669
            b'success', (b'ok', b'branch token', b'repo token'))
1670
        client.add_expected_call(
1671
            b'Branch.last_revision_info',
1672
            (b'branch/',),
1673
            b'success', (b'ok', b'0', b'null:'))
1674
        lines = [b'rev-id2']
1675
        encoded_body = bz2.compress(b'\n'.join(lines))
1676
        client.add_success_response_with_body(encoded_body, b'ok')
1677
        client.add_expected_call(
1678
            b'Branch.set_last_revision', (b'branch/', b'branch token', b'repo token', b'rev-id2',),
1679
            b'success', (b'ok',))
1680
        client.add_expected_call(
1681
            b'Branch.unlock', (b'branch/', b'branch token', b'repo token'),
1682
            b'success', (b'ok',))
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1683
        branch = self.make_remote_branch(transport, client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1684
        # Lock the branch, reset the record of remote calls.
1685
        branch.lock_write()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1686
        result = branch._set_last_revision(b'rev-id2')
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1687
        branch.unlock()
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1688
        self.assertEqual(None, result)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1689
        self.assertFinished(client)
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1690
1691
    def test_no_such_revision(self):
1692
        transport = MemoryTransport()
1693
        transport.mkdir('branch')
1694
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1695
        # A response of 'NoSuchRevision' is translated into an exception.
1696
        client = FakeClient(transport.base)
3691.2.9 by Martin Pool
Convert and update more test_remote tests
1697
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1698
            b'Branch.get_stacked_on_url', (b'branch/',),
1699
            b'error', (b'NotStacked',))
1700
        client.add_expected_call(
1701
            b'Branch.lock_write', (b'branch/', b'', b''),
1702
            b'success', (b'ok', b'branch token', b'repo token'))
1703
        client.add_expected_call(
1704
            b'Branch.last_revision_info',
1705
            (b'branch/',),
1706
            b'success', (b'ok', b'0', b'null:'))
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.
1707
        # get_graph calls to construct the revision history, for the set_rh
1708
        # hook
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1709
        lines = [b'rev-id']
1710
        encoded_body = bz2.compress(b'\n'.join(lines))
1711
        client.add_success_response_with_body(encoded_body, b'ok')
1712
        client.add_expected_call(
1713
            b'Branch.set_last_revision', (b'branch/', b'branch token', b'repo token', b'rev-id',),
1714
            b'error', (b'NoSuchRevision', b'rev-id'))
1715
        client.add_expected_call(
1716
            b'Branch.unlock', (b'branch/', b'branch token', b'repo token'),
1717
            b'success', (b'ok',))
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1718
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1719
        branch = self.make_remote_branch(transport, client)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1720
        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.
1721
        self.assertRaises(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1722
            errors.NoSuchRevision, branch._set_last_revision, b'rev-id')
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1723
        branch.unlock()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1724
        self.assertFinished(client)
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1725
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1726
    def test_tip_change_rejected(self):
1727
        """TipChangeRejected responses cause a TipChangeRejected exception to
1728
        be raised.
1729
        """
1730
        transport = MemoryTransport()
1731
        transport.mkdir('branch')
1732
        transport = transport.clone('branch')
1733
        client = FakeClient(transport.base)
1734
        rejection_msg_unicode = u'rejection message\N{INTERROBANG}'
1735
        rejection_msg_utf8 = rejection_msg_unicode.encode('utf8')
3691.2.10 by Martin Pool
Update more test_remote tests
1736
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1737
            b'Branch.get_stacked_on_url', (b'branch/',),
1738
            b'error', (b'NotStacked',))
1739
        client.add_expected_call(
1740
            b'Branch.lock_write', (b'branch/', b'', b''),
1741
            b'success', (b'ok', b'branch token', b'repo token'))
1742
        client.add_expected_call(
1743
            b'Branch.last_revision_info',
1744
            (b'branch/',),
1745
            b'success', (b'ok', b'0', b'null:'))
1746
        lines = [b'rev-id']
1747
        encoded_body = bz2.compress(b'\n'.join(lines))
1748
        client.add_success_response_with_body(encoded_body, b'ok')
1749
        client.add_expected_call(
1750
            b'Branch.set_last_revision', (b'branch/', b'branch token', b'repo token', b'rev-id',),
1751
            b'error', (b'TipChangeRejected', rejection_msg_utf8))
1752
        client.add_expected_call(
1753
            b'Branch.unlock', (b'branch/', b'branch token', b'repo token'),
1754
            b'success', (b'ok',))
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1755
        branch = self.make_remote_branch(transport, client)
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1756
        branch.lock_write()
1757
        # The 'TipChangeRejected' error response triggered by calling
5718.7.4 by Jelmer Vernooij
Branch.set_revision_history.
1758
        # set_last_revision_info causes a TipChangeRejected exception.
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1759
        err = self.assertRaises(
5718.7.4 by Jelmer Vernooij
Branch.set_revision_history.
1760
            errors.TipChangeRejected,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1761
            branch._set_last_revision, b'rev-id')
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1762
        # The UTF-8 message from the response has been decoded into a unicode
1763
        # object.
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1764
        self.assertIsInstance(err.msg, text_type)
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1765
        self.assertEqual(rejection_msg_unicode, err.msg)
3691.2.10 by Martin Pool
Update more test_remote tests
1766
        branch.unlock()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1767
        self.assertFinished(client)
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1768
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
1769
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1770
class TestBranchSetLastRevisionInfo(RemoteBranchTestCase):
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1771
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1772
    def test_set_last_revision_info(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1773
        # set_last_revision_info(num, b'rev-id') is translated to calling
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1774
        # 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'.
1775
        transport = MemoryTransport()
1776
        transport.mkdir('branch')
1777
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1778
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1779
        # get_stacked_on_url
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1780
        client.add_error_response(b'NotStacked')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1781
        # lock_write
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1782
        client.add_success_response(b'ok', b'branch token', b'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.
1783
        # query the current revision
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1784
        client.add_success_response(b'ok', b'0', b'null:')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1785
        # set_last_revision
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1786
        client.add_success_response(b'ok')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1787
        # unlock
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1788
        client.add_success_response(b'ok')
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1789
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1790
        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.
1791
        # Lock the branch, reset the record of remote calls.
1792
        branch.lock_write()
1793
        client._calls = []
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1794
        result = branch.set_last_revision_info(1234, b'a-revision-id')
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1795
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1796
            [('call', b'Branch.last_revision_info', (b'branch/',)),
1797
             ('call', b'Branch.set_last_revision_info',
1798
                (b'branch/', b'branch token', b'repo token',
1799
                 b'1234', b'a-revision-id'))],
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1800
            client._calls)
1801
        self.assertEqual(None, result)
1802
1803
    def test_no_such_revision(self):
1804
        # A response of 'NoSuchRevision' is translated into an exception.
1805
        transport = MemoryTransport()
1806
        transport.mkdir('branch')
1807
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1808
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1809
        # get_stacked_on_url
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1810
        client.add_error_response(b'NotStacked')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1811
        # lock_write
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1812
        client.add_success_response(b'ok', b'branch token', b'repo token')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1813
        # set_last_revision
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1814
        client.add_error_response(b'NoSuchRevision', b'revid')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1815
        # unlock
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1816
        client.add_success_response(b'ok')
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1817
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1818
        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.
1819
        # Lock the branch, reset the record of remote calls.
1820
        branch.lock_write()
1821
        client._calls = []
1822
1823
        self.assertRaises(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1824
            errors.NoSuchRevision, branch.set_last_revision_info, 123, b'revid')
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1825
        branch.unlock()
1826
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1827
    def test_backwards_compatibility(self):
1828
        """If the server does not support the Branch.set_last_revision_info
1829
        verb (which is new in 1.4), then the client falls back to VFS methods.
1830
        """
1831
        # This test is a little messy.  Unlike most tests in this file, it
1832
        # doesn't purely test what a Remote* object sends over the wire, and
1833
        # how it reacts to responses from the wire.  It instead relies partly
1834
        # on asserting that the RemoteBranch will call
1835
        # self._real_branch.set_last_revision_info(...).
1836
1837
        # First, set up our RemoteBranch with a FakeClient that raises
1838
        # UnknownSmartMethod, and a StubRealBranch that logs how it is called.
1839
        transport = MemoryTransport()
1840
        transport.mkdir('branch')
1841
        transport = transport.clone('branch')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
1842
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1843
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1844
            b'Branch.get_stacked_on_url', (b'branch/',),
1845
            b'error', (b'NotStacked',))
1846
        client.add_expected_call(
1847
            b'Branch.last_revision_info',
1848
            (b'branch/',),
1849
            b'success', (b'ok', b'0', b'null:'))
1850
        client.add_expected_call(
1851
            b'Branch.set_last_revision_info',
1852
            (b'branch/', b'branch token', b'repo token', b'1234', b'a-revision-id',),
1853
            b'unknown', b'Branch.set_last_revision_info')
3691.2.10 by Martin Pool
Update more test_remote tests
1854
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1855
        branch = self.make_remote_branch(transport, client)
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1856
        class StubRealBranch(object):
1857
            def __init__(self):
1858
                self.calls = []
1859
            def set_last_revision_info(self, revno, revision_id):
1860
                self.calls.append(
1861
                    ('set_last_revision_info', revno, revision_id))
3441.5.5 by Andrew Bennetts
Some small tweaks and comments.
1862
            def _clear_cached_state(self):
1863
                pass
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1864
        real_branch = StubRealBranch()
1865
        branch._real_branch = real_branch
1866
        self.lock_remote_branch(branch)
1867
1868
        # Call set_last_revision_info, and verify it behaved as expected.
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1869
        result = branch.set_last_revision_info(1234, b'a-revision-id')
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1870
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1871
            [('set_last_revision_info', 1234, b'a-revision-id')],
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1872
            real_branch.calls)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1873
        self.assertFinished(client)
3297.4.2 by Andrew Bennetts
Add backwards compatibility for servers older than 1.4.
1874
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1875
    def test_unexpected_error(self):
3697.2.6 by Martin Pool
Merge 261315 fix into 1.7 branch
1876
        # If the server sends an error the client doesn't understand, it gets
1877
        # turned into an UnknownErrorFromSmartServer, which is presented as a
1878
        # non-internal error to the user.
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1879
        transport = MemoryTransport()
1880
        transport.mkdir('branch')
1881
        transport = transport.clone('branch')
1882
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1883
        # get_stacked_on_url
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1884
        client.add_error_response(b'NotStacked')
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1885
        # lock_write
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1886
        client.add_success_response(b'ok', b'branch token', b'repo token')
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1887
        # set_last_revision
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1888
        client.add_error_response(b'UnexpectedError')
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1889
        # unlock
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1890
        client.add_success_response(b'ok')
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1891
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1892
        branch = self.make_remote_branch(transport, client)
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1893
        # Lock the branch, reset the record of remote calls.
1894
        branch.lock_write()
1895
        client._calls = []
1896
1897
        err = self.assertRaises(
3690.1.2 by Andrew Bennetts
Rename UntranslateableErrorFromSmartServer -> UnknownErrorFromSmartServer.
1898
            errors.UnknownErrorFromSmartServer,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1899
            branch.set_last_revision_info, 123, b'revid')
1900
        self.assertEqual((b'UnexpectedError',), err.error_tuple)
3245.4.53 by Andrew Bennetts
Add some missing 'raise' statements to test_remote.
1901
        branch.unlock()
1902
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1903
    def test_tip_change_rejected(self):
1904
        """TipChangeRejected responses cause a TipChangeRejected exception to
1905
        be raised.
1906
        """
1907
        transport = MemoryTransport()
1908
        transport.mkdir('branch')
1909
        transport = transport.clone('branch')
1910
        client = FakeClient(transport.base)
3691.2.10 by Martin Pool
Update more test_remote tests
1911
        # get_stacked_on_url
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1912
        client.add_error_response(b'NotStacked')
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1913
        # lock_write
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1914
        client.add_success_response(b'ok', b'branch token', b'repo token')
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1915
        # set_last_revision
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1916
        client.add_error_response(b'TipChangeRejected', b'rejection message')
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1917
        # unlock
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1918
        client.add_success_response(b'ok')
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1919
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
1920
        branch = self.make_remote_branch(transport, client)
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1921
        # Lock the branch, reset the record of remote calls.
1922
        branch.lock_write()
1923
        self.addCleanup(branch.unlock)
1924
        client._calls = []
1925
1926
        # The 'TipChangeRejected' error response triggered by calling
1927
        # set_last_revision_info causes a TipChangeRejected exception.
1928
        err = self.assertRaises(
1929
            errors.TipChangeRejected,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1930
            branch.set_last_revision_info, 123, b'revid')
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1931
        self.assertEqual('rejection message', err.msg)
1932
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1933
4226.2.1 by Robert Collins
Set branch config options via a smart method.
1934
class TestBranchGetSetConfig(RemoteBranchTestCase):
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
1935
1936
    def test_get_branch_conf(self):
4226.1.5 by Robert Collins
Reinstate the use of the Branch.get_config_file verb.
1937
        # in an empty branch we decode the response properly
1938
        client = FakeClient()
1939
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1940
            b'Branch.get_stacked_on_url', (b'memory:///',),
1941
            b'error', (b'NotStacked',),)
1942
        client.add_success_response_with_body(b'# config file body', b'ok')
4226.1.5 by Robert Collins
Reinstate the use of the Branch.get_config_file verb.
1943
        transport = MemoryTransport()
1944
        branch = self.make_remote_branch(transport, client)
1945
        config = branch.get_config()
1946
        config.has_explicit_nickname()
1947
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1948
            [('call', b'Branch.get_stacked_on_url', (b'memory:///',)),
1949
             ('call_expecting_body', b'Branch.get_config_file', (b'memory:///',))],
4226.1.5 by Robert Collins
Reinstate the use of the Branch.get_config_file verb.
1950
            client._calls)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
1951
4241.5.2 by Matt Nordhoff
Add a test
1952
    def test_get_multi_line_branch_conf(self):
1953
        # Make sure that multiple-line branch.conf files are supported
1954
        #
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
1955
        # https://bugs.launchpad.net/bzr/+bug/354075
4241.5.2 by Matt Nordhoff
Add a test
1956
        client = FakeClient()
1957
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1958
            b'Branch.get_stacked_on_url', (b'memory:///',),
1959
            b'error', (b'NotStacked',),)
1960
        client.add_success_response_with_body(b'a = 1\nb = 2\nc = 3\n', b'ok')
4241.5.2 by Matt Nordhoff
Add a test
1961
        transport = MemoryTransport()
1962
        branch = self.make_remote_branch(transport, client)
1963
        config = branch.get_config()
1964
        self.assertEqual(u'2', config.get_user_option('b'))
1965
4226.2.1 by Robert Collins
Set branch config options via a smart method.
1966
    def test_set_option(self):
1967
        client = FakeClient()
1968
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1969
            b'Branch.get_stacked_on_url', (b'memory:///',),
1970
            b'error', (b'NotStacked',),)
1971
        client.add_expected_call(
1972
            b'Branch.lock_write', (b'memory:///', b'', b''),
1973
            b'success', (b'ok', b'branch token', b'repo token'))
1974
        client.add_expected_call(
1975
            b'Branch.set_config_option', (b'memory:///', b'branch token',
1976
            b'repo token', b'foo', b'bar', b''),
1977
            b'success', ())
1978
        client.add_expected_call(
1979
            b'Branch.unlock', (b'memory:///', b'branch token', b'repo token'),
1980
            b'success', (b'ok',))
4226.2.1 by Robert Collins
Set branch config options via a smart method.
1981
        transport = MemoryTransport()
1982
        branch = self.make_remote_branch(transport, client)
1983
        branch.lock_write()
1984
        config = branch._get_config()
1985
        config.set_option('foo', 'bar')
1986
        branch.unlock()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
1987
        self.assertFinished(client)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
1988
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
1989
    def test_set_option_with_dict(self):
1990
        client = FakeClient()
1991
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1992
            b'Branch.get_stacked_on_url', (b'memory:///',),
1993
            b'error', (b'NotStacked',),)
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
1994
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1995
            b'Branch.lock_write', (b'memory:///', b'', b''),
1996
            b'success', (b'ok', b'branch token', b'repo token'))
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
1997
        encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
1998
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1999
            b'Branch.set_config_option_dict', (b'memory:///', b'branch token',
2000
            b'repo token', encoded_dict_value, b'foo', b''),
2001
            b'success', ())
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
2002
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2003
            b'Branch.unlock', (b'memory:///', b'branch token', b'repo token'),
2004
            b'success', (b'ok',))
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
2005
        transport = MemoryTransport()
2006
        branch = self.make_remote_branch(transport, client)
2007
        branch.lock_write()
2008
        config = branch._get_config()
2009
        config.set_option(
2010
            {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
2011
            'foo')
2012
        branch.unlock()
2013
        self.assertFinished(client)
2014
4226.2.1 by Robert Collins
Set branch config options via a smart method.
2015
    def test_backwards_compat_set_option(self):
2016
        self.setup_smart_server_with_call_log()
2017
        branch = self.make_branch('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2018
        verb = b'Branch.set_config_option'
4226.2.1 by Robert Collins
Set branch config options via a smart method.
2019
        self.disable_verb(verb)
2020
        branch.lock_write()
2021
        self.addCleanup(branch.unlock)
2022
        self.reset_smart_call_log()
2023
        branch._get_config().set_option('value', 'name')
6213.1.61 by Jelmer Vernooij
Fix tests.
2024
        self.assertLength(11, self.hpss_calls)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
2025
        self.assertEqual('value', branch._get_config().get_option('name'))
2026
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
2027
    def test_backwards_compat_set_option_with_dict(self):
2028
        self.setup_smart_server_with_call_log()
2029
        branch = self.make_branch('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2030
        verb = b'Branch.set_config_option_dict'
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
2031
        self.disable_verb(verb)
2032
        branch.lock_write()
2033
        self.addCleanup(branch.unlock)
2034
        self.reset_smart_call_log()
2035
        config = branch._get_config()
2036
        value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
2037
        config.set_option(value_dict, 'name')
6213.1.61 by Jelmer Vernooij
Fix tests.
2038
        self.assertLength(11, self.hpss_calls)
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
2039
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
2040
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
2041
6270.1.23 by Jelmer Vernooij
Add notes about Remote{Control,Branch}Store.
2042
class TestBranchGetPutConfigStore(RemoteBranchTestCase):
6270.1.10 by Jelmer Vernooij
Fix testing Branch.set_config_file.
2043
2044
    def test_get_branch_conf(self):
2045
        # in an empty branch we decode the response properly
2046
        client = FakeClient()
2047
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2048
            b'Branch.get_stacked_on_url', (b'memory:///',),
2049
            b'error', (b'NotStacked',),)
2050
        client.add_success_response_with_body(b'# config file body', b'ok')
6270.1.10 by Jelmer Vernooij
Fix testing Branch.set_config_file.
2051
        transport = MemoryTransport()
2052
        branch = self.make_remote_branch(transport, client)
2053
        config = branch.get_config_stack()
2054
        config.get("email")
2055
        config.get("log_format")
2056
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2057
            [('call', b'Branch.get_stacked_on_url', (b'memory:///',)),
2058
             ('call_expecting_body', b'Branch.get_config_file', (b'memory:///',))],
6270.1.10 by Jelmer Vernooij
Fix testing Branch.set_config_file.
2059
            client._calls)
2060
2061
    def test_set_branch_conf(self):
2062
        client = FakeClient()
2063
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2064
            b'Branch.get_stacked_on_url', (b'memory:///',),
2065
            b'error', (b'NotStacked',),)
2066
        client.add_expected_call(
2067
            b'Branch.lock_write', (b'memory:///', b'', b''),
2068
            b'success', (b'ok', b'branch token', b'repo token'))
2069
        client.add_expected_call(
2070
            b'Branch.get_config_file', (b'memory:///', ),
2071
            b'success', (b'ok', ), b"# line 1\n")
2072
        client.add_expected_call(
2073
            b'Branch.get_config_file', (b'memory:///', ),
2074
            b'success', (b'ok', ), b"# line 1\n")
2075
        client.add_expected_call(
2076
            b'Branch.put_config_file', (b'memory:///', b'branch token',
2077
            b'repo token'),
2078
            b'success', (b'ok',))
2079
        client.add_expected_call(
2080
            b'Branch.unlock', (b'memory:///', b'branch token', b'repo token'),
2081
            b'success', (b'ok',))
6270.1.10 by Jelmer Vernooij
Fix testing Branch.set_config_file.
2082
        transport = MemoryTransport()
2083
        branch = self.make_remote_branch(transport, client)
2084
        branch.lock_write()
2085
        config = branch.get_config_stack()
2086
        config.set('email', 'The Dude <lebowski@example.com>')
2087
        branch.unlock()
2088
        self.assertFinished(client)
2089
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2090
            [('call', b'Branch.get_stacked_on_url', (b'memory:///',)),
2091
             ('call', b'Branch.lock_write', (b'memory:///', b'', b'')),
2092
             ('call_expecting_body', b'Branch.get_config_file', (b'memory:///',)),
2093
             ('call_expecting_body', b'Branch.get_config_file', (b'memory:///',)),
2094
             ('call_with_body_bytes_expecting_body', b'Branch.put_config_file',
2095
                 (b'memory:///', b'branch token', b'repo token'),
2096
                 b'# line 1\nemail = The Dude <lebowski@example.com>\n'),
2097
             ('call', b'Branch.unlock', (b'memory:///', b'branch token', b'repo token'))],
6270.1.10 by Jelmer Vernooij
Fix testing Branch.set_config_file.
2098
            client._calls)
2099
2100
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
2101
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.
2102
2103
    def test_lock_write_unlockable(self):
2104
        transport = MemoryTransport()
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2105
        client = FakeClient(transport.base)
3691.2.9 by Martin Pool
Convert and update more test_remote tests
2106
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2107
            b'Branch.get_stacked_on_url', (b'quack/',),
2108
            b'error', (b'NotStacked',),)
3691.2.9 by Martin Pool
Convert and update more test_remote tests
2109
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2110
            b'Branch.lock_write', (b'quack/', b'', b''),
2111
            b'error', (b'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.
2112
        transport.mkdir('quack')
2113
        transport = transport.clone('quack')
3692.1.1 by Andrew Bennetts
Make RemoteBranch.lock_write lock the repository too.
2114
        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.
2115
        self.assertRaises(errors.UnlockableTransport, branch.lock_write)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
2116
        self.assertFinished(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.
2117
2118
6263.1.3 by Jelmer Vernooij
Add dotted revno test.
2119
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
2120
2121
    def test_simple(self):
2122
        transport = MemoryTransport()
2123
        client = FakeClient(transport.base)
2124
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2125
            b'Branch.get_stacked_on_url', (b'quack/',),
2126
            b'error', (b'NotStacked',),)
2127
        client.add_expected_call(
2128
            b'Branch.revision_id_to_revno', (b'quack/', b'null:'),
2129
            b'success', (b'ok', b'0',),)
2130
        client.add_expected_call(
2131
            b'Branch.revision_id_to_revno', (b'quack/', b'unknown'),
2132
            b'error', (b'NoSuchRevision', b'unknown',),)
6263.1.3 by Jelmer Vernooij
Add dotted revno test.
2133
        transport.mkdir('quack')
2134
        transport = transport.clone('quack')
2135
        branch = self.make_remote_branch(transport, client)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2136
        self.assertEqual(0, branch.revision_id_to_revno(b'null:'))
6263.1.3 by Jelmer Vernooij
Add dotted revno test.
2137
        self.assertRaises(errors.NoSuchRevision,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2138
            branch.revision_id_to_revno, b'unknown')
6263.1.3 by Jelmer Vernooij
Add dotted revno test.
2139
        self.assertFinished(client)
2140
2141
    def test_dotted(self):
2142
        transport = MemoryTransport()
2143
        client = FakeClient(transport.base)
2144
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2145
            b'Branch.get_stacked_on_url', (b'quack/',),
2146
            b'error', (b'NotStacked',),)
2147
        client.add_expected_call(
2148
            b'Branch.revision_id_to_revno', (b'quack/', b'null:'),
2149
            b'success', (b'ok', b'0',),)
2150
        client.add_expected_call(
2151
            b'Branch.revision_id_to_revno', (b'quack/', b'unknown'),
2152
            b'error', (b'NoSuchRevision', b'unknown',),)
6263.1.3 by Jelmer Vernooij
Add dotted revno test.
2153
        transport.mkdir('quack')
2154
        transport = transport.clone('quack')
2155
        branch = self.make_remote_branch(transport, client)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2156
        self.assertEqual((0, ), branch.revision_id_to_dotted_revno(b'null:'))
6263.1.3 by Jelmer Vernooij
Add dotted revno test.
2157
        self.assertRaises(errors.NoSuchRevision,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2158
            branch.revision_id_to_dotted_revno, b'unknown')
6263.1.3 by Jelmer Vernooij
Add dotted revno test.
2159
        self.assertFinished(client)
2160
6305.1.1 by Jelmer Vernooij
Add test for Branch.revision_id_to_dotted_revno fallback.
2161
    def test_dotted_no_smart_verb(self):
2162
        self.setup_smart_server_with_call_log()
2163
        branch = self.make_branch('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2164
        self.disable_verb(b'Branch.revision_id_to_revno')
6305.1.1 by Jelmer Vernooij
Add test for Branch.revision_id_to_dotted_revno fallback.
2165
        self.reset_smart_call_log()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2166
        self.assertEqual((0, ),
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2167
            branch.revision_id_to_dotted_revno(b'null:'))
6213.1.61 by Jelmer Vernooij
Fix tests.
2168
        self.assertLength(8, self.hpss_calls)
6305.1.1 by Jelmer Vernooij
Add test for Branch.revision_id_to_dotted_revno fallback.
2169
6263.1.3 by Jelmer Vernooij
Add dotted revno test.
2170
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
2171
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
2172
2173
    def test__get_config(self):
2174
        client = FakeClient()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2175
        client.add_success_response_with_body(b'default_stack_on = /\n', b'ok')
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
2176
        transport = MemoryTransport()
2177
        bzrdir = self.make_remote_bzrdir(transport, client)
2178
        config = bzrdir.get_config()
2179
        self.assertEqual('/', config.get_default_stack_on())
2180
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2181
            [('call_expecting_body', b'BzrDir.get_config_file', (b'memory:///',))],
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
2182
            client._calls)
2183
2184
    def test_set_option_uses_vfs(self):
2185
        self.setup_smart_server_with_call_log()
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
2186
        bzrdir = self.make_controldir('.')
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
2187
        self.reset_smart_call_log()
2188
        config = bzrdir.get_config()
2189
        config.set_default_stack_on('/')
6213.1.61 by Jelmer Vernooij
Fix tests.
2190
        self.assertLength(4, self.hpss_calls)
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
2191
2192
    def test_backwards_compat_get_option(self):
2193
        self.setup_smart_server_with_call_log()
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
2194
        bzrdir = self.make_controldir('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2195
        verb = b'BzrDir.get_config_file'
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2196
        self.disable_verb(verb)
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
2197
        self.reset_smart_call_log()
2198
        self.assertEqual(None,
2199
            bzrdir._get_config().get_option('default_stack_on'))
6213.1.61 by Jelmer Vernooij
Fix tests.
2200
        self.assertLength(4, self.hpss_calls)
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
2201
2202
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
2203
class TestTransportIsReadonly(tests.TestCase):
2204
2205
    def test_true(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2206
        client = FakeClient()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2207
        client.add_success_response(b'yes')
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
2208
        transport = RemoteTransport('bzr://example.com/', medium=False,
2209
                                    _client=client)
2210
        self.assertEqual(True, transport.is_readonly())
2211
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2212
            [('call', b'Transport.is_readonly', ())],
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
2213
            client._calls)
2214
2215
    def test_false(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2216
        client = FakeClient()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2217
        client.add_success_response(b'no')
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
2218
        transport = RemoteTransport('bzr://example.com/', medium=False,
2219
                                    _client=client)
2220
        self.assertEqual(False, transport.is_readonly())
2221
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2222
            [('call', b'Transport.is_readonly', ())],
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
2223
            client._calls)
2224
2225
    def test_error_from_old_server(self):
2226
        """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
2227
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
2228
        Clients should treat it as a "no" response, because is_readonly is only
2229
        advisory anyway (a transport could be read-write, but then the
2230
        underlying filesystem could be readonly anyway).
2231
        """
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2232
        client = FakeClient()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2233
        client.add_unknown_method_response(b'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.
2234
        transport = RemoteTransport('bzr://example.com/', medium=False,
2235
                                    _client=client)
2236
        self.assertEqual(False, transport.is_readonly())
2237
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2238
            [('call', b'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.
2239
            client._calls)
2240
2466.2.2 by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.
2241
3840.1.1 by Andrew Bennetts
Fix RemoteTransport's translation of errors involving paths; it wasn't passing orig_path to _translate_error.
2242
class TestTransportMkdir(tests.TestCase):
2243
2244
    def test_permissiondenied(self):
2245
        client = FakeClient()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2246
        client.add_error_response(b'PermissionDenied', b'remote path', b'extra')
3840.1.1 by Andrew Bennetts
Fix RemoteTransport's translation of errors involving paths; it wasn't passing orig_path to _translate_error.
2247
        transport = RemoteTransport('bzr://example.com/', medium=False,
2248
                                    _client=client)
2249
        exc = self.assertRaises(
2250
            errors.PermissionDenied, transport.mkdir, 'client path')
2251
        expected_error = errors.PermissionDenied('/client path', 'extra')
2252
        self.assertEqual(expected_error, exc)
2253
2254
3777.1.3 by Aaron Bentley
Use SSH default username from authentication.conf
2255
class TestRemoteSSHTransportAuthentication(tests.TestCaseInTempDir):
2256
4304.2.1 by Vincent Ladeuil
Fix bug #367726 by reverting some default user handling introduced
2257
    def test_defaults_to_none(self):
3777.1.3 by Aaron Bentley
Use SSH default username from authentication.conf
2258
        t = RemoteSSHTransport('bzr+ssh://example.com')
4304.2.1 by Vincent Ladeuil
Fix bug #367726 by reverting some default user handling introduced
2259
        self.assertIs(None, t._get_credentials()[0])
3777.1.3 by Aaron Bentley
Use SSH default username from authentication.conf
2260
2261
    def test_uses_authentication_config(self):
2262
        conf = config.AuthenticationConfig()
2263
        conf._get_config().update(
2264
            {'bzr+sshtest': {'scheme': 'ssh', 'user': 'bar', 'host':
2265
            'example.com'}})
2266
        conf._save()
2267
        t = RemoteSSHTransport('bzr+ssh://example.com')
2268
        self.assertEqual('bar', t._get_credentials()[0])
2269
2270
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2271
class TestRemoteRepository(TestRemote):
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
2272
    """Base for testing RemoteRepository protocol usage.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2273
2274
    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
2275
    what is sent or expected to be require a thoughtful update to these tests
2276
    because they might break compatibility with different-versioned servers.
2277
    """
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2278
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2279
    def setup_fake_client_and_repository(self, transport_path):
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
2280
        """Create the fake client and repository for testing with.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2281
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
2282
        There's no real server here; we just have canned responses sent
2283
        back one by one.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2284
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
2285
        :param transport_path: Path below the root of the MemoryTransport
2286
            where the repository will be created.
2287
        """
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2288
        transport = MemoryTransport()
2289
        transport.mkdir(transport_path)
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2290
        client = FakeClient(transport.base)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2291
        transport = transport.clone(transport_path)
2292
        # we do not want bzrdir to make any remote calls
5712.3.17 by Jelmer Vernooij
more fixes.
2293
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
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.
2294
            _client=False)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2295
        repo = RemoteRepository(bzrdir, None, _client=client)
2296
        return repo, client
2297
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
2298
4792.1.1 by Andrew Bennetts
Show real branch/repo format description in 'info -v' over HPSS.
2299
def remoted_description(format):
2300
    return 'Remote: ' + format.get_format_description()
2301
2302
2303
class TestBranchFormat(tests.TestCase):
2304
2305
    def test_get_format_description(self):
2306
        remote_format = RemoteBranchFormat()
5662.2.2 by Jelmer Vernooij
Move most format registration functions to BranchFormatRegistry.
2307
        real_format = branch.format_registry.get_default()
4792.1.1 by Andrew Bennetts
Show real branch/repo format description in 'info -v' over HPSS.
2308
        remote_format._network_name = real_format.network_name()
2309
        self.assertEqual(remoted_description(real_format),
2310
            remote_format.get_format_description())
2311
2312
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
2313
class TestRepositoryFormat(TestRemoteRepository):
2314
2315
    def test_fast_delta(self):
5546.1.1 by Andrew Bennetts
Remove RepositoryFormatCHK1 and RepositoryFormatCHK2.
2316
        true_name = groupcompress_repo.RepositoryFormat2a().network_name()
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
2317
        true_format = RemoteRepositoryFormat()
2318
        true_format._network_name = true_name
2319
        self.assertEqual(True, true_format.fast_deltas)
5757.1.7 by Jelmer Vernooij
Fix more imports.
2320
        false_name = knitpack_repo.RepositoryFormatKnitPack1().network_name()
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
2321
        false_format = RemoteRepositoryFormat()
2322
        false_format._network_name = false_name
2323
        self.assertEqual(False, false_format.fast_deltas)
2324
4792.1.1 by Andrew Bennetts
Show real branch/repo format description in 'info -v' over HPSS.
2325
    def test_get_format_description(self):
2326
        remote_repo_format = RemoteRepositoryFormat()
5651.3.9 by Jelmer Vernooij
Avoid using deprecated functions.
2327
        real_format = repository.format_registry.get_default()
4792.1.1 by Andrew Bennetts
Show real branch/repo format description in 'info -v' over HPSS.
2328
        remote_repo_format._network_name = real_format.network_name()
2329
        self.assertEqual(remoted_description(real_format),
2330
            remote_repo_format.get_format_description())
2331
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
2332
6280.3.1 by Jelmer Vernooij
Add remote side of Repository.all_revision_ids.
2333
class TestRepositoryAllRevisionIds(TestRemoteRepository):
2334
2335
    def test_empty(self):
2336
        transport_path = 'quack'
2337
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2338
        client.add_success_response_with_body(b'', b'ok')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2339
        self.assertEqual([], repo.all_revision_ids())
6280.3.1 by Jelmer Vernooij
Add remote side of Repository.all_revision_ids.
2340
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2341
            [('call_expecting_body', b'Repository.all_revision_ids',
2342
             (b'quack/',))],
6280.3.1 by Jelmer Vernooij
Add remote side of Repository.all_revision_ids.
2343
            client._calls)
2344
2345
    def test_with_some_content(self):
2346
        transport_path = 'quack'
2347
        repo, client = self.setup_fake_client_and_repository(transport_path)
2348
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2349
            b'rev1\nrev2\nanotherrev\n', b'ok')
6973.7.10 by Jelmer Vernooij
More fixes.
2350
        self.assertEqual(
2351
            set([b"rev1", b"rev2", b"anotherrev"]),
2352
            set(repo.all_revision_ids()))
6280.3.1 by Jelmer Vernooij
Add remote side of Repository.all_revision_ids.
2353
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2354
            [('call_expecting_body', b'Repository.all_revision_ids',
2355
             (b'quack/',))],
6280.3.1 by Jelmer Vernooij
Add remote side of Repository.all_revision_ids.
2356
            client._calls)
2357
2358
2018.12.2 by Andrew Bennetts
Remove some duplicate code in test_remote
2359
class TestRepositoryGatherStats(TestRemoteRepository):
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2360
2361
    def test_revid_none(self):
2362
        # ('ok',), body with revisions and size
2363
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2364
        repo, client = self.setup_fake_client_and_repository(transport_path)
2365
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2366
            b'revisions: 2\nsize: 18\n', b'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2367
        result = repo.gather_stats(None)
2368
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2369
            [('call_expecting_body', b'Repository.gather_stats',
2370
             (b'quack/', b'', b'no'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2371
            client._calls)
2372
        self.assertEqual({'revisions': 2, 'size': 18}, result)
2373
2374
    def test_revid_no_committers(self):
2375
        # ('ok',), body without committers
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2376
        body = (b'firstrev: 123456.300 3600\n'
2377
                b'latestrev: 654231.400 0\n'
2378
                b'revisions: 2\n'
2379
                b'size: 18\n')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2380
        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.
2381
        revid = u'\xc8'.encode('utf8')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2382
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2383
        client.add_success_response_with_body(body, b'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2384
        result = repo.gather_stats(revid)
2385
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2386
            [('call_expecting_body', b'Repository.gather_stats',
2387
              (b'quick/', revid, b'no'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2388
            client._calls)
2389
        self.assertEqual({'revisions': 2, 'size': 18,
2390
                          'firstrev': (123456.300, 3600),
2391
                          'latestrev': (654231.400, 0),},
2392
                         result)
2393
2394
    def test_revid_with_committers(self):
2395
        # ('ok',), body with committers
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2396
        body = (b'committers: 128\n'
2397
                b'firstrev: 123456.300 3600\n'
2398
                b'latestrev: 654231.400 0\n'
2399
                b'revisions: 2\n'
2400
                b'size: 18\n')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2401
        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.
2402
        revid = u'\xc8'.encode('utf8')
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2403
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2404
        client.add_success_response_with_body(body, b'ok')
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2405
        result = repo.gather_stats(revid, True)
2406
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2407
            [('call_expecting_body', b'Repository.gather_stats',
2408
              (b'buick/', revid, b'yes'))],
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
2409
            client._calls)
2410
        self.assertEqual({'revisions': 2, 'size': 18,
2411
                          'committers': 128,
2412
                          'firstrev': (123456.300, 3600),
2413
                          'latestrev': (654231.400, 0),},
2414
                         result)
2415
2416
6280.4.1 by Jelmer Vernooij
Add remote side of Repository.break_lock.
2417
class TestRepositoryBreakLock(TestRemoteRepository):
2418
2419
    def test_break_lock(self):
2420
        transport_path = 'quack'
2421
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2422
        client.add_success_response(b'ok')
6280.4.1 by Jelmer Vernooij
Add remote side of Repository.break_lock.
2423
        repo.break_lock()
2424
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2425
            [('call', b'Repository.break_lock', (b'quack/',))],
6280.4.1 by Jelmer Vernooij
Add remote side of Repository.break_lock.
2426
            client._calls)
2427
2428
6280.5.1 by Jelmer Vernooij
Add client side of Repository.get_serializer_format.
2429
class TestRepositoryGetSerializerFormat(TestRemoteRepository):
2430
2431
    def test_get_serializer_format(self):
2432
        transport_path = 'hill'
2433
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2434
        client.add_success_response(b'ok', b'7')
2435
        self.assertEqual(b'7', repo.get_serializer_format())
6280.5.1 by Jelmer Vernooij
Add client side of Repository.get_serializer_format.
2436
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2437
            [('call', b'VersionedFileRepository.get_serializer_format',
2438
              (b'hill/', ))],
6280.5.1 by Jelmer Vernooij
Add client side of Repository.get_serializer_format.
2439
            client._calls)
2440
2441
6300.1.1 by Jelmer Vernooij
Add remote implementation of RemoteRepository.reconcile.
2442
class TestRepositoryReconcile(TestRemoteRepository):
2443
2444
    def test_reconcile(self):
2445
        transport_path = 'hill'
2446
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2447
        body = (b"garbage_inventories: 2\n"
2448
                b"inconsistent_parents: 3\n")
6300.1.7 by Jelmer Vernooij
Fix test.
2449
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2450
            b'Repository.lock_write', (b'hill/', b''),
2451
            b'success', (b'ok', b'a token'))
2452
        client.add_success_response_with_body(body, b'ok')
6300.1.4 by Jelmer Vernooij
Add reconcile results.
2453
        reconciler = repo.reconcile()
6300.1.1 by Jelmer Vernooij
Add remote implementation of RemoteRepository.reconcile.
2454
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2455
            [('call', b'Repository.lock_write', (b'hill/', b'')),
2456
             ('call_expecting_body', b'Repository.reconcile',
2457
                (b'hill/', b'a token'))],
6300.1.1 by Jelmer Vernooij
Add remote implementation of RemoteRepository.reconcile.
2458
            client._calls)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2459
        self.assertEqual(2, reconciler.garbage_inventories)
2460
        self.assertEqual(3, reconciler.inconsistent_parents)
6300.1.1 by Jelmer Vernooij
Add remote implementation of RemoteRepository.reconcile.
2461
2462
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2463
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2464
2465
    def test_text(self):
2466
        # ('ok',), body with signature text
2467
        transport_path = 'quack'
2468
        repo, client = self.setup_fake_client_and_repository(transport_path)
2469
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2470
            b'THETEXT', b'ok')
2471
        self.assertEqual(b"THETEXT", repo.get_signature_text(b"revid"))
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2472
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2473
            [('call_expecting_body', b'Repository.get_revision_signature_text',
2474
             (b'quack/', b'revid'))],
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2475
            client._calls)
2476
2477
    def test_no_signature(self):
2478
        transport_path = 'quick'
2479
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2480
        client.add_error_response(b'nosuchrevision', b'unknown')
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2481
        self.assertRaises(errors.NoSuchRevision, repo.get_signature_text,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2482
                b"unknown")
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2483
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2484
            [('call_expecting_body', b'Repository.get_revision_signature_text',
2485
              (b'quick/', b'unknown'))],
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2486
            client._calls)
2487
2488
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
2489
class TestRepositoryGetGraph(TestRemoteRepository):
2490
2491
    def test_get_graph(self):
3835.1.6 by Aaron Bentley
Reduce inefficiency when doing make_parents_provider frequently
2492
        # 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.
2493
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2494
        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.
2495
        graph = repo.get_graph()
3835.1.6 by Aaron Bentley
Reduce inefficiency when doing make_parents_provider frequently
2496
        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.
2497
2498
6268.1.2 by Jelmer Vernooij
Initial work on Repository.add_signature_text.
2499
class TestRepositoryAddSignatureText(TestRemoteRepository):
2500
2501
    def test_add_signature_text(self):
2502
        transport_path = 'quack'
2503
        repo, client = self.setup_fake_client_and_repository(transport_path)
6280.10.32 by Jelmer Vernooij
Merge bzr.dev.
2504
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2505
            b'Repository.lock_write', (b'quack/', b''),
2506
            b'success', (b'ok', b'a token'))
2507
        client.add_expected_call(
2508
            b'Repository.start_write_group', (b'quack/', b'a token'),
2509
            b'success', (b'ok', (b'token1', )))
2510
        client.add_expected_call(
2511
            b'Repository.add_signature_text', (b'quack/', b'a token', b'rev1',
2512
                b'token1'),
2513
            b'success', (b'ok', ), None)
6280.10.32 by Jelmer Vernooij
Merge bzr.dev.
2514
        repo.lock_write()
2515
        repo.start_write_group()
6268.1.2 by Jelmer Vernooij
Initial work on Repository.add_signature_text.
2516
        self.assertIs(None,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2517
            repo.add_signature_text(b"rev1", b"every bloody emperor"))
6268.1.2 by Jelmer Vernooij
Initial work on Repository.add_signature_text.
2518
        self.assertEqual(
6280.10.39 by Jelmer Vernooij
Merge bzr.dev.
2519
            ('call_with_body_bytes_expecting_body',
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2520
              b'Repository.add_signature_text',
2521
                (b'quack/', b'a token', b'rev1', b'token1'),
2522
              b'every bloody emperor'),
6280.10.32 by Jelmer Vernooij
Merge bzr.dev.
2523
            client._calls[-1])
6268.1.2 by Jelmer Vernooij
Initial work on Repository.add_signature_text.
2524
2525
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
2526
class TestRepositoryGetParentMap(TestRemoteRepository):
2527
2528
    def test_get_parent_map_caching(self):
2529
        # get_parent_map returns from cache until unlock()
2530
        # setup a reponse with two revisions
2531
        r1 = u'\u0e33'.encode('utf8')
2532
        r2 = u'\u0dab'.encode('utf8')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2533
        lines = [b' '.join([r2, r1]), r1]
2534
        encoded_body = bz2.compress(b'\n'.join(lines))
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
2535
2536
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2537
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2538
        client.add_success_response_with_body(encoded_body, b'ok')
2539
        client.add_success_response_with_body(encoded_body, b'ok')
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
2540
        repo.lock_read()
2541
        graph = repo.get_graph()
2542
        parents = graph.get_parent_map([r2])
2543
        self.assertEqual({r2: (r1,)}, parents)
2544
        # locking and unlocking deeper should not reset
2545
        repo.lock_read()
2546
        repo.unlock()
2547
        parents = graph.get_parent_map([r1])
3172.5.6 by Robert Collins
Create new smart server verb Repository.get_parent_map.
2548
        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.
2549
        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.
2550
            [('call_with_body_bytes_expecting_body',
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2551
              b'Repository.get_parent_map', (b'quack/', b'include-missing:', r2),
2552
              b'\n\n0')],
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
2553
            client._calls)
2554
        repo.unlock()
2555
        # now we call again, and it should use the second response.
2556
        repo.lock_read()
2557
        graph = repo.get_graph()
3172.5.6 by Robert Collins
Create new smart server verb Repository.get_parent_map.
2558
        parents = graph.get_parent_map([r1])
2559
        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.
2560
        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.
2561
            [('call_with_body_bytes_expecting_body',
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2562
              b'Repository.get_parent_map', (b'quack/', b'include-missing:', r2),
2563
              b'\n\n0'),
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.
2564
             ('call_with_body_bytes_expecting_body',
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2565
              b'Repository.get_parent_map', (b'quack/', b'include-missing:', r1),
2566
              b'\n\n0'),
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
2567
            ],
2568
            client._calls)
2569
        repo.unlock()
2570
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
2571
    def test_get_parent_map_reconnects_if_unknown_method(self):
2572
        transport_path = 'quack'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2573
        rev_id = b'revision-id'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2574
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2575
        client.add_unknown_method_response(b'Repository.get_parent_map')
2576
        client.add_success_response_with_body(rev_id, b'ok')
3453.4.10 by Andrew Bennetts
Change _is_remote_at_least to _is_remote_before.
2577
        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.
2578
        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.
2579
        self.assertEqual(
3213.1.8 by Andrew Bennetts
Merge from bzr.dev.
2580
            [('call_with_body_bytes_expecting_body',
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2581
              b'Repository.get_parent_map',
2582
              (b'quack/', b'include-missing:', rev_id), b'\n\n0'),
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
2583
             ('disconnect medium',),
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2584
             ('call_expecting_body', b'Repository.get_revision_graph',
2585
              (b'quack/', b''))],
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
2586
            client._calls)
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
2587
        # 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.
2588
        self.assertTrue(client._medium._is_remote_before((1, 2)))
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2589
        self.assertEqual({rev_id: (b'null:',)}, parents)
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
2590
2591
    def test_get_parent_map_fallback_parentless_node(self):
2592
        """get_parent_map falls back to get_revision_graph on old servers.  The
2593
        results from get_revision_graph are tweaked to match the get_parent_map
2594
        API.
2595
3389.1.3 by Andrew Bennetts
Remove XXX from test description.
2596
        Specifically, a {key: ()} result from get_revision_graph means "no
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
2597
        parents" for that key, which in get_parent_map results should be
3389.1.3 by Andrew Bennetts
Remove XXX from test description.
2598
        represented as {key: ('null:',)}.
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
2599
2600
        This is the test for https://bugs.launchpad.net/bzr/+bug/214894
2601
        """
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2602
        rev_id = b'revision-id'
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
2603
        transport_path = 'quack'
3245.4.40 by Andrew Bennetts
Merge from bzr.dev.
2604
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2605
        client.add_success_response_with_body(rev_id, b'ok')
3453.4.9 by Andrew Bennetts
Rename _remote_is_not to _remember_remote_is_before.
2606
        client._medium._remember_remote_is_before((1, 2))
3948.3.7 by Martin Pool
Updated tests for RemoteRepository.get_parent_map on old servers.
2607
        parents = repo.get_parent_map([rev_id])
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
2608
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2609
            [('call_expecting_body', b'Repository.get_revision_graph',
2610
             (b'quack/', b''))],
3389.1.2 by Andrew Bennetts
Add test for the bug John found.
2611
            client._calls)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2612
        self.assertEqual({rev_id: (b'null:',)}, parents)
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
2613
3297.2.3 by Andrew Bennetts
Test the code path that the typo is on.
2614
    def test_get_parent_map_unexpected_response(self):
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
2615
        repo, client = self.setup_fake_client_and_repository('path')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2616
        client.add_success_response(b'something unexpected!')
3297.2.3 by Andrew Bennetts
Test the code path that the typo is on.
2617
        self.assertRaises(
2618
            errors.UnexpectedSmartServerResponse,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2619
            repo.get_parent_map, [b'a-revision-id'])
3213.1.2 by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server.
2620
4190.1.1 by Robert Collins
Negatively cache misses during read-locks in RemoteRepository.
2621
    def test_get_parent_map_negative_caches_missing_keys(self):
2622
        self.setup_smart_server_with_call_log()
2623
        repo = self.make_repository('foo')
2624
        self.assertIsInstance(repo, RemoteRepository)
2625
        repo.lock_read()
2626
        self.addCleanup(repo.unlock)
2627
        self.reset_smart_call_log()
2628
        graph = repo.get_graph()
2629
        self.assertEqual({},
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2630
            graph.get_parent_map([b'some-missing', b'other-missing']))
4190.1.1 by Robert Collins
Negatively cache misses during read-locks in RemoteRepository.
2631
        self.assertLength(1, self.hpss_calls)
2632
        # No call if we repeat this
2633
        self.reset_smart_call_log()
2634
        graph = repo.get_graph()
2635
        self.assertEqual({},
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2636
            graph.get_parent_map([b'some-missing', b'other-missing']))
4190.1.1 by Robert Collins
Negatively cache misses during read-locks in RemoteRepository.
2637
        self.assertLength(0, self.hpss_calls)
2638
        # Asking for more unknown keys makes a request.
2639
        self.reset_smart_call_log()
2640
        graph = repo.get_graph()
2641
        self.assertEqual({},
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2642
            graph.get_parent_map([b'some-missing', b'other-missing',
2643
                b'more-missing']))
4190.1.1 by Robert Collins
Negatively cache misses during read-locks in RemoteRepository.
2644
        self.assertLength(1, self.hpss_calls)
2645
4214.2.1 by Andrew Bennetts
A long but failing test for the get_parent_map RPC bug.
2646
    def disableExtraResults(self):
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
2647
        self.overrideAttr(SmartServerRepositoryGetParentMap,
2648
                          'no_extra_results', True)
4214.2.1 by Andrew Bennetts
A long but failing test for the get_parent_map RPC bug.
2649
4214.2.5 by Andrew Bennetts
Fix the bug.
2650
    def test_null_cached_missing_and_stop_key(self):
4214.2.1 by Andrew Bennetts
A long but failing test for the get_parent_map RPC bug.
2651
        self.setup_smart_server_with_call_log()
4214.2.4 by Andrew Bennetts
Further simplify the test to reproduce the bug.
2652
        # Make a branch with a single revision.
4214.2.1 by Andrew Bennetts
A long but failing test for the get_parent_map RPC bug.
2653
        builder = self.make_branch_builder('foo')
2654
        builder.start_series()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2655
        builder.build_snapshot(None, [
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2656
            ('add', ('', b'root-id', 'directory', ''))],
2657
            revision_id=b'first')
4214.2.1 by Andrew Bennetts
A long but failing test for the get_parent_map RPC bug.
2658
        builder.finish_series()
2659
        branch = builder.get_branch()
2660
        repo = branch.repository
2661
        self.assertIsInstance(repo, RemoteRepository)
4214.2.3 by Andrew Bennetts
Further simplify test case, and add more comments.
2662
        # Stop the server from sending extra results.
2663
        self.disableExtraResults()
4214.2.1 by Andrew Bennetts
A long but failing test for the get_parent_map RPC bug.
2664
        repo.lock_read()
2665
        self.addCleanup(repo.unlock)
2666
        self.reset_smart_call_log()
2667
        graph = repo.get_graph()
6973.14.6 by Jelmer Vernooij
Fix some more tests.
2668
        # Query for b'first' and b'null:'.  Because b'null:' is a parent of
4214.2.5 by Andrew Bennetts
Fix the bug.
2669
        # 'first' it will be a candidate for the stop_keys of subsequent
6973.14.6 by Jelmer Vernooij
Fix some more tests.
2670
        # requests, and because b'null:' was queried but not returned it will be
4214.2.5 by Andrew Bennetts
Fix the bug.
2671
        # cached as missing.
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2672
        self.assertEqual({b'first': (b'null:',)},
2673
            graph.get_parent_map([b'first', b'null:']))
4214.2.4 by Andrew Bennetts
Further simplify the test to reproduce the bug.
2674
        # Now query for another key.  This request will pass along a recipe of
2675
        # start and stop keys describing the already cached results, and this
4214.2.5 by Andrew Bennetts
Fix the bug.
2676
        # recipe's revision count must be correct (or else it will trigger an
4214.2.4 by Andrew Bennetts
Further simplify the test to reproduce the bug.
2677
        # error from the server).
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2678
        self.assertEqual({}, graph.get_parent_map([b'another-key']))
4214.2.3 by Andrew Bennetts
Further simplify test case, and add more comments.
2679
        # This assertion guards against disableExtraResults silently failing to
2680
        # work, thus invalidating the test.
4214.2.4 by Andrew Bennetts
Further simplify the test to reproduce the bug.
2681
        self.assertLength(2, self.hpss_calls)
4214.2.1 by Andrew Bennetts
A long but failing test for the get_parent_map RPC bug.
2682
4190.1.4 by Robert Collins
Cache ghosts when we can get them from a RemoteRepository in get_parent_map.
2683
    def test_get_parent_map_gets_ghosts_from_result(self):
2684
        # asking for a revision should negatively cache close ghosts in its
2685
        # ancestry.
2686
        self.setup_smart_server_with_call_log()
2687
        tree = self.make_branch_and_memory_tree('foo')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2688
        with tree.lock_write():
4190.1.4 by Robert Collins
Cache ghosts when we can get them from a RemoteRepository in get_parent_map.
2689
            builder = treebuilder.TreeBuilder()
2690
            builder.start_tree(tree)
2691
            builder.build([])
2692
            builder.finish_tree()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2693
            tree.set_parent_ids([b'non-existant'], allow_leftmost_as_ghost=True)
4190.1.4 by Robert Collins
Cache ghosts when we can get them from a RemoteRepository in get_parent_map.
2694
            rev_id = tree.commit('')
2695
        tree.lock_read()
2696
        self.addCleanup(tree.unlock)
2697
        repo = tree.branch.repository
2698
        self.assertIsInstance(repo, RemoteRepository)
2699
        # ask for rev_id
2700
        repo.get_parent_map([rev_id])
2701
        self.reset_smart_call_log()
2702
        # Now asking for rev_id's ghost parent should not make calls
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2703
        self.assertEqual({}, repo.get_parent_map([b'non-existant']))
4190.1.4 by Robert Collins
Cache ghosts when we can get them from a RemoteRepository in get_parent_map.
2704
        self.assertLength(0, self.hpss_calls)
2705
6015.24.4 by John Arbash Meinel
For it to all work properly, we have to expose get_parent_map_cached on RemoteRepository.
2706
    def test_exposes_get_cached_parent_map(self):
2707
        """RemoteRepository exposes get_cached_parent_map from
2708
        _unstacked_provider
2709
        """
2710
        r1 = u'\u0e33'.encode('utf8')
2711
        r2 = u'\u0dab'.encode('utf8')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2712
        lines = [b' '.join([r2, r1]), r1]
2713
        encoded_body = bz2.compress(b'\n'.join(lines))
6015.24.4 by John Arbash Meinel
For it to all work properly, we have to expose get_parent_map_cached on RemoteRepository.
2714
2715
        transport_path = 'quack'
2716
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2717
        client.add_success_response_with_body(encoded_body, b'ok')
6015.24.4 by John Arbash Meinel
For it to all work properly, we have to expose get_parent_map_cached on RemoteRepository.
2718
        repo.lock_read()
6015.24.5 by John Arbash Meinel
Bug #388269.
2719
        # get_cached_parent_map should *not* trigger an RPC
2720
        self.assertEqual({}, repo.get_cached_parent_map([r1]))
2721
        self.assertEqual([], client._calls)
6015.24.4 by John Arbash Meinel
For it to all work properly, we have to expose get_parent_map_cached on RemoteRepository.
2722
        self.assertEqual({r2: (r1,)}, repo.get_parent_map([r2]))
2723
        self.assertEqual({r1: (NULL_REVISION,)},
2724
            repo.get_cached_parent_map([r1]))
2725
        self.assertEqual(
2726
            [('call_with_body_bytes_expecting_body',
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2727
              b'Repository.get_parent_map', (b'quack/', b'include-missing:', r2),
2728
              b'\n\n0')],
6015.24.4 by John Arbash Meinel
For it to all work properly, we have to expose get_parent_map_cached on RemoteRepository.
2729
            client._calls)
2730
        repo.unlock()
2731
3172.5.4 by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.
2732
3835.1.15 by Aaron Bentley
Allow miss caching to be disabled.
2733
class TestGetParentMapAllowsNew(tests.TestCaseWithTransport):
2734
2735
    def test_allows_new_revisions(self):
2736
        """get_parent_map's results can be updated by commit."""
5017.3.28 by Vincent Ladeuil
selftest -s bt.test_remote passing
2737
        smart_server = test_server.SmartTCPServer_for_testing()
4659.1.2 by Robert Collins
Refactor creation and shutdown of test servers to use a common helper,
2738
        self.start_server(smart_server)
3835.1.15 by Aaron Bentley
Allow miss caching to be disabled.
2739
        self.make_branch('branch')
2740
        branch = Branch.open(smart_server.get_url() + '/branch')
2741
        tree = branch.create_checkout('tree', lightweight=True)
2742
        tree.lock_write()
2743
        self.addCleanup(tree.unlock)
2744
        graph = tree.branch.repository.get_graph()
2745
        # This provides an opportunity for the missing rev-id to be cached.
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2746
        self.assertEqual({}, graph.get_parent_map([b'rev1']))
6855.4.1 by Jelmer Vernooij
Yet more bees.
2747
        tree.commit('message', rev_id=b'rev1')
3835.1.15 by Aaron Bentley
Allow miss caching to be disabled.
2748
        graph = tree.branch.repository.get_graph()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2749
        self.assertEqual({b'rev1': (b'null:',)}, graph.get_parent_map([b'rev1']))
3835.1.15 by Aaron Bentley
Allow miss caching to be disabled.
2750
2751
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2752
class TestRepositoryGetRevisions(TestRemoteRepository):
2753
2754
    def test_hpss_missing_revision(self):
2755
        transport_path = 'quack'
2756
        repo, client = self.setup_fake_client_and_repository(transport_path)
2757
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2758
            b'', b'ok', b'10')
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2759
        self.assertRaises(errors.NoSuchRevision, repo.get_revisions,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2760
            [b'somerev1', b'anotherrev2'])
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2761
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2762
            [('call_with_body_bytes_expecting_body', b'Repository.iter_revisions',
2763
             (b'quack/', ), b"somerev1\nanotherrev2")],
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2764
            client._calls)
2765
2766
    def test_hpss_get_single_revision(self):
2767
        transport_path = 'quack'
2768
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2769
        somerev1 = Revision(b"somerev1")
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2770
        somerev1.committer = "Joe Committer <joe@example.com>"
2771
        somerev1.timestamp = 1321828927
2772
        somerev1.timezone = -60
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2773
        somerev1.inventory_sha1 = b"691b39be74c67b1212a75fcb19c433aaed903c2b"
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2774
        somerev1.message = "Message"
6280.9.4 by Jelmer Vernooij
use zlib instead.
2775
        body = zlib.compress(chk_bencode_serializer.write_revision_to_string(
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2776
            somerev1))
6280.9.8 by Jelmer Vernooij
Try to make two calls to zlib.decompressobj.decompress.
2777
        # Split up body into two bits to make sure the zlib compression object
2778
        # gets data fed twice.
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2779
        client.add_success_response_with_body(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2780
                [body[:10], body[10:]], b'ok', b'10')
2781
        revs = repo.get_revisions([b'somerev1'])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2782
        self.assertEqual(revs, [somerev1])
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2783
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2784
            [('call_with_body_bytes_expecting_body', b'Repository.iter_revisions',
2785
             (b'quack/', ), b"somerev1")],
6280.9.1 by Jelmer Vernooij
Add remote side of Repository.iter_revisions.
2786
            client._calls)
2787
2788
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2789
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
2790
2791
    def test_null_revision(self):
2792
        # a null revision has the predictable result {}, we should have no wire
2793
        # traffic when calling it with this argument
2794
        transport_path = 'empty'
2795
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2796
        client.add_success_response(b'notused')
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2797
        # actual RemoteRepository.get_revision_graph is gone, but there's an
2798
        # equivalent private method for testing
2799
        result = repo._get_revision_graph(NULL_REVISION)
2800
        self.assertEqual([], client._calls)
2801
        self.assertEqual({}, result)
2802
2803
    def test_none_revision(self):
2804
        # with none we want the entire graph
2805
        r1 = u'\u0e33'.encode('utf8')
2806
        r2 = u'\u0dab'.encode('utf8')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2807
        lines = [b' '.join([r2, r1]), r1]
2808
        encoded_body = b'\n'.join(lines)
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2809
2810
        transport_path = 'sinhala'
2811
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2812
        client.add_success_response_with_body(encoded_body, b'ok')
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2813
        # actual RemoteRepository.get_revision_graph is gone, but there's an
2814
        # equivalent private method for testing
2815
        result = repo._get_revision_graph(None)
2816
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2817
            [('call_expecting_body', b'Repository.get_revision_graph',
2818
             (b'sinhala/', b''))],
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2819
            client._calls)
2820
        self.assertEqual({r1: (), r2: (r1, )}, result)
2821
2822
    def test_specific_revision(self):
2823
        # with a specific revision we want the graph for that
2824
        # with none we want the entire graph
2825
        r11 = u'\u0e33'.encode('utf8')
2826
        r12 = u'\xc9'.encode('utf8')
2827
        r2 = u'\u0dab'.encode('utf8')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2828
        lines = [b' '.join([r2, r11, r12]), r11, r12]
2829
        encoded_body = b'\n'.join(lines)
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2830
2831
        transport_path = 'sinhala'
2832
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2833
        client.add_success_response_with_body(encoded_body, b'ok')
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2834
        result = repo._get_revision_graph(r2)
2835
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2836
            [('call_expecting_body', b'Repository.get_revision_graph',
2837
             (b'sinhala/', r2))],
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2838
            client._calls)
2839
        self.assertEqual({r11: (), r12: (), r2: (r11, r12), }, result)
2840
2841
    def test_no_such_revision(self):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2842
        revid = b'123'
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2843
        transport_path = 'sinhala'
2844
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2845
        client.add_error_response(b'nosuchrevision', revid)
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2846
        # also check that the right revision is reported in the error
2847
        self.assertRaises(errors.NoSuchRevision,
2848
            repo._get_revision_graph, revid)
2849
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2850
            [('call_expecting_body', b'Repository.get_revision_graph',
2851
             (b'sinhala/', revid))],
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2852
            client._calls)
2853
2854
    def test_unexpected_error(self):
2855
        revid = '123'
2856
        transport_path = 'sinhala'
2857
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2858
        client.add_error_response(b'AnUnexpectedError')
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2859
        e = self.assertRaises(errors.UnknownErrorFromSmartServer,
2860
            repo._get_revision_graph, revid)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2861
        self.assertEqual((b'AnUnexpectedError',), e.error_tuple)
3948.3.9 by Martin Pool
Undelete TestRepositoryGetRevisionGraph but make it use private client methods to simulate old clients
2862
2863
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2864
class TestRepositoryGetRevIdForRevno(TestRemoteRepository):
2865
2866
    def test_ok(self):
4419.2.8 by Andrew Bennetts
Add unit test for RemoteRepository.get_rev_id_for_revno using fallbacks if it gets a history-incomplete response.
2867
        repo, client = self.setup_fake_client_and_repository('quack')
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2868
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2869
            b'Repository.get_rev_id_for_revno', (b'quack/', 5, (42, b'rev-foo')),
2870
            b'success', (b'ok', b'rev-five'))
2871
        result = repo.get_rev_id_for_revno(5, (42, b'rev-foo'))
2872
        self.assertEqual((True, b'rev-five'), result)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
2873
        self.assertFinished(client)
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2874
2875
    def test_history_incomplete(self):
4419.2.8 by Andrew Bennetts
Add unit test for RemoteRepository.get_rev_id_for_revno using fallbacks if it gets a history-incomplete response.
2876
        repo, client = self.setup_fake_client_and_repository('quack')
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2877
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2878
            b'Repository.get_rev_id_for_revno', (b'quack/', 5, (42, b'rev-foo')),
2879
            b'success', (b'history-incomplete', 10, b'rev-ten'))
2880
        result = repo.get_rev_id_for_revno(5, (42, b'rev-foo'))
2881
        self.assertEqual((False, (10, b'rev-ten')), result)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
2882
        self.assertFinished(client)
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2883
4419.2.8 by Andrew Bennetts
Add unit test for RemoteRepository.get_rev_id_for_revno using fallbacks if it gets a history-incomplete response.
2884
    def test_history_incomplete_with_fallback(self):
2885
        """A 'history-incomplete' response causes the fallback repository to be
2886
        queried too, if one is set.
2887
        """
2888
        # Make a repo with a fallback repo, both using a FakeClient.
2889
        format = remote.response_tuple_to_repo_format(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2890
            (b'yes', b'no', b'yes', self.get_repo_format().network_name()))
4419.2.8 by Andrew Bennetts
Add unit test for RemoteRepository.get_rev_id_for_revno using fallbacks if it gets a history-incomplete response.
2891
        repo, client = self.setup_fake_client_and_repository('quack')
2892
        repo._format = format
2893
        fallback_repo, ignored = self.setup_fake_client_and_repository(
2894
            'fallback')
2895
        fallback_repo._client = client
5158.4.3 by Andrew Bennetts
Fix test_remote tests that accidentally assumed it was ok to stack mismatched formats.
2896
        fallback_repo._format = format
4419.2.8 by Andrew Bennetts
Add unit test for RemoteRepository.get_rev_id_for_revno using fallbacks if it gets a history-incomplete response.
2897
        repo.add_fallback_repository(fallback_repo)
2898
        # First the client should ask the primary repo
2899
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2900
            b'Repository.get_rev_id_for_revno', (b'quack/', 1, (42, b'rev-foo')),
2901
            b'success', (b'history-incomplete', 2, b'rev-two'))
4419.2.8 by Andrew Bennetts
Add unit test for RemoteRepository.get_rev_id_for_revno using fallbacks if it gets a history-incomplete response.
2902
        # Then it should ask the fallback, using revno/revid from the
2903
        # history-incomplete response as the known revno/revid.
2904
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2905
            b'Repository.get_rev_id_for_revno', (b'fallback/', 1, (2, b'rev-two')),
2906
            b'success', (b'ok', b'rev-one'))
2907
        result = repo.get_rev_id_for_revno(1, (42, b'rev-foo'))
2908
        self.assertEqual((True, b'rev-one'), result)
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
2909
        self.assertFinished(client)
4419.2.8 by Andrew Bennetts
Add unit test for RemoteRepository.get_rev_id_for_revno using fallbacks if it gets a history-incomplete response.
2910
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2911
    def test_nosuchrevision(self):
2912
        # 'nosuchrevision' is returned when the known-revid is not found in the
2913
        # remote repo.  The client translates that response to NoSuchRevision.
4419.2.8 by Andrew Bennetts
Add unit test for RemoteRepository.get_rev_id_for_revno using fallbacks if it gets a history-incomplete response.
2914
        repo, client = self.setup_fake_client_and_repository('quack')
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2915
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2916
            b'Repository.get_rev_id_for_revno', (b'quack/', 5, (42, b'rev-foo')),
2917
            b'error', (b'nosuchrevision', b'rev-foo'))
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2918
        self.assertRaises(
2919
            errors.NoSuchRevision,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2920
            repo.get_rev_id_for_revno, 5, (42, b'rev-foo'))
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
2921
        self.assertFinished(client)
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2922
4634.69.1 by Andrew Bennetts
Apply @needs_read_lock to RemoteBranch.get_rev_id.
2923
    def test_branch_fallback_locking(self):
2924
        """RemoteBranch.get_rev_id takes a read lock, and tries to call the
2925
        get_rev_id_for_revno verb.  If the verb is unknown the VFS fallback
2926
        will be invoked, which will fail if the repo is unlocked.
2927
        """
2928
        self.setup_smart_server_with_call_log()
2929
        tree = self.make_branch_and_memory_tree('.')
2930
        tree.lock_write()
5222.1.1 by Aaron Bentley
Refuse to commit trees with no root.
2931
        tree.add('')
4634.69.1 by Andrew Bennetts
Apply @needs_read_lock to RemoteBranch.get_rev_id.
2932
        rev1 = tree.commit('First')
2933
        rev2 = tree.commit('Second')
2934
        tree.unlock()
2935
        branch = tree.branch
2936
        self.assertFalse(branch.is_locked())
2937
        self.reset_smart_call_log()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2938
        verb = b'Repository.get_rev_id_for_revno'
4634.69.1 by Andrew Bennetts
Apply @needs_read_lock to RemoteBranch.get_rev_id.
2939
        self.disable_verb(verb)
2940
        self.assertEqual(rev1, branch.get_rev_id(1))
2941
        self.assertLength(1, [call for call in self.hpss_calls if
2942
                              call.call.method == verb])
2943
4419.2.7 by Andrew Bennetts
Add unit tests for RemoteRepository.get_rev_id_for_revno.
2944
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
2945
class TestRepositoryHasSignatureForRevisionId(TestRemoteRepository):
2946
2947
    def test_has_signature_for_revision_id(self):
2948
        # ('yes', ) for Repository.has_signature_for_revision_id -> 'True'.
2949
        transport_path = 'quack'
2950
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2951
        client.add_success_response(b'yes')
2952
        result = repo.has_signature_for_revision_id(b'A')
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
2953
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2954
            [('call', b'Repository.has_signature_for_revision_id',
2955
              (b'quack/', b'A'))],
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
2956
            client._calls)
2957
        self.assertEqual(True, result)
2958
2959
    def test_is_not_shared(self):
2960
        # ('no', ) for Repository.has_signature_for_revision_id -> 'False'.
2961
        transport_path = 'qwack'
2962
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2963
        client.add_success_response(b'no')
2964
        result = repo.has_signature_for_revision_id(b'A')
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
2965
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2966
            [('call', b'Repository.has_signature_for_revision_id',
2967
              (b'qwack/', b'A'))],
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
2968
            client._calls)
2969
        self.assertEqual(False, result)
2970
2971
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
2972
class TestRepositoryPhysicalLockStatus(TestRemoteRepository):
2973
2974
    def test_get_physical_lock_status_yes(self):
2975
        transport_path = 'qwack'
2976
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2977
        client.add_success_response(b'yes')
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
2978
        result = repo.get_physical_lock_status()
2979
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2980
            [('call', b'Repository.get_physical_lock_status',
2981
              (b'qwack/', ))],
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
2982
            client._calls)
2983
        self.assertEqual(True, result)
2984
2985
    def test_get_physical_lock_status_no(self):
2986
        transport_path = 'qwack'
2987
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2988
        client.add_success_response(b'no')
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
2989
        result = repo.get_physical_lock_status()
2990
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2991
            [('call', b'Repository.get_physical_lock_status',
2992
              (b'qwack/', ))],
6280.6.1 by Jelmer Vernooij
Implement remote side of {Branch,Repository}.get_physical_lock_status.
2993
            client._calls)
2994
        self.assertEqual(False, result)
2995
2996
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
2997
class TestRepositoryIsShared(TestRemoteRepository):
2998
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2999
    def test_is_shared(self):
3000
        # ('yes', ) for Repository.is_shared -> 'True'.
3001
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3002
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3003
        client.add_success_response(b'yes')
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
3004
        result = repo.is_shared()
3005
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3006
            [('call', b'Repository.is_shared', (b'quack/',))],
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
3007
            client._calls)
3008
        self.assertEqual(True, result)
3009
3010
    def test_is_not_shared(self):
3011
        # ('no', ) for Repository.is_shared -> 'False'.
3012
        transport_path = 'qwack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3013
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3014
        client.add_success_response(b'no')
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
3015
        result = repo.is_shared()
3016
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3017
            [('call', b'Repository.is_shared', (b'qwack/',))],
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
3018
            client._calls)
3019
        self.assertEqual(False, result)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3020
3021
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
3022
class TestRepositoryMakeWorkingTrees(TestRemoteRepository):
3023
3024
    def test_make_working_trees(self):
3025
        # ('yes', ) for Repository.make_working_trees -> 'True'.
3026
        transport_path = 'quack'
3027
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3028
        client.add_success_response(b'yes')
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
3029
        result = repo.make_working_trees()
3030
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3031
            [('call', b'Repository.make_working_trees', (b'quack/',))],
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
3032
            client._calls)
3033
        self.assertEqual(True, result)
3034
3035
    def test_no_working_trees(self):
3036
        # ('no', ) for Repository.make_working_trees -> 'False'.
3037
        transport_path = 'qwack'
3038
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3039
        client.add_success_response(b'no')
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
3040
        result = repo.make_working_trees()
3041
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3042
            [('call', b'Repository.make_working_trees', (b'qwack/',))],
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
3043
            client._calls)
3044
        self.assertEqual(False, result)
3045
3046
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3047
class TestRepositoryLockWrite(TestRemoteRepository):
3048
3049
    def test_lock_write(self):
3050
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3051
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3052
        client.add_success_response(b'ok', b'a token')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
3053
        token = repo.lock_write().repository_token
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3054
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3055
            [('call', b'Repository.lock_write', (b'quack/', b''))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3056
            client._calls)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3057
        self.assertEqual(b'a token', token)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3058
3059
    def test_lock_write_already_locked(self):
3060
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3061
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3062
        client.add_error_response(b'LockContention')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3063
        self.assertRaises(errors.LockContention, repo.lock_write)
3064
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3065
            [('call', b'Repository.lock_write', (b'quack/', b''))],
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.
3066
            client._calls)
3067
3068
    def test_lock_write_unlockable(self):
3069
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3070
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3071
        client.add_error_response(b'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.
3072
        self.assertRaises(errors.UnlockableTransport, repo.lock_write)
3073
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3074
            [('call', b'Repository.lock_write', (b'quack/', b''))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3075
            client._calls)
3076
3077
6280.7.1 by Jelmer Vernooij
Implement RemoteRepository side of write group HPSS methods.
3078
class TestRepositoryWriteGroups(TestRemoteRepository):
3079
3080
    def test_start_write_group(self):
3081
        transport_path = 'quack'
3082
        repo, client = self.setup_fake_client_and_repository(transport_path)
3083
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3084
            b'Repository.lock_write', (b'quack/', b''),
3085
            b'success', (b'ok', b'a token'))
6280.7.2 by Jelmer Vernooij
Add HPSS calls ``Repository.start_write_group``, ``Repository.abort_write_group`` and ``Repository.commit_write_group``.
3086
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3087
            b'Repository.start_write_group', (b'quack/', b'a token'),
3088
            b'success', (b'ok', (b'token1', )))
6280.7.2 by Jelmer Vernooij
Add HPSS calls ``Repository.start_write_group``, ``Repository.abort_write_group`` and ``Repository.commit_write_group``.
3089
        repo.lock_write()
6280.7.1 by Jelmer Vernooij
Implement RemoteRepository side of write group HPSS methods.
3090
        repo.start_write_group()
3091
6280.7.8 by Jelmer Vernooij
make sure start_write_group falls back to real_repository if write groups aren't suspendable.
3092
    def test_start_write_group_unsuspendable(self):
3093
        # Some repositories do not support suspending write
3094
        # groups. For those, fall back to the "real" repository.
3095
        transport_path = 'quack'
3096
        repo, client = self.setup_fake_client_and_repository(transport_path)
3097
        def stub_ensure_real():
3098
            client._calls.append(('_ensure_real',))
3099
            repo._real_repository = _StubRealPackRepository(client._calls)
3100
        repo._ensure_real = stub_ensure_real
3101
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3102
            b'Repository.lock_write', (b'quack/', b''),
3103
            b'success', (b'ok', b'a token'))
6280.7.8 by Jelmer Vernooij
make sure start_write_group falls back to real_repository if write groups aren't suspendable.
3104
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3105
            b'Repository.start_write_group', (b'quack/', b'a token'),
3106
            b'error', (b'UnsuspendableWriteGroup',))
6280.7.8 by Jelmer Vernooij
make sure start_write_group falls back to real_repository if write groups aren't suspendable.
3107
        repo.lock_write()
3108
        repo.start_write_group()
6963.1.2 by Jelmer Vernooij
Fix some more tests.
3109
        self.assertEqual(client._calls[-2:], [
6280.7.8 by Jelmer Vernooij
make sure start_write_group falls back to real_repository if write groups aren't suspendable.
3110
            ('_ensure_real',),
3111
            ('start_write_group',)])
3112
6280.7.1 by Jelmer Vernooij
Implement RemoteRepository side of write group HPSS methods.
3113
    def test_commit_write_group(self):
3114
        transport_path = 'quack'
3115
        repo, client = self.setup_fake_client_and_repository(transport_path)
3116
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3117
            b'Repository.lock_write', (b'quack/', b''),
3118
            b'success', (b'ok', b'a token'))
3119
        client.add_expected_call(
3120
            b'Repository.start_write_group', (b'quack/', b'a token'),
3121
            b'success', (b'ok', [b'token1']))
3122
        client.add_expected_call(
3123
            b'Repository.commit_write_group', (b'quack/', b'a token', [b'token1']),
3124
            b'success', (b'ok',))
6280.7.2 by Jelmer Vernooij
Add HPSS calls ``Repository.start_write_group``, ``Repository.abort_write_group`` and ``Repository.commit_write_group``.
3125
        repo.lock_write()
3126
        repo.start_write_group()
6280.7.1 by Jelmer Vernooij
Implement RemoteRepository side of write group HPSS methods.
3127
        repo.commit_write_group()
3128
3129
    def test_abort_write_group(self):
3130
        transport_path = 'quack'
3131
        repo, client = self.setup_fake_client_and_repository(transport_path)
3132
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3133
            b'Repository.lock_write', (b'quack/', b''),
3134
            b'success', (b'ok', b'a token'))
3135
        client.add_expected_call(
3136
            b'Repository.start_write_group', (b'quack/', b'a token'),
3137
            b'success', (b'ok', [b'token1']))
3138
        client.add_expected_call(
3139
            b'Repository.abort_write_group', (b'quack/', b'a token', [b'token1']),
3140
            b'success', (b'ok',))
6280.7.2 by Jelmer Vernooij
Add HPSS calls ``Repository.start_write_group``, ``Repository.abort_write_group`` and ``Repository.commit_write_group``.
3141
        repo.lock_write()
3142
        repo.start_write_group()
6280.7.1 by Jelmer Vernooij
Implement RemoteRepository side of write group HPSS methods.
3143
        repo.abort_write_group(False)
3144
3145
    def test_suspend_write_group(self):
3146
        transport_path = 'quack'
3147
        repo, client = self.setup_fake_client_and_repository(transport_path)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
3148
        self.assertEqual([], repo.suspend_write_group())
6280.7.1 by Jelmer Vernooij
Implement RemoteRepository side of write group HPSS methods.
3149
3150
    def test_resume_write_group(self):
3151
        transport_path = 'quack'
3152
        repo, client = self.setup_fake_client_and_repository(transport_path)
6280.7.6 by Jelmer Vernooij
Fix remaining tests.
3153
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3154
            b'Repository.lock_write', (b'quack/', b''),
3155
            b'success', (b'ok', b'a token'))
6280.7.6 by Jelmer Vernooij
Fix remaining tests.
3156
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3157
            b'Repository.check_write_group', (b'quack/', b'a token', [b'token1']),
3158
            b'success', (b'ok',))
6280.7.6 by Jelmer Vernooij
Fix remaining tests.
3159
        repo.lock_write()
7045.2.20 by Jelmer Vernooij
Fix remaining tests.
3160
        repo.resume_write_group(['token1'])
6280.7.1 by Jelmer Vernooij
Implement RemoteRepository side of write group HPSS methods.
3161
3162
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
3163
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
3164
3165
    def test_backwards_compat(self):
3166
        self.setup_smart_server_with_call_log()
3167
        repo = self.make_repository('.')
3168
        self.reset_smart_call_log()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3169
        verb = b'Repository.set_make_working_trees'
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
3170
        self.disable_verb(verb)
3171
        repo.set_make_working_trees(True)
3172
        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.
3173
            call.call.method == verb])
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
3174
        self.assertEqual(1, call_count)
3175
3176
    def test_current(self):
3177
        transport_path = 'quack'
3178
        repo, client = self.setup_fake_client_and_repository(transport_path)
3179
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3180
            b'Repository.set_make_working_trees', (b'quack/', b'True'),
3181
            b'success', (b'ok',))
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
3182
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3183
            b'Repository.set_make_working_trees', (b'quack/', b'False'),
3184
            b'success', (b'ok',))
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
3185
        repo.set_make_working_trees(True)
3186
        repo.set_make_working_trees(False)
3187
3188
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3189
class TestRepositoryUnlock(TestRemoteRepository):
3190
3191
    def test_unlock(self):
3192
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3193
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3194
        client.add_success_response(b'ok', b'a token')
3195
        client.add_success_response(b'ok')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3196
        repo.lock_write()
3197
        repo.unlock()
3198
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3199
            [('call', b'Repository.lock_write', (b'quack/', b'')),
3200
             ('call', b'Repository.unlock', (b'quack/', b'a token'))],
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3201
            client._calls)
3202
3203
    def test_unlock_wrong_token(self):
3204
        # If somehow the token is wrong, unlock will raise TokenMismatch.
3205
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3206
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3207
        client.add_success_response(b'ok', b'a token')
3208
        client.add_error_response(b'TokenMismatch')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
3209
        repo.lock_write()
3210
        self.assertRaises(errors.TokenMismatch, repo.unlock)
3211
3212
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
3213
class TestRepositoryHasRevision(TestRemoteRepository):
3214
3215
    def test_none(self):
3216
        # repo.has_revision(None) should not cause any traffic.
3217
        transport_path = 'quack'
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3218
        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.
3219
3220
        # The null revision is always there, so has_revision(None) == True.
3172.3.3 by Robert Collins
Missed one occurence of None -> NULL_REVISION.
3221
        self.assertEqual(True, repo.has_revision(NULL_REVISION))
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
3222
3223
        # The remote repo shouldn't be accessed.
3224
        self.assertEqual([], client._calls)
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
3225
3226
6280.10.7 by Jelmer Vernooij
Fix remote.
3227
class TestRepositoryIterFilesBytes(TestRemoteRepository):
6280.10.1 by Jelmer Vernooij
Add remote side of Repository.iter_file_bytes.
3228
    """Test Repository.iter_file_bytes."""
3229
3230
    def test_single(self):
3231
        transport_path = 'quack'
3232
        repo, client = self.setup_fake_client_and_repository(transport_path)
3233
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3234
            b'Repository.iter_files_bytes', (b'quack/', ),
3235
            b'success', (b'ok',), iter([b"ok\x000", b"\n", zlib.compress(b"mydata" * 10)]))
3236
        for (identifier, byte_stream) in repo.iter_files_bytes([(b"somefile",
3237
                b"somerev", b"myid")]):
3238
            self.assertEqual(b"myid", identifier)
3239
            self.assertEqual(b"".join(byte_stream), b"mydata" * 10)
6280.10.1 by Jelmer Vernooij
Add remote side of Repository.iter_file_bytes.
3240
6280.10.3 by Jelmer Vernooij
Fix iter_file_bytes.
3241
    def test_missing(self):
3242
        transport_path = 'quack'
3243
        repo, client = self.setup_fake_client_and_repository(transport_path)
3244
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3245
            b'Repository.iter_files_bytes',
3246
                (b'quack/', ),
3247
            b'error', (b'RevisionNotPresent', b'somefile', b'somerev'),
3248
            iter([b"absent\0somefile\0somerev\n"]))
6280.10.3 by Jelmer Vernooij
Fix iter_file_bytes.
3249
        self.assertRaises(errors.RevisionNotPresent, list,
3250
                repo.iter_files_bytes(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3251
                [(b"somefile", b"somerev", b"myid")]))
6280.10.3 by Jelmer Vernooij
Fix iter_file_bytes.
3252
6280.10.1 by Jelmer Vernooij
Add remote side of Repository.iter_file_bytes.
3253
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3254
class TestRepositoryInsertStreamBase(TestRemoteRepository):
4476.3.82 by Andrew Bennetts
Mention another bug fix in NEWS, and update verb name, comments, and NEWS additions for landing on 1.19 rather than 1.18.
3255
    """Base class for Repository.insert_stream and .insert_stream_1.19
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3256
    tests.
3257
    """
3258
    
3259
    def checkInsertEmptyStream(self, repo, client):
3260
        """Insert an empty stream, checking the result.
3261
3262
        This checks that there are no resume_tokens or missing_keys, and that
3263
        the client is finished.
3264
        """
3265
        sink = repo._get_sink()
5651.3.9 by Jelmer Vernooij
Avoid using deprecated functions.
3266
        fmt = repository.format_registry.get_default()
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3267
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
3268
        self.assertEqual([], resume_tokens)
3269
        self.assertEqual(set(), missing_keys)
3270
        self.assertFinished(client)
3271
3272
3273
class TestRepositoryInsertStream(TestRepositoryInsertStreamBase):
4476.3.82 by Andrew Bennetts
Mention another bug fix in NEWS, and update verb name, comments, and NEWS additions for landing on 1.19 rather than 1.18.
3274
    """Tests for using Repository.insert_stream verb when the _1.19 variant is
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3275
    not available.
3276
4476.3.82 by Andrew Bennetts
Mention another bug fix in NEWS, and update verb name, comments, and NEWS additions for landing on 1.19 rather than 1.18.
3277
    This test case is very similar to TestRepositoryInsertStream_1_19.
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3278
    """
3279
3280
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
3281
        super(TestRepositoryInsertStream, self).setUp()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3282
        self.disable_verb(b'Repository.insert_stream_1.19')
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3283
3284
    def test_unlocked_repo(self):
3285
        transport_path = 'quack'
3286
        repo, client = self.setup_fake_client_and_repository(transport_path)
3287
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3288
            b'Repository.insert_stream_1.19', (b'quack/', b''),
3289
            b'unknown', (b'Repository.insert_stream_1.19',))
3290
        client.add_expected_call(
3291
            b'Repository.insert_stream', (b'quack/', b''),
3292
            b'success', (b'ok',))
3293
        client.add_expected_call(
3294
            b'Repository.insert_stream', (b'quack/', b''),
3295
            b'success', (b'ok',))
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3296
        self.checkInsertEmptyStream(repo, client)
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3297
3298
    def test_locked_repo_with_no_lock_token(self):
3299
        transport_path = 'quack'
3300
        repo, client = self.setup_fake_client_and_repository(transport_path)
3301
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3302
            b'Repository.lock_write', (b'quack/', b''),
3303
            b'success', (b'ok', b''))
3304
        client.add_expected_call(
3305
            b'Repository.insert_stream_1.19', (b'quack/', b''),
3306
            b'unknown', (b'Repository.insert_stream_1.19',))
3307
        client.add_expected_call(
3308
            b'Repository.insert_stream', (b'quack/', b''),
3309
            b'success', (b'ok',))
3310
        client.add_expected_call(
3311
            b'Repository.insert_stream', (b'quack/', b''),
3312
            b'success', (b'ok',))
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3313
        repo.lock_write()
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3314
        self.checkInsertEmptyStream(repo, client)
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3315
3316
    def test_locked_repo_with_lock_token(self):
3317
        transport_path = 'quack'
3318
        repo, client = self.setup_fake_client_and_repository(transport_path)
3319
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3320
            b'Repository.lock_write', (b'quack/', b''),
3321
            b'success', (b'ok', b'a token'))
3322
        client.add_expected_call(
3323
            b'Repository.insert_stream_1.19', (b'quack/', b'', b'a token'),
3324
            b'unknown', (b'Repository.insert_stream_1.19',))
3325
        client.add_expected_call(
3326
            b'Repository.insert_stream_locked', (b'quack/', b'', b'a token'),
3327
            b'success', (b'ok',))
3328
        client.add_expected_call(
3329
            b'Repository.insert_stream_locked', (b'quack/', b'', b'a token'),
3330
            b'success', (b'ok',))
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3331
        repo.lock_write()
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3332
        self.checkInsertEmptyStream(repo, client)
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3333
4476.3.56 by Andrew Bennetts
Update test_stream_with_inventory_deltas for inventory-deltas substream.
3334
    def test_stream_with_inventory_deltas(self):
4476.3.71 by Andrew Bennetts
Clearer comments prompted by Robert's review.
3335
        """'inventory-deltas' substreams cannot be sent to the
3336
        Repository.insert_stream verb, because not all servers that implement
3337
        that verb will accept them.  So when one is encountered the RemoteSink
3338
        immediately stops using that verb and falls back to VFS insert_stream.
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3339
        """
3340
        transport_path = 'quack'
3341
        repo, client = self.setup_fake_client_and_repository(transport_path)
3342
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3343
            b'Repository.insert_stream_1.19', (b'quack/', b''),
3344
            b'unknown', (b'Repository.insert_stream_1.19',))
3345
        client.add_expected_call(
3346
            b'Repository.insert_stream', (b'quack/', b''),
3347
            b'success', (b'ok',))
3348
        client.add_expected_call(
3349
            b'Repository.insert_stream', (b'quack/', b''),
3350
            b'success', (b'ok',))
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3351
        # Create a fake real repository for insert_stream to fall back on, so
3352
        # that we can directly see the records the RemoteSink passes to the
3353
        # real sink.
3354
        class FakeRealSink:
3355
            def __init__(self):
3356
                self.records = []
3357
            def insert_stream(self, stream, src_format, resume_tokens):
3358
                for substream_kind, substream in stream:
3359
                    self.records.append(
3360
                        (substream_kind, [record.key for record in substream]))
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3361
                return [b'fake tokens'], [b'fake missing keys']
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3362
        fake_real_sink = FakeRealSink()
3363
        class FakeRealRepository:
3364
            def _get_sink(self):
3365
                return fake_real_sink
4634.35.20 by Andrew Bennetts
Fix test_remote.
3366
            def is_in_write_group(self):
3367
                return False
3368
            def refresh_data(self):
3369
                return True
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3370
        repo._real_repository = FakeRealRepository()
3371
        sink = repo._get_sink()
5651.3.9 by Jelmer Vernooij
Avoid using deprecated functions.
3372
        fmt = repository.format_registry.get_default()
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3373
        stream = self.make_stream_with_inv_deltas(fmt)
3374
        resume_tokens, missing_keys = sink.insert_stream(stream, fmt, [])
3375
        # Every record from the first inventory delta should have been sent to
3376
        # the VFS sink.
3377
        expected_records = [
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3378
            ('inventory-deltas', [(b'rev2',), (b'rev3',)]),
3379
            ('texts', [(b'some-rev', b'some-file')])]
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3380
        self.assertEqual(expected_records, fake_real_sink.records)
3381
        # The return values from the real sink's insert_stream are propagated
3382
        # back to the original caller.
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3383
        self.assertEqual([b'fake tokens'], resume_tokens)
3384
        self.assertEqual([b'fake missing keys'], missing_keys)
4476.3.40 by Andrew Bennetts
Merge bzr.dev.
3385
        self.assertFinished(client)
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3386
3387
    def make_stream_with_inv_deltas(self, fmt):
3388
        """Make a simple stream with an inventory delta followed by more
3389
        records and more substreams to test that all records and substreams
3390
        from that point on are used.
3391
3392
        This sends, in order:
3393
           * inventories substream: rev1, rev2, rev3.  rev2 and rev3 are
3394
             inventory-deltas.
3395
           * texts substream: (some-rev, some-file)
3396
        """
3397
        # Define a stream using generators so that it isn't rewindable.
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3398
        inv = inventory.Inventory(revision_id=b'rev1')
3399
        inv.root.revision = b'rev1'
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3400
        def stream_with_inv_delta():
4476.3.56 by Andrew Bennetts
Update test_stream_with_inventory_deltas for inventory-deltas substream.
3401
            yield ('inventories', inventories_substream())
3402
            yield ('inventory-deltas', inventory_delta_substream())
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3403
            yield ('texts', [
3404
                versionedfile.FulltextContentFactory(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
3405
                    (b'some-rev', b'some-file'), (), None, b'content')])
4476.3.56 by Andrew Bennetts
Update test_stream_with_inventory_deltas for inventory-deltas substream.
3406
        def inventories_substream():
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3407
            # An empty inventory fulltext.  This will be streamed normally.
3408
            text = fmt._serializer.write_inventory_to_string(inv)
3409
            yield versionedfile.FulltextContentFactory(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3410
                (b'rev1',), (), None, text)
4476.3.56 by Andrew Bennetts
Update test_stream_with_inventory_deltas for inventory-deltas substream.
3411
        def inventory_delta_substream():
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3412
            # An inventory delta.  This can't be streamed via this verb, so it
3413
            # will trigger a fallback to VFS insert_stream.
3414
            entry = inv.make_entry(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3415
                'directory', 'newdir', inv.root.file_id, b'newdir-id')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
3416
            entry.revision = b'ghost'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3417
            delta = [(None, 'newdir', b'newdir-id', entry)]
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
3418
            serializer = inventory_delta.InventoryDeltaSerializer(
3419
                versioned_root=True, tree_references=False)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3420
            lines = serializer.delta_to_lines(b'rev1', b'rev2', delta)
4476.3.56 by Andrew Bennetts
Update test_stream_with_inventory_deltas for inventory-deltas substream.
3421
            yield versionedfile.ChunkedContentFactory(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3422
                (b'rev2',), ((b'rev1',)), None, lines)
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3423
            # Another delta.
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3424
            lines = serializer.delta_to_lines(b'rev1', b'rev3', delta)
4476.3.56 by Andrew Bennetts
Update test_stream_with_inventory_deltas for inventory-deltas substream.
3425
            yield versionedfile.ChunkedContentFactory(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3426
                (b'rev3',), ((b'rev1',)), None, lines)
4476.3.36 by Andrew Bennetts
Add a somewhat complex test to exercise the fallback-to-vfs logic in RemoteSink when an inventory-delta is encountered and the 1.18 verb isn't accepted.
3427
        return stream_with_inv_delta()
3428
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3429
4476.3.82 by Andrew Bennetts
Mention another bug fix in NEWS, and update verb name, comments, and NEWS additions for landing on 1.19 rather than 1.18.
3430
class TestRepositoryInsertStream_1_19(TestRepositoryInsertStreamBase):
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3431
3432
    def test_unlocked_repo(self):
3433
        transport_path = 'quack'
3434
        repo, client = self.setup_fake_client_and_repository(transport_path)
3435
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3436
            b'Repository.insert_stream_1.19', (b'quack/', b''),
3437
            b'success', (b'ok',))
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3438
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3439
            b'Repository.insert_stream_1.19', (b'quack/', b''),
3440
            b'success', (b'ok',))
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3441
        self.checkInsertEmptyStream(repo, client)
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3442
3443
    def test_locked_repo_with_no_lock_token(self):
3444
        transport_path = 'quack'
3445
        repo, client = self.setup_fake_client_and_repository(transport_path)
3446
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3447
            b'Repository.lock_write', (b'quack/', b''),
3448
            b'success', (b'ok', b''))
3449
        client.add_expected_call(
3450
            b'Repository.insert_stream_1.19', (b'quack/', b''),
3451
            b'success', (b'ok',))
3452
        client.add_expected_call(
3453
            b'Repository.insert_stream_1.19', (b'quack/', b''),
3454
            b'success', (b'ok',))
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3455
        repo.lock_write()
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3456
        self.checkInsertEmptyStream(repo, client)
4476.3.32 by Andrew Bennetts
Move disable_verb into base TestCase to remove duplication, fix trivial test failures due to new insert_stream verb in test_remote (and also add some trivial tests for the new verb).
3457
3458
    def test_locked_repo_with_lock_token(self):
3459
        transport_path = 'quack'
3460
        repo, client = self.setup_fake_client_and_repository(transport_path)
3461
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3462
            b'Repository.lock_write', (b'quack/', b''),
3463
            b'success', (b'ok', b'a token'))
3464
        client.add_expected_call(
3465
            b'Repository.insert_stream_1.19', (b'quack/', b'', b'a token'),
3466
            b'success', (b'ok',))
3467
        client.add_expected_call(
3468
            b'Repository.insert_stream_1.19', (b'quack/', b'', b'a token'),
3469
            b'success', (b'ok',))
4144.3.2 by Andrew Bennetts
Use Repository.insert_stream_locked if there is a lock_token for the remote repo.
3470
        repo.lock_write()
4476.3.79 by Andrew Bennetts
Remove a bit of duplication from Repository.insert_stream* tests.
3471
        self.checkInsertEmptyStream(repo, client)
4144.3.2 by Andrew Bennetts
Use Repository.insert_stream_locked if there is a lock_token for the remote repo.
3472
3473
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
3474
class TestRepositoryTarball(TestRemoteRepository):
3475
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
3476
    # This is a canned tarball reponse we can validate against
6791.2.3 by Jelmer Vernooij
Fix more imports.
3477
    tarball_content = base64.b64decode(
2018.18.23 by Martin Pool
review cleanups
3478
        'QlpoOTFBWSZTWdGkj3wAAWF/k8aQACBIB//A9+8cIX/v33AACEAYABAECEACNz'
3479
        'JqsgJJFPTSnk1A3qh6mTQAAAANPUHkagkSTEkaA09QaNAAAGgAAAcwCYCZGAEY'
3480
        'mJhMJghpiaYBUkKammSHqNMZQ0NABkNAeo0AGneAevnlwQoGzEzNVzaYxp/1Uk'
3481
        'xXzA1CQX0BJMZZLcPBrluJir5SQyijWHYZ6ZUtVqqlYDdB2QoCwa9GyWwGYDMA'
3482
        'OQYhkpLt/OKFnnlT8E0PmO8+ZNSo2WWqeCzGB5fBXZ3IvV7uNJVE7DYnWj6qwB'
3483
        'k5DJDIrQ5OQHHIjkS9KqwG3mc3t+F1+iujb89ufyBNIKCgeZBWrl5cXxbMGoMs'
3484
        'c9JuUkg5YsiVcaZJurc6KLi6yKOkgCUOlIlOpOoXyrTJjK8ZgbklReDdwGmFgt'
3485
        'dkVsAIslSVCd4AtACSLbyhLHryfb14PKegrVDba+U8OL6KQtzdM5HLjAc8/p6n'
3486
        '0lgaWU8skgO7xupPTkyuwheSckejFLK5T4ZOo0Gda9viaIhpD1Qn7JqqlKAJqC'
3487
        'QplPKp2nqBWAfwBGaOwVrz3y1T+UZZNismXHsb2Jq18T+VaD9k4P8DqE3g70qV'
3488
        'JLurpnDI6VS5oqDDPVbtVjMxMxMg4rzQVipn2Bv1fVNK0iq3Gl0hhnnHKm/egy'
3489
        'nWQ7QH/F3JFOFCQ0aSPfA='
6791.2.3 by Jelmer Vernooij
Fix more imports.
3490
        )
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
3491
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
3492
    def test_repository_tarball(self):
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
3493
        # Test that Repository.tarball generates the right operations
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
3494
        transport_path = 'repo'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3495
        expected_calls = [('call_expecting_body', b'Repository.tarball',
3496
                           (b'repo/', b'bz2',),),
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
3497
            ]
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3498
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3499
        client.add_success_response_with_body(self.tarball_content, b'ok')
2018.18.7 by Martin Pool
(broken) Start addng client proxy test for Repository.tarball
3500
        # Now actually ask for the tarball
3245.4.24 by Andrew Bennetts
Consistently raise errors from the server as ErrorFromSmartServer exceptions.
3501
        tarball_file = repo._get_tarball('bz2')
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
3502
        try:
3503
            self.assertEqual(expected_calls, client._calls)
3504
            self.assertEqual(self.tarball_content, tarball_file.read())
3505
        finally:
3506
            tarball_file.close()
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
3507
3508
3509
class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):
3510
    """RemoteRepository.copy_content_into optimizations"""
3511
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
3512
    def test_copy_content_remote_to_local(self):
5017.3.28 by Vincent Ladeuil
selftest -s bt.test_remote passing
3513
        self.transport_server = test_server.SmartTCPServer_for_testing
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
3514
        src_repo = self.make_repository('repo1')
3515
        src_repo = repository.Repository.open(self.get_url('repo1'))
3516
        # At the moment the tarball-based copy_content_into can't write back
3517
        # into a smart server.  It would be good if it could upload the
3518
        # tarball; once that works we'd have to create repositories of
3519
        # different formats. -- mbp 20070410
3520
        dest_url = self.get_vfs_only_url('repo2')
3521
        dest_bzrdir = BzrDir.create(dest_url)
3522
        dest_repo = dest_bzrdir.create_repository()
3523
        self.assertFalse(isinstance(dest_repo, RemoteRepository))
3524
        self.assertTrue(isinstance(src_repo, RemoteRepository))
3525
        src_repo.copy_content_into(dest_repo)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3526
3527
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3528
class _StubRealPackRepository(object):
3529
3530
    def __init__(self, calls):
4145.1.6 by Robert Collins
More test fallout, but all caught now.
3531
        self.calls = calls
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3532
        self._pack_collection = _StubPackCollection(calls)
3533
6280.7.8 by Jelmer Vernooij
make sure start_write_group falls back to real_repository if write groups aren't suspendable.
3534
    def start_write_group(self):
3535
        self.calls.append(('start_write_group',))
3536
4145.1.6 by Robert Collins
More test fallout, but all caught now.
3537
    def is_in_write_group(self):
3538
        return False
3539
3540
    def refresh_data(self):
3541
        self.calls.append(('pack collection reload_pack_names',))
3542
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3543
3544
class _StubPackCollection(object):
3545
3546
    def __init__(self, calls):
3547
        self.calls = calls
3548
3549
    def autopack(self):
3550
        self.calls.append(('pack collection autopack',))
3551
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
3552
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3553
class TestRemotePackRepositoryAutoPack(TestRemoteRepository):
3554
    """Tests for RemoteRepository.autopack implementation."""
3555
3556
    def test_ok(self):
3557
        """When the server returns 'ok' and there's no _real_repository, then
3558
        nothing else happens: the autopack method is done.
3559
        """
3560
        transport_path = 'quack'
3561
        repo, client = self.setup_fake_client_and_repository(transport_path)
3562
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3563
            b'PackRepository.autopack', (b'quack/',), b'success', (b'ok',))
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3564
        repo.autopack()
4523.3.1 by Andrew Bennetts
Change FakeClient.finished_test into a more typical assertion method on TestRemote.
3565
        self.assertFinished(client)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3566
3567
    def test_ok_with_real_repo(self):
3568
        """When the server returns 'ok' and there is a _real_repository, then
3569
        the _real_repository's reload_pack_name's method will be called.
3570
        """
3571
        transport_path = 'quack'
3572
        repo, client = self.setup_fake_client_and_repository(transport_path)
3573
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3574
            b'PackRepository.autopack', (b'quack/',),
3575
            b'success', (b'ok',))
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3576
        repo._real_repository = _StubRealPackRepository(client._calls)
3577
        repo.autopack()
3578
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3579
            [('call', b'PackRepository.autopack', (b'quack/',)),
3801.1.13 by Andrew Bennetts
Revert returning of pack-names from the RPC.
3580
             ('pack collection reload_pack_names',)],
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3581
            client._calls)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
3582
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3583
    def test_backwards_compatibility(self):
3584
        """If the server does not recognise the PackRepository.autopack verb,
3585
        fallback to the real_repository's implementation.
3586
        """
3587
        transport_path = 'quack'
3588
        repo, client = self.setup_fake_client_and_repository(transport_path)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3589
        client.add_unknown_method_response(b'PackRepository.autopack')
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3590
        def stub_ensure_real():
3591
            client._calls.append(('_ensure_real',))
3592
            repo._real_repository = _StubRealPackRepository(client._calls)
3593
        repo._ensure_real = stub_ensure_real
3594
        repo.autopack()
3595
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3596
            [('call', b'PackRepository.autopack', (b'quack/',)),
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3597
             ('_ensure_real',),
3598
             ('pack collection autopack',)],
3599
            client._calls)
3600
5677.2.2 by Martin
Give clearer message when remote server reports a MemoryError
3601
    def test_oom_error_reporting(self):
3602
        """An out-of-memory condition on the server is reported clearly"""
3603
        transport_path = 'quack'
3604
        repo, client = self.setup_fake_client_and_repository(transport_path)
3605
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3606
            b'PackRepository.autopack', (b'quack/',),
3607
            b'error', (b'MemoryError',))
5677.2.2 by Martin
Give clearer message when remote server reports a MemoryError
3608
        err = self.assertRaises(errors.BzrError, repo.autopack)
3609
        self.assertContainsRe(str(err), "^remote server out of mem")
3610
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3611
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3612
class TestErrorTranslationBase(tests.TestCaseWithMemoryTransport):
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
3613
    """Base class for unit tests for breezy.bzr.remote._translate_error."""
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3614
3615
    def translateTuple(self, error_tuple, **context):
3616
        """Call _translate_error with an ErrorFromSmartServer built from the
3617
        given error_tuple.
3618
3619
        :param error_tuple: A tuple of a smart server response, as would be
3620
            passed to an ErrorFromSmartServer.
3621
        :kwargs context: context items to call _translate_error with.
3622
3623
        :returns: The error raised by _translate_error.
3624
        """
3625
        # Raise the ErrorFromSmartServer before passing it as an argument,
3626
        # because _translate_error may need to re-raise it with a bare 'raise'
3627
        # statement.
3628
        server_error = errors.ErrorFromSmartServer(error_tuple)
3629
        translated_error = self.translateErrorFromSmartServer(
3630
            server_error, **context)
3631
        return translated_error
3632
3633
    def translateErrorFromSmartServer(self, error_object, **context):
3634
        """Like translateTuple, but takes an already constructed
3635
        ErrorFromSmartServer rather than a tuple.
3636
        """
3637
        try:
3638
            raise error_object
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
3639
        except errors.ErrorFromSmartServer as server_error:
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3640
            translated_error = self.assertRaises(
3641
                errors.BzrError, remote._translate_error, server_error,
3642
                **context)
3643
        return translated_error
3644
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
3645
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3646
class TestErrorTranslationSuccess(TestErrorTranslationBase):
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
3647
    """Unit tests for breezy.bzr.remote._translate_error.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
3648
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3649
    Given an ErrorFromSmartServer (which has an error tuple from a smart
3650
    server) and some context, _translate_error raises more specific errors from
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
3651
    breezy.errors.
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3652
3653
    This test case covers the cases where _translate_error succeeds in
3654
    translating an ErrorFromSmartServer to something better.  See
3655
    TestErrorTranslationRobustness for other cases.
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3656
    """
3657
3658
    def test_NoSuchRevision(self):
3659
        branch = self.make_branch('')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3660
        revid = b'revid'
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3661
        translated_error = self.translateTuple(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3662
            (b'NoSuchRevision', revid), branch=branch)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3663
        expected_error = errors.NoSuchRevision(branch, revid)
3664
        self.assertEqual(expected_error, translated_error)
3665
3666
    def test_nosuchrevision(self):
3667
        repository = self.make_repository('')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3668
        revid = b'revid'
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3669
        translated_error = self.translateTuple(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3670
            (b'nosuchrevision', revid), repository=repository)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3671
        expected_error = errors.NoSuchRevision(repository, revid)
3672
        self.assertEqual(expected_error, translated_error)
3673
3674
    def test_nobranch(self):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
3675
        bzrdir = self.make_controldir('')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3676
        translated_error = self.translateTuple((b'nobranch',), bzrdir=bzrdir)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3677
        expected_error = errors.NotBranchError(path=bzrdir.root_transport.base)
3678
        self.assertEqual(expected_error, translated_error)
3679
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
3680
    def test_nobranch_one_arg(self):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
3681
        bzrdir = self.make_controldir('')
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
3682
        translated_error = self.translateTuple(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3683
            (b'nobranch', b'extra detail'), bzrdir=bzrdir)
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
3684
        expected_error = errors.NotBranchError(
3685
            path=bzrdir.root_transport.base,
3686
            detail='extra detail')
3687
        self.assertEqual(expected_error, translated_error)
3688
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3689
    def test_norepository(self):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
3690
        bzrdir = self.make_controldir('')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3691
        translated_error = self.translateTuple((b'norepository',),
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3692
            bzrdir=bzrdir)
3693
        expected_error = errors.NoRepositoryPresent(bzrdir)
3694
        self.assertEqual(expected_error, translated_error)
3695
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3696
    def test_LockContention(self):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3697
        translated_error = self.translateTuple((b'LockContention',))
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3698
        expected_error = errors.LockContention('(remote lock)')
3699
        self.assertEqual(expected_error, translated_error)
3700
3701
    def test_UnlockableTransport(self):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
3702
        bzrdir = self.make_controldir('')
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3703
        translated_error = self.translateTuple(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3704
            (b'UnlockableTransport',), bzrdir=bzrdir)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3705
        expected_error = errors.UnlockableTransport(bzrdir.root_transport)
3706
        self.assertEqual(expected_error, translated_error)
3707
3708
    def test_LockFailed(self):
3709
        lock = 'str() of a server lock'
3710
        why = 'str() of why'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3711
        translated_error = self.translateTuple((b'LockFailed', lock.encode('ascii'), why.encode('ascii')))
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3712
        expected_error = errors.LockFailed(lock, why)
3713
        self.assertEqual(expected_error, translated_error)
3714
3715
    def test_TokenMismatch(self):
3716
        token = 'a lock token'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3717
        translated_error = self.translateTuple((b'TokenMismatch',), token=token)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3718
        expected_error = errors.TokenMismatch(token, '(remote token)')
3719
        self.assertEqual(expected_error, translated_error)
3720
3721
    def test_Diverged(self):
3722
        branch = self.make_branch('a')
3723
        other_branch = self.make_branch('b')
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3724
        translated_error = self.translateTuple(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3725
            (b'Diverged',), branch=branch, other_branch=other_branch)
3533.3.3 by Andrew Bennetts
Add unit tests for bzrlib.remote._translate_error.
3726
        expected_error = errors.DivergedBranches(branch, other_branch)
3727
        self.assertEqual(expected_error, translated_error)
3728
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3729
    def test_NotStacked(self):
3730
        branch = self.make_branch('')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3731
        translated_error = self.translateTuple((b'NotStacked',), branch=branch)
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3732
        expected_error = errors.NotStacked(branch)
3733
        self.assertEqual(expected_error, translated_error)
3734
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3735
    def test_ReadError_no_args(self):
3736
        path = 'a path'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3737
        translated_error = self.translateTuple((b'ReadError',), path=path)
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3738
        expected_error = errors.ReadError(path)
3739
        self.assertEqual(expected_error, translated_error)
3740
3741
    def test_ReadError(self):
3742
        path = 'a path'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3743
        translated_error = self.translateTuple((b'ReadError', path.encode('utf-8')))
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3744
        expected_error = errors.ReadError(path)
3745
        self.assertEqual(expected_error, translated_error)
3746
4650.2.1 by Robert Collins
Deserialise IncompatibleRepositories errors in the client, generating
3747
    def test_IncompatibleRepositories(self):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3748
        translated_error = self.translateTuple((b'IncompatibleRepositories',
3749
            b"repo1", b"repo2", b"details here"))
4650.2.1 by Robert Collins
Deserialise IncompatibleRepositories errors in the client, generating
3750
        expected_error = errors.IncompatibleRepositories("repo1", "repo2",
3751
            "details here")
3752
        self.assertEqual(expected_error, translated_error)
3753
6969.1.1 by Jelmer Vernooij
Handle GhostRevisionsHaveNoRevno in hpss.
3754
    def test_GhostRevisionsHaveNoRevno(self):
3755
        translated_error = self.translateTuple((b'GhostRevisionsHaveNoRevno',
3756
            b"revid1", b"revid2"))
3757
        expected_error = errors.GhostRevisionsHaveNoRevno(b"revid1", b"revid2")
3758
        self.assertEqual(expected_error, translated_error)
3759
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3760
    def test_PermissionDenied_no_args(self):
3761
        path = 'a path'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3762
        translated_error = self.translateTuple((b'PermissionDenied',),
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3763
            path=path)
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3764
        expected_error = errors.PermissionDenied(path)
3765
        self.assertEqual(expected_error, translated_error)
3766
3767
    def test_PermissionDenied_one_arg(self):
3768
        path = 'a path'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3769
        translated_error = self.translateTuple((b'PermissionDenied', path.encode('utf-8')))
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3770
        expected_error = errors.PermissionDenied(path)
3771
        self.assertEqual(expected_error, translated_error)
3772
3773
    def test_PermissionDenied_one_arg_and_context(self):
3774
        """Given a choice between a path from the local context and a path on
3775
        the wire, _translate_error prefers the path from the local context.
3776
        """
3777
        local_path = 'local path'
3778
        remote_path = 'remote path'
3779
        translated_error = self.translateTuple(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3780
            (b'PermissionDenied', remote_path.encode('utf-8')), path=local_path)
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3781
        expected_error = errors.PermissionDenied(local_path)
3782
        self.assertEqual(expected_error, translated_error)
3783
3784
    def test_PermissionDenied_two_args(self):
3785
        path = 'a path'
3786
        extra = 'a string with extra info'
3787
        translated_error = self.translateTuple(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3788
            (b'PermissionDenied', path.encode('utf-8'), extra.encode('utf-8')))
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3789
        expected_error = errors.PermissionDenied(path, extra)
3790
        self.assertEqual(expected_error, translated_error)
3791
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3792
    # GZ 2011-03-02: TODO test for PermissionDenied with non-ascii 'extra'
3793
3794
    def test_NoSuchFile_context_path(self):
3795
        local_path = "local path"
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3796
        translated_error = self.translateTuple((b'ReadError', b"remote path"),
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3797
            path=local_path)
3798
        expected_error = errors.ReadError(local_path)
3799
        self.assertEqual(expected_error, translated_error)
3800
3801
    def test_NoSuchFile_without_context(self):
3802
        remote_path = "remote path"
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3803
        translated_error = self.translateTuple((b'ReadError', remote_path.encode('utf-8')))
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3804
        expected_error = errors.ReadError(remote_path)
3805
        self.assertEqual(expected_error, translated_error)
3806
3807
    def test_ReadOnlyError(self):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3808
        translated_error = self.translateTuple((b'ReadOnlyError',))
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3809
        expected_error = errors.TransportNotPossible("readonly transport")
3810
        self.assertEqual(expected_error, translated_error)
3811
3812
    def test_MemoryError(self):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3813
        translated_error = self.translateTuple((b'MemoryError',))
5677.2.9 by Martin
Add hint to possible ways forward for user in remote MemoryError message
3814
        self.assertStartsWith(str(translated_error),
3815
            "remote server out of memory")
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3816
5677.2.8 by Martin
More tests for handling of unexpected remote errors
3817
    def test_generic_IndexError_no_classname(self):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3818
        err = errors.ErrorFromSmartServer((b'error', b"list index out of range"))
5677.2.5 by Martin
Add more tests for remote._translate_error including for MemoryError handling
3819
        translated_error = self.translateErrorFromSmartServer(err)
3820
        expected_error = errors.UnknownErrorFromSmartServer(err)
3821
        self.assertEqual(expected_error, translated_error)
3822
3823
    # GZ 2011-03-02: TODO test generic non-ascii error string
3824
5677.2.8 by Martin
More tests for handling of unexpected remote errors
3825
    def test_generic_KeyError(self):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3826
        err = errors.ErrorFromSmartServer((b'error', b'KeyError', b"1"))
5677.2.8 by Martin
More tests for handling of unexpected remote errors
3827
        translated_error = self.translateErrorFromSmartServer(err)
3828
        expected_error = errors.UnknownErrorFromSmartServer(err)
3829
        self.assertEqual(expected_error, translated_error)
3830
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3831
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3832
class TestErrorTranslationRobustness(TestErrorTranslationBase):
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
3833
    """Unit tests for breezy.bzr.remote._translate_error's robustness.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
3834
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3835
    TestErrorTranslationSuccess is for cases where _translate_error can
3836
    translate successfully.  This class about how _translate_err behaves when
3837
    it fails to translate: it re-raises the original error.
3838
    """
3839
3840
    def test_unrecognised_server_error(self):
3841
        """If the error code from the server is not recognised, the original
3842
        ErrorFromSmartServer is propagated unmodified.
3843
        """
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3844
        error_tuple = (b'An unknown error tuple',)
3690.1.2 by Andrew Bennetts
Rename UntranslateableErrorFromSmartServer -> UnknownErrorFromSmartServer.
3845
        server_error = errors.ErrorFromSmartServer(error_tuple)
3846
        translated_error = self.translateErrorFromSmartServer(server_error)
3847
        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.
3848
        self.assertEqual(expected_error, translated_error)
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3849
3850
    def test_context_missing_a_key(self):
3851
        """In case of a bug in the client, or perhaps an unexpected response
3852
        from a server, _translate_error returns the original error tuple from
3853
        the server and mutters a warning.
3854
        """
3855
        # To translate a NoSuchRevision error _translate_error needs a 'branch'
3856
        # in the context dict.  So let's give it an empty context dict instead
3857
        # to exercise its error recovery.
3858
        empty_context = {}
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3859
        error_tuple = (b'NoSuchRevision', b'revid')
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3860
        server_error = errors.ErrorFromSmartServer(error_tuple)
3861
        translated_error = self.translateErrorFromSmartServer(server_error)
3862
        self.assertEqual(server_error, translated_error)
3863
        # In addition to re-raising ErrorFromSmartServer, some debug info has
3864
        # been muttered to the log file for developer to look at.
3865
        self.assertContainsRe(
4794.1.15 by Robert Collins
Review feedback.
3866
            self.get_log(),
3533.3.4 by Andrew Bennetts
Add tests for _translate_error's robustness.
3867
            "Missing key 'branch' in context")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
3868
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3869
    def test_path_missing(self):
3870
        """Some translations (PermissionDenied, ReadError) can determine the
3871
        'path' variable from either the wire or the local context.  If neither
3872
        has it, then an error is raised.
3873
        """
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3874
        error_tuple = (b'ReadError',)
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3875
        server_error = errors.ErrorFromSmartServer(error_tuple)
3876
        translated_error = self.translateErrorFromSmartServer(server_error)
3877
        self.assertEqual(server_error, translated_error)
3878
        # In addition to re-raising ErrorFromSmartServer, some debug info has
3879
        # been muttered to the log file for developer to look at.
4794.1.15 by Robert Collins
Review feedback.
3880
        self.assertContainsRe(self.get_log(), "Missing key 'path' in context")
3786.4.2 by Andrew Bennetts
Add tests and fix code to make sure ReadError and PermissionDenied are robustly handled by _translate_error.
3881
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
3882
3883
class TestStacking(tests.TestCaseWithTransport):
3884
    """Tests for operations on stacked remote repositories.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
3885
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
3886
    The underlying format type must support stacking.
3887
    """
3888
3889
    def test_access_stacked_remote(self):
3890
        # based on <http://launchpad.net/bugs/261315>
3891
        # make a branch stacked on another repository containing an empty
3892
        # revision, then open it over hpss - we should be able to see that
3893
        # revision.
3894
        base_transport = self.get_transport()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3895
        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)
3896
        base_builder.start_series()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
3897
        base_revid = base_builder.build_snapshot(None,
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
3898
            [('add', ('', None, 'directory', None))],
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3899
            'message', revision_id=b'rev-id')
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
3900
        base_builder.finish_series()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3901
        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)
3902
        stacked_branch.set_stacked_on_url('../base')
3903
        # start a server looking at this
5017.3.28 by Vincent Ladeuil
selftest -s bt.test_remote passing
3904
        smart_server = test_server.SmartTCPServer_for_testing()
4659.1.3 by Robert Collins
Review feedback.
3905
        self.start_server(smart_server)
3691.2.2 by Martin Pool
Fix some problems in access to stacked repositories over hpss (#261315)
3906
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
3907
        # can get its branch and repository
3908
        remote_branch = remote_bzrdir.open_branch()
3909
        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
3910
        remote_repo.lock_read()
3911
        try:
3912
            # it should have an appropriate fallback repository, which should also
3913
            # be a RemoteRepository
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
3914
            self.assertLength(1, remote_repo._fallback_repositories)
3691.2.6 by Martin Pool
Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions
3915
            self.assertIsInstance(remote_repo._fallback_repositories[0],
3916
                RemoteRepository)
3917
            # and it has the revision committed to the underlying repository;
3918
            # these have varying implementations so we try several of them
3919
            self.assertTrue(remote_repo.has_revisions([base_revid]))
3920
            self.assertTrue(remote_repo.has_revision(base_revid))
3921
            self.assertEqual(remote_repo.get_revision(base_revid).message,
3922
                'message')
3923
        finally:
3924
            remote_repo.unlock()
3835.1.2 by Aaron Bentley
Add tests for get_parent_map
3925
3835.1.7 by Aaron Bentley
Updates from review
3926
    def prepare_stacked_remote_branch(self):
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3927
        """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.
3928
        self.setup_smart_server_with_call_log()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3929
        tree1 = self.make_branch_and_tree('tree1', format='1.9')
6855.4.1 by Jelmer Vernooij
Yet more bees.
3930
        tree1.commit('rev1', rev_id=b'rev1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
3931
        tree2 = tree1.branch.controldir.sprout('tree2', stacked=True
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3932
            ).open_workingtree()
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
3933
        local_tree = tree2.branch.create_checkout('local')
3934
        local_tree.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.
3935
        branch2 = Branch.open(self.get_url('tree2'))
3835.1.2 by Aaron Bentley
Add tests for get_parent_map
3936
        branch2.lock_read()
3937
        self.addCleanup(branch2.unlock)
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3938
        return tree1.branch, branch2
3835.1.7 by Aaron Bentley
Updates from review
3939
3940
    def test_stacked_get_parent_map(self):
3941
        # 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.
3942
        _, branch = self.prepare_stacked_remote_branch()
3835.1.7 by Aaron Bentley
Updates from review
3943
        repo = branch.repository
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3944
        self.assertEqual({'rev1'}, set(repo.get_parent_map([b'rev1'])))
3835.1.7 by Aaron Bentley
Updates from review
3945
3835.1.10 by Aaron Bentley
Move CachingExtraParentsProvider to Graph
3946
    def test_unstacked_get_parent_map(self):
3947
        # _unstacked_provider.get_parent_map ignores stacking
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3948
        _, branch = self.prepare_stacked_remote_branch()
3835.1.10 by Aaron Bentley
Move CachingExtraParentsProvider to Graph
3949
        provider = branch.repository._unstacked_provider
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
3950
        self.assertEqual(set(), set(provider.get_parent_map([b'rev1'])))
3834.3.3 by John Arbash Meinel
Merge bzr.dev, resolve conflict in tests.
3951
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3952
    def fetch_stream_to_rev_order(self, stream):
3953
        result = []
3954
        for kind, substream in stream:
3955
            if not kind == 'revisions':
3956
                list(substream)
3957
            else:
3958
                for content in substream:
3959
                    result.append(content.key[-1])
3960
        return result
3961
4577.1.1 by Robert Collins
Fix fetching from smart servers where there is a chain of stacked repositories rather than a single stacking point. (Robert Collins, bug #406597)
3962
    def get_ordered_revs(self, format, order, branch_factory=None):
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3963
        """Get a list of the revisions in a stream to format format.
3964
3965
        :param format: The format of the target.
3966
        :param order: the order that target should have requested.
4577.1.1 by Robert Collins
Fix fetching from smart servers where there is a chain of stacked repositories rather than a single stacking point. (Robert Collins, bug #406597)
3967
        :param branch_factory: A callable to create a trunk and stacked branch
3968
            to fetch from. If none, self.prepare_stacked_remote_branch is used.
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3969
        :result: The revision ids in the stream, in the order seen,
3970
            the topological order of revisions in the source.
3971
        """
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
3972
        unordered_format = controldir.format_registry.get(format)()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3973
        target_repository_format = unordered_format.repository_format
3974
        # Cross check
3975
        self.assertEqual(order, target_repository_format._fetch_order)
4577.1.1 by Robert Collins
Fix fetching from smart servers where there is a chain of stacked repositories rather than a single stacking point. (Robert Collins, bug #406597)
3976
        if branch_factory is None:
3977
            branch_factory = self.prepare_stacked_remote_branch
3978
        _, stacked = branch_factory()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3979
        source = stacked.repository._get_source(target_repository_format)
3980
        tip = stacked.last_revision()
5972.3.25 by Jelmer Vernooij
Fix another use of get_ancestry.
3981
        stacked.repository._ensure_real()
3982
        graph = stacked.repository.get_graph()
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
3983
        revs = [r for (r, ps) in graph.iter_ancestry([tip])
5972.3.25 by Jelmer Vernooij
Fix another use of get_ancestry.
3984
                if r != NULL_REVISION]
3985
        revs.reverse()
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
3986
        search = vf_search.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.
3987
        self.reset_smart_call_log()
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
3988
        stream = source.get_stream(search)
3989
        # We trust that if a revision is in the stream the rest of the new
3990
        # content for it is too, as per our main fetch tests; here we are
3991
        # checking that the revisions are actually included at all, and their
3992
        # order.
3993
        return self.fetch_stream_to_rev_order(stream), revs
3994
3995
    def test_stacked_get_stream_unordered(self):
3996
        # Repository._get_source.get_stream() from a stacked repository with
3997
        # unordered yields the full data from both stacked and stacked upon
3998
        # sources.
3999
        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.
4000
        self.assertEqual(set(expected_revs), set(rev_ord))
4001
        # Getting unordered results should have made a streaming data request
4002
        # from the server, then one from the backing branch.
4003
        self.assertLength(2, self.hpss_calls)
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
4004
4577.1.1 by Robert Collins
Fix fetching from smart servers where there is a chain of stacked repositories rather than a single stacking point. (Robert Collins, bug #406597)
4005
    def test_stacked_on_stacked_get_stream_unordered(self):
4006
        # Repository._get_source.get_stream() from a stacked repository which
4007
        # is itself stacked yields the full data from all three sources.
4008
        def make_stacked_stacked():
4009
            _, stacked = self.prepare_stacked_remote_branch()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
4010
            tree = stacked.controldir.sprout('tree3', stacked=True
4577.1.1 by Robert Collins
Fix fetching from smart servers where there is a chain of stacked repositories rather than a single stacking point. (Robert Collins, bug #406597)
4011
                ).open_workingtree()
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
4012
            local_tree = tree.branch.create_checkout('local-tree3')
4013
            local_tree.commit('more local changes are better')
4577.1.1 by Robert Collins
Fix fetching from smart servers where there is a chain of stacked repositories rather than a single stacking point. (Robert Collins, bug #406597)
4014
            branch = Branch.open(self.get_url('tree3'))
4015
            branch.lock_read()
4857.2.3 by John Arbash Meinel
Found the failed-to-unlocked branches in test_remote.
4016
            self.addCleanup(branch.unlock)
4577.1.1 by Robert Collins
Fix fetching from smart servers where there is a chain of stacked repositories rather than a single stacking point. (Robert Collins, bug #406597)
4017
            return None, branch
4018
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered',
4019
            branch_factory=make_stacked_stacked)
4020
        self.assertEqual(set(expected_revs), set(rev_ord))
4021
        # Getting unordered results should have made a streaming data request
4022
        # from the server, and one from each backing repo
4023
        self.assertLength(3, self.hpss_calls)
4024
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
4025
    def test_stacked_get_stream_topological(self):
4026
        # Repository._get_source.get_stream() from a stacked repository with
4027
        # topological sorting yields the full data from both stacked and
4028
        # stacked upon sources in topological order.
4029
        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.
4030
        self.assertEqual(expected_revs, rev_ord)
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
4031
        # Getting topological sort requires VFS calls still - one of which is
4032
        # pushing up from the bound branch.
5972.3.25 by Jelmer Vernooij
Fix another use of get_ancestry.
4033
        self.assertLength(14, self.hpss_calls)
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
4034
4035
    def test_stacked_get_stream_groupcompress(self):
4036
        # Repository._get_source.get_stream() from a stacked repository with
4037
        # groupcompress sorting yields the full data from both stacked and
4038
        # stacked upon sources in groupcompress order.
4039
        raise tests.TestSkipped('No groupcompress ordered format available')
4040
        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.
4041
        self.assertEqual(expected_revs, reversed(rev_ord))
4042
        # Getting unordered results should have made a streaming data request
4043
        # from the backing branch, and one from the stacked on branch.
4044
        self.assertLength(2, self.hpss_calls)
4152.1.1 by Robert Collins
Add specific tests for fetch streaming in the bzr protocol client.
4045
4332.2.1 by Robert Collins
Fix bug 360791 by not raising an error when a smart server is asked for more content than it has locally; the client is assumed to be monitoring what it gets.
4046
    def test_stacked_pull_more_than_stacking_has_bug_360791(self):
4047
        # When pulling some fixed amount of content that is more than the
4048
        # source has (because some is coming from a fallback branch, no error
4049
        # should be received. This was reported as bug 360791.
4050
        # Need three branches: a trunk, a stacked branch, and a preexisting
4051
        # branch pulling content from stacked and trunk.
4052
        self.setup_smart_server_with_call_log()
4053
        trunk = self.make_branch_and_tree('trunk', format="1.9-rich-root")
4054
        r1 = trunk.commit('start')
4055
        stacked_branch = trunk.branch.create_clone_on_transport(
4056
            self.get_transport('stacked'), stacked_on=trunk.branch.base)
4057
        local = self.make_branch('local', format='1.9-rich-root')
4058
        local.repository.fetch(stacked_branch.repository,
4059
            stacked_branch.last_revision())
4060
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.
4061
4062
class TestRemoteBranchEffort(tests.TestCaseWithTransport):
4063
4064
    def setUp(self):
4065
        super(TestRemoteBranchEffort, self).setUp()
4066
        # Create a smart server that publishes whatever the backing VFS server
4067
        # does.
5017.3.28 by Vincent Ladeuil
selftest -s bt.test_remote passing
4068
        self.smart_server = test_server.SmartTCPServer_for_testing()
4659.1.2 by Robert Collins
Refactor creation and shutdown of test servers to use a common helper,
4069
        self.start_server(self.smart_server, self.get_server())
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.
4070
        # Log all HPSS calls into self.hpss_calls.
4071
        _SmartClient.hooks.install_named_hook(
4072
            'call', self.capture_hpss_call, None)
4073
        self.hpss_calls = []
4074
4075
    def capture_hpss_call(self, params):
4076
        self.hpss_calls.append(params.method)
4077
4078
    def test_copy_content_into_avoids_revision_history(self):
4079
        local = self.make_branch('local')
5539.2.5 by Andrew Bennetts
Add test to test_remote, fix another shallow bug.
4080
        builder = self.make_branch_builder('remote')
4081
        builder.build_commit(message="Commit.")
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.
4082
        remote_branch_url = self.smart_server.get_url() + 'remote'
4083
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4084
        local.repository.fetch(remote_branch.repository)
4085
        self.hpss_calls = []
4086
        remote_branch.copy_content_into(local)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4087
        self.assertFalse(b'Branch.revision_history' in self.hpss_calls)
5539.2.5 by Andrew Bennetts
Add test to test_remote, fix another shallow bug.
4088
5539.2.6 by Andrew Bennetts
Better test name.
4089
    def test_fetch_everything_needs_just_one_call(self):
5539.2.5 by Andrew Bennetts
Add test to test_remote, fix another shallow bug.
4090
        local = self.make_branch('local')
4091
        builder = self.make_branch_builder('remote')
4092
        builder.build_commit(message="Commit.")
4093
        remote_branch_url = self.smart_server.get_url() + 'remote'
4094
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4095
        self.hpss_calls = []
6015.5.1 by Vincent Ladeuil
Merge 2.3 into 2.4
4096
        local.repository.fetch(
4097
            remote_branch.repository,
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
4098
            fetch_spec=vf_search.EverythingResult(remote_branch.repository))
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4099
        self.assertEqual([b'Repository.get_stream_1.19'], self.hpss_calls)
5539.2.13 by Andrew Bennetts
Add a test for compatibility with pre-2.3 servers.
4100
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4101
    def override_verb(self, verb_name, verb):
4102
        request_handlers = request.request_handlers
4103
        orig_verb = request_handlers.get(verb_name)
6206.1.11 by Jelmer Vernooij
Preserve info when restoring verbs after disabling/overriding.
4104
        orig_info = request_handlers.get_info(verb_name)
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4105
        request_handlers.register(verb_name, verb, override_existing=True)
4106
        self.addCleanup(request_handlers.register, verb_name, orig_verb,
6206.1.11 by Jelmer Vernooij
Preserve info when restoring verbs after disabling/overriding.
4107
                override_existing=True, info=orig_info)
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4108
5539.2.13 by Andrew Bennetts
Add a test for compatibility with pre-2.3 servers.
4109
    def test_fetch_everything_backwards_compat(self):
5536.3.3 by Andrew Bennetts
Merge lp:bzr.
4110
        """Can fetch with EverythingResult even with pre 2.4 servers.
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4111
        
5536.3.3 by Andrew Bennetts
Merge lp:bzr.
4112
        Pre-2.4 do not support 'everything' searches with the
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4113
        Repository.get_stream_1.19 verb.
5539.2.13 by Andrew Bennetts
Add a test for compatibility with pre-2.3 servers.
4114
        """
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4115
        verb_log = []
4116
        class OldGetStreamVerb(SmartServerRepositoryGetStream_1_19):
4117
            """A version of the Repository.get_stream_1.19 verb patched to
5536.3.3 by Andrew Bennetts
Merge lp:bzr.
4118
            reject 'everything' searches the way 2.3 and earlier do.
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4119
            """
6015.5.1 by Vincent Ladeuil
Merge 2.3 into 2.4
4120
            def recreate_search(self, repository, search_bytes,
4121
                                discard_excess=False):
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4122
                verb_log.append(search_bytes.split(b'\n', 1)[0])
4123
                if search_bytes == b'everything':
6015.5.1 by Vincent Ladeuil
Merge 2.3 into 2.4
4124
                    return (None,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4125
                            request.FailedSmartServerResponse((b'BadSearch',)))
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4126
                return super(OldGetStreamVerb,
4127
                        self).recreate_search(repository, search_bytes,
4128
                            discard_excess=discard_excess)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4129
        self.override_verb(b'Repository.get_stream_1.19', OldGetStreamVerb)
5539.2.13 by Andrew Bennetts
Add a test for compatibility with pre-2.3 servers.
4130
        local = self.make_branch('local')
4131
        builder = self.make_branch_builder('remote')
4132
        builder.build_commit(message="Commit.")
4133
        remote_branch_url = self.smart_server.get_url() + 'remote'
4134
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4135
        self.hpss_calls = []
6015.5.1 by Vincent Ladeuil
Merge 2.3 into 2.4
4136
        local.repository.fetch(
4137
            remote_branch.repository,
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
4138
            fetch_spec=vf_search.EverythingResult(remote_branch.repository))
5536.2.7 by Andrew Bennetts
Fix test_fetch_everything_backwards_compat to actually test what it is intended to test.
4139
        # make sure the overridden verb was used
4140
        self.assertLength(1, verb_log)
4141
        # more than one HPSS call is needed, but because it's a VFS callback
4142
        # its hard to predict exactly how many.
4143
        self.assertTrue(len(self.hpss_calls) > 1)
5539.2.13 by Andrew Bennetts
Add a test for compatibility with pre-2.3 servers.
4144
5609.50.1 by Vincent Ladeuil
Be more tolerant about ``bound_location`` from config files
4145
5609.50.4 by Vincent Ladeuil
Add more tests for accepted bound_location variations.
4146
class TestUpdateBoundBranchWithModifiedBoundLocation(
4147
    tests.TestCaseWithTransport):
4148
    """Ensure correct handling of bound_location modifications.
4149
4150
    This is tested against a smart server as http://pad.lv/786980 was about a
4151
    ReadOnlyError (write attempt during a read-only transaction) which can only
4152
    happen in this context.
4153
    """
4154
4155
    def setUp(self):
4156
        super(TestUpdateBoundBranchWithModifiedBoundLocation, self).setUp()
5609.50.1 by Vincent Ladeuil
Be more tolerant about ``bound_location`` from config files
4157
        self.transport_server = test_server.SmartTCPServer_for_testing
5609.50.4 by Vincent Ladeuil
Add more tests for accepted bound_location variations.
4158
4159
    def make_master_and_checkout(self, master_name, checkout_name):
4160
        # Create the master branch and its associated checkout
4161
        self.master = self.make_branch_and_tree(master_name)
4162
        self.checkout = self.master.branch.create_checkout(checkout_name)
4163
        # Modify the master branch so there is something to update
4164
        self.master.commit('add stuff')
4165
        self.last_revid = self.master.commit('even more stuff')
4166
        self.bound_location = self.checkout.branch.get_bound_location()
4167
4168
    def assertUpdateSucceeds(self, new_location):
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
4169
        self.checkout.branch.set_bound_location(new_location)
4170
        self.checkout.update()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
4171
        self.assertEqual(self.last_revid, self.checkout.last_revision())
5609.50.4 by Vincent Ladeuil
Add more tests for accepted bound_location variations.
4172
4173
    def test_without_final_slash(self):
4174
        self.make_master_and_checkout('master', 'checkout')
5609.50.1 by Vincent Ladeuil
Be more tolerant about ``bound_location`` from config files
4175
        # For unclear reasons some users have a bound_location without a final
4176
        # '/', simulate that by forcing such a value
5609.50.4 by Vincent Ladeuil
Add more tests for accepted bound_location variations.
4177
        self.assertEndsWith(self.bound_location, '/')
4178
        self.assertUpdateSucceeds(self.bound_location.rstrip('/'))
4179
4180
    def test_plus_sign(self):
4181
        self.make_master_and_checkout('+master', 'checkout')
4182
        self.assertUpdateSucceeds(self.bound_location.replace('%2B', '+', 1))
4183
4184
    def test_tilda(self):
4185
        # Embed ~ in the middle of the path just to avoid any $HOME
4186
        # interpretation
4187
        self.make_master_and_checkout('mas~ter', 'checkout')
4188
        self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
6284.1.1 by Jelmer Vernooij
Allow registering custom error handlers in the HPSS client.
4189
4190
4191
class TestWithCustomErrorHandler(RemoteBranchTestCase):
4192
4193
    def test_no_context(self):
4194
        class OutOfCoffee(errors.BzrError):
4195
            """A dummy exception for testing."""
4196
4197
            def __init__(self, urgency):
4198
                self.urgency = urgency
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4199
        remote.no_context_error_translators.register(b"OutOfCoffee",
6284.1.1 by Jelmer Vernooij
Allow registering custom error handlers in the HPSS client.
4200
            lambda err: OutOfCoffee(err.error_args[0]))
4201
        transport = MemoryTransport()
4202
        client = FakeClient(transport.base)
4203
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4204
            b'Branch.get_stacked_on_url', (b'quack/',),
4205
            b'error', (b'NotStacked',))
6284.1.1 by Jelmer Vernooij
Allow registering custom error handlers in the HPSS client.
4206
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4207
            b'Branch.last_revision_info',
4208
            (b'quack/',),
4209
            b'error', (b'OutOfCoffee', b'low'))
6284.1.1 by Jelmer Vernooij
Allow registering custom error handlers in the HPSS client.
4210
        transport.mkdir('quack')
4211
        transport = transport.clone('quack')
4212
        branch = self.make_remote_branch(transport, client)
4213
        self.assertRaises(OutOfCoffee, branch.last_revision_info)
4214
        self.assertFinished(client)
4215
4216
    def test_with_context(self):
4217
        class OutOfTea(errors.BzrError):
4218
            def __init__(self, branch, urgency):
4219
                self.branch = branch
4220
                self.urgency = urgency
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4221
        remote.error_translators.register(b"OutOfTea",
4222
            lambda err, find, path: OutOfTea(
4223
                err.error_args[0].decode('utf-8'),
6284.1.1 by Jelmer Vernooij
Allow registering custom error handlers in the HPSS client.
4224
                find("branch")))
4225
        transport = MemoryTransport()
4226
        client = FakeClient(transport.base)
4227
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4228
            b'Branch.get_stacked_on_url', (b'quack/',),
4229
            b'error', (b'NotStacked',))
6284.1.1 by Jelmer Vernooij
Allow registering custom error handlers in the HPSS client.
4230
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4231
            b'Branch.last_revision_info',
4232
            (b'quack/',),
4233
            b'error', (b'OutOfTea', b'low'))
6284.1.1 by Jelmer Vernooij
Allow registering custom error handlers in the HPSS client.
4234
        transport.mkdir('quack')
4235
        transport = transport.clone('quack')
4236
        branch = self.make_remote_branch(transport, client)
4237
        self.assertRaises(OutOfTea, branch.last_revision_info)
4238
        self.assertFinished(client)
6305.2.1 by Jelmer Vernooij
add remote call for Repository.pack.
4239
4240
4241
class TestRepositoryPack(TestRemoteRepository):
4242
4243
    def test_pack(self):
4244
        transport_path = 'quack'
4245
        repo, client = self.setup_fake_client_and_repository(transport_path)
4246
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4247
            b'Repository.lock_write', (b'quack/', b''),
4248
            b'success', (b'ok', b'token'))
4249
        client.add_expected_call(
4250
            b'Repository.pack', (b'quack/', b'token', b'False'),
4251
            b'success', (b'ok',), )
4252
        client.add_expected_call(
4253
            b'Repository.unlock', (b'quack/', b'token'),
4254
            b'success', (b'ok', ))
6305.2.1 by Jelmer Vernooij
add remote call for Repository.pack.
4255
        repo.pack()
4256
4257
    def test_pack_with_hint(self):
4258
        transport_path = 'quack'
4259
        repo, client = self.setup_fake_client_and_repository(transport_path)
4260
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4261
            b'Repository.lock_write', (b'quack/', b''),
4262
            b'success', (b'ok', b'token'))
4263
        client.add_expected_call(
4264
            b'Repository.pack', (b'quack/', b'token', b'False'),
4265
            b'success', (b'ok',), )
4266
        client.add_expected_call(
4267
            b'Repository.unlock', (b'quack/', b'token', b'False'),
4268
            b'success', (b'ok', ))
4269
        repo.pack([b'hinta', b'hintb'])
6282.6.8 by Jelmer Vernooij
Adjust _iter_inventories contract slightly, don't raise NoSuchRevision immediately
4270
4271
6282.6.9 by Jelmer Vernooij
More tests.
4272
class TestRepositoryIterInventories(TestRemoteRepository):
4273
    """Test Repository.iter_inventories."""
6282.6.8 by Jelmer Vernooij
Adjust _iter_inventories contract slightly, don't raise NoSuchRevision immediately
4274
4275
    def _serialize_inv_delta(self, old_name, new_name, delta):
4276
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4277
        return b"".join(serializer.delta_to_lines(old_name, new_name, delta))
6282.6.8 by Jelmer Vernooij
Adjust _iter_inventories contract slightly, don't raise NoSuchRevision immediately
4278
6282.6.9 by Jelmer Vernooij
More tests.
4279
    def test_single_empty(self):
6282.6.8 by Jelmer Vernooij
Adjust _iter_inventories contract slightly, don't raise NoSuchRevision immediately
4280
        transport_path = 'quack'
4281
        repo, client = self.setup_fake_client_and_repository(transport_path)
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
4282
        fmt = controldir.format_registry.get('2a')().repository_format
6282.6.37 by Jelmer Vernooij
Cope with empty results.
4283
        repo._format = fmt
6282.6.43 by Jelmer Vernooij
Fix stream name.
4284
        stream = [('inventory-deltas', [
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4285
            versionedfile.FulltextContentFactory(b'somerevid', None, None,
4286
                self._serialize_inv_delta(b'null:', b'somerevid', []))])]
6282.6.8 by Jelmer Vernooij
Adjust _iter_inventories contract slightly, don't raise NoSuchRevision immediately
4287
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4288
            b'VersionedFileRepository.get_inventories', (b'quack/', b'unordered'),
4289
            b'success', (b'ok', ),
6282.6.37 by Jelmer Vernooij
Cope with empty results.
4290
            _stream_to_byte_stream(stream, fmt))
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4291
        ret = list(repo.iter_inventories([b"somerevid"]))
6282.6.9 by Jelmer Vernooij
More tests.
4292
        self.assertLength(1, ret)
4293
        inv = ret[0]
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4294
        self.assertEqual(b"somerevid", inv.revision_id)
6282.6.9 by Jelmer Vernooij
More tests.
4295
4296
    def test_empty(self):
4297
        transport_path = 'quack'
4298
        repo, client = self.setup_fake_client_and_repository(transport_path)
4299
        ret = list(repo.iter_inventories([]))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
4300
        self.assertEqual(ret, [])
6282.6.9 by Jelmer Vernooij
More tests.
4301
4302
    def test_missing(self):
4303
        transport_path = 'quack'
4304
        repo, client = self.setup_fake_client_and_repository(transport_path)
4305
        client.add_expected_call(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4306
            b'VersionedFileRepository.get_inventories', (b'quack/', b'unordered'),
4307
            b'success', (b'ok', ), iter([]))
6282.6.9 by Jelmer Vernooij
More tests.
4308
        self.assertRaises(errors.NoSuchRevision, list, repo.iter_inventories(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
4309
            [b"somerevid"]))
6968.5.7 by Jelmer Vernooij
Add client side test.
4310
4311
4312
class TestRepositoryRevisionTreeArchive(TestRemoteRepository):
4313
    """Test Repository.iter_inventories."""
4314
4315
    def _serialize_inv_delta(self, old_name, new_name, delta):
4316
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
4317
        return b"".join(serializer.delta_to_lines(old_name, new_name, delta))
4318
4319
    def test_simple(self):
4320
        transport_path = 'quack'
4321
        repo, client = self.setup_fake_client_and_repository(transport_path)
4322
        fmt = controldir.format_registry.get('2a')().repository_format
4323
        repo._format = fmt
4324
        stream = [('inventory-deltas', [
4325
            versionedfile.FulltextContentFactory(b'somerevid', None, None,
4326
                self._serialize_inv_delta(b'null:', b'somerevid', []))])]
4327
        client.add_expected_call(
4328
            b'VersionedFileRepository.get_inventories', (b'quack/', b'unordered'),
4329
            b'success', (b'ok', ),
4330
            _stream_to_byte_stream(stream, fmt))
4331
        f = BytesIO()
4332
        with tarfile.open(mode='w', fileobj=f) as tf:
4333
            info = tarfile.TarInfo('somefile')
4334
            info.mtime = 432432
4335
            contents = b'some data'
4336
            info.type = tarfile.REGTYPE
4337
            info.mode = 0o644
4338
            info.size = len(contents)
4339
            tf.addfile(info, BytesIO(contents))
4340
        client.add_expected_call(
6995 by Jelmer Vernooij
Merge lp:~jelmer/brz/hpss-archive.
4341
            b'Repository.revision_archive', (b'quack/', b'somerevid', b'tar', b'foo.tar', b'', b'', None),
6968.5.7 by Jelmer Vernooij
Add client side test.
4342
            b'success', (b'ok', ),
4343
            f.getvalue())
4344
        tree = repo.revision_tree(b'somerevid')
6995 by Jelmer Vernooij
Merge lp:~jelmer/brz/hpss-archive.
4345
        self.assertEqual(f.getvalue(), b''.join(tree.archive('tar', 'foo.tar')))
6997.6.5 by Jelmer Vernooij
Add tests.
4346
4347
4348
class TestRepositoryAnnotate(TestRemoteRepository):
4349
    """Test RemoteRevisionTree.annotate.."""
4350
4351
    def _serialize_inv_delta(self, old_name, new_name, delta):
4352
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
4353
        return b"".join(serializer.delta_to_lines(old_name, new_name, delta))
4354
4355
    def test_simple(self):
4356
        transport_path = 'quack'
4357
        repo, client = self.setup_fake_client_and_repository(transport_path)
4358
        fmt = controldir.format_registry.get('2a')().repository_format
4359
        repo._format = fmt
4360
        stream = [('inventory-deltas', [
4361
            versionedfile.FulltextContentFactory(b'somerevid', None, None,
4362
                self._serialize_inv_delta(b'null:', b'somerevid', []))])]
4363
        client.add_expected_call(
4364
            b'VersionedFileRepository.get_inventories', (b'quack/', b'unordered'),
4365
            b'success', (b'ok', ),
4366
            _stream_to_byte_stream(stream, fmt))
4367
        client.add_expected_call(
4368
            b'Repository.annotate_file_revision',
4369
            (b'quack/', b'somerevid', b'filename', b'', b'current:'),
4370
            b'success', (b'ok', ),
4371
            bencode.bencode([[b'baserevid', b'line 1\n'],
4372
                             [b'somerevid', b'line2\n']]))
4373
        tree = repo.revision_tree(b'somerevid')
4374
        self.assertEqual([
4375
            (b'baserevid', b'line 1\n'),
4376
            (b'somerevid', b'line2\n')],
4377
            list(tree.annotate_iter('filename')))