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