/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2018.18.1 by Martin Pool
Add stub Repository.tarball smart method
1
# Copyright (C) 2006, 2007 Canonical Ltd
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
2748.4.1 by Andrew Bennetts
Implement a ChunkedBodyDecoder.
17
"""Tests for the smart wire/domain protocol.
18
19
This module contains tests for the domain-level smart requests and responses,
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
20
such as the 'Branch.lock_write' request. Many of these use specific disk
21
formats to exercise calls that only make sense for formats with specific
22
properties.
2748.4.1 by Andrew Bennetts
Implement a ChunkedBodyDecoder.
23
24
Tests for low-level protocol encoding are found in test_smart_transport.
25
"""
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
26
3211.5.2 by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression.
27
import bz2
2692.1.18 by Andrew Bennetts
Merge from bzr.dev.
28
from cStringIO import StringIO
2018.18.2 by Martin Pool
smart method Repository.tarball actually returns the tarball
29
import tarfile
30
2692.1.2 by Andrew Bennetts
Merge from bzr.dev.
31
from bzrlib import (
32
    bzrdir,
33
    errors,
34
    pack,
35
    smart,
36
    tests,
37
    urlutils,
38
    )
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
39
from bzrlib.branch import Branch, BranchReferenceFormat
2692.1.22 by Andrew Bennetts
Reinstate imports needed to run test_smart alone.
40
import bzrlib.smart.branch
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
41
import bzrlib.smart.bzrdir, bzrlib.smart.bzrdir as smart_dir
42
import bzrlib.smart.packrepository
2692.1.22 by Andrew Bennetts
Reinstate imports needed to run test_smart alone.
43
import bzrlib.smart.repository
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
44
from bzrlib.smart.request import (
45
    FailedSmartServerResponse,
46
    SmartServerRequest,
47
    SmartServerResponse,
48
    SuccessfulSmartServerResponse,
49
    )
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
50
from bzrlib.tests import (
51
    split_suite_by_re,
52
    )
2692.1.3 by Andrew Bennetts
Fix imports so that tests in test_smart.py can be run alone.
53
from bzrlib.transport import chroot, get_transport
2535.3.15 by Andrew Bennetts
Add KnitVersionedFile.get_stream_as_bytes, start smart implementation of RemoteRepository.get_data_stream.
54
from bzrlib.util import bencode
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
55
56
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
57
def load_tests(standard_tests, module, loader):
58
    """Multiply tests version and protocol consistency."""
59
    # FindRepository tests.
60
    bzrdir_mod = bzrlib.smart.bzrdir
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
61
    scenarios = [
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
62
        ("find_repository", {
63
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV1}),
64
        ("find_repositoryV2", {
65
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV2}),
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
66
        ("find_repositoryV3", {
67
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV3}),
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
68
        ]
69
    to_adapt, result = split_suite_by_re(standard_tests,
70
        "TestSmartServerRequestFindRepository")
71
    v2_only, v1_and_2 = split_suite_by_re(to_adapt,
72
        "_v2")
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
73
    tests.multiply_tests(v1_and_2, scenarios, result)
74
    # The first scenario is only applicable to v1 protocols, it is deleted
75
    # since.
76
    tests.multiply_tests(v2_only, scenarios[1:], result)
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
77
    return result
78
79
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
80
class TestCaseWithChrootedTransport(tests.TestCaseWithTransport):
81
82
    def setUp(self):
83
        tests.TestCaseWithTransport.setUp(self)
84
        self._chroot_server = None
85
86
    def get_transport(self, relpath=None):
87
        if self._chroot_server is None:
88
            backing_transport = tests.TestCaseWithTransport.get_transport(self)
89
            self._chroot_server = chroot.ChrootServer(backing_transport)
90
            self._chroot_server.setUp()
91
            self.addCleanup(self._chroot_server.tearDown)
92
        t = get_transport(self._chroot_server.get_url())
93
        if relpath is not None:
94
            t = t.clone(relpath)
95
        return t
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
96
97
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
98
class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
99
100
    def setUp(self):
101
        super(TestCaseWithSmartMedium, self).setUp()
102
        # We're allowed to set  the transport class here, so that we don't use
103
        # the default or a parameterized class, but rather use the
104
        # TestCaseWithTransport infrastructure to set up a smart server and
105
        # transport.
3245.4.28 by Andrew Bennetts
Remove another XXX, and include test ID in smart server thread names.
106
        self.transport_server = self.make_transport_server
107
108
    def make_transport_server(self):
109
        return smart.server.SmartTCPServer_for_testing('-' + self.id())
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
110
111
    def get_smart_medium(self):
112
        """Get a smart medium to use in tests."""
113
        return self.get_transport().get_smart_medium()
114
115
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
116
class TestSmartServerResponse(tests.TestCase):
117
118
    def test__eq__(self):
119
        self.assertEqual(SmartServerResponse(('ok', )),
120
            SmartServerResponse(('ok', )))
121
        self.assertEqual(SmartServerResponse(('ok', ), 'body'),
122
            SmartServerResponse(('ok', ), 'body'))
123
        self.assertNotEqual(SmartServerResponse(('ok', )),
124
            SmartServerResponse(('notok', )))
125
        self.assertNotEqual(SmartServerResponse(('ok', ), 'body'),
126
            SmartServerResponse(('ok', )))
2018.5.41 by Robert Collins
Fix SmartServerResponse.__eq__ to handle None.
127
        self.assertNotEqual(None,
128
            SmartServerResponse(('ok', )))
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
129
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
130
    def test__str__(self):
131
        """SmartServerResponses can be stringified."""
132
        self.assertEqual(
3691.2.6 by Martin Pool
Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions
133
            "<SuccessfulSmartServerResponse args=('args',) body='body'>",
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
134
            str(SuccessfulSmartServerResponse(('args',), 'body')))
135
        self.assertEqual(
3691.2.6 by Martin Pool
Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions
136
            "<FailedSmartServerResponse args=('args',) body='body'>",
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
137
            str(FailedSmartServerResponse(('args',), 'body')))
138
139
140
class TestSmartServerRequest(tests.TestCaseWithMemoryTransport):
141
142
    def test_translate_client_path(self):
143
        transport = self.get_transport()
144
        request = SmartServerRequest(transport, 'foo/')
145
        self.assertEqual('./', request.translate_client_path('foo/'))
146
        self.assertRaises(
147
            errors.InvalidURLJoin, request.translate_client_path, 'foo/..')
148
        self.assertRaises(
149
            errors.PathNotChild, request.translate_client_path, '/')
150
        self.assertRaises(
151
            errors.PathNotChild, request.translate_client_path, 'bar/')
152
        self.assertEqual('./baz', request.translate_client_path('foo/baz'))
153
154
    def test_transport_from_client_path(self):
155
        transport = self.get_transport()
156
        request = SmartServerRequest(transport, 'foo/')
157
        self.assertEqual(
158
            transport.base,
159
            request.transport_from_client_path('foo/').base)
160
161
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
162
class TestSmartServerBzrDirRequestCloningMetaDir(
163
    tests.TestCaseWithMemoryTransport):
164
    """Tests for BzrDir.cloning_metadir."""
165
166
    def test_cloning_metadir(self):
167
        """When there is a bzrdir present, the call succeeds."""
168
        backing = self.get_transport()
169
        dir = self.make_bzrdir('.')
170
        local_result = dir.cloning_metadir()
171
        request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
172
        request = request_class(backing)
173
        expected = SuccessfulSmartServerResponse(
174
            (local_result.network_name(),
175
            local_result.repository_format.network_name(),
4084.2.2 by Robert Collins
Review feedback.
176
            ('branch', local_result.get_branch_format().network_name())))
4070.7.4 by Andrew Bennetts
Deal with branch references better in BzrDir.cloning_metadir RPC (changes protocol).
177
        self.assertEqual(expected, request.execute('', 'False'))
178
179
    def test_cloning_metadir_reference(self):
180
        """The request works when bzrdir contains a branch reference."""
181
        backing = self.get_transport()
182
        referenced_branch = self.make_branch('referenced')
183
        dir = self.make_bzrdir('.')
184
        local_result = dir.cloning_metadir()
185
        reference = BranchReferenceFormat().initialize(dir, referenced_branch)
186
        reference_url = BranchReferenceFormat().get_reference(dir)
187
        # The server shouldn't try to follow the branch reference, so it's fine
188
        # if the referenced branch isn't reachable.
189
        backing.rename('referenced', 'moved')
190
        request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
191
        request = request_class(backing)
192
        expected = SuccessfulSmartServerResponse(
193
            (local_result.network_name(),
194
            local_result.repository_format.network_name(),
4084.2.2 by Robert Collins
Review feedback.
195
            ('ref', reference_url)))
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
196
        self.assertEqual(expected, request.execute('', 'False'))
197
198
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
199
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
200
    """Tests for BzrDir.create_repository."""
201
202
    def test_makes_repository(self):
203
        """When there is a bzrdir present, the call succeeds."""
204
        backing = self.get_transport()
205
        self.make_bzrdir('.')
206
        request_class = bzrlib.smart.bzrdir.SmartServerRequestCreateRepository
207
        request = request_class(backing)
208
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
209
        reference_format = reference_bzrdir_format.repository_format
210
        network_name = reference_format.network_name()
211
        expected = SuccessfulSmartServerResponse(
212
            ('ok', 'no', 'no', 'no', network_name))
213
        self.assertEqual(expected, request.execute('', network_name, 'True'))
214
215
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
216
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport):
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
217
    """Tests for BzrDir.find_repository."""
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
218
219
    def test_no_repository(self):
220
        """When there is no repository to be found, ('norepository', ) is returned."""
221
        backing = self.get_transport()
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
222
        request = self._request_class(backing)
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
223
        self.make_bzrdir('.')
224
        self.assertEqual(SmartServerResponse(('norepository', )),
2692.1.19 by Andrew Bennetts
Tweak for consistency suggested by John's review.
225
            request.execute(''))
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
226
227
    def test_nonshared_repository(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
228
        # nonshared repositorys only allow 'find' to return a handle when the
229
        # path the repository is being searched on is the same as that that
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
230
        # the repository is at.
231
        backing = self.get_transport()
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
232
        request = self._request_class(backing)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
233
        result = self._make_repository_and_result()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
234
        self.assertEqual(result, request.execute(''))
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
235
        self.make_bzrdir('subdir')
236
        self.assertEqual(SmartServerResponse(('norepository', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
237
            request.execute('subdir'))
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
238
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
239
    def _make_repository_and_result(self, shared=False, format=None):
240
        """Convenience function to setup a repository.
241
242
        :result: The SmartServerResponse to expect when opening it.
243
        """
244
        repo = self.make_repository('.', shared=shared, format=format)
245
        if repo.supports_rich_root():
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
246
            rich_root = 'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
247
        else:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
248
            rich_root = 'no'
2018.5.138 by Robert Collins
Merge bzr.dev.
249
        if repo._format.supports_tree_reference:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
250
            subtrees = 'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
251
        else:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
252
            subtrees = 'no'
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
253
        if (smart.bzrdir.SmartServerRequestFindRepositoryV3 ==
254
            self._request_class):
255
            return SuccessfulSmartServerResponse(
256
                ('ok', '', rich_root, subtrees, 'no',
257
                 repo._format.network_name()))
258
        elif (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
259
            self._request_class):
260
            # All tests so far are on formats, and for non-external
261
            # repositories.
262
            return SuccessfulSmartServerResponse(
263
                ('ok', '', rich_root, subtrees, 'no'))
264
        else:
265
            return SuccessfulSmartServerResponse(('ok', '', rich_root, subtrees))
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
266
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
267
    def test_shared_repository(self):
268
        """When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
269
        backing = self.get_transport()
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
270
        request = self._request_class(backing)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
271
        result = self._make_repository_and_result(shared=True)
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
272
        self.assertEqual(result, request.execute(''))
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
273
        self.make_bzrdir('subdir')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
274
        result2 = SmartServerResponse(result.args[0:1] + ('..', ) + result.args[2:])
275
        self.assertEqual(result2,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
276
            request.execute('subdir'))
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
277
        self.make_bzrdir('subdir/deeper')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
278
        result3 = SmartServerResponse(result.args[0:1] + ('../..', ) + result.args[2:])
279
        self.assertEqual(result3,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
280
            request.execute('subdir/deeper'))
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
281
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
282
    def test_rich_root_and_subtree_encoding(self):
283
        """Test for the format attributes for rich root and subtree support."""
284
        backing = self.get_transport()
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
285
        request = self._request_class(backing)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
286
        result = self._make_repository_and_result(format='dirstate-with-subtree')
287
        # check the test will be valid
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
288
        self.assertEqual('yes', result.args[2])
289
        self.assertEqual('yes', result.args[3])
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
290
        self.assertEqual(result, request.execute(''))
291
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
292
    def test_supports_external_lookups_no_v2(self):
293
        """Test for the supports_external_lookups attribute."""
294
        backing = self.get_transport()
295
        request = self._request_class(backing)
296
        result = self._make_repository_and_result(format='dirstate-with-subtree')
297
        # check the test will be valid
298
        self.assertEqual('no', result.args[4])
2692.1.24 by Andrew Bennetts
Merge from bzr.dev.
299
        self.assertEqual(result, request.execute(''))
300
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
301
302
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
303
304
    def test_empty_dir(self):
305
        """Initializing an empty dir should succeed and do it."""
306
        backing = self.get_transport()
307
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
308
        self.assertEqual(SmartServerResponse(('ok', )),
2692.1.20 by Andrew Bennetts
Tweak for consistency suggested by John's review.
309
            request.execute(''))
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
310
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
311
        # no branch, tree or repository is expected with the current
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
312
        # default formart.
313
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
314
        self.assertRaises(errors.NotBranchError, made_dir.open_branch)
315
        self.assertRaises(errors.NoRepositoryPresent, made_dir.open_repository)
316
317
    def test_missing_dir(self):
318
        """Initializing a missing directory should fail like the bzrdir api."""
319
        backing = self.get_transport()
320
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
321
        self.assertRaises(errors.NoSuchFile,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
322
            request.execute, 'subdir')
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
323
324
    def test_initialized_dir(self):
325
        """Initializing an extant bzrdir should fail like the bzrdir api."""
326
        backing = self.get_transport()
327
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
328
        self.make_bzrdir('subdir')
329
        self.assertRaises(errors.FileExists,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
330
            request.execute, 'subdir')
331
332
333
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
334
335
    def test_no_branch(self):
336
        """When there is no branch, ('nobranch', ) is returned."""
337
        backing = self.get_transport()
338
        request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
339
        self.make_bzrdir('.')
340
        self.assertEqual(SmartServerResponse(('nobranch', )),
2692.1.20 by Andrew Bennetts
Tweak for consistency suggested by John's review.
341
            request.execute(''))
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
342
343
    def test_branch(self):
344
        """When there is a branch, 'ok' is returned."""
345
        backing = self.get_transport()
346
        request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
347
        self.make_branch('.')
348
        self.assertEqual(SmartServerResponse(('ok', '')),
2692.1.20 by Andrew Bennetts
Tweak for consistency suggested by John's review.
349
            request.execute(''))
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
350
351
    def test_branch_reference(self):
352
        """When there is a branch reference, the reference URL is returned."""
353
        backing = self.get_transport()
354
        request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
355
        branch = self.make_branch('branch')
356
        checkout = branch.create_checkout('reference',lightweight=True)
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
357
        reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir)
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
358
        self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
359
        self.assertEqual(SmartServerResponse(('ok', reference_url)),
2692.1.20 by Andrew Bennetts
Tweak for consistency suggested by John's review.
360
            request.execute('reference'))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
361
362
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.
363
class TestSmartServerRequestOpenBranchV2(TestCaseWithChrootedTransport):
364
365
    def test_no_branch(self):
366
        """When there is no branch, ('nobranch', ) is returned."""
367
        backing = self.get_transport()
368
        self.make_bzrdir('.')
369
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
370
        self.assertEqual(SmartServerResponse(('nobranch', )),
371
            request.execute(''))
372
373
    def test_branch(self):
374
        """When there is a branch, 'ok' is returned."""
375
        backing = self.get_transport()
376
        expected = self.make_branch('.')._format.network_name()
377
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
378
        self.assertEqual(SuccessfulSmartServerResponse(('branch', expected)),
379
            request.execute(''))
380
381
    def test_branch_reference(self):
382
        """When there is a branch reference, the reference URL is returned."""
383
        backing = self.get_transport()
384
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
385
        branch = self.make_branch('branch')
386
        checkout = branch.create_checkout('reference',lightweight=True)
387
        reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir)
388
        self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
389
        self.assertEqual(SuccessfulSmartServerResponse(('ref', reference_url)),
390
            request.execute('reference'))
391
4160.2.1 by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch.
392
    def test_stacked_branch(self):
393
        """Opening a stacked branch does not open the stacked-on branch."""
394
        trunk = self.make_branch('trunk')
395
        feature = self.make_branch('feature', format='1.9')
396
        feature.set_stacked_on_url(trunk.base)
397
        opened_branches = []
398
        Branch.hooks.install_named_hook('open', opened_branches.append, None)
399
        backing = self.get_transport()
400
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
4160.2.4 by Andrew Bennetts
Use BzrDir pre_open hook to jail request code from accessing transports other than the backing transport.
401
        request.setup_jail()
402
        try:
403
            response = request.execute('feature')
404
        finally:
405
            request.teardown_jail()
4160.2.1 by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch.
406
        expected_format = feature._format.network_name()
407
        self.assertEqual(
408
            SuccessfulSmartServerResponse(('branch', expected_format)),
409
            response)
410
        self.assertLength(1, opened_branches)
411
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.
412
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
413
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
414
415
    def test_empty(self):
416
        """For an empty branch, the body is empty."""
417
        backing = self.get_transport()
418
        request = smart.branch.SmartServerRequestRevisionHistory(backing)
419
        self.make_branch('.')
420
        self.assertEqual(SmartServerResponse(('ok', ), ''),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
421
            request.execute(''))
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
422
423
    def test_not_empty(self):
424
        """For a non-empty branch, the body is empty."""
425
        backing = self.get_transport()
426
        request = smart.branch.SmartServerRequestRevisionHistory(backing)
427
        tree = self.make_branch_and_memory_tree('.')
428
        tree.lock_write()
429
        tree.add('')
430
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
431
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
432
        tree.unlock()
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
433
        self.assertEqual(
434
            SmartServerResponse(('ok', ), ('\x00'.join([r1, r2]))),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
435
            request.execute(''))
436
437
438
class TestSmartServerBranchRequest(tests.TestCaseWithMemoryTransport):
2018.5.49 by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to
439
440
    def test_no_branch(self):
441
        """When there is a bzrdir and no branch, NotBranchError is raised."""
442
        backing = self.get_transport()
443
        request = smart.branch.SmartServerBranchRequest(backing)
444
        self.make_bzrdir('.')
445
        self.assertRaises(errors.NotBranchError,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
446
            request.execute, '')
2018.5.49 by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to
447
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
448
    def test_branch_reference(self):
449
        """When there is a branch reference, NotBranchError is raised."""
450
        backing = self.get_transport()
2018.5.49 by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to
451
        request = smart.branch.SmartServerBranchRequest(backing)
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
452
        branch = self.make_branch('branch')
453
        checkout = branch.create_checkout('reference',lightweight=True)
454
        self.assertRaises(errors.NotBranchError,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
455
            request.execute, 'checkout')
456
457
458
class TestSmartServerBranchRequestLastRevisionInfo(tests.TestCaseWithMemoryTransport):
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
459
460
    def test_empty(self):
2018.5.170 by Andrew Bennetts
Use 'null:' instead of '' to mean NULL_REVISION on the wire.
461
        """For an empty branch, the result is ('ok', '0', 'null:')."""
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
462
        backing = self.get_transport()
463
        request = smart.branch.SmartServerBranchRequestLastRevisionInfo(backing)
464
        self.make_branch('.')
2018.5.170 by Andrew Bennetts
Use 'null:' instead of '' to mean NULL_REVISION on the wire.
465
        self.assertEqual(SmartServerResponse(('ok', '0', 'null:')),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
466
            request.execute(''))
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
467
468
    def test_not_empty(self):
469
        """For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
470
        backing = self.get_transport()
471
        request = smart.branch.SmartServerBranchRequestLastRevisionInfo(backing)
472
        tree = self.make_branch_and_memory_tree('.')
473
        tree.lock_write()
474
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
475
        rev_id_utf8 = u'\xc8'.encode('utf-8')
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
476
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
477
        r2 = tree.commit('2nd commit', rev_id=rev_id_utf8)
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
478
        tree.unlock()
479
        self.assertEqual(
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
480
            SmartServerResponse(('ok', '2', rev_id_utf8)),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
481
            request.execute(''))
482
483
484
class TestSmartServerBranchRequestGetConfigFile(tests.TestCaseWithMemoryTransport):
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
485
486
    def test_default(self):
487
        """With no file, we get empty content."""
488
        backing = self.get_transport()
489
        request = smart.branch.SmartServerBranchGetConfigFile(backing)
490
        branch = self.make_branch('.')
491
        # there should be no file by default
492
        content = ''
493
        self.assertEqual(SmartServerResponse(('ok', ), content),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
494
            request.execute(''))
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
495
496
    def test_with_content(self):
497
        # SmartServerBranchGetConfigFile should return the content from
498
        # branch.control_files.get('branch.conf') for now - in the future it may
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
499
        # perform more complex processing.
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
500
        backing = self.get_transport()
501
        request = smart.branch.SmartServerBranchGetConfigFile(backing)
502
        branch = self.make_branch('.')
3407.2.5 by Martin Pool
Deprecate LockableFiles.put_utf8
503
        branch._transport.put_bytes('branch.conf', 'foo bar baz')
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
504
        self.assertEqual(SmartServerResponse(('ok', ), 'foo bar baz'),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
505
            request.execute(''))
506
507
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
508
class SetLastRevisionTestBase(tests.TestCaseWithMemoryTransport):
509
    """Base test case for verbs that implement set_last_revision."""
510
511
    def setUp(self):
512
        tests.TestCaseWithMemoryTransport.setUp(self)
513
        backing_transport = self.get_transport()
514
        self.request = self.request_class(backing_transport)
515
        self.tree = self.make_branch_and_memory_tree('.')
516
517
    def lock_branch(self):
518
        b = self.tree.branch
519
        branch_token = b.lock_write()
520
        repo_token = b.repository.lock_write()
521
        b.repository.unlock()
522
        return branch_token, repo_token
523
524
    def unlock_branch(self):
525
        self.tree.branch.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
526
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
527
    def set_last_revision(self, revision_id, revno):
528
        branch_token, repo_token = self.lock_branch()
529
        response = self._set_last_revision(
530
            revision_id, revno, branch_token, repo_token)
531
        self.unlock_branch()
532
        return response
533
534
    def assertRequestSucceeds(self, revision_id, revno):
535
        response = self.set_last_revision(revision_id, revno)
536
        self.assertEqual(SuccessfulSmartServerResponse(('ok',)), response)
537
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
538
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
539
class TestSetLastRevisionVerbMixin(object):
540
    """Mixin test case for verbs that implement set_last_revision."""
541
542
    def test_set_null_to_null(self):
543
        """An empty branch can have its last revision set to 'null:'."""
544
        self.assertRequestSucceeds('null:', 0)
545
546
    def test_NoSuchRevision(self):
547
        """If the revision_id is not present, the verb returns NoSuchRevision.
548
        """
549
        revision_id = 'non-existent revision'
550
        self.assertEqual(
551
            FailedSmartServerResponse(('NoSuchRevision', revision_id)),
552
            self.set_last_revision(revision_id, 1))
553
554
    def make_tree_with_two_commits(self):
555
        self.tree.lock_write()
556
        self.tree.add('')
557
        rev_id_utf8 = u'\xc8'.encode('utf-8')
558
        r1 = self.tree.commit('1st commit', rev_id=rev_id_utf8)
559
        r2 = self.tree.commit('2nd commit', rev_id='rev-2')
560
        self.tree.unlock()
561
562
    def test_branch_last_revision_info_is_updated(self):
563
        """A branch's tip can be set to a revision that is present in its
564
        repository.
565
        """
566
        # Make a branch with an empty revision history, but two revisions in
567
        # its repository.
568
        self.make_tree_with_two_commits()
569
        rev_id_utf8 = u'\xc8'.encode('utf-8')
570
        self.tree.branch.set_revision_history([])
571
        self.assertEqual(
572
            (0, 'null:'), self.tree.branch.last_revision_info())
573
        # We can update the branch to a revision that is present in the
574
        # repository.
575
        self.assertRequestSucceeds(rev_id_utf8, 1)
576
        self.assertEqual(
577
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
578
579
    def test_branch_last_revision_info_rewind(self):
580
        """A branch's tip can be set to a revision that is an ancestor of the
581
        current tip.
582
        """
583
        self.make_tree_with_two_commits()
584
        rev_id_utf8 = u'\xc8'.encode('utf-8')
585
        self.assertEqual(
586
            (2, 'rev-2'), self.tree.branch.last_revision_info())
587
        self.assertRequestSucceeds(rev_id_utf8, 1)
588
        self.assertEqual(
589
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
590
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
591
    def test_TipChangeRejected(self):
592
        """If a pre_change_branch_tip hook raises TipChangeRejected, the verb
593
        returns TipChangeRejected.
594
        """
595
        rejection_message = u'rejection message\N{INTERROBANG}'
596
        def hook_that_rejects(params):
597
            raise errors.TipChangeRejected(rejection_message)
598
        Branch.hooks.install_named_hook(
599
            'pre_change_branch_tip', hook_that_rejects, None)
600
        self.assertEqual(
601
            FailedSmartServerResponse(
602
                ('TipChangeRejected', rejection_message.encode('utf-8'))),
603
            self.set_last_revision('null:', 0))
604
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
605
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
606
class TestSmartServerBranchRequestSetLastRevision(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
607
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
608
    """Tests for Branch.set_last_revision verb."""
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
609
610
    request_class = smart.branch.SmartServerBranchRequestSetLastRevision
611
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
612
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
613
        return self.request.execute(
614
            '', branch_token, repo_token, revision_id)
615
616
617
class TestSmartServerBranchRequestSetLastRevisionInfo(
618
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
619
    """Tests for Branch.set_last_revision_info verb."""
620
621
    request_class = smart.branch.SmartServerBranchRequestSetLastRevisionInfo
622
623
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
624
        return self.request.execute(
625
            '', branch_token, repo_token, revno, revision_id)
626
627
    def test_NoSuchRevision(self):
628
        """Branch.set_last_revision_info does not have to return
629
        NoSuchRevision if the revision_id is absent.
630
        """
631
        raise tests.TestNotApplicable()
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
632
633
3441.5.25 by Andrew Bennetts
Rename Branch.set_last_revision_descendant verb to Branch.set_last_revision_ex. It's a cop out, but at least it's not misleading.
634
class TestSmartServerBranchRequestSetLastRevisionEx(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
635
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
636
    """Tests for Branch.set_last_revision_ex verb."""
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
637
3441.5.25 by Andrew Bennetts
Rename Branch.set_last_revision_descendant verb to Branch.set_last_revision_ex. It's a cop out, but at least it's not misleading.
638
    request_class = smart.branch.SmartServerBranchRequestSetLastRevisionEx
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
639
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
640
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
641
        return self.request.execute(
642
            '', branch_token, repo_token, revision_id, 0, 0)
643
644
    def assertRequestSucceeds(self, revision_id, revno):
645
        response = self.set_last_revision(revision_id, revno)
646
        self.assertEqual(
647
            SuccessfulSmartServerResponse(('ok', revno, revision_id)),
648
            response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
649
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
650
    def test_branch_last_revision_info_rewind(self):
651
        """A branch's tip can be set to a revision that is an ancestor of the
652
        current tip, but only if allow_overwrite_descendant is passed.
653
        """
654
        self.make_tree_with_two_commits()
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
655
        rev_id_utf8 = u'\xc8'.encode('utf-8')
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
656
        self.assertEqual(
657
            (2, 'rev-2'), self.tree.branch.last_revision_info())
658
        # If allow_overwrite_descendant flag is 0, then trying to set the tip
659
        # to an older revision ID has no effect.
660
        branch_token, repo_token = self.lock_branch()
661
        response = self.request.execute(
662
            '', branch_token, repo_token, rev_id_utf8, 0, 0)
663
        self.assertEqual(
664
            SuccessfulSmartServerResponse(('ok', 2, 'rev-2')),
665
            response)
666
        self.assertEqual(
667
            (2, 'rev-2'), self.tree.branch.last_revision_info())
668
669
        # If allow_overwrite_descendant flag is 1, then setting the tip to an
670
        # ancestor works.
671
        response = self.request.execute(
672
            '', branch_token, repo_token, rev_id_utf8, 0, 1)
673
        self.assertEqual(
674
            SuccessfulSmartServerResponse(('ok', 1, rev_id_utf8)),
675
            response)
676
        self.unlock_branch()
677
        self.assertEqual(
678
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
679
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
680
    def make_branch_with_divergent_history(self):
681
        """Make a branch with divergent history in its repo.
682
683
        The branch's tip will be 'child-2', and the repo will also contain
684
        'child-1', which diverges from a common base revision.
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
685
        """
686
        self.tree.lock_write()
687
        self.tree.add('')
688
        r1 = self.tree.commit('1st commit')
689
        revno_1, revid_1 = self.tree.branch.last_revision_info()
690
        r2 = self.tree.commit('2nd commit', rev_id='child-1')
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
691
        # Undo the second commit
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
692
        self.tree.branch.set_last_revision_info(revno_1, revid_1)
693
        self.tree.set_parent_ids([revid_1])
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
694
        # Make a new second commit, child-2.  child-2 has diverged from
695
        # child-1.
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
696
        new_r2 = self.tree.commit('2nd commit', rev_id='child-2')
697
        self.tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
698
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
699
    def test_not_allow_diverged(self):
700
        """If allow_diverged is not passed, then setting a divergent history
701
        returns a Diverged error.
702
        """
703
        self.make_branch_with_divergent_history()
3297.4.3 by Andrew Bennetts
Add more tests, handle NoSuchRevision in case the remote branch's format can raise it.
704
        self.assertEqual(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
705
            FailedSmartServerResponse(('Diverged',)),
706
            self.set_last_revision('child-1', 2))
707
        # The branch tip was not changed.
708
        self.assertEqual('child-2', self.tree.branch.last_revision())
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
709
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
710
    def test_allow_diverged(self):
711
        """If allow_diverged is passed, then setting a divergent history
712
        succeeds.
713
        """
714
        self.make_branch_with_divergent_history()
715
        branch_token, repo_token = self.lock_branch()
716
        response = self.request.execute(
717
            '', branch_token, repo_token, 'child-1', 1, 0)
718
        self.assertEqual(
719
            SuccessfulSmartServerResponse(('ok', 2, 'child-1')),
720
            response)
721
        self.unlock_branch()
722
        # The branch tip was changed.
723
        self.assertEqual('child-1', self.tree.branch.last_revision())
724
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
725
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
726
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
727
728
    def test_get_parent_none(self):
729
        base_branch = self.make_branch('base')
730
        request = smart.branch.SmartServerBranchGetParent(self.get_transport())
731
        response = request.execute('base')
732
        self.assertEquals(
4083.1.7 by Andrew Bennetts
Fix same trivial bug [(x) != (x,)] in test_remote and test_smart.
733
            SuccessfulSmartServerResponse(('',)), response)
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
734
735
    def test_get_parent_something(self):
736
        base_branch = self.make_branch('base')
737
        base_branch.set_parent(self.get_url('foo'))
738
        request = smart.branch.SmartServerBranchGetParent(self.get_transport())
739
        response = request.execute('base')
740
        self.assertEquals(
4083.1.7 by Andrew Bennetts
Fix same trivial bug [(x) != (x,)] in test_remote and test_smart.
741
            SuccessfulSmartServerResponse(("../foo",)),
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
742
            response)
743
744
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.
745
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
746
# Only called when the branch format and tags match [yay factory
747
# methods] so only need to test straight forward cases.
748
749
    def test_get_bytes(self):
750
        base_branch = self.make_branch('base')
751
        request = smart.branch.SmartServerBranchGetTagsBytes(
752
            self.get_transport())
753
        response = request.execute('base')
754
        self.assertEquals(
755
            SuccessfulSmartServerResponse(('',)), response)
756
757
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
758
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
759
760
    def test_get_stacked_on_url(self):
761
        base_branch = self.make_branch('base', format='1.6')
762
        stacked_branch = self.make_branch('stacked', format='1.6')
763
        # typically should be relative
764
        stacked_branch.set_stacked_on_url('../base')
765
        request = smart.branch.SmartServerBranchRequestGetStackedOnURL(
766
            self.get_transport())
767
        response = request.execute('stacked')
768
        self.assertEquals(
769
            SmartServerResponse(('ok', '../base')),
770
            response)
771
772
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
773
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
774
775
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
776
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
777
778
    def test_lock_write_on_unlocked_branch(self):
779
        backing = self.get_transport()
780
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
781
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
782
        repository = branch.repository
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
783
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
784
        branch_nonce = branch.control_files._lock.peek().get('nonce')
785
        repository_nonce = repository.control_files._lock.peek().get('nonce')
786
        self.assertEqual(
787
            SmartServerResponse(('ok', branch_nonce, repository_nonce)),
788
            response)
789
        # The branch (and associated repository) is now locked.  Verify that
790
        # with a new branch object.
791
        new_branch = repository.bzrdir.open_branch()
792
        self.assertRaises(errors.LockContention, new_branch.lock_write)
793
794
    def test_lock_write_on_locked_branch(self):
795
        backing = self.get_transport()
796
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
797
        branch = self.make_branch('.')
798
        branch.lock_write()
799
        branch.leave_lock_in_place()
800
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
801
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
802
        self.assertEqual(
803
            SmartServerResponse(('LockContention',)), response)
804
805
    def test_lock_write_with_tokens_on_locked_branch(self):
806
        backing = self.get_transport()
807
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
808
        branch = self.make_branch('.', format='knit')
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
809
        branch_token = branch.lock_write()
810
        repo_token = branch.repository.lock_write()
811
        branch.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
812
        branch.leave_lock_in_place()
813
        branch.repository.leave_lock_in_place()
814
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
815
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
816
                                   branch_token, repo_token)
817
        self.assertEqual(
818
            SmartServerResponse(('ok', branch_token, repo_token)), response)
819
820
    def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
821
        backing = self.get_transport()
822
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
823
        branch = self.make_branch('.', format='knit')
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
824
        branch_token = branch.lock_write()
825
        repo_token = branch.repository.lock_write()
826
        branch.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
827
        branch.leave_lock_in_place()
828
        branch.repository.leave_lock_in_place()
829
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
830
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
831
                                   branch_token+'xxx', repo_token)
832
        self.assertEqual(
833
            SmartServerResponse(('TokenMismatch',)), response)
834
835
    def test_lock_write_on_locked_repo(self):
836
        backing = self.get_transport()
837
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
838
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
839
        branch.repository.lock_write()
840
        branch.repository.leave_lock_in_place()
841
        branch.repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
842
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
843
        self.assertEqual(
844
            SmartServerResponse(('LockContention',)), response)
845
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.
846
    def test_lock_write_on_readonly_transport(self):
847
        backing = self.get_readonly_transport()
848
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
849
        branch = self.make_branch('.')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
850
        root = self.get_transport().clone('/')
851
        path = urlutils.relative_url(root.base, self.get_transport().base)
852
        response = request.execute(path)
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
853
        error_name, lock_str, why_str = response.args
854
        self.assertFalse(response.is_successful())
855
        self.assertEqual('LockFailed', error_name)
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.
856
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
857
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
858
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithMemoryTransport):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
859
860
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
861
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
862
863
    def test_unlock_on_locked_branch_and_repo(self):
864
        backing = self.get_transport()
865
        request = smart.branch.SmartServerBranchRequestUnlock(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
866
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
867
        # Lock the branch
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
868
        branch_token = branch.lock_write()
869
        repo_token = branch.repository.lock_write()
870
        branch.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
871
        # Unlock the branch (and repo) object, leaving the physical locks
872
        # in place.
873
        branch.leave_lock_in_place()
874
        branch.repository.leave_lock_in_place()
875
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
876
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
877
                                   branch_token, repo_token)
878
        self.assertEqual(
879
            SmartServerResponse(('ok',)), response)
880
        # The branch is now unlocked.  Verify that with a new branch
881
        # object.
882
        new_branch = branch.bzrdir.open_branch()
883
        new_branch.lock_write()
884
        new_branch.unlock()
885
886
    def test_unlock_on_unlocked_branch_unlocked_repo(self):
887
        backing = self.get_transport()
888
        request = smart.branch.SmartServerBranchRequestUnlock(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
889
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
890
        response = request.execute(
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
891
            '', 'branch token', 'repo token')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
892
        self.assertEqual(
893
            SmartServerResponse(('TokenMismatch',)), response)
894
895
    def test_unlock_on_unlocked_branch_locked_repo(self):
896
        backing = self.get_transport()
897
        request = smart.branch.SmartServerBranchRequestUnlock(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
898
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
899
        # Lock the repository.
900
        repo_token = branch.repository.lock_write()
901
        branch.repository.leave_lock_in_place()
902
        branch.repository.unlock()
903
        # Issue branch lock_write request on the unlocked branch (with locked
904
        # repo).
905
        response = request.execute(
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
906
            '', 'branch token', repo_token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
907
        self.assertEqual(
908
            SmartServerResponse(('TokenMismatch',)), response)
909
910
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
911
class TestSmartServerRepositoryRequest(tests.TestCaseWithMemoryTransport):
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
912
913
    def test_no_repository(self):
914
        """Raise NoRepositoryPresent when there is a bzrdir and no repo."""
915
        # we test this using a shared repository above the named path,
916
        # thus checking the right search logic is used - that is, that
917
        # its the exact path being looked at and the server is not
918
        # searching.
919
        backing = self.get_transport()
2018.5.58 by Wouter van Heyst
Small test fixes to reflect naming and documentation
920
        request = smart.repository.SmartServerRepositoryRequest(backing)
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
921
        self.make_repository('.', shared=True)
922
        self.make_bzrdir('subdir')
923
        self.assertRaises(errors.NoRepositoryPresent,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
924
            request.execute, 'subdir')
925
926
3441.5.4 by Andrew Bennetts
Fix test failures, and add some tests for the remote graph heads RPC.
927
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithMemoryTransport):
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.
928
3211.5.3 by Robert Collins
Adjust size of batch and change gzip comments to bzip2.
929
    def test_trivial_bzipped(self):
930
        # This tests that the wire encoding is actually bzipped
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.
931
        backing = self.get_transport()
932
        request = smart.repository.SmartServerRepositoryGetParentMap(backing)
933
        tree = self.make_branch_and_memory_tree('.')
934
935
        self.assertEqual(None,
2692.1.24 by Andrew Bennetts
Merge from bzr.dev.
936
            request.execute('', 'missing-id'))
3211.5.3 by Robert Collins
Adjust size of batch and change gzip comments to bzip2.
937
        # Note that it returns a body (of '' bzipped).
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.
938
        self.assertEqual(
3211.5.2 by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression.
939
            SuccessfulSmartServerResponse(('ok', ), bz2.compress('')),
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.
940
            request.do_body('\n\n0\n'))
941
942
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
943
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithMemoryTransport):
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
944
945
    def test_none_argument(self):
946
        backing = self.get_transport()
947
        request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
948
        tree = self.make_branch_and_memory_tree('.')
949
        tree.lock_write()
950
        tree.add('')
951
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
952
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
953
        tree.unlock()
954
955
        # the lines of revision_id->revision_parent_list has no guaranteed
956
        # order coming out of a dict, so sort both our test and response
957
        lines = sorted([' '.join([r2, r1]), r1])
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
958
        response = request.execute('', '')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
959
        response.body = '\n'.join(sorted(response.body.split('\n')))
960
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
961
        self.assertEqual(
962
            SmartServerResponse(('ok', ), '\n'.join(lines)), response)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
963
964
    def test_specific_revision_argument(self):
965
        backing = self.get_transport()
966
        request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
967
        tree = self.make_branch_and_memory_tree('.')
968
        tree.lock_write()
969
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
970
        rev_id_utf8 = u'\xc9'.encode('utf-8')
971
        r1 = tree.commit('1st commit', rev_id=rev_id_utf8)
972
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
973
        tree.unlock()
974
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
975
        self.assertEqual(SmartServerResponse(('ok', ), rev_id_utf8),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
976
            request.execute('', rev_id_utf8))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
977
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
978
    def test_no_such_revision(self):
979
        backing = self.get_transport()
980
        request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
981
        tree = self.make_branch_and_memory_tree('.')
982
        tree.lock_write()
983
        tree.add('')
984
        r1 = tree.commit('1st commit')
985
        tree.unlock()
986
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
987
        # Note that it still returns body (of zero bytes).
988
        self.assertEqual(
989
            SmartServerResponse(('nosuchrevision', 'missingrevision', ), ''),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
990
            request.execute('', 'missingrevision'))
991
992
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
993
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
994
995
    def make_two_commit_repo(self):
996
        tree = self.make_branch_and_memory_tree('.')
997
        tree.lock_write()
998
        tree.add('')
999
        r1 = tree.commit('1st commit')
1000
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
1001
        tree.unlock()
1002
        repo = tree.branch.repository
1003
        return repo, r1, r2
1004
1005
    def test_ancestry_of(self):
1006
        """The search argument may be a 'ancestry-of' some heads'."""
1007
        backing = self.get_transport()
1008
        request = smart.repository.SmartServerRepositoryGetStream(backing)
1009
        repo, r1, r2 = self.make_two_commit_repo()
1010
        fetch_spec = ['ancestry-of', r2]
1011
        lines = '\n'.join(fetch_spec)
1012
        request.execute('', repo._format.network_name())
1013
        response = request.do_body(lines)
1014
        self.assertEqual(('ok',), response.args)
1015
        stream_bytes = ''.join(response.body_stream)
1016
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1017
1018
    def test_search(self):
1019
        """The search argument may be a 'search' of some explicit keys."""
1020
        backing = self.get_transport()
1021
        request = smart.repository.SmartServerRepositoryGetStream(backing)
1022
        repo, r1, r2 = self.make_two_commit_repo()
1023
        fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1024
        lines = '\n'.join(fetch_spec)
1025
        request.execute('', repo._format.network_name())
1026
        response = request.do_body(lines)
1027
        self.assertEqual(('ok',), response.args)
1028
        stream_bytes = ''.join(response.body_stream)
1029
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1030
1031
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1032
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
1033
1034
    def test_missing_revision(self):
1035
        """For a missing revision, ('no', ) is returned."""
1036
        backing = self.get_transport()
1037
        request = smart.repository.SmartServerRequestHasRevision(backing)
1038
        self.make_repository('.')
1039
        self.assertEqual(SmartServerResponse(('no', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1040
            request.execute('', 'revid'))
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
1041
1042
    def test_present_revision(self):
2018.5.158 by Andrew Bennetts
Return 'yes'/'no' rather than 'ok'/'no' from the Repository.has_revision smart command.
1043
        """For a present revision, ('yes', ) is returned."""
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
1044
        backing = self.get_transport()
1045
        request = smart.repository.SmartServerRequestHasRevision(backing)
1046
        tree = self.make_branch_and_memory_tree('.')
1047
        tree.lock_write()
1048
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1049
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
1050
        r1 = tree.commit('a commit', rev_id=rev_id_utf8)
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
1051
        tree.unlock()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1052
        self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
2018.5.158 by Andrew Bennetts
Return 'yes'/'no' rather than 'ok'/'no' from the Repository.has_revision smart command.
1053
        self.assertEqual(SmartServerResponse(('yes', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1054
            request.execute('', rev_id_utf8))
1055
1056
1057
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1058
1059
    def test_empty_revid(self):
1060
        """With an empty revid, we get only size an number and revisions"""
1061
        backing = self.get_transport()
1062
        request = smart.repository.SmartServerRepositoryGatherStats(backing)
1063
        repository = self.make_repository('.')
1064
        stats = repository.gather_stats()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1065
        expected_body = 'revisions: 0\n'
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1066
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1067
                         request.execute('', '', 'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1068
1069
    def test_revid_with_committers(self):
1070
        """For a revid we get more infos."""
1071
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1072
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1073
        request = smart.repository.SmartServerRepositoryGatherStats(backing)
1074
        tree = self.make_branch_and_memory_tree('.')
1075
        tree.lock_write()
1076
        tree.add('')
1077
        # Let's build a predictable result
1078
        tree.commit('a commit', timestamp=123456.2, timezone=3600)
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1079
        tree.commit('a commit', timestamp=654321.4, timezone=0,
1080
                    rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1081
        tree.unlock()
1082
1083
        stats = tree.branch.repository.gather_stats()
1084
        expected_body = ('firstrev: 123456.200 3600\n'
1085
                         'latestrev: 654321.400 0\n'
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1086
                         'revisions: 2\n')
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1087
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1088
                         request.execute('',
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1089
                                         rev_id_utf8, 'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1090
1091
    def test_not_empty_repository_with_committers(self):
1092
        """For a revid and requesting committers we get the whole thing."""
1093
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1094
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1095
        request = smart.repository.SmartServerRepositoryGatherStats(backing)
1096
        tree = self.make_branch_and_memory_tree('.')
1097
        tree.lock_write()
1098
        tree.add('')
1099
        # Let's build a predictable result
1100
        tree.commit('a commit', timestamp=123456.2, timezone=3600,
1101
                    committer='foo')
1102
        tree.commit('a commit', timestamp=654321.4, timezone=0,
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1103
                    committer='bar', rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1104
        tree.unlock()
1105
        stats = tree.branch.repository.gather_stats()
1106
1107
        expected_body = ('committers: 2\n'
1108
                         'firstrev: 123456.200 3600\n'
1109
                         'latestrev: 654321.400 0\n'
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1110
                         'revisions: 2\n')
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1111
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1112
                         request.execute('',
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1113
                                         rev_id_utf8, 'yes'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1114
1115
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1116
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport):
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1117
1118
    def test_is_shared(self):
1119
        """For a shared repository, ('yes', ) is returned."""
1120
        backing = self.get_transport()
1121
        request = smart.repository.SmartServerRepositoryIsShared(backing)
1122
        self.make_repository('.', shared=True)
1123
        self.assertEqual(SmartServerResponse(('yes', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1124
            request.execute('', ))
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1125
1126
    def test_is_not_shared(self):
2018.5.58 by Wouter van Heyst
Small test fixes to reflect naming and documentation
1127
        """For a shared repository, ('no', ) is returned."""
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1128
        backing = self.get_transport()
1129
        request = smart.repository.SmartServerRepositoryIsShared(backing)
1130
        self.make_repository('.', shared=False)
1131
        self.assertEqual(SmartServerResponse(('no', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1132
            request.execute('', ))
1133
1134
1135
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1136
1137
    def test_lock_write_on_unlocked_repo(self):
1138
        backing = self.get_transport()
1139
        request = smart.repository.SmartServerRepositoryLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1140
        repository = self.make_repository('.', format='knit')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1141
        response = request.execute('')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1142
        nonce = repository.control_files._lock.peek().get('nonce')
1143
        self.assertEqual(SmartServerResponse(('ok', nonce)), response)
1144
        # The repository is now locked.  Verify that with a new repository
1145
        # object.
1146
        new_repo = repository.bzrdir.open_repository()
1147
        self.assertRaises(errors.LockContention, new_repo.lock_write)
1148
1149
    def test_lock_write_on_locked_repo(self):
1150
        backing = self.get_transport()
1151
        request = smart.repository.SmartServerRepositoryLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1152
        repository = self.make_repository('.', format='knit')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1153
        repository.lock_write()
1154
        repository.leave_lock_in_place()
1155
        repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1156
        response = request.execute('')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1157
        self.assertEqual(
1158
            SmartServerResponse(('LockContention',)), response)
1159
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.
1160
    def test_lock_write_on_readonly_transport(self):
1161
        backing = self.get_readonly_transport()
1162
        request = smart.repository.SmartServerRepositoryLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1163
        repository = self.make_repository('.', format='knit')
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.
1164
        response = request.execute('')
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
1165
        self.assertFalse(response.is_successful())
1166
        self.assertEqual('LockFailed', response.args[0])
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.
1167
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1168
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1169
class TestInsertStreamBase(tests.TestCaseWithMemoryTransport):
1170
1171
    def make_empty_byte_stream(self, repo):
1172
        byte_stream = smart.repository._stream_to_byte_stream([], repo._format)
1173
        return ''.join(byte_stream)
1174
1175
1176
class TestSmartServerRepositoryInsertStream(TestInsertStreamBase):
1177
1178
    def test_insert_stream_empty(self):
1179
        backing = self.get_transport()
1180
        request = smart.repository.SmartServerRepositoryInsertStream(backing)
1181
        repository = self.make_repository('.')
1182
        response = request.execute('', '')
1183
        self.assertEqual(None, response)
1184
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1185
        self.assertEqual(None, response)
1186
        response = request.do_end()
1187
        self.assertEqual(SmartServerResponse(('ok', )), response)
1188
        
1189
1190
class TestSmartServerRepositoryInsertStreamLocked(TestInsertStreamBase):
1191
1192
    def test_insert_stream_empty(self):
1193
        backing = self.get_transport()
1194
        request = smart.repository.SmartServerRepositoryInsertStreamLocked(
1195
            backing)
1196
        repository = self.make_repository('.', format='knit')
1197
        lock_token = repository.lock_write()
1198
        response = request.execute('', '', lock_token)
1199
        self.assertEqual(None, response)
1200
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1201
        self.assertEqual(None, response)
1202
        response = request.do_end()
1203
        self.assertEqual(SmartServerResponse(('ok', )), response)
1204
        repository.unlock()
1205
1206
    def test_insert_stream_with_wrong_lock_token(self):
1207
        backing = self.get_transport()
1208
        request = smart.repository.SmartServerRepositoryInsertStreamLocked(
1209
            backing)
1210
        repository = self.make_repository('.', format='knit')
1211
        lock_token = repository.lock_write()
1212
        self.assertRaises(
1213
            errors.TokenMismatch, request.execute, '', '', 'wrong-token')
1214
        repository.unlock()
1215
1216
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1217
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1218
1219
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1220
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1221
1222
    def test_unlock_on_locked_repo(self):
1223
        backing = self.get_transport()
1224
        request = smart.repository.SmartServerRepositoryUnlock(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1225
        repository = self.make_repository('.', format='knit')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1226
        token = repository.lock_write()
1227
        repository.leave_lock_in_place()
1228
        repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1229
        response = request.execute('', token)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1230
        self.assertEqual(
1231
            SmartServerResponse(('ok',)), response)
1232
        # The repository is now unlocked.  Verify that with a new repository
1233
        # object.
1234
        new_repo = repository.bzrdir.open_repository()
1235
        new_repo.lock_write()
1236
        new_repo.unlock()
1237
1238
    def test_unlock_on_unlocked_repo(self):
1239
        backing = self.get_transport()
1240
        request = smart.repository.SmartServerRepositoryUnlock(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1241
        repository = self.make_repository('.', format='knit')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1242
        response = request.execute('', 'some token')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1243
        self.assertEqual(
1244
            SmartServerResponse(('TokenMismatch',)), response)
1245
1246
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1247
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
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.
1248
1249
    def test_is_readonly_no(self):
1250
        backing = self.get_transport()
1251
        request = smart.request.SmartServerIsReadonly(backing)
1252
        response = request.execute()
1253
        self.assertEqual(
1254
            SmartServerResponse(('no',)), response)
1255
1256
    def test_is_readonly_yes(self):
1257
        backing = self.get_readonly_transport()
1258
        request = smart.request.SmartServerIsReadonly(backing)
1259
        response = request.execute()
1260
        self.assertEqual(
1261
            SmartServerResponse(('yes',)), response)
1262
1263
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1264
class TestSmartServerRepositorySetMakeWorkingTrees(tests.TestCaseWithMemoryTransport):
1265
1266
    def test_set_false(self):
1267
        backing = self.get_transport()
1268
        repo = self.make_repository('.', shared=True)
1269
        repo.set_make_working_trees(True)
1270
        request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
1271
        request = request_class(backing)
1272
        self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
1273
            request.execute('', 'False'))
1274
        repo = repo.bzrdir.open_repository()
1275
        self.assertFalse(repo.make_working_trees())
1276
1277
    def test_set_true(self):
1278
        backing = self.get_transport()
1279
        repo = self.make_repository('.', shared=True)
1280
        repo.set_make_working_trees(False)
1281
        request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
1282
        request = request_class(backing)
1283
        self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
1284
            request.execute('', 'True'))
1285
        repo = repo.bzrdir.open_repository()
1286
        self.assertTrue(repo.make_working_trees())
1287
1288
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1289
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1290
1291
    def make_repo_needing_autopacking(self, path='.'):
1292
        # Make a repo in need of autopacking.
1293
        tree = self.make_branch_and_tree('.', format='pack-0.92')
1294
        repo = tree.branch.repository
1295
        # monkey-patch the pack collection to disable autopacking
1296
        repo._pack_collection._max_pack_count = lambda count: count
1297
        for x in range(10):
1298
            tree.commit('commit %s' % x)
1299
        self.assertEqual(10, len(repo._pack_collection.names()))
1300
        del repo._pack_collection._max_pack_count
1301
        return repo
1302
1303
    def test_autopack_needed(self):
1304
        repo = self.make_repo_needing_autopacking()
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1305
        repo.lock_write()
1306
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1307
        backing = self.get_transport()
1308
        request = smart.packrepository.SmartServerPackRepositoryAutopack(
1309
            backing)
1310
        response = request.execute('')
1311
        self.assertEqual(SmartServerResponse(('ok',)), response)
1312
        repo._pack_collection.reload_pack_names()
1313
        self.assertEqual(1, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1314
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1315
    def test_autopack_not_needed(self):
1316
        tree = self.make_branch_and_tree('.', format='pack-0.92')
1317
        repo = tree.branch.repository
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1318
        repo.lock_write()
1319
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1320
        for x in range(9):
1321
            tree.commit('commit %s' % x)
1322
        backing = self.get_transport()
1323
        request = smart.packrepository.SmartServerPackRepositoryAutopack(
1324
            backing)
1325
        response = request.execute('')
1326
        self.assertEqual(SmartServerResponse(('ok',)), response)
1327
        repo._pack_collection.reload_pack_names()
1328
        self.assertEqual(9, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1329
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1330
    def test_autopack_on_nonpack_format(self):
3801.1.20 by Andrew Bennetts
Return ('ok',) rather than an error the autopack RPC is used on a non-pack repo.
1331
        """A request to autopack a non-pack repo is a no-op."""
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1332
        repo = self.make_repository('.', format='knit')
1333
        backing = self.get_transport()
1334
        request = smart.packrepository.SmartServerPackRepositoryAutopack(
1335
            backing)
1336
        response = request.execute('')
3801.1.20 by Andrew Bennetts
Return ('ok',) rather than an error the autopack RPC is used on a non-pack repo.
1337
        self.assertEqual(SmartServerResponse(('ok',)), response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1338
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1339
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
1340
class TestHandlers(tests.TestCase):
1341
    """Tests for the request.request_handlers object."""
1342
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
1343
    def test_all_registrations_exist(self):
1344
        """All registered request_handlers can be found."""
1345
        # If there's a typo in a register_lazy call, this loop will fail with
1346
        # an AttributeError.
1347
        for key, item in smart.request.request_handlers.iteritems():
1348
            pass
1349
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
1350
    def test_registered_methods(self):
1351
        """Test that known methods are registered to the correct object."""
1352
        self.assertEqual(
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
1353
            smart.request.request_handlers.get('Branch.get_config_file'),
1354
            smart.branch.SmartServerBranchGetConfigFile)
1355
        self.assertEqual(
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1356
            smart.request.request_handlers.get('Branch.get_parent'),
1357
            smart.branch.SmartServerBranchGetParent)
1358
        self.assertEqual(
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
1359
            smart.request.request_handlers.get('Branch.get_tags_bytes'),
1360
            smart.branch.SmartServerBranchGetTagsBytes)
1361
        self.assertEqual(
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1362
            smart.request.request_handlers.get('Branch.lock_write'),
1363
            smart.branch.SmartServerBranchRequestLockWrite)
1364
        self.assertEqual(
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1365
            smart.request.request_handlers.get('Branch.last_revision_info'),
1366
            smart.branch.SmartServerBranchRequestLastRevisionInfo)
1367
        self.assertEqual(
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
1368
            smart.request.request_handlers.get('Branch.revision_history'),
1369
            smart.branch.SmartServerRequestRevisionHistory)
1370
        self.assertEqual(
2018.5.77 by Wouter van Heyst
Fix typo in request_handlers registration of Branch.set_last_revision, and test that registration
1371
            smart.request.request_handlers.get('Branch.set_last_revision'),
1372
            smart.branch.SmartServerBranchRequestSetLastRevision)
1373
        self.assertEqual(
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1374
            smart.request.request_handlers.get('Branch.set_last_revision_info'),
1375
            smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
1376
        self.assertEqual(
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1377
            smart.request.request_handlers.get('Branch.unlock'),
1378
            smart.branch.SmartServerBranchRequestUnlock)
1379
        self.assertEqual(
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
1380
            smart.request.request_handlers.get('BzrDir.find_repository'),
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
1381
            smart.bzrdir.SmartServerRequestFindRepositoryV1)
1382
        self.assertEqual(
1383
            smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
1384
            smart.bzrdir.SmartServerRequestFindRepositoryV2)
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
1385
        self.assertEqual(
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1386
            smart.request.request_handlers.get('BzrDirFormat.initialize'),
1387
            smart.bzrdir.SmartServerRequestInitializeBzrDir)
1388
        self.assertEqual(
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1389
            smart.request.request_handlers.get('BzrDir.cloning_metadir'),
1390
            smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
1391
        self.assertEqual(
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
1392
            smart.request.request_handlers.get('BzrDir.open_branch'),
1393
            smart.bzrdir.SmartServerRequestOpenBranch)
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
1394
        self.assertEqual(
4084.2.1 by Robert Collins
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.
1395
            smart.request.request_handlers.get('BzrDir.open_branchV2'),
1396
            smart.bzrdir.SmartServerRequestOpenBranchV2)
1397
        self.assertEqual(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1398
            smart.request.request_handlers.get('PackRepository.autopack'),
1399
            smart.packrepository.SmartServerPackRepositoryAutopack)
1400
        self.assertEqual(
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1401
            smart.request.request_handlers.get('Repository.gather_stats'),
1402
            smart.repository.SmartServerRepositoryGatherStats)
1403
        self.assertEqual(
3172.5.6 by Robert Collins
Create new smart server verb Repository.get_parent_map.
1404
            smart.request.request_handlers.get('Repository.get_parent_map'),
1405
            smart.repository.SmartServerRepositoryGetParentMap)
1406
        self.assertEqual(
2535.3.69 by Andrew Bennetts
Add check for Repository.stream_knit_data_for_revisions to TestHandlers.test_registered_methods.
1407
            smart.request.request_handlers.get(
1408
                'Repository.get_revision_graph'),
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1409
            smart.repository.SmartServerRepositoryGetRevisionGraph)
1410
        self.assertEqual(
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1411
            smart.request.request_handlers.get('Repository.get_stream'),
1412
            smart.repository.SmartServerRepositoryGetStream)
1413
        self.assertEqual(
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
1414
            smart.request.request_handlers.get('Repository.has_revision'),
1415
            smart.repository.SmartServerRequestHasRevision)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1416
        self.assertEqual(
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1417
            smart.request.request_handlers.get('Repository.insert_stream'),
1418
            smart.repository.SmartServerRepositoryInsertStream)
1419
        self.assertEqual(
1420
            smart.request.request_handlers.get('Repository.insert_stream_locked'),
1421
            smart.repository.SmartServerRepositoryInsertStreamLocked)
1422
        self.assertEqual(
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1423
            smart.request.request_handlers.get('Repository.is_shared'),
1424
            smart.repository.SmartServerRepositoryIsShared)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1425
        self.assertEqual(
1426
            smart.request.request_handlers.get('Repository.lock_write'),
1427
            smart.repository.SmartServerRepositoryLockWrite)
1428
        self.assertEqual(
2535.3.69 by Andrew Bennetts
Add check for Repository.stream_knit_data_for_revisions to TestHandlers.test_registered_methods.
1429
            smart.request.request_handlers.get('Repository.tarball'),
1430
            smart.repository.SmartServerRepositoryTarball)
1431
        self.assertEqual(
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1432
            smart.request.request_handlers.get('Repository.unlock'),
1433
            smart.repository.SmartServerRepositoryUnlock)
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.
1434
        self.assertEqual(
1435
            smart.request.request_handlers.get('Transport.is_readonly'),
1436
            smart.request.SmartServerIsReadonly)