/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2006-2011 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
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
2018.18.2 by Martin Pool
smart method Repository.tarball actually returns the tarball
28
2692.1.2 by Andrew Bennetts
Merge from bzr.dev.
29
from bzrlib import (
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
30
    branch as _mod_branch,
2692.1.2 by Andrew Bennetts
Merge from bzr.dev.
31
    bzrdir,
32
    errors,
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
33
    gpg,
2692.1.2 by Andrew Bennetts
Merge from bzr.dev.
34
    tests,
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
35
    transport,
2692.1.2 by Andrew Bennetts
Merge from bzr.dev.
36
    urlutils,
4634.19.1 by Robert Collins
Combine adjacent substreams of the same type in bzrlib.smart.repository._byte_stream_to_stream.
37
    versionedfile,
2692.1.2 by Andrew Bennetts
Merge from bzr.dev.
38
    )
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
39
from bzrlib.smart import (
40
    branch as smart_branch,
41
    bzrdir as smart_dir,
42
    repository as smart_repo,
43
    packrepository as smart_packrepo,
44
    request as smart_req,
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
45
    server,
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
46
    vfs,
47
    )
5017.3.25 by Vincent Ladeuil
selftest -s bt.test_smart_transport passing
48
from bzrlib.tests import test_server
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
49
from bzrlib.transport import (
50
    chroot,
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
51
    memory,
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
52
    )
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
53
54
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
55
def load_tests(standard_tests, module, loader):
56
    """Multiply tests version and protocol consistency."""
57
    # FindRepository tests.
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
58
    scenarios = [
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
59
        ("find_repository", {
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
60
            "_request_class": smart_dir.SmartServerRequestFindRepositoryV1}),
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
61
        ("find_repositoryV2", {
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
62
            "_request_class": smart_dir.SmartServerRequestFindRepositoryV2}),
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
63
        ("find_repositoryV3", {
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
64
            "_request_class": smart_dir.SmartServerRequestFindRepositoryV3}),
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
65
        ]
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
66
    to_adapt, result = tests.split_suite_by_re(standard_tests,
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
67
        "TestSmartServerRequestFindRepository")
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
68
    v2_only, v1_and_2 = tests.split_suite_by_re(to_adapt,
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
69
        "_v2")
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
70
    tests.multiply_tests(v1_and_2, scenarios, result)
71
    # The first scenario is only applicable to v1 protocols, it is deleted
72
    # since.
73
    tests.multiply_tests(v2_only, scenarios[1:], result)
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
74
    return result
75
76
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
77
class TestCaseWithChrootedTransport(tests.TestCaseWithTransport):
78
79
    def setUp(self):
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
80
        self.vfs_transport_factory = memory.MemoryServer
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
81
        tests.TestCaseWithTransport.setUp(self)
82
        self._chroot_server = None
83
84
    def get_transport(self, relpath=None):
85
        if self._chroot_server is None:
86
            backing_transport = tests.TestCaseWithTransport.get_transport(self)
87
            self._chroot_server = chroot.ChrootServer(backing_transport)
4659.1.2 by Robert Collins
Refactor creation and shutdown of test servers to use a common helper,
88
            self.start_server(self._chroot_server)
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
89
        t = transport.get_transport_from_url(self._chroot_server.get_url())
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
90
        if relpath is not None:
91
            t = t.clone(relpath)
92
        return t
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
93
94
4634.47.4 by Andrew Bennetts
Make more of bzrlib/tests/test_smart.py use MemoryTransport.
95
class TestCaseWithSmartMedium(tests.TestCaseWithMemoryTransport):
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
96
97
    def setUp(self):
98
        super(TestCaseWithSmartMedium, self).setUp()
99
        # We're allowed to set  the transport class here, so that we don't use
100
        # the default or a parameterized class, but rather use the
101
        # TestCaseWithTransport infrastructure to set up a smart server and
102
        # transport.
5340.15.1 by John Arbash Meinel
supersede exc-info branch
103
        self.overrideAttr(self, "transport_server", self.make_transport_server)
3245.4.28 by Andrew Bennetts
Remove another XXX, and include test ID in smart server thread names.
104
105
    def make_transport_server(self):
5017.3.25 by Vincent Ladeuil
selftest -s bt.test_smart_transport passing
106
        return test_server.SmartTCPServer_for_testing('-' + self.id())
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
107
108
    def get_smart_medium(self):
109
        """Get a smart medium to use in tests."""
110
        return self.get_transport().get_smart_medium()
111
112
4634.19.1 by Robert Collins
Combine adjacent substreams of the same type in bzrlib.smart.repository._byte_stream_to_stream.
113
class TestByteStreamToStream(tests.TestCase):
114
115
    def test_repeated_substreams_same_kind_are_one_stream(self):
116
        # Make a stream - an iterable of bytestrings.
117
        stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
118
            None, 'foo')]),('text', [
119
            versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
120
        fmt = bzrdir.format_registry.get('pack-0.92')().repository_format
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
121
        bytes = smart_repo._stream_to_byte_stream(stream, fmt)
4634.19.1 by Robert Collins
Combine adjacent substreams of the same type in bzrlib.smart.repository._byte_stream_to_stream.
122
        streams = []
123
        # Iterate the resulting iterable; checking that we get only one stream
124
        # out.
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
125
        fmt, stream = smart_repo._byte_stream_to_stream(bytes)
4634.19.1 by Robert Collins
Combine adjacent substreams of the same type in bzrlib.smart.repository._byte_stream_to_stream.
126
        for kind, substream in stream:
127
            streams.append((kind, list(substream)))
128
        self.assertLength(1, streams)
129
        self.assertLength(2, streams[0][1])
130
131
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
132
class TestSmartServerResponse(tests.TestCase):
133
134
    def test__eq__(self):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
135
        self.assertEqual(smart_req.SmartServerResponse(('ok', )),
136
            smart_req.SmartServerResponse(('ok', )))
137
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), 'body'),
138
            smart_req.SmartServerResponse(('ok', ), 'body'))
139
        self.assertNotEqual(smart_req.SmartServerResponse(('ok', )),
140
            smart_req.SmartServerResponse(('notok', )))
141
        self.assertNotEqual(smart_req.SmartServerResponse(('ok', ), 'body'),
142
            smart_req.SmartServerResponse(('ok', )))
2018.5.41 by Robert Collins
Fix SmartServerResponse.__eq__ to handle None.
143
        self.assertNotEqual(None,
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
144
            smart_req.SmartServerResponse(('ok', )))
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
145
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
146
    def test__str__(self):
147
        """SmartServerResponses can be stringified."""
148
        self.assertEqual(
3691.2.6 by Martin Pool
Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions
149
            "<SuccessfulSmartServerResponse args=('args',) body='body'>",
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
150
            str(smart_req.SuccessfulSmartServerResponse(('args',), 'body')))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
151
        self.assertEqual(
3691.2.6 by Martin Pool
Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions
152
            "<FailedSmartServerResponse args=('args',) body='body'>",
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
153
            str(smart_req.FailedSmartServerResponse(('args',), 'body')))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
154
155
156
class TestSmartServerRequest(tests.TestCaseWithMemoryTransport):
157
158
    def test_translate_client_path(self):
159
        transport = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
160
        request = smart_req.SmartServerRequest(transport, 'foo/')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
161
        self.assertEqual('./', request.translate_client_path('foo/'))
162
        self.assertRaises(
163
            errors.InvalidURLJoin, request.translate_client_path, 'foo/..')
164
        self.assertRaises(
165
            errors.PathNotChild, request.translate_client_path, '/')
166
        self.assertRaises(
167
            errors.PathNotChild, request.translate_client_path, 'bar/')
168
        self.assertEqual('./baz', request.translate_client_path('foo/baz'))
4760.2.2 by Michael Hudson
test
169
        e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')
170
        self.assertEqual('./' + urlutils.escape(e_acute),
171
                         request.translate_client_path('foo/' + e_acute))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
172
4760.2.5 by Andrew Bennetts
Add some more tests.
173
    def test_translate_client_path_vfs(self):
174
        """VfsRequests receive escaped paths rather than raw UTF-8."""
175
        transport = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
176
        request = vfs.VfsRequest(transport, 'foo/')
4760.2.5 by Andrew Bennetts
Add some more tests.
177
        e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')
178
        escaped = urlutils.escape('foo/' + e_acute)
179
        self.assertEqual('./' + urlutils.escape(e_acute),
180
                         request.translate_client_path(escaped))
181
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
182
    def test_transport_from_client_path(self):
183
        transport = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
184
        request = smart_req.SmartServerRequest(transport, 'foo/')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
185
        self.assertEqual(
186
            transport.base,
187
            request.transport_from_client_path('foo/').base)
188
189
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
190
class TestSmartServerBzrDirRequestCloningMetaDir(
191
    tests.TestCaseWithMemoryTransport):
192
    """Tests for BzrDir.cloning_metadir."""
193
194
    def test_cloning_metadir(self):
195
        """When there is a bzrdir present, the call succeeds."""
196
        backing = self.get_transport()
197
        dir = self.make_bzrdir('.')
198
        local_result = dir.cloning_metadir()
199
        request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
200
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
201
        expected = smart_req.SuccessfulSmartServerResponse(
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
202
            (local_result.network_name(),
203
            local_result.repository_format.network_name(),
4084.2.2 by Robert Collins
Review feedback.
204
            ('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).
205
        self.assertEqual(expected, request.execute('', 'False'))
206
207
    def test_cloning_metadir_reference(self):
4160.2.9 by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make
208
        """The request fails when bzrdir contains a branch reference."""
4070.7.4 by Andrew Bennetts
Deal with branch references better in BzrDir.cloning_metadir RPC (changes protocol).
209
        backing = self.get_transport()
210
        referenced_branch = self.make_branch('referenced')
211
        dir = self.make_bzrdir('.')
212
        local_result = dir.cloning_metadir()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
213
        reference = _mod_branch.BranchReferenceFormat().initialize(
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
214
            dir, target_branch=referenced_branch)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
215
        reference_url = _mod_branch.BranchReferenceFormat().get_reference(dir)
4070.7.4 by Andrew Bennetts
Deal with branch references better in BzrDir.cloning_metadir RPC (changes protocol).
216
        # The server shouldn't try to follow the branch reference, so it's fine
217
        # if the referenced branch isn't reachable.
218
        backing.rename('referenced', 'moved')
219
        request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
220
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
221
        expected = smart_req.FailedSmartServerResponse(('BranchReference',))
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
222
        self.assertEqual(expected, request.execute('', 'False'))
223
224
6266.3.1 by Jelmer Vernooij
Add HPSS call for BzrDir.has_workingtree.
225
class TestSmartServerBzrDirRequestHasWorkingTree(
226
    tests.TestCaseWithTransport):
227
    """Tests for BzrDir.has_workingtree."""
228
229
    def test_has_workingtree_yes(self):
230
        """A working tree is present."""
231
        backing = self.get_transport()
232
        dir = self.make_branch_and_tree('.').bzrdir
233
        request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
234
        request = request_class(backing)
235
        expected = smart_req.SuccessfulSmartServerResponse(('yes',))
236
        self.assertEqual(expected, request.execute(''))
237
238
    def test_has_workingtree_no(self):
239
        """A working tree is missing."""
240
        backing = self.get_transport()
241
        dir = self.make_bzrdir('.')
242
        request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
243
        request = request_class(backing)
244
        expected = smart_req.SuccessfulSmartServerResponse(('no',))
245
        self.assertEqual(expected, request.execute(''))
246
247
6266.2.1 by Jelmer Vernooij
New HPSS call BzrDir.destroy_repository.
248
class TestSmartServerBzrDirRequestDestroyRepository(
249
    tests.TestCaseWithMemoryTransport):
250
    """Tests for BzrDir.destroy_repository."""
251
252
    def test_destroy_repository_default(self):
253
        """The repository can be removed."""
254
        backing = self.get_transport()
255
        dir = self.make_repository('.').bzrdir
6266.2.2 by Jelmer Vernooij
Fix tests.
256
        request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
6266.2.1 by Jelmer Vernooij
New HPSS call BzrDir.destroy_repository.
257
        request = request_class(backing)
258
        expected = smart_req.SuccessfulSmartServerResponse(('ok',))
259
        self.assertEqual(expected, request.execute(''))
260
261
    def test_destroy_repository_missing(self):
262
        """An error is raised if the repository didn't exist."""
263
        backing = self.get_transport()
264
        dir = self.make_bzrdir('.')
6266.2.2 by Jelmer Vernooij
Fix tests.
265
        request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
6266.2.1 by Jelmer Vernooij
New HPSS call BzrDir.destroy_repository.
266
        request = request_class(backing)
6266.2.2 by Jelmer Vernooij
Fix tests.
267
        expected = smart_req.FailedSmartServerResponse(
268
            ('norepository',), None)
6266.2.1 by Jelmer Vernooij
New HPSS call BzrDir.destroy_repository.
269
        self.assertEqual(expected, request.execute(''))
270
271
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
272
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
273
    """Tests for BzrDir.create_repository."""
274
275
    def test_makes_repository(self):
276
        """When there is a bzrdir present, the call succeeds."""
277
        backing = self.get_transport()
278
        self.make_bzrdir('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
279
        request_class = smart_dir.SmartServerRequestCreateRepository
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
280
        request = request_class(backing)
4606.3.1 by Robert Collins
Make test_smart tests more stable when the default format changes.
281
        reference_bzrdir_format = bzrdir.format_registry.get('pack-0.92')()
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
282
        reference_format = reference_bzrdir_format.repository_format
283
        network_name = reference_format.network_name()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
284
        expected = smart_req.SuccessfulSmartServerResponse(
4017.3.2 by Robert Collins
Reduce the number of round trips required to create a repository over the network.
285
            ('ok', 'no', 'no', 'no', network_name))
286
        self.assertEqual(expected, request.execute('', network_name, 'True'))
287
288
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
289
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport):
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
290
    """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.
291
292
    def test_no_repository(self):
293
        """When there is no repository to be found, ('norepository', ) is returned."""
294
        backing = self.get_transport()
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
295
        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.
296
        self.make_bzrdir('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
297
        self.assertEqual(smart_req.SmartServerResponse(('norepository', )),
2692.1.19 by Andrew Bennetts
Tweak for consistency suggested by John's review.
298
            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.
299
300
    def test_nonshared_repository(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
301
        # nonshared repositorys only allow 'find' to return a handle when the
302
        # 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.
303
        # the repository is at.
304
        backing = self.get_transport()
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
305
        request = self._request_class(backing)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
306
        result = self._make_repository_and_result()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
307
        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.
308
        self.make_bzrdir('subdir')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
309
        self.assertEqual(smart_req.SmartServerResponse(('norepository', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
310
            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.
311
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
312
    def _make_repository_and_result(self, shared=False, format=None):
313
        """Convenience function to setup a repository.
314
315
        :result: The SmartServerResponse to expect when opening it.
316
        """
317
        repo = self.make_repository('.', shared=shared, format=format)
318
        if repo.supports_rich_root():
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
319
            rich_root = 'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
320
        else:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
321
            rich_root = 'no'
2018.5.138 by Robert Collins
Merge bzr.dev.
322
        if repo._format.supports_tree_reference:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
323
            subtrees = 'yes'
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
324
        else:
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
325
            subtrees = 'no'
4606.3.1 by Robert Collins
Make test_smart tests more stable when the default format changes.
326
        if repo._format.supports_external_lookups:
327
            external = 'yes'
328
        else:
329
            external = 'no'
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
330
        if (smart_dir.SmartServerRequestFindRepositoryV3 ==
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
331
            self._request_class):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
332
            return smart_req.SuccessfulSmartServerResponse(
4606.3.1 by Robert Collins
Make test_smart tests more stable when the default format changes.
333
                ('ok', '', rich_root, subtrees, external,
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
334
                 repo._format.network_name()))
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
335
        elif (smart_dir.SmartServerRequestFindRepositoryV2 ==
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
336
            self._request_class):
337
            # All tests so far are on formats, and for non-external
338
            # repositories.
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
339
            return smart_req.SuccessfulSmartServerResponse(
4606.3.1 by Robert Collins
Make test_smart tests more stable when the default format changes.
340
                ('ok', '', rich_root, subtrees, external))
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
341
        else:
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
342
            return smart_req.SuccessfulSmartServerResponse(
343
                ('ok', '', rich_root, subtrees))
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
344
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
345
    def test_shared_repository(self):
346
        """When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
347
        backing = self.get_transport()
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
348
        request = self._request_class(backing)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
349
        result = self._make_repository_and_result(shared=True)
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
350
        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.
351
        self.make_bzrdir('subdir')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
352
        result2 = smart_req.SmartServerResponse(
353
            result.args[0:1] + ('..', ) + result.args[2:])
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
354
        self.assertEqual(result2,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
355
            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.
356
        self.make_bzrdir('subdir/deeper')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
357
        result3 = smart_req.SmartServerResponse(
358
            result.args[0:1] + ('../..', ) + result.args[2:])
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
359
        self.assertEqual(result3,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
360
            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.
361
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
362
    def test_rich_root_and_subtree_encoding(self):
363
        """Test for the format attributes for rich root and subtree support."""
364
        backing = self.get_transport()
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
365
        request = self._request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
366
        result = self._make_repository_and_result(
367
            format='dirstate-with-subtree')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
368
        # check the test will be valid
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
369
        self.assertEqual('yes', result.args[2])
370
        self.assertEqual('yes', result.args[3])
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
371
        self.assertEqual(result, request.execute(''))
372
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
373
    def test_supports_external_lookups_no_v2(self):
374
        """Test for the supports_external_lookups attribute."""
375
        backing = self.get_transport()
376
        request = self._request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
377
        result = self._make_repository_and_result(
378
            format='dirstate-with-subtree')
3221.3.2 by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
379
        # check the test will be valid
380
        self.assertEqual('no', result.args[4])
2692.1.24 by Andrew Bennetts
Merge from bzr.dev.
381
        self.assertEqual(result, request.execute(''))
382
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
383
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
384
class TestSmartServerBzrDirRequestGetConfigFile(
385
    tests.TestCaseWithMemoryTransport):
386
    """Tests for BzrDir.get_config_file."""
387
388
    def test_present(self):
389
        backing = self.get_transport()
390
        dir = self.make_bzrdir('.')
391
        dir.get_config().set_default_stack_on("/")
392
        local_result = dir._get_config()._get_config_file().read()
393
        request_class = smart_dir.SmartServerBzrDirRequestConfigFile
394
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
395
        expected = smart_req.SuccessfulSmartServerResponse((), local_result)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
396
        self.assertEqual(expected, request.execute(''))
397
398
    def test_missing(self):
399
        backing = self.get_transport()
400
        dir = self.make_bzrdir('.')
401
        request_class = smart_dir.SmartServerBzrDirRequestConfigFile
402
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
403
        expected = smart_req.SuccessfulSmartServerResponse((), '')
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
404
        self.assertEqual(expected, request.execute(''))
405
406
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
407
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
408
409
    def test_empty_dir(self):
410
        """Initializing an empty dir should succeed and do it."""
411
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
412
        request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
413
        self.assertEqual(smart_req.SmartServerResponse(('ok', )),
2692.1.20 by Andrew Bennetts
Tweak for consistency suggested by John's review.
414
            request.execute(''))
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
415
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
416
        # 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 :).
417
        # default formart.
418
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
419
        self.assertRaises(errors.NotBranchError, made_dir.open_branch)
420
        self.assertRaises(errors.NoRepositoryPresent, made_dir.open_repository)
421
422
    def test_missing_dir(self):
423
        """Initializing a missing directory should fail like the bzrdir api."""
424
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
425
        request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
426
        self.assertRaises(errors.NoSuchFile,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
427
            request.execute, 'subdir')
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
428
429
    def test_initialized_dir(self):
430
        """Initializing an extant bzrdir should fail like the bzrdir api."""
431
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
432
        request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
433
        self.make_bzrdir('subdir')
434
        self.assertRaises(errors.FileExists,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
435
            request.execute, 'subdir')
436
437
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
438
class TestSmartServerRequestBzrDirInitializeEx(
439
    tests.TestCaseWithMemoryTransport):
4436.1.1 by Andrew Bennetts
Rename BzrDirFormat.initialize_ex verb to BzrDirFormat.initialize_ex_1.16.
440
    """Basic tests for BzrDir.initialize_ex_1.16 in the smart server.
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
441
4294.2.10 by Robert Collins
Review feedback.
442
    The main unit tests in test_bzrdir exercise the API comprehensively.
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
443
    """
444
445
    def test_empty_dir(self):
446
        """Initializing an empty dir should succeed and do it."""
447
        backing = self.get_transport()
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
448
        name = self.make_bzrdir('reference')._format.network_name()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
449
        request = smart_dir.SmartServerRequestBzrDirInitializeEx(backing)
450
        self.assertEqual(
451
            smart_req.SmartServerResponse(('', '', '', '', '', '', name,
452
                                           'False', '', '', '')),
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
453
            request.execute(name, '', 'True', 'False', 'False', '', '', '', '',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
454
                            'False'))
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
455
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
456
        # no branch, tree or repository is expected with the current
4294.2.10 by Robert Collins
Review feedback.
457
        # default format.
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
458
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
459
        self.assertRaises(errors.NotBranchError, made_dir.open_branch)
460
        self.assertRaises(errors.NoRepositoryPresent, made_dir.open_repository)
461
462
    def test_missing_dir(self):
463
        """Initializing a missing directory should fail like the bzrdir api."""
464
        backing = self.get_transport()
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
465
        name = self.make_bzrdir('reference')._format.network_name()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
466
        request = smart_dir.SmartServerRequestBzrDirInitializeEx(backing)
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
467
        self.assertRaises(errors.NoSuchFile, request.execute, name,
468
            'subdir/dir', 'False', 'False', 'False', '', '', '', '', 'False')
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
469
470
    def test_initialized_dir(self):
4416.3.4 by Jonathan Lange
Fix a typo.
471
        """Initializing an extant directory should fail like the bzrdir api."""
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
472
        backing = self.get_transport()
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
473
        name = self.make_bzrdir('reference')._format.network_name()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
474
        request = smart_dir.SmartServerRequestBzrDirInitializeEx(backing)
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
475
        self.make_bzrdir('subdir')
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
476
        self.assertRaises(errors.FileExists, request.execute, name, 'subdir',
477
            'False', 'False', 'False', '', '', '', '', 'False')
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
478
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
479
480
class TestSmartServerRequestOpenBzrDir(tests.TestCaseWithMemoryTransport):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
481
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
482
    def test_no_directory(self):
483
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
484
        request = smart_dir.SmartServerRequestOpenBzrDir(backing)
485
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
486
            request.execute('does-not-exist'))
487
488
    def test_empty_directory(self):
489
        backing = self.get_transport()
490
        backing.mkdir('empty')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
491
        request = smart_dir.SmartServerRequestOpenBzrDir(backing)
492
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
493
            request.execute('empty'))
494
495
    def test_outside_root_client_path(self):
496
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
497
        request = smart_dir.SmartServerRequestOpenBzrDir(backing,
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
498
            root_client_path='root')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
499
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
500
            request.execute('not-root'))
501
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
502
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
503
class TestSmartServerRequestOpenBzrDir_2_1(tests.TestCaseWithMemoryTransport):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
504
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
505
    def test_no_directory(self):
506
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
507
        request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing)
508
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
509
            request.execute('does-not-exist'))
510
511
    def test_empty_directory(self):
512
        backing = self.get_transport()
513
        backing.mkdir('empty')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
514
        request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing)
515
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
516
            request.execute('empty'))
517
518
    def test_present_without_workingtree(self):
519
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
520
        request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing)
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
521
        self.make_bzrdir('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
522
        self.assertEqual(smart_req.SmartServerResponse(('yes', 'no')),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
523
            request.execute(''))
524
4634.47.6 by Andrew Bennetts
Give 'no' response for paths outside the root_client_path.
525
    def test_outside_root_client_path(self):
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
526
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
527
        request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing,
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
528
            root_client_path='root')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
529
        self.assertEqual(smart_req.SmartServerResponse(('no',)),
4634.47.6 by Andrew Bennetts
Give 'no' response for paths outside the root_client_path.
530
            request.execute('not-root'))
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
531
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
532
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
533
class TestSmartServerRequestOpenBzrDir_2_1_disk(TestCaseWithChrootedTransport):
534
535
    def test_present_with_workingtree(self):
5017.3.26 by Vincent Ladeuil
./bzr selftest -s bt.test_smart passing
536
        self.vfs_transport_factory = test_server.LocalURLServer
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
537
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
538
        request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing)
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
539
        bd = self.make_bzrdir('.')
540
        bd.create_repository()
541
        bd.create_branch()
542
        bd.create_workingtree()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
543
        self.assertEqual(smart_req.SmartServerResponse(('yes', 'yes')),
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
544
            request.execute(''))
545
546
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
547
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
548
549
    def test_no_branch(self):
550
        """When there is no branch, ('nobranch', ) is returned."""
551
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
552
        request = smart_dir.SmartServerRequestOpenBranch(backing)
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
553
        self.make_bzrdir('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
554
        self.assertEqual(smart_req.SmartServerResponse(('nobranch', )),
2692.1.20 by Andrew Bennetts
Tweak for consistency suggested by John's review.
555
            request.execute(''))
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
556
557
    def test_branch(self):
558
        """When there is a branch, 'ok' is returned."""
559
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
560
        request = smart_dir.SmartServerRequestOpenBranch(backing)
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
561
        self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
562
        self.assertEqual(smart_req.SmartServerResponse(('ok', '')),
2692.1.20 by Andrew Bennetts
Tweak for consistency suggested by John's review.
563
            request.execute(''))
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
564
565
    def test_branch_reference(self):
566
        """When there is a branch reference, the reference URL is returned."""
5017.3.26 by Vincent Ladeuil
./bzr selftest -s bt.test_smart passing
567
        self.vfs_transport_factory = test_server.LocalURLServer
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
568
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
569
        request = smart_dir.SmartServerRequestOpenBranch(backing)
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
570
        branch = self.make_branch('branch')
571
        checkout = branch.create_checkout('reference',lightweight=True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
572
        reference_url = _mod_branch.BranchReferenceFormat().get_reference(
573
            checkout.bzrdir)
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
574
        self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
575
        self.assertEqual(smart_req.SmartServerResponse(('ok', reference_url)),
2692.1.20 by Andrew Bennetts
Tweak for consistency suggested by John's review.
576
            request.execute('reference'))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
577
4734.4.5 by Brian de Alwis
Address comments from Aaron Bentley
578
    def test_notification_on_branch_from_repository(self):
4734.4.4 by Brian de Alwis
Added tests to ensure branching-from-repository error returns detail
579
        """When there is a repository, the error should return details."""
580
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
581
        request = smart_dir.SmartServerRequestOpenBranch(backing)
4734.4.4 by Brian de Alwis
Added tests to ensure branching-from-repository error returns detail
582
        repo = self.make_repository('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
583
        self.assertEqual(smart_req.SmartServerResponse(('nobranch',)),
4734.4.4 by Brian de Alwis
Added tests to ensure branching-from-repository error returns detail
584
            request.execute(''))
585
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
586
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.
587
class TestSmartServerRequestOpenBranchV2(TestCaseWithChrootedTransport):
588
589
    def test_no_branch(self):
590
        """When there is no branch, ('nobranch', ) is returned."""
591
        backing = self.get_transport()
592
        self.make_bzrdir('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
593
        request = smart_dir.SmartServerRequestOpenBranchV2(backing)
594
        self.assertEqual(smart_req.SmartServerResponse(('nobranch', )),
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.
595
            request.execute(''))
596
597
    def test_branch(self):
598
        """When there is a branch, 'ok' is returned."""
599
        backing = self.get_transport()
600
        expected = self.make_branch('.')._format.network_name()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
601
        request = smart_dir.SmartServerRequestOpenBranchV2(backing)
602
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
603
                ('branch', expected)),
604
                         request.execute(''))
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.
605
606
    def test_branch_reference(self):
607
        """When there is a branch reference, the reference URL is returned."""
5017.3.26 by Vincent Ladeuil
./bzr selftest -s bt.test_smart passing
608
        self.vfs_transport_factory = test_server.LocalURLServer
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.
609
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
610
        request = smart_dir.SmartServerRequestOpenBranchV2(backing)
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.
611
        branch = self.make_branch('branch')
612
        checkout = branch.create_checkout('reference',lightweight=True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
613
        reference_url = _mod_branch.BranchReferenceFormat().get_reference(
614
            checkout.bzrdir)
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.
615
        self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
616
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
617
                ('ref', reference_url)),
618
                         request.execute('reference'))
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.
619
4160.2.1 by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch.
620
    def test_stacked_branch(self):
621
        """Opening a stacked branch does not open the stacked-on branch."""
622
        trunk = self.make_branch('trunk')
4599.4.30 by Robert Collins
Remove hard coded format in test_smart's test_stacked_branch now the default format stacks.
623
        feature = self.make_branch('feature')
4160.2.1 by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch.
624
        feature.set_stacked_on_url(trunk.base)
625
        opened_branches = []
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
626
        _mod_branch.Branch.hooks.install_named_hook(
627
            'open', opened_branches.append, None)
4160.2.1 by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch.
628
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
629
        request = smart_dir.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.
630
        request.setup_jail()
631
        try:
632
            response = request.execute('feature')
633
        finally:
634
            request.teardown_jail()
4160.2.1 by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch.
635
        expected_format = feature._format.network_name()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
636
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
637
                ('branch', expected_format)),
638
                         response)
4160.2.1 by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch.
639
        self.assertLength(1, opened_branches)
640
4734.4.5 by Brian de Alwis
Address comments from Aaron Bentley
641
    def test_notification_on_branch_from_repository(self):
4734.4.4 by Brian de Alwis
Added tests to ensure branching-from-repository error returns detail
642
        """When there is a repository, the error should return details."""
643
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
644
        request = smart_dir.SmartServerRequestOpenBranchV2(backing)
4734.4.4 by Brian de Alwis
Added tests to ensure branching-from-repository error returns detail
645
        repo = self.make_repository('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
646
        self.assertEqual(smart_req.SmartServerResponse(('nobranch',)),
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
647
            request.execute(''))
648
649
650
class TestSmartServerRequestOpenBranchV3(TestCaseWithChrootedTransport):
651
652
    def test_no_branch(self):
653
        """When there is no branch, ('nobranch', ) is returned."""
654
        backing = self.get_transport()
655
        self.make_bzrdir('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
656
        request = smart_dir.SmartServerRequestOpenBranchV3(backing)
657
        self.assertEqual(smart_req.SmartServerResponse(('nobranch',)),
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
658
            request.execute(''))
659
660
    def test_branch(self):
661
        """When there is a branch, 'ok' is returned."""
662
        backing = self.get_transport()
663
        expected = self.make_branch('.')._format.network_name()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
664
        request = smart_dir.SmartServerRequestOpenBranchV3(backing)
665
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
666
                ('branch', expected)),
667
                         request.execute(''))
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
668
669
    def test_branch_reference(self):
670
        """When there is a branch reference, the reference URL is returned."""
5017.3.26 by Vincent Ladeuil
./bzr selftest -s bt.test_smart passing
671
        self.vfs_transport_factory = test_server.LocalURLServer
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
672
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
673
        request = smart_dir.SmartServerRequestOpenBranchV3(backing)
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
674
        branch = self.make_branch('branch')
675
        checkout = branch.create_checkout('reference',lightweight=True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
676
        reference_url = _mod_branch.BranchReferenceFormat().get_reference(
677
            checkout.bzrdir)
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
678
        self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
679
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
680
                ('ref', reference_url)),
681
                         request.execute('reference'))
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
682
683
    def test_stacked_branch(self):
684
        """Opening a stacked branch does not open the stacked-on branch."""
685
        trunk = self.make_branch('trunk')
686
        feature = self.make_branch('feature')
687
        feature.set_stacked_on_url(trunk.base)
688
        opened_branches = []
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
689
        _mod_branch.Branch.hooks.install_named_hook(
690
            'open', opened_branches.append, None)
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
691
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
692
        request = smart_dir.SmartServerRequestOpenBranchV3(backing)
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
693
        request.setup_jail()
694
        try:
695
            response = request.execute('feature')
696
        finally:
697
            request.teardown_jail()
698
        expected_format = feature._format.network_name()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
699
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
700
                ('branch', expected_format)),
701
                         response)
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
702
        self.assertLength(1, opened_branches)
703
704
    def test_notification_on_branch_from_repository(self):
705
        """When there is a repository, the error should return details."""
706
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
707
        request = smart_dir.SmartServerRequestOpenBranchV3(backing)
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
708
        repo = self.make_repository('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
709
        self.assertEqual(smart_req.SmartServerResponse(
710
                ('nobranch', 'location is a repository')),
711
                         request.execute(''))
4734.4.4 by Brian de Alwis
Added tests to ensure branching-from-repository error returns detail
712
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.
713
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
714
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
715
716
    def test_empty(self):
717
        """For an empty branch, the body is empty."""
718
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
719
        request = smart_branch.SmartServerRequestRevisionHistory(backing)
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
720
        self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
721
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), ''),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
722
            request.execute(''))
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
723
724
    def test_not_empty(self):
725
        """For a non-empty branch, the body is empty."""
726
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
727
        request = smart_branch.SmartServerRequestRevisionHistory(backing)
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
728
        tree = self.make_branch_and_memory_tree('.')
729
        tree.lock_write()
730
        tree.add('')
731
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
732
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
733
        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.
734
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
735
            smart_req.SmartServerResponse(('ok', ), ('\x00'.join([r1, r2]))),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
736
            request.execute(''))
737
738
739
class TestSmartServerBranchRequest(tests.TestCaseWithMemoryTransport):
2018.5.49 by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to
740
741
    def test_no_branch(self):
742
        """When there is a bzrdir and no branch, NotBranchError is raised."""
743
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
744
        request = smart_branch.SmartServerBranchRequest(backing)
2018.5.49 by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to
745
        self.make_bzrdir('.')
746
        self.assertRaises(errors.NotBranchError,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
747
            request.execute, '')
2018.5.49 by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to
748
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
749
    def test_branch_reference(self):
750
        """When there is a branch reference, NotBranchError is raised."""
751
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
752
        request = smart_branch.SmartServerBranchRequest(backing)
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
753
        branch = self.make_branch('branch')
754
        checkout = branch.create_checkout('reference',lightweight=True)
755
        self.assertRaises(errors.NotBranchError,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
756
            request.execute, 'checkout')
757
758
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
759
class TestSmartServerBranchRequestLastRevisionInfo(
760
    tests.TestCaseWithMemoryTransport):
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
761
762
    def test_empty(self):
2018.5.170 by Andrew Bennetts
Use 'null:' instead of '' to mean NULL_REVISION on the wire.
763
        """For an empty branch, the result is ('ok', '0', 'null:')."""
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
764
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
765
        request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
766
        self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
767
        self.assertEqual(smart_req.SmartServerResponse(('ok', '0', 'null:')),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
768
            request.execute(''))
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
769
770
    def test_not_empty(self):
771
        """For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
772
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
773
        request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
774
        tree = self.make_branch_and_memory_tree('.')
775
        tree.lock_write()
776
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
777
        rev_id_utf8 = u'\xc8'.encode('utf-8')
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
778
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
779
        r2 = tree.commit('2nd commit', rev_id=rev_id_utf8)
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
780
        tree.unlock()
781
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
782
            smart_req.SmartServerResponse(('ok', '2', rev_id_utf8)),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
783
            request.execute(''))
784
785
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
786
class TestSmartServerBranchRequestGetConfigFile(
787
    tests.TestCaseWithMemoryTransport):
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
788
789
    def test_default(self):
790
        """With no file, we get empty content."""
791
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
792
        request = smart_branch.SmartServerBranchGetConfigFile(backing)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
793
        branch = self.make_branch('.')
794
        # there should be no file by default
795
        content = ''
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
796
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), content),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
797
            request.execute(''))
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
798
799
    def test_with_content(self):
800
        # SmartServerBranchGetConfigFile should return the content from
801
        # 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
802
        # perform more complex processing.
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
803
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
804
        request = smart_branch.SmartServerBranchGetConfigFile(backing)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
805
        branch = self.make_branch('.')
3407.2.5 by Martin Pool
Deprecate LockableFiles.put_utf8
806
        branch._transport.put_bytes('branch.conf', 'foo bar baz')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
807
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), 'foo bar baz'),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
808
            request.execute(''))
809
810
4226.2.1 by Robert Collins
Set branch config options via a smart method.
811
class TestLockedBranch(tests.TestCaseWithMemoryTransport):
812
813
    def get_lock_tokens(self, branch):
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
814
        branch_token = branch.lock_write().branch_token
815
        repo_token = branch.repository.lock_write().repository_token
4226.2.1 by Robert Collins
Set branch config options via a smart method.
816
        branch.repository.unlock()
817
        return branch_token, repo_token
818
819
820
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
821
822
    def test_value_name(self):
823
        branch = self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
824
        request = smart_branch.SmartServerBranchRequestSetConfigOption(
4226.2.1 by Robert Collins
Set branch config options via a smart method.
825
            branch.bzrdir.root_transport)
826
        branch_token, repo_token = self.get_lock_tokens(branch)
827
        config = branch._get_config()
828
        result = request.execute('', branch_token, repo_token, 'bar', 'foo',
829
            '')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
830
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
831
        self.assertEqual('bar', config.get_option('foo'))
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
832
        # Cleanup
833
        branch.unlock()
4226.2.1 by Robert Collins
Set branch config options via a smart method.
834
835
    def test_value_name_section(self):
836
        branch = self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
837
        request = smart_branch.SmartServerBranchRequestSetConfigOption(
4226.2.1 by Robert Collins
Set branch config options via a smart method.
838
            branch.bzrdir.root_transport)
839
        branch_token, repo_token = self.get_lock_tokens(branch)
840
        config = branch._get_config()
841
        result = request.execute('', branch_token, repo_token, 'bar', 'foo',
842
            'gam')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
843
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
844
        self.assertEqual('bar', config.get_option('foo', 'gam'))
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
845
        # Cleanup
846
        branch.unlock()
4226.2.1 by Robert Collins
Set branch config options via a smart method.
847
848
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
849
class TestSmartServerBranchRequestSetConfigOptionDict(TestLockedBranch):
850
851
    def setUp(self):
852
        TestLockedBranch.setUp(self)
853
        # A dict with non-ascii keys and values to exercise unicode
854
        # roundtripping.
855
        self.encoded_value_dict = (
856
            'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde')
857
        self.value_dict = {
858
            'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
859
860
    def test_value_name(self):
861
        branch = self.make_branch('.')
862
        request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
863
            branch.bzrdir.root_transport)
864
        branch_token, repo_token = self.get_lock_tokens(branch)
865
        config = branch._get_config()
866
        result = request.execute('', branch_token, repo_token,
867
            self.encoded_value_dict, 'foo', '')
868
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
869
        self.assertEqual(self.value_dict, config.get_option('foo'))
870
        # Cleanup
871
        branch.unlock()
872
873
    def test_value_name_section(self):
874
        branch = self.make_branch('.')
875
        request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
876
            branch.bzrdir.root_transport)
877
        branch_token, repo_token = self.get_lock_tokens(branch)
878
        config = branch._get_config()
879
        result = request.execute('', branch_token, repo_token,
880
            self.encoded_value_dict, 'foo', 'gam')
881
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
882
        self.assertEqual(self.value_dict, config.get_option('foo', 'gam'))
883
        # Cleanup
884
        branch.unlock()
885
886
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
887
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
888
    # Only called when the branch format and tags match [yay factory
889
    # methods] so only need to test straight forward cases.
890
891
    def test_set_bytes(self):
892
        base_branch = self.make_branch('base')
893
        tag_bytes = base_branch._get_tags_bytes()
894
        # get_lock_tokens takes out a lock.
895
        branch_token, repo_token = self.get_lock_tokens(base_branch)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
896
        request = smart_branch.SmartServerBranchSetTagsBytes(
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
897
            self.get_transport())
898
        response = request.execute('base', branch_token, repo_token)
899
        self.assertEqual(None, response)
900
        response = request.do_chunk(tag_bytes)
901
        self.assertEqual(None, response)
902
        response = request.do_end()
903
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
904
            smart_req.SuccessfulSmartServerResponse(()), response)
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
905
        base_branch.unlock()
906
907
    def test_lock_failed(self):
908
        base_branch = self.make_branch('base')
909
        base_branch.lock_write()
910
        tag_bytes = base_branch._get_tags_bytes()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
911
        request = smart_branch.SmartServerBranchSetTagsBytes(
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
912
            self.get_transport())
913
        self.assertRaises(errors.TokenMismatch, request.execute,
914
            'base', 'wrong token', 'wrong token')
915
        # The request handler will keep processing the message parts, so even
916
        # if the request fails immediately do_chunk and do_end are still
917
        # called.
918
        request.do_chunk(tag_bytes)
919
        request.do_end()
920
        base_branch.unlock()
921
922
923
4226.2.1 by Robert Collins
Set branch config options via a smart method.
924
class SetLastRevisionTestBase(TestLockedBranch):
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
925
    """Base test case for verbs that implement set_last_revision."""
926
927
    def setUp(self):
928
        tests.TestCaseWithMemoryTransport.setUp(self)
929
        backing_transport = self.get_transport()
930
        self.request = self.request_class(backing_transport)
931
        self.tree = self.make_branch_and_memory_tree('.')
932
933
    def lock_branch(self):
4226.2.1 by Robert Collins
Set branch config options via a smart method.
934
        return self.get_lock_tokens(self.tree.branch)
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
935
936
    def unlock_branch(self):
937
        self.tree.branch.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
938
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
939
    def set_last_revision(self, revision_id, revno):
940
        branch_token, repo_token = self.lock_branch()
941
        response = self._set_last_revision(
942
            revision_id, revno, branch_token, repo_token)
943
        self.unlock_branch()
944
        return response
945
946
    def assertRequestSucceeds(self, revision_id, revno):
947
        response = self.set_last_revision(revision_id, revno)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
948
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
949
                         response)
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
950
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
951
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
952
class TestSetLastRevisionVerbMixin(object):
953
    """Mixin test case for verbs that implement set_last_revision."""
954
955
    def test_set_null_to_null(self):
956
        """An empty branch can have its last revision set to 'null:'."""
957
        self.assertRequestSucceeds('null:', 0)
958
959
    def test_NoSuchRevision(self):
960
        """If the revision_id is not present, the verb returns NoSuchRevision.
961
        """
962
        revision_id = 'non-existent revision'
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
963
        self.assertEqual(smart_req.FailedSmartServerResponse(('NoSuchRevision',
964
                                                              revision_id)),
965
                         self.set_last_revision(revision_id, 1))
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
966
967
    def make_tree_with_two_commits(self):
968
        self.tree.lock_write()
969
        self.tree.add('')
970
        rev_id_utf8 = u'\xc8'.encode('utf-8')
971
        r1 = self.tree.commit('1st commit', rev_id=rev_id_utf8)
972
        r2 = self.tree.commit('2nd commit', rev_id='rev-2')
973
        self.tree.unlock()
974
975
    def test_branch_last_revision_info_is_updated(self):
976
        """A branch's tip can be set to a revision that is present in its
977
        repository.
978
        """
979
        # Make a branch with an empty revision history, but two revisions in
980
        # its repository.
981
        self.make_tree_with_two_commits()
982
        rev_id_utf8 = u'\xc8'.encode('utf-8')
5718.7.4 by Jelmer Vernooij
Branch.set_revision_history.
983
        self.tree.branch.set_last_revision_info(0, 'null:')
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
984
        self.assertEqual(
985
            (0, 'null:'), self.tree.branch.last_revision_info())
986
        # We can update the branch to a revision that is present in the
987
        # repository.
988
        self.assertRequestSucceeds(rev_id_utf8, 1)
989
        self.assertEqual(
990
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
991
992
    def test_branch_last_revision_info_rewind(self):
993
        """A branch's tip can be set to a revision that is an ancestor of the
994
        current tip.
995
        """
996
        self.make_tree_with_two_commits()
997
        rev_id_utf8 = u'\xc8'.encode('utf-8')
998
        self.assertEqual(
999
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1000
        self.assertRequestSucceeds(rev_id_utf8, 1)
1001
        self.assertEqual(
1002
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1003
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1004
    def test_TipChangeRejected(self):
1005
        """If a pre_change_branch_tip hook raises TipChangeRejected, the verb
1006
        returns TipChangeRejected.
1007
        """
1008
        rejection_message = u'rejection message\N{INTERROBANG}'
1009
        def hook_that_rejects(params):
1010
            raise errors.TipChangeRejected(rejection_message)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1011
        _mod_branch.Branch.hooks.install_named_hook(
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1012
            'pre_change_branch_tip', hook_that_rejects, None)
1013
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1014
            smart_req.FailedSmartServerResponse(
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1015
                ('TipChangeRejected', rejection_message.encode('utf-8'))),
1016
            self.set_last_revision('null:', 0))
1017
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1018
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1019
class TestSmartServerBranchRequestSetLastRevision(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1020
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1021
    """Tests for Branch.set_last_revision verb."""
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1022
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1023
    request_class = smart_branch.SmartServerBranchRequestSetLastRevision
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1024
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1025
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1026
        return self.request.execute(
1027
            '', branch_token, repo_token, revision_id)
1028
1029
1030
class TestSmartServerBranchRequestSetLastRevisionInfo(
1031
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1032
    """Tests for Branch.set_last_revision_info verb."""
1033
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1034
    request_class = smart_branch.SmartServerBranchRequestSetLastRevisionInfo
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1035
1036
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1037
        return self.request.execute(
1038
            '', branch_token, repo_token, revno, revision_id)
1039
1040
    def test_NoSuchRevision(self):
1041
        """Branch.set_last_revision_info does not have to return
1042
        NoSuchRevision if the revision_id is absent.
1043
        """
1044
        raise tests.TestNotApplicable()
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1045
1046
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.
1047
class TestSmartServerBranchRequestSetLastRevisionEx(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1048
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1049
    """Tests for Branch.set_last_revision_ex verb."""
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1050
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1051
    request_class = smart_branch.SmartServerBranchRequestSetLastRevisionEx
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1052
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1053
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1054
        return self.request.execute(
1055
            '', branch_token, repo_token, revision_id, 0, 0)
1056
1057
    def assertRequestSucceeds(self, revision_id, revno):
1058
        response = self.set_last_revision(revision_id, revno)
1059
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1060
            smart_req.SuccessfulSmartServerResponse(('ok', revno, revision_id)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1061
            response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1062
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1063
    def test_branch_last_revision_info_rewind(self):
1064
        """A branch's tip can be set to a revision that is an ancestor of the
1065
        current tip, but only if allow_overwrite_descendant is passed.
1066
        """
1067
        self.make_tree_with_two_commits()
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1068
        rev_id_utf8 = u'\xc8'.encode('utf-8')
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1069
        self.assertEqual(
1070
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1071
        # If allow_overwrite_descendant flag is 0, then trying to set the tip
1072
        # to an older revision ID has no effect.
1073
        branch_token, repo_token = self.lock_branch()
1074
        response = self.request.execute(
1075
            '', branch_token, repo_token, rev_id_utf8, 0, 0)
1076
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1077
            smart_req.SuccessfulSmartServerResponse(('ok', 2, 'rev-2')),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1078
            response)
1079
        self.assertEqual(
1080
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1081
1082
        # If allow_overwrite_descendant flag is 1, then setting the tip to an
1083
        # ancestor works.
1084
        response = self.request.execute(
1085
            '', branch_token, repo_token, rev_id_utf8, 0, 1)
1086
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1087
            smart_req.SuccessfulSmartServerResponse(('ok', 1, rev_id_utf8)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1088
            response)
1089
        self.unlock_branch()
1090
        self.assertEqual(
1091
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1092
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1093
    def make_branch_with_divergent_history(self):
1094
        """Make a branch with divergent history in its repo.
1095
1096
        The branch's tip will be 'child-2', and the repo will also contain
1097
        'child-1', which diverges from a common base revision.
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1098
        """
1099
        self.tree.lock_write()
1100
        self.tree.add('')
1101
        r1 = self.tree.commit('1st commit')
1102
        revno_1, revid_1 = self.tree.branch.last_revision_info()
1103
        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.
1104
        # Undo the second commit
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1105
        self.tree.branch.set_last_revision_info(revno_1, revid_1)
1106
        self.tree.set_parent_ids([revid_1])
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1107
        # Make a new second commit, child-2.  child-2 has diverged from
1108
        # child-1.
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1109
        new_r2 = self.tree.commit('2nd commit', rev_id='child-2')
1110
        self.tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1111
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1112
    def test_not_allow_diverged(self):
1113
        """If allow_diverged is not passed, then setting a divergent history
1114
        returns a Diverged error.
1115
        """
1116
        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.
1117
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1118
            smart_req.FailedSmartServerResponse(('Diverged',)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1119
            self.set_last_revision('child-1', 2))
1120
        # The branch tip was not changed.
1121
        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.
1122
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1123
    def test_allow_diverged(self):
1124
        """If allow_diverged is passed, then setting a divergent history
1125
        succeeds.
1126
        """
1127
        self.make_branch_with_divergent_history()
1128
        branch_token, repo_token = self.lock_branch()
1129
        response = self.request.execute(
1130
            '', branch_token, repo_token, 'child-1', 1, 0)
1131
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1132
            smart_req.SuccessfulSmartServerResponse(('ok', 2, 'child-1')),
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1133
            response)
1134
        self.unlock_branch()
1135
        # The branch tip was changed.
1136
        self.assertEqual('child-1', self.tree.branch.last_revision())
1137
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1138
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1139
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
1140
1141
    def test_get_parent_none(self):
1142
        base_branch = self.make_branch('base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1143
        request = smart_branch.SmartServerBranchGetParent(self.get_transport())
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1144
        response = request.execute('base')
1145
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1146
            smart_req.SuccessfulSmartServerResponse(('',)), response)
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1147
1148
    def test_get_parent_something(self):
1149
        base_branch = self.make_branch('base')
1150
        base_branch.set_parent(self.get_url('foo'))
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1151
        request = smart_branch.SmartServerBranchGetParent(self.get_transport())
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1152
        response = request.execute('base')
1153
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1154
            smart_req.SuccessfulSmartServerResponse(("../foo",)),
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1155
            response)
1156
1157
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1158
class TestSmartServerBranchRequestSetParent(TestLockedBranch):
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1159
1160
    def test_set_parent_none(self):
1161
        branch = self.make_branch('base', format="1.9")
4288.1.9 by Robert Collins
Fix up test usable of _set_parent_location on unlocked branches.
1162
        branch.lock_write()
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1163
        branch._set_parent_location('foo')
4288.1.9 by Robert Collins
Fix up test usable of _set_parent_location on unlocked branches.
1164
        branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1165
        request = smart_branch.SmartServerBranchRequestSetParentLocation(
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1166
            self.get_transport())
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1167
        branch_token, repo_token = self.get_lock_tokens(branch)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1168
        try:
1169
            response = request.execute('base', branch_token, repo_token, '')
1170
        finally:
1171
            branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1172
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1173
        self.assertEqual(None, branch.get_parent())
1174
1175
    def test_set_parent_something(self):
1176
        branch = self.make_branch('base', format="1.9")
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1177
        request = smart_branch.SmartServerBranchRequestSetParentLocation(
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1178
            self.get_transport())
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1179
        branch_token, repo_token = self.get_lock_tokens(branch)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1180
        try:
1181
            response = request.execute('base', branch_token, repo_token,
1182
            'http://bar/')
1183
        finally:
1184
            branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1185
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1186
        self.assertEqual('http://bar/', branch.get_parent())
1187
1188
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1189
class TestSmartServerBranchRequestGetTagsBytes(
1190
    tests.TestCaseWithMemoryTransport):
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
1191
    # Only called when the branch format and tags match [yay factory
1192
    # methods] so only need to test straight forward cases.
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.
1193
1194
    def test_get_bytes(self):
1195
        base_branch = self.make_branch('base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1196
        request = smart_branch.SmartServerBranchGetTagsBytes(
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.
1197
            self.get_transport())
1198
        response = request.execute('base')
1199
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1200
            smart_req.SuccessfulSmartServerResponse(('',)), response)
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.
1201
1202
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1203
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
1204
1205
    def test_get_stacked_on_url(self):
1206
        base_branch = self.make_branch('base', format='1.6')
1207
        stacked_branch = self.make_branch('stacked', format='1.6')
1208
        # typically should be relative
1209
        stacked_branch.set_stacked_on_url('../base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1210
        request = smart_branch.SmartServerBranchRequestGetStackedOnURL(
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1211
            self.get_transport())
1212
        response = request.execute('stacked')
1213
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1214
            smart_req.SmartServerResponse(('ok', '../base')),
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1215
            response)
1216
1217
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1218
class TestSmartServerBranchRequestLockWrite(TestLockedBranch):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1219
1220
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1221
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1222
1223
    def test_lock_write_on_unlocked_branch(self):
1224
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1225
        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.
1226
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1227
        repository = branch.repository
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1228
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1229
        branch_nonce = branch.control_files._lock.peek().get('nonce')
1230
        repository_nonce = repository.control_files._lock.peek().get('nonce')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1231
        self.assertEqual(smart_req.SmartServerResponse(
1232
                ('ok', branch_nonce, repository_nonce)),
1233
                         response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1234
        # The branch (and associated repository) is now locked.  Verify that
1235
        # with a new branch object.
1236
        new_branch = repository.bzrdir.open_branch()
1237
        self.assertRaises(errors.LockContention, new_branch.lock_write)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1238
        # Cleanup
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1239
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1240
        response = request.execute('', branch_nonce, repository_nonce)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1241
1242
    def test_lock_write_on_locked_branch(self):
1243
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1244
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1245
        branch = self.make_branch('.')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1246
        branch_token = branch.lock_write().branch_token
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1247
        branch.leave_lock_in_place()
1248
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1249
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1250
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1251
            smart_req.SmartServerResponse(('LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1252
        # Cleanup
1253
        branch.lock_write(branch_token)
1254
        branch.dont_leave_lock_in_place()
1255
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1256
1257
    def test_lock_write_with_tokens_on_locked_branch(self):
1258
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1259
        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.
1260
        branch = self.make_branch('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1261
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1262
        branch.leave_lock_in_place()
1263
        branch.repository.leave_lock_in_place()
1264
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1265
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1266
                                   branch_token, repo_token)
1267
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1268
            smart_req.SmartServerResponse(('ok', branch_token, repo_token)),
1269
            response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1270
        # Cleanup
1271
        branch.repository.lock_write(repo_token)
1272
        branch.repository.dont_leave_lock_in_place()
1273
        branch.repository.unlock()
1274
        branch.lock_write(branch_token)
1275
        branch.dont_leave_lock_in_place()
1276
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1277
1278
    def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
1279
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1280
        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.
1281
        branch = self.make_branch('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1282
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1283
        branch.leave_lock_in_place()
1284
        branch.repository.leave_lock_in_place()
1285
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1286
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1287
                                   branch_token+'xxx', repo_token)
1288
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1289
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1290
        # Cleanup
1291
        branch.repository.lock_write(repo_token)
1292
        branch.repository.dont_leave_lock_in_place()
1293
        branch.repository.unlock()
1294
        branch.lock_write(branch_token)
1295
        branch.dont_leave_lock_in_place()
1296
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1297
1298
    def test_lock_write_on_locked_repo(self):
1299
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1300
        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.
1301
        branch = self.make_branch('.', format='knit')
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1302
        repo = branch.repository
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1303
        repo_token = repo.lock_write().repository_token
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1304
        repo.leave_lock_in_place()
1305
        repo.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1306
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1307
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1308
            smart_req.SmartServerResponse(('LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1309
        # Cleanup
1310
        repo.lock_write(repo_token)
1311
        repo.dont_leave_lock_in_place()
1312
        repo.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1313
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.
1314
    def test_lock_write_on_readonly_transport(self):
1315
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1316
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
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.
1317
        branch = self.make_branch('.')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1318
        root = self.get_transport().clone('/')
1319
        path = urlutils.relative_url(root.base, self.get_transport().base)
1320
        response = request.execute(path)
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
1321
        error_name, lock_str, why_str = response.args
1322
        self.assertFalse(response.is_successful())
1323
        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.
1324
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1325
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1326
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1327
1328
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1329
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1330
1331
    def test_unlock_on_locked_branch_and_repo(self):
1332
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1333
        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.
1334
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1335
        # Lock the branch
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1336
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1337
        # Unlock the branch (and repo) object, leaving the physical locks
1338
        # in place.
1339
        branch.leave_lock_in_place()
1340
        branch.repository.leave_lock_in_place()
1341
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1342
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1343
                                   branch_token, repo_token)
1344
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1345
            smart_req.SmartServerResponse(('ok',)), response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1346
        # The branch is now unlocked.  Verify that with a new branch
1347
        # object.
1348
        new_branch = branch.bzrdir.open_branch()
1349
        new_branch.lock_write()
1350
        new_branch.unlock()
1351
1352
    def test_unlock_on_unlocked_branch_unlocked_repo(self):
1353
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1354
        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.
1355
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1356
        response = request.execute(
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1357
            '', 'branch token', 'repo token')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1358
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1359
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1360
1361
    def test_unlock_on_unlocked_branch_locked_repo(self):
1362
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1363
        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.
1364
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1365
        # Lock the repository.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1366
        repo_token = branch.repository.lock_write().repository_token
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1367
        branch.repository.leave_lock_in_place()
1368
        branch.repository.unlock()
1369
        # Issue branch lock_write request on the unlocked branch (with locked
1370
        # repo).
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1371
        response = request.execute('', 'branch token', repo_token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1372
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1373
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1374
        # Cleanup
1375
        branch.repository.lock_write(repo_token)
1376
        branch.repository.dont_leave_lock_in_place()
1377
        branch.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1378
1379
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1380
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).
1381
1382
    def test_no_repository(self):
1383
        """Raise NoRepositoryPresent when there is a bzrdir and no repo."""
1384
        # we test this using a shared repository above the named path,
1385
        # thus checking the right search logic is used - that is, that
1386
        # its the exact path being looked at and the server is not
1387
        # searching.
1388
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1389
        request = smart_repo.SmartServerRepositoryRequest(backing)
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
1390
        self.make_repository('.', shared=True)
1391
        self.make_bzrdir('subdir')
1392
        self.assertRaises(errors.NoRepositoryPresent,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1393
            request.execute, 'subdir')
1394
1395
6280.4.2 by Jelmer Vernooij
Provide server side of Repository.break_lock HPSS call.
1396
class TestSmartServerRepositoryBreakLock(tests.TestCaseWithMemoryTransport):
1397
1398
    def test_lock_to_break(self):
1399
        backing = self.get_transport()
1400
        request = smart_repo.SmartServerRepositoryBreakLock(backing)
1401
        tree = self.make_branch_and_memory_tree('.')
1402
        tree.branch.repository.lock_write()
1403
        self.assertEqual(
1404
            smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1405
            request.execute(''))
1406
1407
    def test_nothing_to_break(self):
1408
        backing = self.get_transport()
1409
        request = smart_repo.SmartServerRepositoryBreakLock(backing)
1410
        tree = self.make_branch_and_memory_tree('.')
1411
        self.assertEqual(
1412
            smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1413
            request.execute(''))
1414
1415
3441.5.4 by Andrew Bennetts
Fix test failures, and add some tests for the remote graph heads RPC.
1416
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.
1417
3211.5.3 by Robert Collins
Adjust size of batch and change gzip comments to bzip2.
1418
    def test_trivial_bzipped(self):
1419
        # 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.
1420
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1421
        request = smart_repo.SmartServerRepositoryGetParentMap(backing)
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.
1422
        tree = self.make_branch_and_memory_tree('.')
1423
1424
        self.assertEqual(None,
2692.1.24 by Andrew Bennetts
Merge from bzr.dev.
1425
            request.execute('', 'missing-id'))
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1426
        # Note that it returns a body that is 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.
1427
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1428
            smart_req.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.
1429
            request.do_body('\n\n0\n'))
1430
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1431
    def test_trivial_include_missing(self):
1432
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1433
        request = smart_repo.SmartServerRepositoryGetParentMap(backing)
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1434
        tree = self.make_branch_and_memory_tree('.')
1435
1436
        self.assertEqual(None,
1437
            request.execute('', 'missing-id', 'include-missing:'))
1438
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1439
            smart_req.SuccessfulSmartServerResponse(('ok', ),
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1440
                bz2.compress('missing:missing-id')),
1441
            request.do_body('\n\n0\n'))
1442
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.
1443
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1444
class TestSmartServerRepositoryGetRevisionGraph(
1445
    tests.TestCaseWithMemoryTransport):
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1446
1447
    def test_none_argument(self):
1448
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1449
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1450
        tree = self.make_branch_and_memory_tree('.')
1451
        tree.lock_write()
1452
        tree.add('')
1453
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1454
        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)
1455
        tree.unlock()
1456
1457
        # the lines of revision_id->revision_parent_list has no guaranteed
1458
        # order coming out of a dict, so sort both our test and response
1459
        lines = sorted([' '.join([r2, r1]), r1])
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1460
        response = request.execute('', '')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1461
        response.body = '\n'.join(sorted(response.body.split('\n')))
1462
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
1463
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1464
            smart_req.SmartServerResponse(('ok', ), '\n'.join(lines)), response)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1465
1466
    def test_specific_revision_argument(self):
1467
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1468
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1469
        tree = self.make_branch_and_memory_tree('.')
1470
        tree.lock_write()
1471
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1472
        rev_id_utf8 = u'\xc9'.encode('utf-8')
1473
        r1 = tree.commit('1st commit', rev_id=rev_id_utf8)
1474
        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)
1475
        tree.unlock()
1476
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1477
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), rev_id_utf8),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1478
            request.execute('', rev_id_utf8))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1479
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1480
    def test_no_such_revision(self):
1481
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1482
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1483
        tree = self.make_branch_and_memory_tree('.')
1484
        tree.lock_write()
1485
        tree.add('')
1486
        r1 = tree.commit('1st commit')
1487
        tree.unlock()
1488
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1489
        # Note that it still returns body (of zero bytes).
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1490
        self.assertEqual(smart_req.SmartServerResponse(
1491
                ('nosuchrevision', 'missingrevision', ), ''),
1492
                         request.execute('', 'missingrevision'))
1493
1494
1495
class TestSmartServerRepositoryGetRevIdForRevno(
1496
    tests.TestCaseWithMemoryTransport):
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1497
1498
    def test_revno_found(self):
1499
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1500
        request = smart_repo.SmartServerRepositoryGetRevIdForRevno(backing)
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1501
        tree = self.make_branch_and_memory_tree('.')
1502
        tree.lock_write()
1503
        tree.add('')
1504
        rev1_id_utf8 = u'\xc8'.encode('utf-8')
1505
        rev2_id_utf8 = u'\xc9'.encode('utf-8')
1506
        tree.commit('1st commit', rev_id=rev1_id_utf8)
1507
        tree.commit('2nd commit', rev_id=rev2_id_utf8)
1508
        tree.unlock()
1509
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1510
        self.assertEqual(smart_req.SmartServerResponse(('ok', rev1_id_utf8)),
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1511
            request.execute('', 1, (2, rev2_id_utf8)))
1512
1513
    def test_known_revid_missing(self):
1514
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1515
        request = smart_repo.SmartServerRepositoryGetRevIdForRevno(backing)
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1516
        repo = self.make_repository('.')
1517
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1518
            smart_req.FailedSmartServerResponse(('nosuchrevision', 'ghost')),
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1519
            request.execute('', 1, (2, 'ghost')))
1520
1521
    def test_history_incomplete(self):
1522
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1523
        request = smart_repo.SmartServerRepositoryGetRevIdForRevno(backing)
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1524
        parent = self.make_branch_and_memory_tree('parent', format='1.9')
4526.9.21 by Robert Collins
Fix test_smart's test_history_incomplete to generate a good tree before committing.
1525
        parent.lock_write()
1526
        parent.add([''], ['TREE_ROOT'])
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1527
        r1 = parent.commit(message='first commit')
1528
        r2 = parent.commit(message='second commit')
4526.9.21 by Robert Collins
Fix test_smart's test_history_incomplete to generate a good tree before committing.
1529
        parent.unlock()
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1530
        local = self.make_branch_and_memory_tree('local', format='1.9')
1531
        local.branch.pull(parent.branch)
1532
        local.set_parent_ids([r2])
1533
        r3 = local.commit(message='local commit')
1534
        local.branch.create_clone_on_transport(
1535
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
1536
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1537
            smart_req.SmartServerResponse(('history-incomplete', 2, r2)),
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1538
            request.execute('stacked', 1, (3, r3)))
1539
4476.3.68 by Andrew Bennetts
Review comments from John.
1540
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1541
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1542
1543
    def make_two_commit_repo(self):
1544
        tree = self.make_branch_and_memory_tree('.')
1545
        tree.lock_write()
1546
        tree.add('')
1547
        r1 = tree.commit('1st commit')
1548
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
1549
        tree.unlock()
1550
        repo = tree.branch.repository
1551
        return repo, r1, r2
1552
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1553
1554
class TestSmartServerRepositoryGetStream(GetStreamTestBase):
1555
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1556
    def test_ancestry_of(self):
1557
        """The search argument may be a 'ancestry-of' some heads'."""
1558
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1559
        request = smart_repo.SmartServerRepositoryGetStream(backing)
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1560
        repo, r1, r2 = self.make_two_commit_repo()
1561
        fetch_spec = ['ancestry-of', r2]
1562
        lines = '\n'.join(fetch_spec)
1563
        request.execute('', repo._format.network_name())
1564
        response = request.do_body(lines)
1565
        self.assertEqual(('ok',), response.args)
1566
        stream_bytes = ''.join(response.body_stream)
1567
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1568
1569
    def test_search(self):
1570
        """The search argument may be a 'search' of some explicit keys."""
1571
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1572
        request = smart_repo.SmartServerRepositoryGetStream(backing)
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1573
        repo, r1, r2 = self.make_two_commit_repo()
1574
        fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1575
        lines = '\n'.join(fetch_spec)
1576
        request.execute('', repo._format.network_name())
1577
        response = request.do_body(lines)
1578
        self.assertEqual(('ok',), response.args)
1579
        stream_bytes = ''.join(response.body_stream)
1580
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1581
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1582
    def test_search_everything(self):
1583
        """A search of 'everything' returns a stream."""
1584
        backing = self.get_transport()
5539.2.14 by Andrew Bennetts
Don't add a new verb; instead just teach the client to fallback if it gets a BadSearch error.
1585
        request = smart_repo.SmartServerRepositoryGetStream_1_19(backing)
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1586
        repo, r1, r2 = self.make_two_commit_repo()
1587
        serialised_fetch_spec = 'everything'
1588
        request.execute('', repo._format.network_name())
1589
        response = request.do_body(serialised_fetch_spec)
1590
        self.assertEqual(('ok',), response.args)
1591
        stream_bytes = ''.join(response.body_stream)
1592
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1593
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1594
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1595
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).
1596
1597
    def test_missing_revision(self):
1598
        """For a missing revision, ('no', ) is returned."""
1599
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1600
        request = smart_repo.SmartServerRequestHasRevision(backing)
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
1601
        self.make_repository('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1602
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1603
            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).
1604
1605
    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.
1606
        """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).
1607
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1608
        request = smart_repo.SmartServerRequestHasRevision(backing)
2018.5.56 by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
1609
        tree = self.make_branch_and_memory_tree('.')
1610
        tree.lock_write()
1611
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1612
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
1613
        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).
1614
        tree.unlock()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1615
        self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1616
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1617
            request.execute('', rev_id_utf8))
1618
1619
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1620
class TestSmartServerRequestHasSignatureForRevisionId(
1621
        tests.TestCaseWithMemoryTransport):
1622
1623
    def test_missing_revision(self):
1624
        """For a missing revision, NoSuchRevision is returned."""
1625
        backing = self.get_transport()
1626
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1627
            backing)
1628
        self.make_repository('.')
1629
        self.assertEqual(
1630
            smart_req.FailedSmartServerResponse(
6265.1.5 by Jelmer Vernooij
Fix capitalization - NoSuchRevision is for branches.
1631
                ('nosuchrevision', 'revid'), None),
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1632
            request.execute('', 'revid'))
1633
1634
    def test_missing_signature(self):
1635
        """For a missing signature, ('no', ) is returned."""
1636
        backing = self.get_transport()
1637
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1638
            backing)
1639
        tree = self.make_branch_and_memory_tree('.')
1640
        tree.lock_write()
1641
        tree.add('')
1642
        r1 = tree.commit('a commit', rev_id='A')
1643
        tree.unlock()
1644
        self.assertTrue(tree.branch.repository.has_revision('A'))
1645
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
1646
            request.execute('', 'A'))
1647
1648
    def test_present_signature(self):
1649
        """For a present signature, ('yes', ) is returned."""
1650
        backing = self.get_transport()
1651
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1652
            backing)
1653
        strategy = gpg.LoopbackGPGStrategy(None)
1654
        tree = self.make_branch_and_memory_tree('.')
1655
        tree.lock_write()
1656
        tree.add('')
1657
        r1 = tree.commit('a commit', rev_id='A')
1658
        tree.branch.repository.start_write_group()
1659
        tree.branch.repository.sign_revision('A', strategy)
1660
        tree.branch.repository.commit_write_group()
1661
        tree.unlock()
1662
        self.assertTrue(tree.branch.repository.has_revision('A'))
1663
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1664
            request.execute('', 'A'))
1665
1666
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1667
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1668
1669
    def test_empty_revid(self):
1670
        """With an empty revid, we get only size an number and revisions"""
1671
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1672
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1673
        repository = self.make_repository('.')
1674
        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.
1675
        expected_body = 'revisions: 0\n'
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1676
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1677
                         request.execute('', '', 'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1678
1679
    def test_revid_with_committers(self):
1680
        """For a revid we get more infos."""
1681
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1682
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1683
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1684
        tree = self.make_branch_and_memory_tree('.')
1685
        tree.lock_write()
1686
        tree.add('')
1687
        # Let's build a predictable result
1688
        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.
1689
        tree.commit('a commit', timestamp=654321.4, timezone=0,
1690
                    rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1691
        tree.unlock()
1692
1693
        stats = tree.branch.repository.gather_stats()
1694
        expected_body = ('firstrev: 123456.200 3600\n'
1695
                         '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.
1696
                         'revisions: 2\n')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1697
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1698
                         request.execute('',
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1699
                                         rev_id_utf8, 'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1700
1701
    def test_not_empty_repository_with_committers(self):
1702
        """For a revid and requesting committers we get the whole thing."""
1703
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1704
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1705
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1706
        tree = self.make_branch_and_memory_tree('.')
1707
        tree.lock_write()
1708
        tree.add('')
1709
        # Let's build a predictable result
1710
        tree.commit('a commit', timestamp=123456.2, timezone=3600,
1711
                    committer='foo')
1712
        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.
1713
                    committer='bar', rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1714
        tree.unlock()
1715
        stats = tree.branch.repository.gather_stats()
1716
1717
        expected_body = ('committers: 2\n'
1718
                         'firstrev: 123456.200 3600\n'
1719
                         '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.
1720
                         'revisions: 2\n')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1721
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1722
                         request.execute('',
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1723
                                         rev_id_utf8, 'yes'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1724
1725
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1726
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport):
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1727
1728
    def test_is_shared(self):
1729
        """For a shared repository, ('yes', ) is returned."""
1730
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1731
        request = smart_repo.SmartServerRepositoryIsShared(backing)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1732
        self.make_repository('.', shared=True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1733
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1734
            request.execute('', ))
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1735
1736
    def test_is_not_shared(self):
2018.5.58 by Wouter van Heyst
Small test fixes to reflect naming and documentation
1737
        """For a shared repository, ('no', ) is returned."""
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1738
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1739
        request = smart_repo.SmartServerRepositoryIsShared(backing)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1740
        self.make_repository('.', shared=False)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1741
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1742
            request.execute('', ))
1743
1744
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
1745
class TestSmartServerRepositoryMakeWorkingTrees(
1746
        tests.TestCaseWithMemoryTransport):
1747
1748
    def test_make_working_trees(self):
1749
        """For a repository with working trees, ('yes', ) is returned."""
1750
        backing = self.get_transport()
1751
        request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
1752
        r = self.make_repository('.')
1753
        r.set_make_working_trees(True)
1754
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1755
            request.execute('', ))
1756
1757
    def test_is_not_shared(self):
1758
        """For a repository with working trees, ('no', ) is returned."""
1759
        backing = self.get_transport()
1760
        request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
1761
        r = self.make_repository('.')
1762
        r.set_make_working_trees(False)
1763
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
1764
            request.execute('', ))
1765
1766
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1767
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1768
1769
    def test_lock_write_on_unlocked_repo(self):
1770
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1771
        request = smart_repo.SmartServerRepositoryLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1772
        repository = self.make_repository('.', format='knit')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1773
        response = request.execute('')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1774
        nonce = repository.control_files._lock.peek().get('nonce')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1775
        self.assertEqual(smart_req.SmartServerResponse(('ok', nonce)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1776
        # The repository is now locked.  Verify that with a new repository
1777
        # object.
1778
        new_repo = repository.bzrdir.open_repository()
1779
        self.assertRaises(errors.LockContention, new_repo.lock_write)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1780
        # Cleanup
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1781
        request = smart_repo.SmartServerRepositoryUnlock(backing)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1782
        response = request.execute('', nonce)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1783
1784
    def test_lock_write_on_locked_repo(self):
1785
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1786
        request = smart_repo.SmartServerRepositoryLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1787
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1788
        repo_token = repository.lock_write().repository_token
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1789
        repository.leave_lock_in_place()
1790
        repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1791
        response = request.execute('')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1792
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1793
            smart_req.SmartServerResponse(('LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1794
        # Cleanup
1795
        repository.lock_write(repo_token)
1796
        repository.dont_leave_lock_in_place()
1797
        repository.unlock()
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1798
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.
1799
    def test_lock_write_on_readonly_transport(self):
1800
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1801
        request = smart_repo.SmartServerRepositoryLockWrite(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1802
        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.
1803
        response = request.execute('')
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
1804
        self.assertFalse(response.is_successful())
1805
        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.
1806
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1807
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1808
class TestInsertStreamBase(tests.TestCaseWithMemoryTransport):
1809
1810
    def make_empty_byte_stream(self, repo):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1811
        byte_stream = smart_repo._stream_to_byte_stream([], repo._format)
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1812
        return ''.join(byte_stream)
1813
1814
1815
class TestSmartServerRepositoryInsertStream(TestInsertStreamBase):
1816
1817
    def test_insert_stream_empty(self):
1818
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1819
        request = smart_repo.SmartServerRepositoryInsertStream(backing)
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1820
        repository = self.make_repository('.')
1821
        response = request.execute('', '')
1822
        self.assertEqual(None, response)
1823
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1824
        self.assertEqual(None, response)
1825
        response = request.do_end()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1826
        self.assertEqual(smart_req.SmartServerResponse(('ok', )), response)
1827
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1828
1829
class TestSmartServerRepositoryInsertStreamLocked(TestInsertStreamBase):
1830
1831
    def test_insert_stream_empty(self):
1832
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1833
        request = smart_repo.SmartServerRepositoryInsertStreamLocked(
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1834
            backing)
1835
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1836
        lock_token = repository.lock_write().repository_token
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1837
        response = request.execute('', '', lock_token)
1838
        self.assertEqual(None, response)
1839
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1840
        self.assertEqual(None, response)
1841
        response = request.do_end()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1842
        self.assertEqual(smart_req.SmartServerResponse(('ok', )), response)
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1843
        repository.unlock()
1844
1845
    def test_insert_stream_with_wrong_lock_token(self):
1846
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1847
        request = smart_repo.SmartServerRepositoryInsertStreamLocked(
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1848
            backing)
1849
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1850
        lock_token = repository.lock_write().repository_token
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1851
        self.assertRaises(
1852
            errors.TokenMismatch, request.execute, '', '', 'wrong-token')
1853
        repository.unlock()
1854
1855
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1856
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1857
1858
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1859
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1860
1861
    def test_unlock_on_locked_repo(self):
1862
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1863
        request = smart_repo.SmartServerRepositoryUnlock(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1864
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1865
        token = repository.lock_write().repository_token
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1866
        repository.leave_lock_in_place()
1867
        repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1868
        response = request.execute('', token)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1869
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1870
            smart_req.SmartServerResponse(('ok',)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1871
        # The repository is now unlocked.  Verify that with a new repository
1872
        # object.
1873
        new_repo = repository.bzrdir.open_repository()
1874
        new_repo.lock_write()
1875
        new_repo.unlock()
1876
1877
    def test_unlock_on_unlocked_repo(self):
1878
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1879
        request = smart_repo.SmartServerRepositoryUnlock(backing)
3015.2.12 by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories.
1880
        repository = self.make_repository('.', format='knit')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1881
        response = request.execute('', 'some token')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1882
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1883
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1884
1885
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1886
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.
1887
1888
    def test_is_readonly_no(self):
1889
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1890
        request = smart_req.SmartServerIsReadonly(backing)
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.
1891
        response = request.execute()
1892
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1893
            smart_req.SmartServerResponse(('no',)), response)
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.
1894
1895
    def test_is_readonly_yes(self):
1896
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1897
        request = smart_req.SmartServerIsReadonly(backing)
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.
1898
        response = request.execute()
1899
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1900
            smart_req.SmartServerResponse(('yes',)), response)
1901
1902
1903
class TestSmartServerRepositorySetMakeWorkingTrees(
1904
    tests.TestCaseWithMemoryTransport):
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1905
1906
    def test_set_false(self):
1907
        backing = self.get_transport()
1908
        repo = self.make_repository('.', shared=True)
1909
        repo.set_make_working_trees(True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1910
        request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1911
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1912
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1913
            request.execute('', 'False'))
1914
        repo = repo.bzrdir.open_repository()
1915
        self.assertFalse(repo.make_working_trees())
1916
1917
    def test_set_true(self):
1918
        backing = self.get_transport()
1919
        repo = self.make_repository('.', shared=True)
1920
        repo.set_make_working_trees(False)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1921
        request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1922
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1923
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1924
            request.execute('', 'True'))
1925
        repo = repo.bzrdir.open_repository()
1926
        self.assertTrue(repo.make_working_trees())
1927
1928
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1929
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1930
1931
    def make_repo_needing_autopacking(self, path='.'):
1932
        # Make a repo in need of autopacking.
1933
        tree = self.make_branch_and_tree('.', format='pack-0.92')
1934
        repo = tree.branch.repository
1935
        # monkey-patch the pack collection to disable autopacking
1936
        repo._pack_collection._max_pack_count = lambda count: count
1937
        for x in range(10):
1938
            tree.commit('commit %s' % x)
1939
        self.assertEqual(10, len(repo._pack_collection.names()))
1940
        del repo._pack_collection._max_pack_count
1941
        return repo
1942
1943
    def test_autopack_needed(self):
1944
        repo = self.make_repo_needing_autopacking()
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1945
        repo.lock_write()
1946
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1947
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1948
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1949
            backing)
1950
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1951
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1952
        repo._pack_collection.reload_pack_names()
1953
        self.assertEqual(1, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1954
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1955
    def test_autopack_not_needed(self):
1956
        tree = self.make_branch_and_tree('.', format='pack-0.92')
1957
        repo = tree.branch.repository
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1958
        repo.lock_write()
1959
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1960
        for x in range(9):
1961
            tree.commit('commit %s' % x)
1962
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1963
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1964
            backing)
1965
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1966
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1967
        repo._pack_collection.reload_pack_names()
1968
        self.assertEqual(9, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1969
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1970
    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.
1971
        """A request to autopack a non-pack repo is a no-op."""
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1972
        repo = self.make_repository('.', format='knit')
1973
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1974
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1975
            backing)
1976
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1977
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1978
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1979
4760.2.5 by Andrew Bennetts
Add some more tests.
1980
class TestSmartServerVfsGet(tests.TestCaseWithMemoryTransport):
1981
1982
    def test_unicode_path(self):
1983
        """VFS requests expect unicode paths to be escaped."""
1984
        filename = u'foo\N{INTERROBANG}'
1985
        filename_escaped = urlutils.escape(filename)
1986
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1987
        request = vfs.GetRequest(backing)
4760.2.5 by Andrew Bennetts
Add some more tests.
1988
        backing.put_bytes_non_atomic(filename_escaped, 'contents')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1989
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), 'contents'),
4760.2.5 by Andrew Bennetts
Add some more tests.
1990
            request.execute(filename_escaped))
1991
1992
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
1993
class TestHandlers(tests.TestCase):
1994
    """Tests for the request.request_handlers object."""
1995
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
1996
    def test_all_registrations_exist(self):
1997
        """All registered request_handlers can be found."""
1998
        # If there's a typo in a register_lazy call, this loop will fail with
1999
        # an AttributeError.
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2000
        for key, item in smart_req.request_handlers.iteritems():
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
2001
            pass
2002
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2003
    def assertHandlerEqual(self, verb, handler):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2004
        self.assertEqual(smart_req.request_handlers.get(verb), handler)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2005
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
2006
    def test_registered_methods(self):
2007
        """Test that known methods are registered to the correct object."""
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2008
        self.assertHandlerEqual('Branch.get_config_file',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2009
            smart_branch.SmartServerBranchGetConfigFile)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2010
        self.assertHandlerEqual('Branch.get_parent',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2011
            smart_branch.SmartServerBranchGetParent)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2012
        self.assertHandlerEqual('Branch.get_tags_bytes',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2013
            smart_branch.SmartServerBranchGetTagsBytes)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2014
        self.assertHandlerEqual('Branch.lock_write',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2015
            smart_branch.SmartServerBranchRequestLockWrite)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2016
        self.assertHandlerEqual('Branch.last_revision_info',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2017
            smart_branch.SmartServerBranchRequestLastRevisionInfo)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2018
        self.assertHandlerEqual('Branch.revision_history',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2019
            smart_branch.SmartServerRequestRevisionHistory)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2020
        self.assertHandlerEqual('Branch.set_config_option',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2021
            smart_branch.SmartServerBranchRequestSetConfigOption)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2022
        self.assertHandlerEqual('Branch.set_last_revision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2023
            smart_branch.SmartServerBranchRequestSetLastRevision)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2024
        self.assertHandlerEqual('Branch.set_last_revision_info',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2025
            smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
2026
        self.assertHandlerEqual('Branch.set_last_revision_ex',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2027
            smart_branch.SmartServerBranchRequestSetLastRevisionEx)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
2028
        self.assertHandlerEqual('Branch.set_parent_location',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2029
            smart_branch.SmartServerBranchRequestSetParentLocation)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2030
        self.assertHandlerEqual('Branch.unlock',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2031
            smart_branch.SmartServerBranchRequestUnlock)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2032
        self.assertHandlerEqual('BzrDir.find_repository',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2033
            smart_dir.SmartServerRequestFindRepositoryV1)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2034
        self.assertHandlerEqual('BzrDir.find_repositoryV2',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2035
            smart_dir.SmartServerRequestFindRepositoryV2)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2036
        self.assertHandlerEqual('BzrDirFormat.initialize',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2037
            smart_dir.SmartServerRequestInitializeBzrDir)
4436.1.1 by Andrew Bennetts
Rename BzrDirFormat.initialize_ex verb to BzrDirFormat.initialize_ex_1.16.
2038
        self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2039
            smart_dir.SmartServerRequestBzrDirInitializeEx)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2040
        self.assertHandlerEqual('BzrDir.cloning_metadir',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2041
            smart_dir.SmartServerBzrDirRequestCloningMetaDir)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2042
        self.assertHandlerEqual('BzrDir.get_config_file',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2043
            smart_dir.SmartServerBzrDirRequestConfigFile)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2044
        self.assertHandlerEqual('BzrDir.open_branch',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2045
            smart_dir.SmartServerRequestOpenBranch)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2046
        self.assertHandlerEqual('BzrDir.open_branchV2',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2047
            smart_dir.SmartServerRequestOpenBranchV2)
4734.4.8 by Andrew Bennetts
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).
2048
        self.assertHandlerEqual('BzrDir.open_branchV3',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2049
            smart_dir.SmartServerRequestOpenBranchV3)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2050
        self.assertHandlerEqual('PackRepository.autopack',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2051
            smart_packrepo.SmartServerPackRepositoryAutopack)
6280.4.2 by Jelmer Vernooij
Provide server side of Repository.break_lock HPSS call.
2052
        self.assertHandlerEqual('Repository.break_lock',
2053
            smart_repo.SmartServerRepositoryBreakLock)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2054
        self.assertHandlerEqual('Repository.gather_stats',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2055
            smart_repo.SmartServerRepositoryGatherStats)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2056
        self.assertHandlerEqual('Repository.get_parent_map',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2057
            smart_repo.SmartServerRepositoryGetParentMap)
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
2058
        self.assertHandlerEqual('Repository.get_rev_id_for_revno',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2059
            smart_repo.SmartServerRepositoryGetRevIdForRevno)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2060
        self.assertHandlerEqual('Repository.get_revision_graph',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2061
            smart_repo.SmartServerRepositoryGetRevisionGraph)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2062
        self.assertHandlerEqual('Repository.get_stream',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2063
            smart_repo.SmartServerRepositoryGetStream)
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
2064
        self.assertHandlerEqual('Repository.get_stream_1.19',
2065
            smart_repo.SmartServerRepositoryGetStream_1_19)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2066
        self.assertHandlerEqual('Repository.has_revision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2067
            smart_repo.SmartServerRequestHasRevision)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2068
        self.assertHandlerEqual('Repository.insert_stream',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2069
            smart_repo.SmartServerRepositoryInsertStream)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2070
        self.assertHandlerEqual('Repository.insert_stream_locked',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2071
            smart_repo.SmartServerRepositoryInsertStreamLocked)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2072
        self.assertHandlerEqual('Repository.is_shared',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2073
            smart_repo.SmartServerRepositoryIsShared)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2074
        self.assertHandlerEqual('Repository.lock_write',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2075
            smart_repo.SmartServerRepositoryLockWrite)
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
2076
        self.assertHandlerEqual('Repository.make_working_trees',
2077
            smart_repo.SmartServerRepositoryMakeWorkingTrees)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2078
        self.assertHandlerEqual('Repository.tarball',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2079
            smart_repo.SmartServerRepositoryTarball)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2080
        self.assertHandlerEqual('Repository.unlock',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2081
            smart_repo.SmartServerRepositoryUnlock)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2082
        self.assertHandlerEqual('Transport.is_readonly',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2083
            smart_req.SmartServerIsReadonly)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2084
2085
2086
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2087
    """Tests for SmartTCPServer hooks."""
2088
2089
    def setUp(self):
2090
        super(SmartTCPServerHookTests, self).setUp()
2091
        self.server = server.SmartTCPServer(self.get_transport())
2092
2093
    def test_run_server_started_hooks(self):
2094
        """Test the server started hooks get fired properly."""
2095
        started_calls = []
2096
        server.SmartTCPServer.hooks.install_named_hook('server_started',
2097
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2098
            None)
2099
        started_ex_calls = []
2100
        server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2101
            lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2102
            None)
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2103
        self.server._sockname = ('example.com', 42)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2104
        self.server.run_server_started_hooks()
2105
        self.assertEquals(started_calls,
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2106
            [([self.get_transport().base], 'bzr://example.com:42/')])
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2107
        self.assertEquals(started_ex_calls,
2108
            [([self.get_transport().base], self.server)])
2109
2110
    def test_run_server_started_hooks_ipv6(self):
2111
        """Test that socknames can contain 4-tuples."""
2112
        self.server._sockname = ('::', 42, 0, 0)
2113
        started_calls = []
2114
        server.SmartTCPServer.hooks.install_named_hook('server_started',
2115
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2116
            None)
2117
        self.server.run_server_started_hooks()
2118
        self.assertEquals(started_calls,
2119
                [([self.get_transport().base], 'bzr://:::42/')])
2120
2121
    def test_run_server_stopped_hooks(self):
2122
        """Test the server stopped hooks."""
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2123
        self.server._sockname = ('example.com', 42)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2124
        stopped_calls = []
2125
        server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2126
            lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2127
            None)
2128
        self.server.run_server_stopped_hooks()
2129
        self.assertEquals(stopped_calls,
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2130
            [([self.get_transport().base], 'bzr://example.com:42/')])