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