~bzr-pqm/bzr/bzr.dev

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