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