/brz/remove-bazaar

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