/brz/remove-bazaar

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