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