/brz/remove-bazaar

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