/brz/remove-bazaar

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