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