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