/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
6270.1.17 by Jelmer Vernooij
s/set_config_file/put_config_file.
820
class TestSmartServerBranchRequestPutConfigFile(TestLockedBranch):
6270.1.9 by Jelmer Vernooij
add Branch.set_config_file.
821
822
    def test_with_content(self):
823
        backing = self.get_transport()
6270.1.17 by Jelmer Vernooij
s/set_config_file/put_config_file.
824
        request = smart_branch.SmartServerBranchPutConfigFile(backing)
6270.1.9 by Jelmer Vernooij
add Branch.set_config_file.
825
        branch = self.make_branch('.')
826
        branch_token, repo_token = self.get_lock_tokens(branch)
6270.1.10 by Jelmer Vernooij
Fix testing Branch.set_config_file.
827
        self.assertIs(None, request.execute('', branch_token, repo_token))
6270.1.9 by Jelmer Vernooij
add Branch.set_config_file.
828
        self.assertEqual(
829
            smart_req.SmartServerResponse(('ok', )),
830
            request.do_body('foo bar baz'))
831
        self.assertEquals(
832
            branch.control_transport.get_bytes('branch.conf'),
833
            'foo bar baz')
834
        branch.unlock()
835
836
4226.2.1 by Robert Collins
Set branch config options via a smart method.
837
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
838
839
    def test_value_name(self):
840
        branch = self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
841
        request = smart_branch.SmartServerBranchRequestSetConfigOption(
4226.2.1 by Robert Collins
Set branch config options via a smart method.
842
            branch.bzrdir.root_transport)
843
        branch_token, repo_token = self.get_lock_tokens(branch)
844
        config = branch._get_config()
845
        result = request.execute('', branch_token, repo_token, 'bar', 'foo',
846
            '')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
847
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
848
        self.assertEqual('bar', config.get_option('foo'))
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
849
        # Cleanup
850
        branch.unlock()
4226.2.1 by Robert Collins
Set branch config options via a smart method.
851
852
    def test_value_name_section(self):
853
        branch = self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
854
        request = smart_branch.SmartServerBranchRequestSetConfigOption(
4226.2.1 by Robert Collins
Set branch config options via a smart method.
855
            branch.bzrdir.root_transport)
856
        branch_token, repo_token = self.get_lock_tokens(branch)
857
        config = branch._get_config()
858
        result = request.execute('', branch_token, repo_token, 'bar', 'foo',
859
            'gam')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
860
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
861
        self.assertEqual('bar', config.get_option('foo', 'gam'))
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
862
        # Cleanup
863
        branch.unlock()
4226.2.1 by Robert Collins
Set branch config options via a smart method.
864
865
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
866
class TestSmartServerBranchRequestSetConfigOptionDict(TestLockedBranch):
867
868
    def setUp(self):
869
        TestLockedBranch.setUp(self)
870
        # A dict with non-ascii keys and values to exercise unicode
871
        # roundtripping.
872
        self.encoded_value_dict = (
873
            'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde')
874
        self.value_dict = {
875
            'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
876
877
    def test_value_name(self):
878
        branch = self.make_branch('.')
879
        request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
880
            branch.bzrdir.root_transport)
881
        branch_token, repo_token = self.get_lock_tokens(branch)
882
        config = branch._get_config()
883
        result = request.execute('', branch_token, repo_token,
884
            self.encoded_value_dict, 'foo', '')
885
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
886
        self.assertEqual(self.value_dict, config.get_option('foo'))
887
        # Cleanup
888
        branch.unlock()
889
890
    def test_value_name_section(self):
891
        branch = self.make_branch('.')
892
        request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
893
            branch.bzrdir.root_transport)
894
        branch_token, repo_token = self.get_lock_tokens(branch)
895
        config = branch._get_config()
896
        result = request.execute('', branch_token, repo_token,
897
            self.encoded_value_dict, 'foo', 'gam')
898
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
899
        self.assertEqual(self.value_dict, config.get_option('foo', 'gam'))
900
        # Cleanup
901
        branch.unlock()
902
903
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
904
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
905
    # Only called when the branch format and tags match [yay factory
906
    # methods] so only need to test straight forward cases.
907
908
    def test_set_bytes(self):
909
        base_branch = self.make_branch('base')
910
        tag_bytes = base_branch._get_tags_bytes()
911
        # get_lock_tokens takes out a lock.
912
        branch_token, repo_token = self.get_lock_tokens(base_branch)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
913
        request = smart_branch.SmartServerBranchSetTagsBytes(
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
914
            self.get_transport())
915
        response = request.execute('base', branch_token, repo_token)
916
        self.assertEqual(None, response)
917
        response = request.do_chunk(tag_bytes)
918
        self.assertEqual(None, response)
919
        response = request.do_end()
920
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
921
            smart_req.SuccessfulSmartServerResponse(()), response)
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
922
        base_branch.unlock()
923
924
    def test_lock_failed(self):
925
        base_branch = self.make_branch('base')
926
        base_branch.lock_write()
927
        tag_bytes = base_branch._get_tags_bytes()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
928
        request = smart_branch.SmartServerBranchSetTagsBytes(
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
929
            self.get_transport())
930
        self.assertRaises(errors.TokenMismatch, request.execute,
931
            'base', 'wrong token', 'wrong token')
932
        # The request handler will keep processing the message parts, so even
933
        # if the request fails immediately do_chunk and do_end are still
934
        # called.
935
        request.do_chunk(tag_bytes)
936
        request.do_end()
937
        base_branch.unlock()
938
939
940
4226.2.1 by Robert Collins
Set branch config options via a smart method.
941
class SetLastRevisionTestBase(TestLockedBranch):
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
942
    """Base test case for verbs that implement set_last_revision."""
943
944
    def setUp(self):
945
        tests.TestCaseWithMemoryTransport.setUp(self)
946
        backing_transport = self.get_transport()
947
        self.request = self.request_class(backing_transport)
948
        self.tree = self.make_branch_and_memory_tree('.')
949
950
    def lock_branch(self):
4226.2.1 by Robert Collins
Set branch config options via a smart method.
951
        return self.get_lock_tokens(self.tree.branch)
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
952
953
    def unlock_branch(self):
954
        self.tree.branch.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
955
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
956
    def set_last_revision(self, revision_id, revno):
957
        branch_token, repo_token = self.lock_branch()
958
        response = self._set_last_revision(
959
            revision_id, revno, branch_token, repo_token)
960
        self.unlock_branch()
961
        return response
962
963
    def assertRequestSucceeds(self, revision_id, revno):
964
        response = self.set_last_revision(revision_id, revno)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
965
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
966
                         response)
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
967
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
968
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
969
class TestSetLastRevisionVerbMixin(object):
970
    """Mixin test case for verbs that implement set_last_revision."""
971
972
    def test_set_null_to_null(self):
973
        """An empty branch can have its last revision set to 'null:'."""
974
        self.assertRequestSucceeds('null:', 0)
975
976
    def test_NoSuchRevision(self):
977
        """If the revision_id is not present, the verb returns NoSuchRevision.
978
        """
979
        revision_id = 'non-existent revision'
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
980
        self.assertEqual(smart_req.FailedSmartServerResponse(('NoSuchRevision',
981
                                                              revision_id)),
982
                         self.set_last_revision(revision_id, 1))
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
983
984
    def make_tree_with_two_commits(self):
985
        self.tree.lock_write()
986
        self.tree.add('')
987
        rev_id_utf8 = u'\xc8'.encode('utf-8')
988
        r1 = self.tree.commit('1st commit', rev_id=rev_id_utf8)
989
        r2 = self.tree.commit('2nd commit', rev_id='rev-2')
990
        self.tree.unlock()
991
992
    def test_branch_last_revision_info_is_updated(self):
993
        """A branch's tip can be set to a revision that is present in its
994
        repository.
995
        """
996
        # Make a branch with an empty revision history, but two revisions in
997
        # its repository.
998
        self.make_tree_with_two_commits()
999
        rev_id_utf8 = u'\xc8'.encode('utf-8')
5718.7.4 by Jelmer Vernooij
Branch.set_revision_history.
1000
        self.tree.branch.set_last_revision_info(0, 'null:')
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1001
        self.assertEqual(
1002
            (0, 'null:'), self.tree.branch.last_revision_info())
1003
        # We can update the branch to a revision that is present in the
1004
        # repository.
1005
        self.assertRequestSucceeds(rev_id_utf8, 1)
1006
        self.assertEqual(
1007
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1008
1009
    def test_branch_last_revision_info_rewind(self):
1010
        """A branch's tip can be set to a revision that is an ancestor of the
1011
        current tip.
1012
        """
1013
        self.make_tree_with_two_commits()
1014
        rev_id_utf8 = u'\xc8'.encode('utf-8')
1015
        self.assertEqual(
1016
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1017
        self.assertRequestSucceeds(rev_id_utf8, 1)
1018
        self.assertEqual(
1019
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1020
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1021
    def test_TipChangeRejected(self):
1022
        """If a pre_change_branch_tip hook raises TipChangeRejected, the verb
1023
        returns TipChangeRejected.
1024
        """
1025
        rejection_message = u'rejection message\N{INTERROBANG}'
1026
        def hook_that_rejects(params):
1027
            raise errors.TipChangeRejected(rejection_message)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1028
        _mod_branch.Branch.hooks.install_named_hook(
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1029
            'pre_change_branch_tip', hook_that_rejects, None)
1030
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1031
            smart_req.FailedSmartServerResponse(
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1032
                ('TipChangeRejected', rejection_message.encode('utf-8'))),
1033
            self.set_last_revision('null:', 0))
1034
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1035
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1036
class TestSmartServerBranchRequestSetLastRevision(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1037
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1038
    """Tests for Branch.set_last_revision verb."""
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1039
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1040
    request_class = smart_branch.SmartServerBranchRequestSetLastRevision
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1041
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1042
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1043
        return self.request.execute(
1044
            '', branch_token, repo_token, revision_id)
1045
1046
1047
class TestSmartServerBranchRequestSetLastRevisionInfo(
1048
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1049
    """Tests for Branch.set_last_revision_info verb."""
1050
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1051
    request_class = smart_branch.SmartServerBranchRequestSetLastRevisionInfo
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1052
1053
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1054
        return self.request.execute(
1055
            '', branch_token, repo_token, revno, revision_id)
1056
1057
    def test_NoSuchRevision(self):
1058
        """Branch.set_last_revision_info does not have to return
1059
        NoSuchRevision if the revision_id is absent.
1060
        """
1061
        raise tests.TestNotApplicable()
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1062
1063
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.
1064
class TestSmartServerBranchRequestSetLastRevisionEx(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1065
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1066
    """Tests for Branch.set_last_revision_ex verb."""
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1067
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1068
    request_class = smart_branch.SmartServerBranchRequestSetLastRevisionEx
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1069
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1070
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1071
        return self.request.execute(
1072
            '', branch_token, repo_token, revision_id, 0, 0)
1073
1074
    def assertRequestSucceeds(self, revision_id, revno):
1075
        response = self.set_last_revision(revision_id, revno)
1076
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1077
            smart_req.SuccessfulSmartServerResponse(('ok', revno, revision_id)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1078
            response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1079
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1080
    def test_branch_last_revision_info_rewind(self):
1081
        """A branch's tip can be set to a revision that is an ancestor of the
1082
        current tip, but only if allow_overwrite_descendant is passed.
1083
        """
1084
        self.make_tree_with_two_commits()
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1085
        rev_id_utf8 = u'\xc8'.encode('utf-8')
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1086
        self.assertEqual(
1087
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1088
        # If allow_overwrite_descendant flag is 0, then trying to set the tip
1089
        # to an older revision ID has no effect.
1090
        branch_token, repo_token = self.lock_branch()
1091
        response = self.request.execute(
1092
            '', branch_token, repo_token, rev_id_utf8, 0, 0)
1093
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1094
            smart_req.SuccessfulSmartServerResponse(('ok', 2, 'rev-2')),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1095
            response)
1096
        self.assertEqual(
1097
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1098
1099
        # If allow_overwrite_descendant flag is 1, then setting the tip to an
1100
        # ancestor works.
1101
        response = self.request.execute(
1102
            '', branch_token, repo_token, rev_id_utf8, 0, 1)
1103
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1104
            smart_req.SuccessfulSmartServerResponse(('ok', 1, rev_id_utf8)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1105
            response)
1106
        self.unlock_branch()
1107
        self.assertEqual(
1108
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1109
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1110
    def make_branch_with_divergent_history(self):
1111
        """Make a branch with divergent history in its repo.
1112
1113
        The branch's tip will be 'child-2', and the repo will also contain
1114
        'child-1', which diverges from a common base revision.
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1115
        """
1116
        self.tree.lock_write()
1117
        self.tree.add('')
1118
        r1 = self.tree.commit('1st commit')
1119
        revno_1, revid_1 = self.tree.branch.last_revision_info()
1120
        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.
1121
        # Undo the second commit
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1122
        self.tree.branch.set_last_revision_info(revno_1, revid_1)
1123
        self.tree.set_parent_ids([revid_1])
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1124
        # Make a new second commit, child-2.  child-2 has diverged from
1125
        # child-1.
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1126
        new_r2 = self.tree.commit('2nd commit', rev_id='child-2')
1127
        self.tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1128
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1129
    def test_not_allow_diverged(self):
1130
        """If allow_diverged is not passed, then setting a divergent history
1131
        returns a Diverged error.
1132
        """
1133
        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.
1134
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1135
            smart_req.FailedSmartServerResponse(('Diverged',)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1136
            self.set_last_revision('child-1', 2))
1137
        # The branch tip was not changed.
1138
        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.
1139
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1140
    def test_allow_diverged(self):
1141
        """If allow_diverged is passed, then setting a divergent history
1142
        succeeds.
1143
        """
1144
        self.make_branch_with_divergent_history()
1145
        branch_token, repo_token = self.lock_branch()
1146
        response = self.request.execute(
1147
            '', branch_token, repo_token, 'child-1', 1, 0)
1148
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1149
            smart_req.SuccessfulSmartServerResponse(('ok', 2, 'child-1')),
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1150
            response)
1151
        self.unlock_branch()
1152
        # The branch tip was changed.
1153
        self.assertEqual('child-1', self.tree.branch.last_revision())
1154
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1155
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1156
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
1157
1158
    def test_get_parent_none(self):
1159
        base_branch = self.make_branch('base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1160
        request = smart_branch.SmartServerBranchGetParent(self.get_transport())
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1161
        response = request.execute('base')
1162
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1163
            smart_req.SuccessfulSmartServerResponse(('',)), response)
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1164
1165
    def test_get_parent_something(self):
1166
        base_branch = self.make_branch('base')
1167
        base_branch.set_parent(self.get_url('foo'))
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1168
        request = smart_branch.SmartServerBranchGetParent(self.get_transport())
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1169
        response = request.execute('base')
1170
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1171
            smart_req.SuccessfulSmartServerResponse(("../foo",)),
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1172
            response)
1173
1174
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1175
class TestSmartServerBranchRequestSetParent(TestLockedBranch):
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1176
1177
    def test_set_parent_none(self):
1178
        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.
1179
        branch.lock_write()
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1180
        branch._set_parent_location('foo')
4288.1.9 by Robert Collins
Fix up test usable of _set_parent_location on unlocked branches.
1181
        branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1182
        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.
1183
            self.get_transport())
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1184
        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.
1185
        try:
1186
            response = request.execute('base', branch_token, repo_token, '')
1187
        finally:
1188
            branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1189
        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.
1190
        self.assertEqual(None, branch.get_parent())
1191
1192
    def test_set_parent_something(self):
1193
        branch = self.make_branch('base', format="1.9")
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1194
        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.
1195
            self.get_transport())
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1196
        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.
1197
        try:
1198
            response = request.execute('base', branch_token, repo_token,
1199
            'http://bar/')
1200
        finally:
1201
            branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1202
        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.
1203
        self.assertEqual('http://bar/', branch.get_parent())
1204
1205
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1206
class TestSmartServerBranchRequestGetTagsBytes(
1207
    tests.TestCaseWithMemoryTransport):
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
1208
    # Only called when the branch format and tags match [yay factory
1209
    # 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.
1210
1211
    def test_get_bytes(self):
1212
        base_branch = self.make_branch('base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1213
        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.
1214
            self.get_transport())
1215
        response = request.execute('base')
1216
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1217
            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.
1218
1219
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1220
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
1221
1222
    def test_get_stacked_on_url(self):
1223
        base_branch = self.make_branch('base', format='1.6')
1224
        stacked_branch = self.make_branch('stacked', format='1.6')
1225
        # typically should be relative
1226
        stacked_branch.set_stacked_on_url('../base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1227
        request = smart_branch.SmartServerBranchRequestGetStackedOnURL(
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1228
            self.get_transport())
1229
        response = request.execute('stacked')
1230
        self.assertEquals(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1231
            smart_req.SmartServerResponse(('ok', '../base')),
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1232
            response)
1233
1234
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1235
class TestSmartServerBranchRequestLockWrite(TestLockedBranch):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1236
1237
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1238
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1239
1240
    def test_lock_write_on_unlocked_branch(self):
1241
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1242
        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.
1243
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1244
        repository = branch.repository
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1245
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1246
        branch_nonce = branch.control_files._lock.peek().get('nonce')
1247
        repository_nonce = repository.control_files._lock.peek().get('nonce')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1248
        self.assertEqual(smart_req.SmartServerResponse(
1249
                ('ok', branch_nonce, repository_nonce)),
1250
                         response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1251
        # The branch (and associated repository) is now locked.  Verify that
1252
        # with a new branch object.
1253
        new_branch = repository.bzrdir.open_branch()
1254
        self.assertRaises(errors.LockContention, new_branch.lock_write)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1255
        # Cleanup
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1256
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1257
        response = request.execute('', branch_nonce, repository_nonce)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1258
1259
    def test_lock_write_on_locked_branch(self):
1260
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1261
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1262
        branch = self.make_branch('.')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1263
        branch_token = branch.lock_write().branch_token
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1264
        branch.leave_lock_in_place()
1265
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1266
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1267
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1268
            smart_req.SmartServerResponse(('LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1269
        # Cleanup
1270
        branch.lock_write(branch_token)
1271
        branch.dont_leave_lock_in_place()
1272
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1273
1274
    def test_lock_write_with_tokens_on_locked_branch(self):
1275
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1276
        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.
1277
        branch = self.make_branch('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1278
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1279
        branch.leave_lock_in_place()
1280
        branch.repository.leave_lock_in_place()
1281
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1282
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1283
                                   branch_token, repo_token)
1284
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1285
            smart_req.SmartServerResponse(('ok', branch_token, repo_token)),
1286
            response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1287
        # Cleanup
1288
        branch.repository.lock_write(repo_token)
1289
        branch.repository.dont_leave_lock_in_place()
1290
        branch.repository.unlock()
1291
        branch.lock_write(branch_token)
1292
        branch.dont_leave_lock_in_place()
1293
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1294
1295
    def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
1296
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1297
        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.
1298
        branch = self.make_branch('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1299
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1300
        branch.leave_lock_in_place()
1301
        branch.repository.leave_lock_in_place()
1302
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1303
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1304
                                   branch_token+'xxx', repo_token)
1305
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1306
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1307
        # Cleanup
1308
        branch.repository.lock_write(repo_token)
1309
        branch.repository.dont_leave_lock_in_place()
1310
        branch.repository.unlock()
1311
        branch.lock_write(branch_token)
1312
        branch.dont_leave_lock_in_place()
1313
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1314
1315
    def test_lock_write_on_locked_repo(self):
1316
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1317
        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.
1318
        branch = self.make_branch('.', format='knit')
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1319
        repo = branch.repository
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1320
        repo_token = repo.lock_write().repository_token
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1321
        repo.leave_lock_in_place()
1322
        repo.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1323
        response = request.execute('')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1324
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1325
            smart_req.SmartServerResponse(('LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1326
        # Cleanup
1327
        repo.lock_write(repo_token)
1328
        repo.dont_leave_lock_in_place()
1329
        repo.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1330
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.
1331
    def test_lock_write_on_readonly_transport(self):
1332
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1333
        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.
1334
        branch = self.make_branch('.')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1335
        root = self.get_transport().clone('/')
1336
        path = urlutils.relative_url(root.base, self.get_transport().base)
1337
        response = request.execute(path)
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
1338
        error_name, lock_str, why_str = response.args
1339
        self.assertFalse(response.is_successful())
1340
        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.
1341
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1342
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1343
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1344
1345
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1346
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1347
1348
    def test_unlock_on_locked_branch_and_repo(self):
1349
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1350
        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.
1351
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1352
        # Lock the branch
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1353
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1354
        # Unlock the branch (and repo) object, leaving the physical locks
1355
        # in place.
1356
        branch.leave_lock_in_place()
1357
        branch.repository.leave_lock_in_place()
1358
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1359
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1360
                                   branch_token, repo_token)
1361
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1362
            smart_req.SmartServerResponse(('ok',)), response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1363
        # The branch is now unlocked.  Verify that with a new branch
1364
        # object.
1365
        new_branch = branch.bzrdir.open_branch()
1366
        new_branch.lock_write()
1367
        new_branch.unlock()
1368
1369
    def test_unlock_on_unlocked_branch_unlocked_repo(self):
1370
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1371
        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.
1372
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1373
        response = request.execute(
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1374
            '', 'branch token', 'repo token')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1375
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1376
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1377
1378
    def test_unlock_on_unlocked_branch_locked_repo(self):
1379
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1380
        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.
1381
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1382
        # Lock the repository.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1383
        repo_token = branch.repository.lock_write().repository_token
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1384
        branch.repository.leave_lock_in_place()
1385
        branch.repository.unlock()
1386
        # Issue branch lock_write request on the unlocked branch (with locked
1387
        # repo).
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1388
        response = request.execute('', 'branch token', repo_token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1389
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1390
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1391
        # Cleanup
1392
        branch.repository.lock_write(repo_token)
1393
        branch.repository.dont_leave_lock_in_place()
1394
        branch.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1395
1396
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1397
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).
1398
1399
    def test_no_repository(self):
1400
        """Raise NoRepositoryPresent when there is a bzrdir and no repo."""
1401
        # we test this using a shared repository above the named path,
1402
        # thus checking the right search logic is used - that is, that
1403
        # its the exact path being looked at and the server is not
1404
        # searching.
1405
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1406
        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).
1407
        self.make_repository('.', shared=True)
1408
        self.make_bzrdir('subdir')
1409
        self.assertRaises(errors.NoRepositoryPresent,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1410
            request.execute, 'subdir')
1411
1412
3441.5.4 by Andrew Bennetts
Fix test failures, and add some tests for the remote graph heads RPC.
1413
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.
1414
3211.5.3 by Robert Collins
Adjust size of batch and change gzip comments to bzip2.
1415
    def test_trivial_bzipped(self):
1416
        # 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.
1417
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1418
        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.
1419
        tree = self.make_branch_and_memory_tree('.')
1420
1421
        self.assertEqual(None,
2692.1.24 by Andrew Bennetts
Merge from bzr.dev.
1422
            request.execute('', 'missing-id'))
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1423
        # 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.
1424
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1425
            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.
1426
            request.do_body('\n\n0\n'))
1427
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1428
    def test_trivial_include_missing(self):
1429
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1430
        request = smart_repo.SmartServerRepositoryGetParentMap(backing)
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1431
        tree = self.make_branch_and_memory_tree('.')
1432
1433
        self.assertEqual(None,
1434
            request.execute('', 'missing-id', 'include-missing:'))
1435
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1436
            smart_req.SuccessfulSmartServerResponse(('ok', ),
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1437
                bz2.compress('missing:missing-id')),
1438
            request.do_body('\n\n0\n'))
1439
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.
1440
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1441
class TestSmartServerRepositoryGetRevisionGraph(
1442
    tests.TestCaseWithMemoryTransport):
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1443
1444
    def test_none_argument(self):
1445
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1446
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1447
        tree = self.make_branch_and_memory_tree('.')
1448
        tree.lock_write()
1449
        tree.add('')
1450
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1451
        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)
1452
        tree.unlock()
1453
1454
        # the lines of revision_id->revision_parent_list has no guaranteed
1455
        # order coming out of a dict, so sort both our test and response
1456
        lines = sorted([' '.join([r2, r1]), r1])
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1457
        response = request.execute('', '')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1458
        response.body = '\n'.join(sorted(response.body.split('\n')))
1459
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
1460
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1461
            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)
1462
1463
    def test_specific_revision_argument(self):
1464
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1465
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1466
        tree = self.make_branch_and_memory_tree('.')
1467
        tree.lock_write()
1468
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1469
        rev_id_utf8 = u'\xc9'.encode('utf-8')
1470
        r1 = tree.commit('1st commit', rev_id=rev_id_utf8)
1471
        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)
1472
        tree.unlock()
1473
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1474
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), rev_id_utf8),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1475
            request.execute('', rev_id_utf8))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1476
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1477
    def test_no_such_revision(self):
1478
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1479
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1480
        tree = self.make_branch_and_memory_tree('.')
1481
        tree.lock_write()
1482
        tree.add('')
1483
        r1 = tree.commit('1st commit')
1484
        tree.unlock()
1485
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1486
        # Note that it still returns body (of zero bytes).
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1487
        self.assertEqual(smart_req.SmartServerResponse(
1488
                ('nosuchrevision', 'missingrevision', ), ''),
1489
                         request.execute('', 'missingrevision'))
1490
1491
1492
class TestSmartServerRepositoryGetRevIdForRevno(
1493
    tests.TestCaseWithMemoryTransport):
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1494
1495
    def test_revno_found(self):
1496
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1497
        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.
1498
        tree = self.make_branch_and_memory_tree('.')
1499
        tree.lock_write()
1500
        tree.add('')
1501
        rev1_id_utf8 = u'\xc8'.encode('utf-8')
1502
        rev2_id_utf8 = u'\xc9'.encode('utf-8')
1503
        tree.commit('1st commit', rev_id=rev1_id_utf8)
1504
        tree.commit('2nd commit', rev_id=rev2_id_utf8)
1505
        tree.unlock()
1506
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1507
        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.
1508
            request.execute('', 1, (2, rev2_id_utf8)))
1509
1510
    def test_known_revid_missing(self):
1511
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1512
        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.
1513
        repo = self.make_repository('.')
1514
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1515
            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.
1516
            request.execute('', 1, (2, 'ghost')))
1517
1518
    def test_history_incomplete(self):
1519
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1520
        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.
1521
        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.
1522
        parent.lock_write()
1523
        parent.add([''], ['TREE_ROOT'])
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1524
        r1 = parent.commit(message='first commit')
1525
        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.
1526
        parent.unlock()
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1527
        local = self.make_branch_and_memory_tree('local', format='1.9')
1528
        local.branch.pull(parent.branch)
1529
        local.set_parent_ids([r2])
1530
        r3 = local.commit(message='local commit')
1531
        local.branch.create_clone_on_transport(
1532
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
1533
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1534
            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.
1535
            request.execute('stacked', 1, (3, r3)))
1536
4476.3.68 by Andrew Bennetts
Review comments from John.
1537
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1538
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1539
1540
    def make_two_commit_repo(self):
1541
        tree = self.make_branch_and_memory_tree('.')
1542
        tree.lock_write()
1543
        tree.add('')
1544
        r1 = tree.commit('1st commit')
1545
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
1546
        tree.unlock()
1547
        repo = tree.branch.repository
1548
        return repo, r1, r2
1549
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1550
1551
class TestSmartServerRepositoryGetStream(GetStreamTestBase):
1552
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1553
    def test_ancestry_of(self):
1554
        """The search argument may be a 'ancestry-of' some heads'."""
1555
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1556
        request = smart_repo.SmartServerRepositoryGetStream(backing)
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1557
        repo, r1, r2 = self.make_two_commit_repo()
1558
        fetch_spec = ['ancestry-of', r2]
1559
        lines = '\n'.join(fetch_spec)
1560
        request.execute('', repo._format.network_name())
1561
        response = request.do_body(lines)
1562
        self.assertEqual(('ok',), response.args)
1563
        stream_bytes = ''.join(response.body_stream)
1564
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1565
1566
    def test_search(self):
1567
        """The search argument may be a 'search' of some explicit keys."""
1568
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1569
        request = smart_repo.SmartServerRepositoryGetStream(backing)
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1570
        repo, r1, r2 = self.make_two_commit_repo()
1571
        fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1572
        lines = '\n'.join(fetch_spec)
1573
        request.execute('', repo._format.network_name())
1574
        response = request.do_body(lines)
1575
        self.assertEqual(('ok',), response.args)
1576
        stream_bytes = ''.join(response.body_stream)
1577
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1578
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1579
    def test_search_everything(self):
1580
        """A search of 'everything' returns a stream."""
1581
        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.
1582
        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.
1583
        repo, r1, r2 = self.make_two_commit_repo()
1584
        serialised_fetch_spec = 'everything'
1585
        request.execute('', repo._format.network_name())
1586
        response = request.do_body(serialised_fetch_spec)
1587
        self.assertEqual(('ok',), response.args)
1588
        stream_bytes = ''.join(response.body_stream)
1589
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1590
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1591
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1592
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).
1593
1594
    def test_missing_revision(self):
1595
        """For a missing revision, ('no', ) is returned."""
1596
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1597
        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).
1598
        self.make_repository('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1599
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1600
            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).
1601
1602
    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.
1603
        """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).
1604
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1605
        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).
1606
        tree = self.make_branch_and_memory_tree('.')
1607
        tree.lock_write()
1608
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1609
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
1610
        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).
1611
        tree.unlock()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1612
        self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1613
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1614
            request.execute('', rev_id_utf8))
1615
1616
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1617
class TestSmartServerRequestHasSignatureForRevisionId(
1618
        tests.TestCaseWithMemoryTransport):
1619
1620
    def test_missing_revision(self):
1621
        """For a missing revision, NoSuchRevision is returned."""
1622
        backing = self.get_transport()
1623
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1624
            backing)
1625
        self.make_repository('.')
1626
        self.assertEqual(
1627
            smart_req.FailedSmartServerResponse(
6265.1.5 by Jelmer Vernooij
Fix capitalization - NoSuchRevision is for branches.
1628
                ('nosuchrevision', 'revid'), None),
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1629
            request.execute('', 'revid'))
1630
1631
    def test_missing_signature(self):
1632
        """For a missing signature, ('no', ) is returned."""
1633
        backing = self.get_transport()
1634
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1635
            backing)
1636
        tree = self.make_branch_and_memory_tree('.')
1637
        tree.lock_write()
1638
        tree.add('')
1639
        r1 = tree.commit('a commit', rev_id='A')
1640
        tree.unlock()
1641
        self.assertTrue(tree.branch.repository.has_revision('A'))
1642
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
1643
            request.execute('', 'A'))
1644
1645
    def test_present_signature(self):
1646
        """For a present signature, ('yes', ) is returned."""
1647
        backing = self.get_transport()
1648
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1649
            backing)
1650
        strategy = gpg.LoopbackGPGStrategy(None)
1651
        tree = self.make_branch_and_memory_tree('.')
1652
        tree.lock_write()
1653
        tree.add('')
1654
        r1 = tree.commit('a commit', rev_id='A')
1655
        tree.branch.repository.start_write_group()
1656
        tree.branch.repository.sign_revision('A', strategy)
1657
        tree.branch.repository.commit_write_group()
1658
        tree.unlock()
1659
        self.assertTrue(tree.branch.repository.has_revision('A'))
1660
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1661
            request.execute('', 'A'))
1662
1663
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1664
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1665
1666
    def test_empty_revid(self):
1667
        """With an empty revid, we get only size an number and revisions"""
1668
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1669
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1670
        repository = self.make_repository('.')
1671
        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.
1672
        expected_body = 'revisions: 0\n'
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1673
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1674
                         request.execute('', '', 'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1675
1676
    def test_revid_with_committers(self):
1677
        """For a revid we get more infos."""
1678
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1679
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1680
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1681
        tree = self.make_branch_and_memory_tree('.')
1682
        tree.lock_write()
1683
        tree.add('')
1684
        # Let's build a predictable result
1685
        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.
1686
        tree.commit('a commit', timestamp=654321.4, timezone=0,
1687
                    rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1688
        tree.unlock()
1689
1690
        stats = tree.branch.repository.gather_stats()
1691
        expected_body = ('firstrev: 123456.200 3600\n'
1692
                         '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.
1693
                         'revisions: 2\n')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1694
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1695
                         request.execute('',
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1696
                                         rev_id_utf8, 'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1697
1698
    def test_not_empty_repository_with_committers(self):
1699
        """For a revid and requesting committers we get the whole thing."""
1700
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1701
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1702
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1703
        tree = self.make_branch_and_memory_tree('.')
1704
        tree.lock_write()
1705
        tree.add('')
1706
        # Let's build a predictable result
1707
        tree.commit('a commit', timestamp=123456.2, timezone=3600,
1708
                    committer='foo')
1709
        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.
1710
                    committer='bar', rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1711
        tree.unlock()
1712
        stats = tree.branch.repository.gather_stats()
1713
1714
        expected_body = ('committers: 2\n'
1715
                         'firstrev: 123456.200 3600\n'
1716
                         '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.
1717
                         'revisions: 2\n')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1718
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1719
                         request.execute('',
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1720
                                         rev_id_utf8, 'yes'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1721
6291.1.1 by Jelmer Vernooij
Cope with missing revision ids being specified to
1722
    def test_unknown_revid(self):
1723
        """An unknown revision id causes a 'nosuchrevision' error."""
1724
        backing = self.get_transport()
1725
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
1726
        repository = self.make_repository('.')
1727
        expected_body = 'revisions: 0\n'
1728
        self.assertEqual(
1729
            smart_req.FailedSmartServerResponse(
1730
                ('nosuchrevision', 'mia'), None),
1731
            request.execute('', 'mia', 'yes'))
1732
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1733
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1734
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport):
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1735
1736
    def test_is_shared(self):
1737
        """For a shared repository, ('yes', ) is returned."""
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=True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1741
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1742
            request.execute('', ))
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1743
1744
    def test_is_not_shared(self):
2018.5.58 by Wouter van Heyst
Small test fixes to reflect naming and documentation
1745
        """For a shared repository, ('no', ) is returned."""
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1746
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1747
        request = smart_repo.SmartServerRepositoryIsShared(backing)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1748
        self.make_repository('.', shared=False)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1749
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1750
            request.execute('', ))
1751
1752
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
1753
class TestSmartServerRepositoryMakeWorkingTrees(
1754
        tests.TestCaseWithMemoryTransport):
1755
1756
    def test_make_working_trees(self):
1757
        """For a repository with working trees, ('yes', ) is returned."""
1758
        backing = self.get_transport()
1759
        request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
1760
        r = self.make_repository('.')
1761
        r.set_make_working_trees(True)
1762
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1763
            request.execute('', ))
1764
1765
    def test_is_not_shared(self):
1766
        """For a repository with working trees, ('no', ) is returned."""
1767
        backing = self.get_transport()
1768
        request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
1769
        r = self.make_repository('.')
1770
        r.set_make_working_trees(False)
1771
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
1772
            request.execute('', ))
1773
1774
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1775
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1776
1777
    def test_lock_write_on_unlocked_repo(self):
1778
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1779
        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.
1780
        repository = self.make_repository('.', format='knit')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1781
        response = request.execute('')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1782
        nonce = repository.control_files._lock.peek().get('nonce')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1783
        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
1784
        # The repository is now locked.  Verify that with a new repository
1785
        # object.
1786
        new_repo = repository.bzrdir.open_repository()
1787
        self.assertRaises(errors.LockContention, new_repo.lock_write)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1788
        # Cleanup
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1789
        request = smart_repo.SmartServerRepositoryUnlock(backing)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1790
        response = request.execute('', nonce)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1791
1792
    def test_lock_write_on_locked_repo(self):
1793
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1794
        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.
1795
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1796
        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
1797
        repository.leave_lock_in_place()
1798
        repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1799
        response = request.execute('')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1800
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1801
            smart_req.SmartServerResponse(('LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1802
        # Cleanup
1803
        repository.lock_write(repo_token)
1804
        repository.dont_leave_lock_in_place()
1805
        repository.unlock()
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1806
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.
1807
    def test_lock_write_on_readonly_transport(self):
1808
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1809
        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.
1810
        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.
1811
        response = request.execute('')
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
1812
        self.assertFalse(response.is_successful())
1813
        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.
1814
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1815
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1816
class TestInsertStreamBase(tests.TestCaseWithMemoryTransport):
1817
1818
    def make_empty_byte_stream(self, repo):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1819
        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.
1820
        return ''.join(byte_stream)
1821
1822
1823
class TestSmartServerRepositoryInsertStream(TestInsertStreamBase):
1824
1825
    def test_insert_stream_empty(self):
1826
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1827
        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.
1828
        repository = self.make_repository('.')
1829
        response = request.execute('', '')
1830
        self.assertEqual(None, response)
1831
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1832
        self.assertEqual(None, response)
1833
        response = request.do_end()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1834
        self.assertEqual(smart_req.SmartServerResponse(('ok', )), response)
1835
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1836
1837
class TestSmartServerRepositoryInsertStreamLocked(TestInsertStreamBase):
1838
1839
    def test_insert_stream_empty(self):
1840
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1841
        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.
1842
            backing)
1843
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1844
        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.
1845
        response = request.execute('', '', lock_token)
1846
        self.assertEqual(None, response)
1847
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1848
        self.assertEqual(None, response)
1849
        response = request.do_end()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1850
        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.
1851
        repository.unlock()
1852
1853
    def test_insert_stream_with_wrong_lock_token(self):
1854
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1855
        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.
1856
            backing)
1857
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1858
        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.
1859
        self.assertRaises(
1860
            errors.TokenMismatch, request.execute, '', '', 'wrong-token')
1861
        repository.unlock()
1862
1863
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1864
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1865
1866
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1867
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1868
1869
    def test_unlock_on_locked_repo(self):
1870
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1871
        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.
1872
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1873
        token = repository.lock_write().repository_token
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1874
        repository.leave_lock_in_place()
1875
        repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1876
        response = request.execute('', token)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1877
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1878
            smart_req.SmartServerResponse(('ok',)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1879
        # The repository is now unlocked.  Verify that with a new repository
1880
        # object.
1881
        new_repo = repository.bzrdir.open_repository()
1882
        new_repo.lock_write()
1883
        new_repo.unlock()
1884
1885
    def test_unlock_on_unlocked_repo(self):
1886
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1887
        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.
1888
        repository = self.make_repository('.', format='knit')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1889
        response = request.execute('', 'some token')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1890
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1891
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1892
1893
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1894
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.
1895
1896
    def test_is_readonly_no(self):
1897
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1898
        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.
1899
        response = request.execute()
1900
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1901
            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.
1902
1903
    def test_is_readonly_yes(self):
1904
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1905
        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.
1906
        response = request.execute()
1907
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1908
            smart_req.SmartServerResponse(('yes',)), response)
1909
1910
1911
class TestSmartServerRepositorySetMakeWorkingTrees(
1912
    tests.TestCaseWithMemoryTransport):
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1913
1914
    def test_set_false(self):
1915
        backing = self.get_transport()
1916
        repo = self.make_repository('.', shared=True)
1917
        repo.set_make_working_trees(True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1918
        request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1919
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1920
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1921
            request.execute('', 'False'))
1922
        repo = repo.bzrdir.open_repository()
1923
        self.assertFalse(repo.make_working_trees())
1924
1925
    def test_set_true(self):
1926
        backing = self.get_transport()
1927
        repo = self.make_repository('.', shared=True)
1928
        repo.set_make_working_trees(False)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1929
        request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1930
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1931
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
1932
            request.execute('', 'True'))
1933
        repo = repo.bzrdir.open_repository()
1934
        self.assertTrue(repo.make_working_trees())
1935
1936
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1937
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1938
1939
    def make_repo_needing_autopacking(self, path='.'):
1940
        # Make a repo in need of autopacking.
1941
        tree = self.make_branch_and_tree('.', format='pack-0.92')
1942
        repo = tree.branch.repository
1943
        # monkey-patch the pack collection to disable autopacking
1944
        repo._pack_collection._max_pack_count = lambda count: count
1945
        for x in range(10):
1946
            tree.commit('commit %s' % x)
1947
        self.assertEqual(10, len(repo._pack_collection.names()))
1948
        del repo._pack_collection._max_pack_count
1949
        return repo
1950
1951
    def test_autopack_needed(self):
1952
        repo = self.make_repo_needing_autopacking()
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1953
        repo.lock_write()
1954
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1955
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1956
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1957
            backing)
1958
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1959
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1960
        repo._pack_collection.reload_pack_names()
1961
        self.assertEqual(1, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1962
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1963
    def test_autopack_not_needed(self):
1964
        tree = self.make_branch_and_tree('.', format='pack-0.92')
1965
        repo = tree.branch.repository
4145.1.6 by Robert Collins
More test fallout, but all caught now.
1966
        repo.lock_write()
1967
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1968
        for x in range(9):
1969
            tree.commit('commit %s' % x)
1970
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1971
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1972
            backing)
1973
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1974
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1975
        repo._pack_collection.reload_pack_names()
1976
        self.assertEqual(9, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1977
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1978
    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.
1979
        """A request to autopack a non-pack repo is a no-op."""
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1980
        repo = self.make_repository('.', format='knit')
1981
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1982
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1983
            backing)
1984
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1985
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1986
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
1987
4760.2.5 by Andrew Bennetts
Add some more tests.
1988
class TestSmartServerVfsGet(tests.TestCaseWithMemoryTransport):
1989
1990
    def test_unicode_path(self):
1991
        """VFS requests expect unicode paths to be escaped."""
1992
        filename = u'foo\N{INTERROBANG}'
1993
        filename_escaped = urlutils.escape(filename)
1994
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1995
        request = vfs.GetRequest(backing)
4760.2.5 by Andrew Bennetts
Add some more tests.
1996
        backing.put_bytes_non_atomic(filename_escaped, 'contents')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1997
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), 'contents'),
4760.2.5 by Andrew Bennetts
Add some more tests.
1998
            request.execute(filename_escaped))
1999
2000
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
2001
class TestHandlers(tests.TestCase):
2002
    """Tests for the request.request_handlers object."""
2003
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
2004
    def test_all_registrations_exist(self):
2005
        """All registered request_handlers can be found."""
2006
        # If there's a typo in a register_lazy call, this loop will fail with
2007
        # an AttributeError.
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2008
        for key, item in smart_req.request_handlers.iteritems():
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
2009
            pass
2010
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2011
    def assertHandlerEqual(self, verb, handler):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2012
        self.assertEqual(smart_req.request_handlers.get(verb), handler)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2013
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
2014
    def test_registered_methods(self):
2015
        """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()
2016
        self.assertHandlerEqual('Branch.get_config_file',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2017
            smart_branch.SmartServerBranchGetConfigFile)
6270.1.17 by Jelmer Vernooij
s/set_config_file/put_config_file.
2018
        self.assertHandlerEqual('Branch.put_config_file',
2019
            smart_branch.SmartServerBranchPutConfigFile)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2020
        self.assertHandlerEqual('Branch.get_parent',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2021
            smart_branch.SmartServerBranchGetParent)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2022
        self.assertHandlerEqual('Branch.get_tags_bytes',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2023
            smart_branch.SmartServerBranchGetTagsBytes)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2024
        self.assertHandlerEqual('Branch.lock_write',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2025
            smart_branch.SmartServerBranchRequestLockWrite)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2026
        self.assertHandlerEqual('Branch.last_revision_info',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2027
            smart_branch.SmartServerBranchRequestLastRevisionInfo)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2028
        self.assertHandlerEqual('Branch.revision_history',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2029
            smart_branch.SmartServerRequestRevisionHistory)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2030
        self.assertHandlerEqual('Branch.set_config_option',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2031
            smart_branch.SmartServerBranchRequestSetConfigOption)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2032
        self.assertHandlerEqual('Branch.set_last_revision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2033
            smart_branch.SmartServerBranchRequestSetLastRevision)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2034
        self.assertHandlerEqual('Branch.set_last_revision_info',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2035
            smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
2036
        self.assertHandlerEqual('Branch.set_last_revision_ex',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2037
            smart_branch.SmartServerBranchRequestSetLastRevisionEx)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
2038
        self.assertHandlerEqual('Branch.set_parent_location',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2039
            smart_branch.SmartServerBranchRequestSetParentLocation)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2040
        self.assertHandlerEqual('Branch.unlock',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2041
            smart_branch.SmartServerBranchRequestUnlock)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2042
        self.assertHandlerEqual('BzrDir.find_repository',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2043
            smart_dir.SmartServerRequestFindRepositoryV1)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2044
        self.assertHandlerEqual('BzrDir.find_repositoryV2',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2045
            smart_dir.SmartServerRequestFindRepositoryV2)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2046
        self.assertHandlerEqual('BzrDirFormat.initialize',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2047
            smart_dir.SmartServerRequestInitializeBzrDir)
4436.1.1 by Andrew Bennetts
Rename BzrDirFormat.initialize_ex verb to BzrDirFormat.initialize_ex_1.16.
2048
        self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2049
            smart_dir.SmartServerRequestBzrDirInitializeEx)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2050
        self.assertHandlerEqual('BzrDir.cloning_metadir',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2051
            smart_dir.SmartServerBzrDirRequestCloningMetaDir)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2052
        self.assertHandlerEqual('BzrDir.get_config_file',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2053
            smart_dir.SmartServerBzrDirRequestConfigFile)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2054
        self.assertHandlerEqual('BzrDir.open_branch',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2055
            smart_dir.SmartServerRequestOpenBranch)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2056
        self.assertHandlerEqual('BzrDir.open_branchV2',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2057
            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).
2058
        self.assertHandlerEqual('BzrDir.open_branchV3',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2059
            smart_dir.SmartServerRequestOpenBranchV3)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2060
        self.assertHandlerEqual('PackRepository.autopack',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2061
            smart_packrepo.SmartServerPackRepositoryAutopack)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2062
        self.assertHandlerEqual('Repository.gather_stats',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2063
            smart_repo.SmartServerRepositoryGatherStats)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2064
        self.assertHandlerEqual('Repository.get_parent_map',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2065
            smart_repo.SmartServerRepositoryGetParentMap)
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
2066
        self.assertHandlerEqual('Repository.get_rev_id_for_revno',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2067
            smart_repo.SmartServerRepositoryGetRevIdForRevno)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2068
        self.assertHandlerEqual('Repository.get_revision_graph',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2069
            smart_repo.SmartServerRepositoryGetRevisionGraph)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2070
        self.assertHandlerEqual('Repository.get_stream',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2071
            smart_repo.SmartServerRepositoryGetStream)
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
2072
        self.assertHandlerEqual('Repository.get_stream_1.19',
2073
            smart_repo.SmartServerRepositoryGetStream_1_19)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2074
        self.assertHandlerEqual('Repository.has_revision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2075
            smart_repo.SmartServerRequestHasRevision)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2076
        self.assertHandlerEqual('Repository.insert_stream',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2077
            smart_repo.SmartServerRepositoryInsertStream)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2078
        self.assertHandlerEqual('Repository.insert_stream_locked',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2079
            smart_repo.SmartServerRepositoryInsertStreamLocked)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2080
        self.assertHandlerEqual('Repository.is_shared',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2081
            smart_repo.SmartServerRepositoryIsShared)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2082
        self.assertHandlerEqual('Repository.lock_write',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2083
            smart_repo.SmartServerRepositoryLockWrite)
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
2084
        self.assertHandlerEqual('Repository.make_working_trees',
2085
            smart_repo.SmartServerRepositoryMakeWorkingTrees)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2086
        self.assertHandlerEqual('Repository.tarball',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2087
            smart_repo.SmartServerRepositoryTarball)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2088
        self.assertHandlerEqual('Repository.unlock',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2089
            smart_repo.SmartServerRepositoryUnlock)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2090
        self.assertHandlerEqual('Transport.is_readonly',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2091
            smart_req.SmartServerIsReadonly)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2092
2093
2094
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2095
    """Tests for SmartTCPServer hooks."""
2096
2097
    def setUp(self):
2098
        super(SmartTCPServerHookTests, self).setUp()
2099
        self.server = server.SmartTCPServer(self.get_transport())
2100
2101
    def test_run_server_started_hooks(self):
2102
        """Test the server started hooks get fired properly."""
2103
        started_calls = []
2104
        server.SmartTCPServer.hooks.install_named_hook('server_started',
2105
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2106
            None)
2107
        started_ex_calls = []
2108
        server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2109
            lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2110
            None)
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2111
        self.server._sockname = ('example.com', 42)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2112
        self.server.run_server_started_hooks()
2113
        self.assertEquals(started_calls,
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2114
            [([self.get_transport().base], 'bzr://example.com:42/')])
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2115
        self.assertEquals(started_ex_calls,
2116
            [([self.get_transport().base], self.server)])
2117
2118
    def test_run_server_started_hooks_ipv6(self):
2119
        """Test that socknames can contain 4-tuples."""
2120
        self.server._sockname = ('::', 42, 0, 0)
2121
        started_calls = []
2122
        server.SmartTCPServer.hooks.install_named_hook('server_started',
2123
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2124
            None)
2125
        self.server.run_server_started_hooks()
2126
        self.assertEquals(started_calls,
2127
                [([self.get_transport().base], 'bzr://:::42/')])
2128
2129
    def test_run_server_stopped_hooks(self):
2130
        """Test the server stopped hooks."""
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2131
        self.server._sockname = ('example.com', 42)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2132
        stopped_calls = []
2133
        server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2134
            lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2135
            None)
2136
        self.server.run_server_stopped_hooks()
2137
        self.assertEquals(stopped_calls,
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2138
            [([self.get_transport().base], 'bzr://example.com:42/')])