/brz/remove-bazaar

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