/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
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1431
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1432
1433
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1434
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1435
1436
    def test_unlock_on_locked_branch_and_repo(self):
1437
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1438
        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.
1439
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1440
        # Lock the branch
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1441
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1442
        # Unlock the branch (and repo) object, leaving the physical locks
1443
        # in place.
1444
        branch.leave_lock_in_place()
1445
        branch.repository.leave_lock_in_place()
1446
        branch.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1447
        response = request.execute('',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1448
                                   branch_token, repo_token)
1449
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1450
            smart_req.SmartServerResponse(('ok',)), response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1451
        # The branch is now unlocked.  Verify that with a new branch
1452
        # object.
1453
        new_branch = branch.bzrdir.open_branch()
1454
        new_branch.lock_write()
1455
        new_branch.unlock()
1456
1457
    def test_unlock_on_unlocked_branch_unlocked_repo(self):
1458
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1459
        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.
1460
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1461
        response = request.execute(
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1462
            '', 'branch token', 'repo token')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1463
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1464
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1465
1466
    def test_unlock_on_unlocked_branch_locked_repo(self):
1467
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1468
        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.
1469
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1470
        # Lock the repository.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1471
        repo_token = branch.repository.lock_write().repository_token
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1472
        branch.repository.leave_lock_in_place()
1473
        branch.repository.unlock()
1474
        # Issue branch lock_write request on the unlocked branch (with locked
1475
        # repo).
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1476
        response = request.execute('', 'branch token', repo_token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1477
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1478
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1479
        # Cleanup
1480
        branch.repository.lock_write(repo_token)
1481
        branch.repository.dont_leave_lock_in_place()
1482
        branch.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1483
1484
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1485
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).
1486
1487
    def test_no_repository(self):
1488
        """Raise NoRepositoryPresent when there is a bzrdir and no repo."""
1489
        # we test this using a shared repository above the named path,
1490
        # thus checking the right search logic is used - that is, that
1491
        # its the exact path being looked at and the server is not
1492
        # searching.
1493
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1494
        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).
1495
        self.make_repository('.', shared=True)
1496
        self.make_bzrdir('subdir')
1497
        self.assertRaises(errors.NoRepositoryPresent,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1498
            request.execute, 'subdir')
1499
1500
6280.3.2 by Jelmer Vernooij
Add smart side of RemoteRepository.all_revision_ids().
1501
class TestSmartServerRepositoryAllRevisionIds(
1502
    tests.TestCaseWithMemoryTransport):
1503
1504
    def test_empty(self):
1505
        """An empty body should be returned for an empty repository."""
1506
        backing = self.get_transport()
1507
        request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1508
        self.make_repository('.')
1509
        self.assertEquals(
1510
            smart_req.SuccessfulSmartServerResponse(("ok", ), ""),
1511
            request.execute(''))
1512
1513
    def test_some_revisions(self):
1514
        """An empty body should be returned for an empty repository."""
1515
        backing = self.get_transport()
1516
        request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1517
        tree = self.make_branch_and_memory_tree('.')
1518
        tree.lock_write()
1519
        tree.add('')
1520
        tree.commit(rev_id='origineel', message="message")
1521
        tree.commit(rev_id='nog-een-revisie', message="message")
1522
        tree.unlock()
1523
        self.assertEquals(
1524
            smart_req.SuccessfulSmartServerResponse(("ok", ),
1525
                "origineel\nnog-een-revisie"),
1526
            request.execute(''))
1527
1528
6280.4.2 by Jelmer Vernooij
Provide server side of Repository.break_lock HPSS call.
1529
class TestSmartServerRepositoryBreakLock(tests.TestCaseWithMemoryTransport):
1530
1531
    def test_lock_to_break(self):
1532
        backing = self.get_transport()
1533
        request = smart_repo.SmartServerRepositoryBreakLock(backing)
1534
        tree = self.make_branch_and_memory_tree('.')
1535
        tree.branch.repository.lock_write()
1536
        self.assertEqual(
1537
            smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1538
            request.execute(''))
1539
1540
    def test_nothing_to_break(self):
1541
        backing = self.get_transport()
1542
        request = smart_repo.SmartServerRepositoryBreakLock(backing)
1543
        tree = self.make_branch_and_memory_tree('.')
1544
        self.assertEqual(
1545
            smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1546
            request.execute(''))
1547
1548
3441.5.4 by Andrew Bennetts
Fix test failures, and add some tests for the remote graph heads RPC.
1549
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.
1550
3211.5.3 by Robert Collins
Adjust size of batch and change gzip comments to bzip2.
1551
    def test_trivial_bzipped(self):
1552
        # 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.
1553
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1554
        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.
1555
        tree = self.make_branch_and_memory_tree('.')
1556
1557
        self.assertEqual(None,
2692.1.24 by Andrew Bennetts
Merge from bzr.dev.
1558
            request.execute('', 'missing-id'))
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1559
        # 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.
1560
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1561
            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.
1562
            request.do_body('\n\n0\n'))
1563
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1564
    def test_trivial_include_missing(self):
1565
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1566
        request = smart_repo.SmartServerRepositoryGetParentMap(backing)
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1567
        tree = self.make_branch_and_memory_tree('.')
1568
1569
        self.assertEqual(None,
1570
            request.execute('', 'missing-id', 'include-missing:'))
1571
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1572
            smart_req.SuccessfulSmartServerResponse(('ok', ),
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1573
                bz2.compress('missing:missing-id')),
1574
            request.do_body('\n\n0\n'))
1575
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.
1576
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1577
class TestSmartServerRepositoryGetRevisionGraph(
1578
    tests.TestCaseWithMemoryTransport):
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1579
1580
    def test_none_argument(self):
1581
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1582
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1583
        tree = self.make_branch_and_memory_tree('.')
1584
        tree.lock_write()
1585
        tree.add('')
1586
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1587
        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)
1588
        tree.unlock()
1589
1590
        # the lines of revision_id->revision_parent_list has no guaranteed
1591
        # order coming out of a dict, so sort both our test and response
1592
        lines = sorted([' '.join([r2, r1]), r1])
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1593
        response = request.execute('', '')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1594
        response.body = '\n'.join(sorted(response.body.split('\n')))
1595
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
1596
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1597
            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)
1598
1599
    def test_specific_revision_argument(self):
1600
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1601
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1602
        tree = self.make_branch_and_memory_tree('.')
1603
        tree.lock_write()
1604
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1605
        rev_id_utf8 = u'\xc9'.encode('utf-8')
1606
        r1 = tree.commit('1st commit', rev_id=rev_id_utf8)
1607
        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)
1608
        tree.unlock()
1609
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1610
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), rev_id_utf8),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1611
            request.execute('', rev_id_utf8))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1612
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1613
    def test_no_such_revision(self):
1614
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1615
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1616
        tree = self.make_branch_and_memory_tree('.')
1617
        tree.lock_write()
1618
        tree.add('')
1619
        r1 = tree.commit('1st commit')
1620
        tree.unlock()
1621
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1622
        # Note that it still returns body (of zero bytes).
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1623
        self.assertEqual(smart_req.SmartServerResponse(
1624
                ('nosuchrevision', 'missingrevision', ), ''),
1625
                         request.execute('', 'missingrevision'))
1626
1627
1628
class TestSmartServerRepositoryGetRevIdForRevno(
1629
    tests.TestCaseWithMemoryTransport):
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1630
1631
    def test_revno_found(self):
1632
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1633
        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.
1634
        tree = self.make_branch_and_memory_tree('.')
1635
        tree.lock_write()
1636
        tree.add('')
1637
        rev1_id_utf8 = u'\xc8'.encode('utf-8')
1638
        rev2_id_utf8 = u'\xc9'.encode('utf-8')
1639
        tree.commit('1st commit', rev_id=rev1_id_utf8)
1640
        tree.commit('2nd commit', rev_id=rev2_id_utf8)
1641
        tree.unlock()
1642
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1643
        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.
1644
            request.execute('', 1, (2, rev2_id_utf8)))
1645
1646
    def test_known_revid_missing(self):
1647
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1648
        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.
1649
        repo = self.make_repository('.')
1650
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1651
            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.
1652
            request.execute('', 1, (2, 'ghost')))
1653
1654
    def test_history_incomplete(self):
1655
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1656
        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.
1657
        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.
1658
        parent.lock_write()
1659
        parent.add([''], ['TREE_ROOT'])
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1660
        r1 = parent.commit(message='first commit')
1661
        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.
1662
        parent.unlock()
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1663
        local = self.make_branch_and_memory_tree('local', format='1.9')
1664
        local.branch.pull(parent.branch)
1665
        local.set_parent_ids([r2])
1666
        r3 = local.commit(message='local commit')
1667
        local.branch.create_clone_on_transport(
1668
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
1669
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1670
            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.
1671
            request.execute('stacked', 1, (3, r3)))
1672
4476.3.68 by Andrew Bennetts
Review comments from John.
1673
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1674
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1675
1676
    def make_two_commit_repo(self):
1677
        tree = self.make_branch_and_memory_tree('.')
1678
        tree.lock_write()
1679
        tree.add('')
1680
        r1 = tree.commit('1st commit')
1681
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
1682
        tree.unlock()
1683
        repo = tree.branch.repository
1684
        return repo, r1, r2
1685
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1686
1687
class TestSmartServerRepositoryGetStream(GetStreamTestBase):
1688
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1689
    def test_ancestry_of(self):
1690
        """The search argument may be a 'ancestry-of' some heads'."""
1691
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1692
        request = smart_repo.SmartServerRepositoryGetStream(backing)
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1693
        repo, r1, r2 = self.make_two_commit_repo()
1694
        fetch_spec = ['ancestry-of', r2]
1695
        lines = '\n'.join(fetch_spec)
1696
        request.execute('', repo._format.network_name())
1697
        response = request.do_body(lines)
1698
        self.assertEqual(('ok',), response.args)
1699
        stream_bytes = ''.join(response.body_stream)
1700
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1701
1702
    def test_search(self):
1703
        """The search argument may be a 'search' of some explicit keys."""
1704
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1705
        request = smart_repo.SmartServerRepositoryGetStream(backing)
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1706
        repo, r1, r2 = self.make_two_commit_repo()
1707
        fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1708
        lines = '\n'.join(fetch_spec)
1709
        request.execute('', repo._format.network_name())
1710
        response = request.do_body(lines)
1711
        self.assertEqual(('ok',), response.args)
1712
        stream_bytes = ''.join(response.body_stream)
1713
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1714
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1715
    def test_search_everything(self):
1716
        """A search of 'everything' returns a stream."""
1717
        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.
1718
        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.
1719
        repo, r1, r2 = self.make_two_commit_repo()
1720
        serialised_fetch_spec = 'everything'
1721
        request.execute('', repo._format.network_name())
1722
        response = request.do_body(serialised_fetch_spec)
1723
        self.assertEqual(('ok',), response.args)
1724
        stream_bytes = ''.join(response.body_stream)
1725
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1726
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1727
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1728
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).
1729
1730
    def test_missing_revision(self):
1731
        """For a missing revision, ('no', ) is returned."""
1732
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1733
        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).
1734
        self.make_repository('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1735
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1736
            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).
1737
1738
    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.
1739
        """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).
1740
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1741
        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).
1742
        tree = self.make_branch_and_memory_tree('.')
1743
        tree.lock_write()
1744
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1745
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
1746
        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).
1747
        tree.unlock()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1748
        self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1749
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1750
            request.execute('', rev_id_utf8))
1751
1752
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1753
class TestSmartServerRequestHasSignatureForRevisionId(
1754
        tests.TestCaseWithMemoryTransport):
1755
1756
    def test_missing_revision(self):
1757
        """For a missing revision, NoSuchRevision is returned."""
1758
        backing = self.get_transport()
1759
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1760
            backing)
1761
        self.make_repository('.')
1762
        self.assertEqual(
1763
            smart_req.FailedSmartServerResponse(
6265.1.5 by Jelmer Vernooij
Fix capitalization - NoSuchRevision is for branches.
1764
                ('nosuchrevision', 'revid'), None),
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1765
            request.execute('', 'revid'))
1766
1767
    def test_missing_signature(self):
1768
        """For a missing signature, ('no', ) is returned."""
1769
        backing = self.get_transport()
1770
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1771
            backing)
1772
        tree = self.make_branch_and_memory_tree('.')
1773
        tree.lock_write()
1774
        tree.add('')
1775
        r1 = tree.commit('a commit', rev_id='A')
1776
        tree.unlock()
1777
        self.assertTrue(tree.branch.repository.has_revision('A'))
1778
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
1779
            request.execute('', 'A'))
1780
1781
    def test_present_signature(self):
1782
        """For a present signature, ('yes', ) is returned."""
1783
        backing = self.get_transport()
1784
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1785
            backing)
1786
        strategy = gpg.LoopbackGPGStrategy(None)
1787
        tree = self.make_branch_and_memory_tree('.')
1788
        tree.lock_write()
1789
        tree.add('')
1790
        r1 = tree.commit('a commit', rev_id='A')
1791
        tree.branch.repository.start_write_group()
1792
        tree.branch.repository.sign_revision('A', strategy)
1793
        tree.branch.repository.commit_write_group()
1794
        tree.unlock()
1795
        self.assertTrue(tree.branch.repository.has_revision('A'))
1796
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1797
            request.execute('', 'A'))
1798
1799
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1800
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1801
1802
    def test_empty_revid(self):
1803
        """With an empty revid, we get only size an number and revisions"""
1804
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1805
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1806
        repository = self.make_repository('.')
1807
        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.
1808
        expected_body = 'revisions: 0\n'
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1809
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1810
                         request.execute('', '', 'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1811
1812
    def test_revid_with_committers(self):
1813
        """For a revid we get more infos."""
1814
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1815
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1816
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1817
        tree = self.make_branch_and_memory_tree('.')
1818
        tree.lock_write()
1819
        tree.add('')
1820
        # Let's build a predictable result
1821
        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.
1822
        tree.commit('a commit', timestamp=654321.4, timezone=0,
1823
                    rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1824
        tree.unlock()
1825
1826
        stats = tree.branch.repository.gather_stats()
1827
        expected_body = ('firstrev: 123456.200 3600\n'
1828
                         '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.
1829
                         'revisions: 2\n')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1830
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1831
                         request.execute('',
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1832
                                         rev_id_utf8, 'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1833
1834
    def test_not_empty_repository_with_committers(self):
1835
        """For a revid and requesting committers we get the whole thing."""
1836
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1837
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1838
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1839
        tree = self.make_branch_and_memory_tree('.')
1840
        tree.lock_write()
1841
        tree.add('')
1842
        # Let's build a predictable result
1843
        tree.commit('a commit', timestamp=123456.2, timezone=3600,
1844
                    committer='foo')
1845
        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.
1846
                    committer='bar', rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1847
        tree.unlock()
1848
        stats = tree.branch.repository.gather_stats()
1849
1850
        expected_body = ('committers: 2\n'
1851
                         'firstrev: 123456.200 3600\n'
1852
                         '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.
1853
                         'revisions: 2\n')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1854
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1855
                         request.execute('',
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1856
                                         rev_id_utf8, 'yes'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1857
6291.1.1 by Jelmer Vernooij
Cope with missing revision ids being specified to
1858
    def test_unknown_revid(self):
1859
        """An unknown revision id causes a 'nosuchrevision' error."""
1860
        backing = self.get_transport()
1861
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
1862
        repository = self.make_repository('.')
1863
        expected_body = 'revisions: 0\n'
1864
        self.assertEqual(
1865
            smart_req.FailedSmartServerResponse(
1866
                ('nosuchrevision', 'mia'), None),
1867
            request.execute('', 'mia', 'yes'))
1868
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1869
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1870
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport):
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1871
1872
    def test_is_shared(self):
1873
        """For a shared repository, ('yes', ) is returned."""
1874
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1875
        request = smart_repo.SmartServerRepositoryIsShared(backing)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1876
        self.make_repository('.', shared=True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1877
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1878
            request.execute('', ))
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1879
1880
    def test_is_not_shared(self):
2018.5.58 by Wouter van Heyst
Small test fixes to reflect naming and documentation
1881
        """For a shared repository, ('no', ) is returned."""
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1882
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1883
        request = smart_repo.SmartServerRepositoryIsShared(backing)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
1884
        self.make_repository('.', shared=False)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1885
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1886
            request.execute('', ))
1887
1888
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
1889
class TestSmartServerRepositoryMakeWorkingTrees(
1890
        tests.TestCaseWithMemoryTransport):
1891
1892
    def test_make_working_trees(self):
1893
        """For a repository with working trees, ('yes', ) is returned."""
1894
        backing = self.get_transport()
1895
        request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
1896
        r = self.make_repository('.')
1897
        r.set_make_working_trees(True)
1898
        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1899
            request.execute('', ))
1900
1901
    def test_is_not_shared(self):
1902
        """For a repository with working trees, ('no', ) is returned."""
1903
        backing = self.get_transport()
1904
        request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
1905
        r = self.make_repository('.')
1906
        r.set_make_working_trees(False)
1907
        self.assertEqual(smart_req.SmartServerResponse(('no', )),
1908
            request.execute('', ))
1909
1910
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1911
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1912
1913
    def test_lock_write_on_unlocked_repo(self):
1914
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1915
        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.
1916
        repository = self.make_repository('.', format='knit')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1917
        response = request.execute('')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1918
        nonce = repository.control_files._lock.peek().get('nonce')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1919
        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
1920
        # The repository is now locked.  Verify that with a new repository
1921
        # object.
1922
        new_repo = repository.bzrdir.open_repository()
1923
        self.assertRaises(errors.LockContention, new_repo.lock_write)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1924
        # Cleanup
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1925
        request = smart_repo.SmartServerRepositoryUnlock(backing)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1926
        response = request.execute('', nonce)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1927
1928
    def test_lock_write_on_locked_repo(self):
1929
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1930
        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.
1931
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1932
        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
1933
        repository.leave_lock_in_place()
1934
        repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1935
        response = request.execute('')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1936
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1937
            smart_req.SmartServerResponse(('LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1938
        # Cleanup
1939
        repository.lock_write(repo_token)
1940
        repository.dont_leave_lock_in_place()
1941
        repository.unlock()
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1942
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.
1943
    def test_lock_write_on_readonly_transport(self):
1944
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1945
        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.
1946
        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.
1947
        response = request.execute('')
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
1948
        self.assertFalse(response.is_successful())
1949
        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.
1950
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
1951
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1952
class TestInsertStreamBase(tests.TestCaseWithMemoryTransport):
1953
1954
    def make_empty_byte_stream(self, repo):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1955
        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.
1956
        return ''.join(byte_stream)
1957
1958
1959
class TestSmartServerRepositoryInsertStream(TestInsertStreamBase):
1960
1961
    def test_insert_stream_empty(self):
1962
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1963
        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.
1964
        repository = self.make_repository('.')
1965
        response = request.execute('', '')
1966
        self.assertEqual(None, response)
1967
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1968
        self.assertEqual(None, response)
1969
        response = request.do_end()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1970
        self.assertEqual(smart_req.SmartServerResponse(('ok', )), response)
1971
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
1972
1973
class TestSmartServerRepositoryInsertStreamLocked(TestInsertStreamBase):
1974
1975
    def test_insert_stream_empty(self):
1976
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1977
        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.
1978
            backing)
1979
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1980
        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.
1981
        response = request.execute('', '', lock_token)
1982
        self.assertEqual(None, response)
1983
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1984
        self.assertEqual(None, response)
1985
        response = request.do_end()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1986
        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.
1987
        repository.unlock()
1988
1989
    def test_insert_stream_with_wrong_lock_token(self):
1990
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1991
        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.
1992
            backing)
1993
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1994
        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.
1995
        self.assertRaises(
1996
            errors.TokenMismatch, request.execute, '', '', 'wrong-token')
1997
        repository.unlock()
1998
1999
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2000
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2001
2002
    def setUp(self):
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2003
        tests.TestCaseWithMemoryTransport.setUp(self)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2004
2005
    def test_unlock_on_locked_repo(self):
2006
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2007
        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.
2008
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
2009
        token = repository.lock_write().repository_token
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2010
        repository.leave_lock_in_place()
2011
        repository.unlock()
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2012
        response = request.execute('', token)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2013
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2014
            smart_req.SmartServerResponse(('ok',)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2015
        # The repository is now unlocked.  Verify that with a new repository
2016
        # object.
2017
        new_repo = repository.bzrdir.open_repository()
2018
        new_repo.lock_write()
2019
        new_repo.unlock()
2020
2021
    def test_unlock_on_unlocked_repo(self):
2022
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2023
        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.
2024
        repository = self.make_repository('.', format='knit')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2025
        response = request.execute('', 'some token')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2026
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2027
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2028
2029
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2030
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.
2031
2032
    def test_is_readonly_no(self):
2033
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2034
        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.
2035
        response = request.execute()
2036
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2037
            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.
2038
2039
    def test_is_readonly_yes(self):
2040
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2041
        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.
2042
        response = request.execute()
2043
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2044
            smart_req.SmartServerResponse(('yes',)), response)
2045
2046
2047
class TestSmartServerRepositorySetMakeWorkingTrees(
2048
    tests.TestCaseWithMemoryTransport):
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2049
2050
    def test_set_false(self):
2051
        backing = self.get_transport()
2052
        repo = self.make_repository('.', shared=True)
2053
        repo.set_make_working_trees(True)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2054
        request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2055
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2056
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2057
            request.execute('', 'False'))
2058
        repo = repo.bzrdir.open_repository()
2059
        self.assertFalse(repo.make_working_trees())
2060
2061
    def test_set_true(self):
2062
        backing = self.get_transport()
2063
        repo = self.make_repository('.', shared=True)
2064
        repo.set_make_working_trees(False)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2065
        request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2066
        request = request_class(backing)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2067
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2068
            request.execute('', 'True'))
2069
        repo = repo.bzrdir.open_repository()
2070
        self.assertTrue(repo.make_working_trees())
2071
2072
6280.5.2 by Jelmer Vernooij
New HPSS call VersionedFileRepository.get_serializer_format.
2073
class TestSmartServerRepositoryGetSerializerFormat(
2074
    tests.TestCaseWithMemoryTransport):
2075
6280.5.4 by Jelmer Vernooij
Fix test name.
2076
    def test_get_serializer_format(self):
6280.5.2 by Jelmer Vernooij
New HPSS call VersionedFileRepository.get_serializer_format.
2077
        backing = self.get_transport()
2078
        repo = self.make_repository('.', format='2a')
2079
        request_class = smart_repo.SmartServerRepositoryGetSerializerFormat
2080
        request = request_class(backing)
2081
        self.assertEqual(
2082
            smart_req.SuccessfulSmartServerResponse(('ok', '10')),
2083
            request.execute(''))
2084
2085
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2086
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
2087
2088
    def make_repo_needing_autopacking(self, path='.'):
2089
        # Make a repo in need of autopacking.
2090
        tree = self.make_branch_and_tree('.', format='pack-0.92')
2091
        repo = tree.branch.repository
2092
        # monkey-patch the pack collection to disable autopacking
2093
        repo._pack_collection._max_pack_count = lambda count: count
2094
        for x in range(10):
2095
            tree.commit('commit %s' % x)
2096
        self.assertEqual(10, len(repo._pack_collection.names()))
2097
        del repo._pack_collection._max_pack_count
2098
        return repo
2099
2100
    def test_autopack_needed(self):
2101
        repo = self.make_repo_needing_autopacking()
4145.1.6 by Robert Collins
More test fallout, but all caught now.
2102
        repo.lock_write()
2103
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2104
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2105
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2106
            backing)
2107
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2108
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2109
        repo._pack_collection.reload_pack_names()
2110
        self.assertEqual(1, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2111
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2112
    def test_autopack_not_needed(self):
2113
        tree = self.make_branch_and_tree('.', format='pack-0.92')
2114
        repo = tree.branch.repository
4145.1.6 by Robert Collins
More test fallout, but all caught now.
2115
        repo.lock_write()
2116
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2117
        for x in range(9):
2118
            tree.commit('commit %s' % x)
2119
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2120
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2121
            backing)
2122
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2123
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2124
        repo._pack_collection.reload_pack_names()
2125
        self.assertEqual(9, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2126
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2127
    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.
2128
        """A request to autopack a non-pack repo is a no-op."""
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2129
        repo = self.make_repository('.', format='knit')
2130
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2131
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2132
            backing)
2133
        response = request.execute('')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2134
        self.assertEqual(smart_req.SmartServerResponse(('ok',)), response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2135
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2136
4760.2.5 by Andrew Bennetts
Add some more tests.
2137
class TestSmartServerVfsGet(tests.TestCaseWithMemoryTransport):
2138
2139
    def test_unicode_path(self):
2140
        """VFS requests expect unicode paths to be escaped."""
2141
        filename = u'foo\N{INTERROBANG}'
2142
        filename_escaped = urlutils.escape(filename)
2143
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2144
        request = vfs.GetRequest(backing)
4760.2.5 by Andrew Bennetts
Add some more tests.
2145
        backing.put_bytes_non_atomic(filename_escaped, 'contents')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2146
        self.assertEqual(smart_req.SmartServerResponse(('ok', ), 'contents'),
4760.2.5 by Andrew Bennetts
Add some more tests.
2147
            request.execute(filename_escaped))
2148
2149
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
2150
class TestHandlers(tests.TestCase):
2151
    """Tests for the request.request_handlers object."""
2152
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
2153
    def test_all_registrations_exist(self):
2154
        """All registered request_handlers can be found."""
2155
        # If there's a typo in a register_lazy call, this loop will fail with
2156
        # an AttributeError.
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2157
        for key, item in smart_req.request_handlers.iteritems():
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
2158
            pass
2159
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2160
    def assertHandlerEqual(self, verb, handler):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2161
        self.assertEqual(smart_req.request_handlers.get(verb), handler)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2162
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
2163
    def test_registered_methods(self):
2164
        """Test that known methods are registered to the correct object."""
6280.4.4 by Jelmer Vernooij
Add Branch.break_lock.
2165
        self.assertHandlerEqual('Branch.break_lock',
2166
            smart_branch.SmartServerBranchBreakLock)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2167
        self.assertHandlerEqual('Branch.get_config_file',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2168
            smart_branch.SmartServerBranchGetConfigFile)
6270.1.17 by Jelmer Vernooij
s/set_config_file/put_config_file.
2169
        self.assertHandlerEqual('Branch.put_config_file',
2170
            smart_branch.SmartServerBranchPutConfigFile)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2171
        self.assertHandlerEqual('Branch.get_parent',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2172
            smart_branch.SmartServerBranchGetParent)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2173
        self.assertHandlerEqual('Branch.get_tags_bytes',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2174
            smart_branch.SmartServerBranchGetTagsBytes)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2175
        self.assertHandlerEqual('Branch.lock_write',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2176
            smart_branch.SmartServerBranchRequestLockWrite)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2177
        self.assertHandlerEqual('Branch.last_revision_info',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2178
            smart_branch.SmartServerBranchRequestLastRevisionInfo)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2179
        self.assertHandlerEqual('Branch.revision_history',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2180
            smart_branch.SmartServerRequestRevisionHistory)
6263.1.5 by Jelmer Vernooij
Test for presence of Branch.revision_id_to_revno verb.
2181
        self.assertHandlerEqual('Branch.revision_id_to_revno',
2182
            smart_branch.SmartServerBranchRequestRevisionIdToRevno)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2183
        self.assertHandlerEqual('Branch.set_config_option',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2184
            smart_branch.SmartServerBranchRequestSetConfigOption)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2185
        self.assertHandlerEqual('Branch.set_last_revision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2186
            smart_branch.SmartServerBranchRequestSetLastRevision)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2187
        self.assertHandlerEqual('Branch.set_last_revision_info',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2188
            smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
2189
        self.assertHandlerEqual('Branch.set_last_revision_ex',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2190
            smart_branch.SmartServerBranchRequestSetLastRevisionEx)
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
2191
        self.assertHandlerEqual('Branch.set_parent_location',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2192
            smart_branch.SmartServerBranchRequestSetParentLocation)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2193
        self.assertHandlerEqual('Branch.unlock',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2194
            smart_branch.SmartServerBranchRequestUnlock)
6266.4.2 by Jelmer Vernooij
Test for the presence of the BzrDir.destroy_branch verb.
2195
        self.assertHandlerEqual('BzrDir.destroy_branch',
6266.4.3 by Jelmer Vernooij
fix tests.
2196
            smart_dir.SmartServerBzrDirRequestDestroyBranch)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2197
        self.assertHandlerEqual('BzrDir.find_repository',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2198
            smart_dir.SmartServerRequestFindRepositoryV1)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2199
        self.assertHandlerEqual('BzrDir.find_repositoryV2',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2200
            smart_dir.SmartServerRequestFindRepositoryV2)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2201
        self.assertHandlerEqual('BzrDirFormat.initialize',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2202
            smart_dir.SmartServerRequestInitializeBzrDir)
4436.1.1 by Andrew Bennetts
Rename BzrDirFormat.initialize_ex verb to BzrDirFormat.initialize_ex_1.16.
2203
        self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2204
            smart_dir.SmartServerRequestBzrDirInitializeEx)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2205
        self.assertHandlerEqual('BzrDir.cloning_metadir',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2206
            smart_dir.SmartServerBzrDirRequestCloningMetaDir)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2207
        self.assertHandlerEqual('BzrDir.get_config_file',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2208
            smart_dir.SmartServerBzrDirRequestConfigFile)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2209
        self.assertHandlerEqual('BzrDir.open_branch',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2210
            smart_dir.SmartServerRequestOpenBranch)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2211
        self.assertHandlerEqual('BzrDir.open_branchV2',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2212
            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).
2213
        self.assertHandlerEqual('BzrDir.open_branchV3',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2214
            smart_dir.SmartServerRequestOpenBranchV3)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2215
        self.assertHandlerEqual('PackRepository.autopack',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2216
            smart_packrepo.SmartServerPackRepositoryAutopack)
6280.3.2 by Jelmer Vernooij
Add smart side of RemoteRepository.all_revision_ids().
2217
        self.assertHandlerEqual('Repository.all_revision_ids',
2218
            smart_repo.SmartServerRepositoryAllRevisionIds)
6280.4.2 by Jelmer Vernooij
Provide server side of Repository.break_lock HPSS call.
2219
        self.assertHandlerEqual('Repository.break_lock',
2220
            smart_repo.SmartServerRepositoryBreakLock)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2221
        self.assertHandlerEqual('Repository.gather_stats',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2222
            smart_repo.SmartServerRepositoryGatherStats)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2223
        self.assertHandlerEqual('Repository.get_parent_map',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2224
            smart_repo.SmartServerRepositoryGetParentMap)
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
2225
        self.assertHandlerEqual('Repository.get_rev_id_for_revno',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2226
            smart_repo.SmartServerRepositoryGetRevIdForRevno)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2227
        self.assertHandlerEqual('Repository.get_revision_graph',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2228
            smart_repo.SmartServerRepositoryGetRevisionGraph)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2229
        self.assertHandlerEqual('Repository.get_stream',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2230
            smart_repo.SmartServerRepositoryGetStream)
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
2231
        self.assertHandlerEqual('Repository.get_stream_1.19',
2232
            smart_repo.SmartServerRepositoryGetStream_1_19)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2233
        self.assertHandlerEqual('Repository.has_revision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2234
            smart_repo.SmartServerRequestHasRevision)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2235
        self.assertHandlerEqual('Repository.insert_stream',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2236
            smart_repo.SmartServerRepositoryInsertStream)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2237
        self.assertHandlerEqual('Repository.insert_stream_locked',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2238
            smart_repo.SmartServerRepositoryInsertStreamLocked)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2239
        self.assertHandlerEqual('Repository.is_shared',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2240
            smart_repo.SmartServerRepositoryIsShared)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2241
        self.assertHandlerEqual('Repository.lock_write',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2242
            smart_repo.SmartServerRepositoryLockWrite)
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
2243
        self.assertHandlerEqual('Repository.make_working_trees',
2244
            smart_repo.SmartServerRepositoryMakeWorkingTrees)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2245
        self.assertHandlerEqual('Repository.tarball',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2246
            smart_repo.SmartServerRepositoryTarball)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2247
        self.assertHandlerEqual('Repository.unlock',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2248
            smart_repo.SmartServerRepositoryUnlock)
6280.5.2 by Jelmer Vernooij
New HPSS call VersionedFileRepository.get_serializer_format.
2249
        self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2250
            smart_repo.SmartServerRepositoryGetSerializerFormat)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2251
        self.assertHandlerEqual('Transport.is_readonly',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2252
            smart_req.SmartServerIsReadonly)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2253
2254
2255
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2256
    """Tests for SmartTCPServer hooks."""
2257
2258
    def setUp(self):
2259
        super(SmartTCPServerHookTests, self).setUp()
2260
        self.server = server.SmartTCPServer(self.get_transport())
2261
2262
    def test_run_server_started_hooks(self):
2263
        """Test the server started hooks get fired properly."""
2264
        started_calls = []
2265
        server.SmartTCPServer.hooks.install_named_hook('server_started',
2266
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2267
            None)
2268
        started_ex_calls = []
2269
        server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2270
            lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2271
            None)
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2272
        self.server._sockname = ('example.com', 42)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2273
        self.server.run_server_started_hooks()
2274
        self.assertEquals(started_calls,
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2275
            [([self.get_transport().base], 'bzr://example.com:42/')])
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2276
        self.assertEquals(started_ex_calls,
2277
            [([self.get_transport().base], self.server)])
2278
2279
    def test_run_server_started_hooks_ipv6(self):
2280
        """Test that socknames can contain 4-tuples."""
2281
        self.server._sockname = ('::', 42, 0, 0)
2282
        started_calls = []
2283
        server.SmartTCPServer.hooks.install_named_hook('server_started',
2284
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2285
            None)
2286
        self.server.run_server_started_hooks()
2287
        self.assertEquals(started_calls,
2288
                [([self.get_transport().base], 'bzr://:::42/')])
2289
2290
    def test_run_server_stopped_hooks(self):
2291
        """Test the server stopped hooks."""
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2292
        self.server._sockname = ('example.com', 42)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2293
        stopped_calls = []
2294
        server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2295
            lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2296
            None)
2297
        self.server.run_server_stopped_hooks()
2298
        self.assertEquals(stopped_calls,
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2299
            [([self.get_transport().base], 'bzr://example.com:42/')])