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