/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
6969.1.1 by Jelmer Vernooij
Handle GhostRevisionsHaveNoRevno in hpss.
856
    def test_ghost(self):
857
        """For an empty branch, the result is ('ok', '0', 'null:')."""
858
        backing = self.get_transport()
859
        request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
860
        branch = self.make_branch('.')
861
        def last_revision_info():
862
            raise errors.GhostRevisionsHaveNoRevno('revid1', 'revid2')
863
        self.overrideAttr(branch, 'last_revision_info', last_revision_info)
864
        self.assertRaises(errors.GhostRevisionsHaveNoRevno,
865
            request.do_with_branch, branch)
866
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
867
    def test_not_empty(self):
868
        """For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
869
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
870
        request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
871
        tree = self.make_branch_and_memory_tree('.')
872
        tree.lock_write()
873
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
874
        rev_id_utf8 = u'\xc8'.encode('utf-8')
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
875
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
876
        r2 = tree.commit('2nd commit', rev_id=rev_id_utf8)
2018.5.50 by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method.
877
        tree.unlock()
878
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
879
            smart_req.SmartServerResponse((b'ok', b'2', rev_id_utf8)),
880
            request.execute(b''))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
881
882
6263.1.2 by Jelmer Vernooij
Add ``Branch.revision_id_to_revno`` smart verb.
883
class TestSmartServerBranchRequestRevisionIdToRevno(
884
    tests.TestCaseWithMemoryTransport):
885
886
    def test_null(self):
887
        backing = self.get_transport()
888
        request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
889
            backing)
890
        self.make_branch('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
891
        self.assertEqual(smart_req.SmartServerResponse((b'ok', b'0')),
892
            request.execute(b'', b'null:'))
6263.1.2 by Jelmer Vernooij
Add ``Branch.revision_id_to_revno`` smart verb.
893
894
    def test_simple(self):
895
        backing = self.get_transport()
896
        request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
897
            backing)
898
        tree = self.make_branch_and_memory_tree('.')
899
        tree.lock_write()
900
        tree.add('')
901
        r1 = tree.commit('1st commit')
902
        tree.unlock()
903
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
904
            smart_req.SmartServerResponse((b'ok', '1')),
905
            request.execute(b'', r1))
6263.1.2 by Jelmer Vernooij
Add ``Branch.revision_id_to_revno`` smart verb.
906
907
    def test_not_found(self):
908
        backing = self.get_transport()
909
        request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
910
            backing)
911
        branch = self.make_branch('.')
912
        self.assertEqual(
913
            smart_req.FailedSmartServerResponse(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
914
                (b'NoSuchRevision', b'idontexist')),
915
            request.execute(b'', b'idontexist'))
6263.1.2 by Jelmer Vernooij
Add ``Branch.revision_id_to_revno`` smart verb.
916
917
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
918
class TestSmartServerBranchRequestGetConfigFile(
919
    tests.TestCaseWithMemoryTransport):
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
920
921
    def test_default(self):
922
        """With no file, we get empty content."""
923
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
924
        request = smart_branch.SmartServerBranchGetConfigFile(backing)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
925
        branch = self.make_branch('.')
926
        # there should be no file by default
927
        content = ''
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
928
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), content),
929
            request.execute(b''))
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
930
931
    def test_with_content(self):
932
        # SmartServerBranchGetConfigFile should return the content from
933
        # 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
934
        # perform more complex processing.
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
935
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
936
        request = smart_branch.SmartServerBranchGetConfigFile(backing)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
937
        branch = self.make_branch('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
938
        branch._transport.put_bytes('branch.conf', b'foo bar baz')
939
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), b'foo bar baz'),
940
            request.execute(b''))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
941
942
4226.2.1 by Robert Collins
Set branch config options via a smart method.
943
class TestLockedBranch(tests.TestCaseWithMemoryTransport):
944
945
    def get_lock_tokens(self, branch):
6754.8.4 by Jelmer Vernooij
Use new context stuff.
946
        branch_token = branch.lock_write().token
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
947
        repo_token = branch.repository.lock_write().repository_token
4226.2.1 by Robert Collins
Set branch config options via a smart method.
948
        branch.repository.unlock()
949
        return branch_token, repo_token
950
951
6270.1.17 by Jelmer Vernooij
s/set_config_file/put_config_file.
952
class TestSmartServerBranchRequestPutConfigFile(TestLockedBranch):
6270.1.9 by Jelmer Vernooij
add Branch.set_config_file.
953
954
    def test_with_content(self):
955
        backing = self.get_transport()
6270.1.17 by Jelmer Vernooij
s/set_config_file/put_config_file.
956
        request = smart_branch.SmartServerBranchPutConfigFile(backing)
6270.1.9 by Jelmer Vernooij
add Branch.set_config_file.
957
        branch = self.make_branch('.')
958
        branch_token, repo_token = self.get_lock_tokens(branch)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
959
        self.assertIs(None, request.execute(b'', branch_token, repo_token))
960
        self.assertEqual(
961
            smart_req.SmartServerResponse((b'ok', )),
962
            request.do_body(b'foo bar baz'))
963
        self.assertEqual(
964
            branch.control_transport.get_bytes(b'branch.conf'),
965
            b'foo bar baz')
6270.1.9 by Jelmer Vernooij
add Branch.set_config_file.
966
        branch.unlock()
967
968
4226.2.1 by Robert Collins
Set branch config options via a smart method.
969
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
970
971
    def test_value_name(self):
972
        branch = self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
973
        request = smart_branch.SmartServerBranchRequestSetConfigOption(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
974
            branch.controldir.root_transport)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
975
        branch_token, repo_token = self.get_lock_tokens(branch)
976
        config = branch._get_config()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
977
        result = request.execute(b'', branch_token, repo_token, b'bar', b'foo',
978
            b'')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
979
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
980
        self.assertEqual('bar', config.get_option('foo'))
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
981
        # Cleanup
982
        branch.unlock()
4226.2.1 by Robert Collins
Set branch config options via a smart method.
983
984
    def test_value_name_section(self):
985
        branch = self.make_branch('.')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
986
        request = smart_branch.SmartServerBranchRequestSetConfigOption(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
987
            branch.controldir.root_transport)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
988
        branch_token, repo_token = self.get_lock_tokens(branch)
989
        config = branch._get_config()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
990
        result = request.execute(b'', branch_token, repo_token, b'bar', b'foo',
991
            b'gam')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
992
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
4226.2.1 by Robert Collins
Set branch config options via a smart method.
993
        self.assertEqual('bar', config.get_option('foo', 'gam'))
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
994
        # Cleanup
995
        branch.unlock()
4226.2.1 by Robert Collins
Set branch config options via a smart method.
996
997
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
998
class TestSmartServerBranchRequestSetConfigOptionDict(TestLockedBranch):
999
1000
    def setUp(self):
1001
        TestLockedBranch.setUp(self)
1002
        # A dict with non-ascii keys and values to exercise unicode
1003
        # roundtripping.
1004
        self.encoded_value_dict = (
1005
            'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde')
1006
        self.value_dict = {
1007
            'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1008
1009
    def test_value_name(self):
1010
        branch = self.make_branch('.')
1011
        request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1012
            branch.controldir.root_transport)
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
1013
        branch_token, repo_token = self.get_lock_tokens(branch)
1014
        config = branch._get_config()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1015
        result = request.execute(b'', branch_token, repo_token,
1016
            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.
1017
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
1018
        self.assertEqual(self.value_dict, config.get_option('foo'))
1019
        # Cleanup
1020
        branch.unlock()
1021
1022
    def test_value_name_section(self):
1023
        branch = self.make_branch('.')
1024
        request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1025
            branch.controldir.root_transport)
5227.1.2 by Andrew Bennetts
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.
1026
        branch_token, repo_token = self.get_lock_tokens(branch)
1027
        config = branch._get_config()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1028
        result = request.execute(b'', branch_token, repo_token,
1029
            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.
1030
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
1031
        self.assertEqual(self.value_dict, config.get_option('foo', 'gam'))
1032
        # Cleanup
1033
        branch.unlock()
1034
1035
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
1036
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
1037
    # Only called when the branch format and tags match [yay factory
1038
    # methods] so only need to test straight forward cases.
1039
1040
    def test_set_bytes(self):
1041
        base_branch = self.make_branch('base')
1042
        tag_bytes = base_branch._get_tags_bytes()
1043
        # get_lock_tokens takes out a lock.
1044
        branch_token, repo_token = self.get_lock_tokens(base_branch)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1045
        request = smart_branch.SmartServerBranchSetTagsBytes(
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
1046
            self.get_transport())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1047
        response = request.execute(b'base', branch_token, repo_token)
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
1048
        self.assertEqual(None, response)
1049
        response = request.do_chunk(tag_bytes)
1050
        self.assertEqual(None, response)
1051
        response = request.do_end()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1052
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1053
            smart_req.SuccessfulSmartServerResponse(()), response)
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
1054
        base_branch.unlock()
1055
1056
    def test_lock_failed(self):
1057
        base_branch = self.make_branch('base')
1058
        base_branch.lock_write()
1059
        tag_bytes = base_branch._get_tags_bytes()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1060
        request = smart_branch.SmartServerBranchSetTagsBytes(
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
1061
            self.get_transport())
1062
        self.assertRaises(errors.TokenMismatch, request.execute,
1063
            'base', 'wrong token', 'wrong token')
1064
        # The request handler will keep processing the message parts, so even
1065
        # if the request fails immediately do_chunk and do_end are still
1066
        # called.
1067
        request.do_chunk(tag_bytes)
1068
        request.do_end()
1069
        base_branch.unlock()
1070
1071
1072
4226.2.1 by Robert Collins
Set branch config options via a smart method.
1073
class SetLastRevisionTestBase(TestLockedBranch):
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1074
    """Base test case for verbs that implement set_last_revision."""
1075
1076
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
1077
        super(SetLastRevisionTestBase, self).setUp()
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1078
        backing_transport = self.get_transport()
1079
        self.request = self.request_class(backing_transport)
1080
        self.tree = self.make_branch_and_memory_tree('.')
1081
1082
    def lock_branch(self):
4226.2.1 by Robert Collins
Set branch config options via a smart method.
1083
        return self.get_lock_tokens(self.tree.branch)
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1084
1085
    def unlock_branch(self):
1086
        self.tree.branch.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1087
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1088
    def set_last_revision(self, revision_id, revno):
1089
        branch_token, repo_token = self.lock_branch()
1090
        response = self._set_last_revision(
1091
            revision_id, revno, branch_token, repo_token)
1092
        self.unlock_branch()
1093
        return response
1094
1095
    def assertRequestSucceeds(self, revision_id, revno):
1096
        response = self.set_last_revision(revision_id, revno)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1097
        self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1098
                         response)
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1099
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1100
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1101
class TestSetLastRevisionVerbMixin(object):
1102
    """Mixin test case for verbs that implement set_last_revision."""
1103
1104
    def test_set_null_to_null(self):
1105
        """An empty branch can have its last revision set to 'null:'."""
1106
        self.assertRequestSucceeds('null:', 0)
1107
1108
    def test_NoSuchRevision(self):
1109
        """If the revision_id is not present, the verb returns NoSuchRevision.
1110
        """
1111
        revision_id = 'non-existent revision'
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1112
        self.assertEqual(smart_req.FailedSmartServerResponse((b'NoSuchRevision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1113
                                                              revision_id)),
1114
                         self.set_last_revision(revision_id, 1))
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1115
1116
    def make_tree_with_two_commits(self):
1117
        self.tree.lock_write()
1118
        self.tree.add('')
1119
        rev_id_utf8 = u'\xc8'.encode('utf-8')
1120
        r1 = self.tree.commit('1st commit', rev_id=rev_id_utf8)
6855.4.1 by Jelmer Vernooij
Yet more bees.
1121
        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.
1122
        self.tree.unlock()
1123
1124
    def test_branch_last_revision_info_is_updated(self):
1125
        """A branch's tip can be set to a revision that is present in its
1126
        repository.
1127
        """
1128
        # Make a branch with an empty revision history, but two revisions in
1129
        # its repository.
1130
        self.make_tree_with_two_commits()
1131
        rev_id_utf8 = u'\xc8'.encode('utf-8')
5718.7.4 by Jelmer Vernooij
Branch.set_revision_history.
1132
        self.tree.branch.set_last_revision_info(0, 'null:')
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1133
        self.assertEqual(
1134
            (0, 'null:'), self.tree.branch.last_revision_info())
1135
        # We can update the branch to a revision that is present in the
1136
        # repository.
1137
        self.assertRequestSucceeds(rev_id_utf8, 1)
1138
        self.assertEqual(
1139
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1140
1141
    def test_branch_last_revision_info_rewind(self):
1142
        """A branch's tip can be set to a revision that is an ancestor of the
1143
        current tip.
1144
        """
1145
        self.make_tree_with_two_commits()
1146
        rev_id_utf8 = u'\xc8'.encode('utf-8')
1147
        self.assertEqual(
1148
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1149
        self.assertRequestSucceeds(rev_id_utf8, 1)
1150
        self.assertEqual(
1151
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1152
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1153
    def test_TipChangeRejected(self):
1154
        """If a pre_change_branch_tip hook raises TipChangeRejected, the verb
1155
        returns TipChangeRejected.
1156
        """
1157
        rejection_message = u'rejection message\N{INTERROBANG}'
1158
        def hook_that_rejects(params):
1159
            raise errors.TipChangeRejected(rejection_message)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1160
        _mod_branch.Branch.hooks.install_named_hook(
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1161
            'pre_change_branch_tip', hook_that_rejects, None)
1162
        self.assertEqual(
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1163
            smart_req.FailedSmartServerResponse(
3577.1.1 by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.
1164
                ('TipChangeRejected', rejection_message.encode('utf-8'))),
1165
            self.set_last_revision('null:', 0))
1166
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1167
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1168
class TestSmartServerBranchRequestSetLastRevision(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1169
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1170
    """Tests for Branch.set_last_revision verb."""
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1171
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1172
    request_class = smart_branch.SmartServerBranchRequestSetLastRevision
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1173
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1174
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1175
        return self.request.execute(
1176
            '', branch_token, repo_token, revision_id)
1177
1178
1179
class TestSmartServerBranchRequestSetLastRevisionInfo(
1180
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1181
    """Tests for Branch.set_last_revision_info verb."""
1182
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1183
    request_class = smart_branch.SmartServerBranchRequestSetLastRevisionInfo
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1184
1185
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1186
        return self.request.execute(
1187
            '', branch_token, repo_token, revno, revision_id)
1188
1189
    def test_NoSuchRevision(self):
1190
        """Branch.set_last_revision_info does not have to return
1191
        NoSuchRevision if the revision_id is absent.
1192
        """
1193
        raise tests.TestNotApplicable()
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1194
1195
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.
1196
class TestSmartServerBranchRequestSetLastRevisionEx(
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1197
        SetLastRevisionTestBase, TestSetLastRevisionVerbMixin):
1198
    """Tests for Branch.set_last_revision_ex verb."""
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1199
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1200
    request_class = smart_branch.SmartServerBranchRequestSetLastRevisionEx
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1201
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1202
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1203
        return self.request.execute(
1204
            '', branch_token, repo_token, revision_id, 0, 0)
1205
1206
    def assertRequestSucceeds(self, revision_id, revno):
1207
        response = self.set_last_revision(revision_id, revno)
1208
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1209
            smart_req.SuccessfulSmartServerResponse((b'ok', revno, revision_id)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1210
            response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1211
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1212
    def test_branch_last_revision_info_rewind(self):
1213
        """A branch's tip can be set to a revision that is an ancestor of the
1214
        current tip, but only if allow_overwrite_descendant is passed.
1215
        """
1216
        self.make_tree_with_two_commits()
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1217
        rev_id_utf8 = u'\xc8'.encode('utf-8')
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1218
        self.assertEqual(
1219
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1220
        # If allow_overwrite_descendant flag is 0, then trying to set the tip
1221
        # to an older revision ID has no effect.
1222
        branch_token, repo_token = self.lock_branch()
1223
        response = self.request.execute(
1224
            '', branch_token, repo_token, rev_id_utf8, 0, 0)
1225
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1226
            smart_req.SuccessfulSmartServerResponse((b'ok', 2, 'rev-2')),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1227
            response)
1228
        self.assertEqual(
1229
            (2, 'rev-2'), self.tree.branch.last_revision_info())
1230
1231
        # If allow_overwrite_descendant flag is 1, then setting the tip to an
1232
        # ancestor works.
1233
        response = self.request.execute(
1234
            '', branch_token, repo_token, rev_id_utf8, 0, 1)
1235
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1236
            smart_req.SuccessfulSmartServerResponse((b'ok', 1, rev_id_utf8)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1237
            response)
1238
        self.unlock_branch()
1239
        self.assertEqual(
1240
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1241
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1242
    def make_branch_with_divergent_history(self):
1243
        """Make a branch with divergent history in its repo.
1244
1245
        The branch's tip will be 'child-2', and the repo will also contain
1246
        'child-1', which diverges from a common base revision.
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1247
        """
1248
        self.tree.lock_write()
1249
        self.tree.add('')
1250
        r1 = self.tree.commit('1st commit')
1251
        revno_1, revid_1 = self.tree.branch.last_revision_info()
6855.4.1 by Jelmer Vernooij
Yet more bees.
1252
        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.
1253
        # Undo the second commit
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1254
        self.tree.branch.set_last_revision_info(revno_1, revid_1)
1255
        self.tree.set_parent_ids([revid_1])
3441.5.6 by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests.
1256
        # Make a new second commit, child-2.  child-2 has diverged from
1257
        # child-1.
6855.4.1 by Jelmer Vernooij
Yet more bees.
1258
        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.
1259
        self.tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1260
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1261
    def test_not_allow_diverged(self):
1262
        """If allow_diverged is not passed, then setting a divergent history
1263
        returns a Diverged error.
1264
        """
1265
        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.
1266
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1267
            smart_req.FailedSmartServerResponse((b'Diverged',)),
3441.5.30 by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs.
1268
            self.set_last_revision('child-1', 2))
1269
        # The branch tip was not changed.
1270
        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.
1271
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1272
    def test_allow_diverged(self):
1273
        """If allow_diverged is passed, then setting a divergent history
1274
        succeeds.
1275
        """
1276
        self.make_branch_with_divergent_history()
1277
        branch_token, repo_token = self.lock_branch()
1278
        response = self.request.execute(
1279
            '', branch_token, repo_token, 'child-1', 1, 0)
1280
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1281
            smart_req.SuccessfulSmartServerResponse((b'ok', 2, 'child-1')),
3441.5.31 by Andrew Bennetts
Add test for allow_diverged flag.
1282
            response)
1283
        self.unlock_branch()
1284
        # The branch tip was changed.
1285
        self.assertEqual('child-1', self.tree.branch.last_revision())
1286
2892.2.1 by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.
1287
6280.4.4 by Jelmer Vernooij
Add Branch.break_lock.
1288
class TestSmartServerBranchBreakLock(tests.TestCaseWithMemoryTransport):
1289
1290
    def test_lock_to_break(self):
1291
        base_branch = self.make_branch('base')
1292
        request = smart_branch.SmartServerBranchBreakLock(
1293
            self.get_transport())
1294
        base_branch.lock_write()
1295
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1296
            smart_req.SuccessfulSmartServerResponse((b'ok', ), None),
1297
            request.execute(b'base'))
6280.4.4 by Jelmer Vernooij
Add Branch.break_lock.
1298
1299
    def test_nothing_to_break(self):
1300
        base_branch = self.make_branch('base')
1301
        request = smart_branch.SmartServerBranchBreakLock(
1302
            self.get_transport())
1303
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1304
            smart_req.SuccessfulSmartServerResponse((b'ok', ), None),
1305
            request.execute(b'base'))
6280.4.4 by Jelmer Vernooij
Add Branch.break_lock.
1306
1307
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1308
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
1309
1310
    def test_get_parent_none(self):
1311
        base_branch = self.make_branch('base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1312
        request = smart_branch.SmartServerBranchGetParent(self.get_transport())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1313
        response = request.execute(b'base')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1314
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1315
            smart_req.SuccessfulSmartServerResponse((b'',)), response)
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1316
1317
    def test_get_parent_something(self):
1318
        base_branch = self.make_branch('base')
1319
        base_branch.set_parent(self.get_url('foo'))
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1320
        request = smart_branch.SmartServerBranchGetParent(self.get_transport())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1321
        response = request.execute(b'base')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1322
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1323
            smart_req.SuccessfulSmartServerResponse((b"../foo",)),
4078.2.1 by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch.
1324
            response)
1325
1326
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1327
class TestSmartServerBranchRequestSetParent(TestLockedBranch):
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1328
1329
    def test_set_parent_none(self):
1330
        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.
1331
        branch.lock_write()
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1332
        branch._set_parent_location('foo')
4288.1.9 by Robert Collins
Fix up test usable of _set_parent_location on unlocked branches.
1333
        branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1334
        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.
1335
            self.get_transport())
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1336
        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.
1337
        try:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1338
            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.
1339
        finally:
1340
            branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1341
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
1342
        # Refresh branch as SetParentLocation modified it
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1343
        branch = branch.controldir.open_branch()
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
1344
        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.
1345
1346
    def test_set_parent_something(self):
1347
        branch = self.make_branch('base', format="1.9")
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1348
        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.
1349
            self.get_transport())
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1350
        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.
1351
        try:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1352
            response = request.execute(b'base', branch_token, repo_token,
1353
                                       b'http://bar/')
4288.1.7 by Robert Collins
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
1354
        finally:
1355
            branch.unlock()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1356
        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.
1357
        refreshed = _mod_branch.Branch.open(branch.base)
1358
        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.
1359
1360
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1361
class TestSmartServerBranchRequestGetTagsBytes(
1362
    tests.TestCaseWithMemoryTransport):
4556.2.2 by Andrew Bennetts
Handle failures more gracefully.
1363
    # Only called when the branch format and tags match [yay factory
1364
    # 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.
1365
1366
    def test_get_bytes(self):
1367
        base_branch = self.make_branch('base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1368
        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.
1369
            self.get_transport())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1370
        response = request.execute(b'base')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1371
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1372
            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.
1373
1374
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1375
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
1376
1377
    def test_get_stacked_on_url(self):
1378
        base_branch = self.make_branch('base', format='1.6')
1379
        stacked_branch = self.make_branch('stacked', format='1.6')
1380
        # typically should be relative
1381
        stacked_branch.set_stacked_on_url('../base')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1382
        request = smart_branch.SmartServerBranchRequestGetStackedOnURL(
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1383
            self.get_transport())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1384
        response = request.execute(b'stacked')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1385
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1386
            smart_req.SmartServerResponse((b'ok', b'../base')),
3691.2.5 by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same
1387
            response)
1388
1389
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1390
class TestSmartServerBranchRequestLockWrite(TestLockedBranch):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1391
1392
    def test_lock_write_on_unlocked_branch(self):
1393
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1394
        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.
1395
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1396
        repository = branch.repository
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1397
        response = request.execute(b'')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1398
        branch_nonce = branch.control_files._lock.peek().get('nonce')
1399
        repository_nonce = repository.control_files._lock.peek().get('nonce')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1400
        self.assertEqual(smart_req.SmartServerResponse(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1401
                (b'ok', branch_nonce, repository_nonce)),
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1402
                         response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1403
        # The branch (and associated repository) is now locked.  Verify that
1404
        # with a new branch object.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1405
        new_branch = repository.controldir.open_branch()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1406
        self.assertRaises(errors.LockContention, new_branch.lock_write)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1407
        # Cleanup
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1408
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1409
        response = request.execute(b'', branch_nonce, repository_nonce)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1410
1411
    def test_lock_write_on_locked_branch(self):
1412
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1413
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1414
        branch = self.make_branch('.')
6754.8.4 by Jelmer Vernooij
Use new context stuff.
1415
        branch_token = branch.lock_write().token
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1416
        branch.leave_lock_in_place()
1417
        branch.unlock()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1418
        response = request.execute(b'')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1419
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1420
            smart_req.SmartServerResponse((b'LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1421
        # Cleanup
1422
        branch.lock_write(branch_token)
1423
        branch.dont_leave_lock_in_place()
1424
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1425
1426
    def test_lock_write_with_tokens_on_locked_branch(self):
1427
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1428
        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.
1429
        branch = self.make_branch('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1430
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1431
        branch.leave_lock_in_place()
1432
        branch.repository.leave_lock_in_place()
1433
        branch.unlock()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1434
        response = request.execute(b'',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1435
                                   branch_token, repo_token)
1436
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1437
            smart_req.SmartServerResponse((b'ok', branch_token, repo_token)),
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1438
            response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1439
        # Cleanup
1440
        branch.repository.lock_write(repo_token)
1441
        branch.repository.dont_leave_lock_in_place()
1442
        branch.repository.unlock()
1443
        branch.lock_write(branch_token)
1444
        branch.dont_leave_lock_in_place()
1445
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1446
1447
    def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
1448
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1449
        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.
1450
        branch = self.make_branch('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1451
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1452
        branch.leave_lock_in_place()
1453
        branch.repository.leave_lock_in_place()
1454
        branch.unlock()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1455
        response = request.execute(b'',
1456
                                   branch_token+b'xxx', repo_token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1457
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1458
            smart_req.SmartServerResponse((b'TokenMismatch',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1459
        # Cleanup
1460
        branch.repository.lock_write(repo_token)
1461
        branch.repository.dont_leave_lock_in_place()
1462
        branch.repository.unlock()
1463
        branch.lock_write(branch_token)
1464
        branch.dont_leave_lock_in_place()
1465
        branch.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1466
1467
    def test_lock_write_on_locked_repo(self):
1468
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1469
        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.
1470
        branch = self.make_branch('.', format='knit')
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1471
        repo = branch.repository
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1472
        repo_token = repo.lock_write().repository_token
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1473
        repo.leave_lock_in_place()
1474
        repo.unlock()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1475
        response = request.execute(b'')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1476
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1477
            smart_req.SmartServerResponse((b'LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1478
        # Cleanup
1479
        repo.lock_write(repo_token)
1480
        repo.dont_leave_lock_in_place()
1481
        repo.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1482
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.
1483
    def test_lock_write_on_readonly_transport(self):
1484
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1485
        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.
1486
        branch = self.make_branch('.')
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1487
        root = self.get_transport().clone('/')
1488
        path = urlutils.relative_url(root.base, self.get_transport().base)
1489
        response = request.execute(path)
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
1490
        error_name, lock_str, why_str = response.args
1491
        self.assertFalse(response.is_successful())
1492
        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.
1493
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1494
6280.6.2 by Jelmer Vernooij
Add HPSS calls Repository.get_physical_lock_status and Branch.get_physical_lock_status.
1495
class TestSmartServerBranchRequestGetPhysicalLockStatus(TestLockedBranch):
1496
1497
    def test_true(self):
1498
        backing = self.get_transport()
1499
        request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1500
            backing)
1501
        branch = self.make_branch('.')
1502
        branch_token, repo_token = self.get_lock_tokens(branch)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1503
        self.assertEqual(True, 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'yes',)), response)
6280.6.2 by Jelmer Vernooij
Add HPSS calls Repository.get_physical_lock_status and Branch.get_physical_lock_status.
1507
        branch.unlock()
1508
1509
    def test_false(self):
1510
        backing = self.get_transport()
1511
        request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1512
            backing)
1513
        branch = self.make_branch('.')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1514
        self.assertEqual(False, branch.get_physical_lock_status())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1515
        response = request.execute(b'')
6280.6.2 by Jelmer Vernooij
Add HPSS calls Repository.get_physical_lock_status and Branch.get_physical_lock_status.
1516
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1517
            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.
1518
1519
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1520
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1521
1522
    def test_unlock_on_locked_branch_and_repo(self):
1523
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1524
        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.
1525
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1526
        # Lock the branch
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1527
        branch_token, repo_token = self.get_lock_tokens(branch)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1528
        # Unlock the branch (and repo) object, leaving the physical locks
1529
        # in place.
1530
        branch.leave_lock_in_place()
1531
        branch.repository.leave_lock_in_place()
1532
        branch.unlock()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1533
        response = request.execute(b'',
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1534
                                   branch_token, repo_token)
1535
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1536
            smart_req.SmartServerResponse((b'ok',)), response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1537
        # The branch is now unlocked.  Verify that with a new branch
1538
        # object.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1539
        new_branch = branch.controldir.open_branch()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1540
        new_branch.lock_write()
1541
        new_branch.unlock()
1542
1543
    def test_unlock_on_unlocked_branch_unlocked_repo(self):
1544
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1545
        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.
1546
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1547
        response = request.execute(
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1548
            '', 'branch token', 'repo token')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1549
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1550
            smart_req.SmartServerResponse((b'TokenMismatch',)), response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1551
1552
    def test_unlock_on_unlocked_branch_locked_repo(self):
1553
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1554
        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.
1555
        branch = self.make_branch('.', format='knit')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1556
        # Lock the repository.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1557
        repo_token = branch.repository.lock_write().repository_token
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1558
        branch.repository.leave_lock_in_place()
1559
        branch.repository.unlock()
1560
        # Issue branch lock_write request on the unlocked branch (with locked
1561
        # repo).
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1562
        response = request.execute(b'', 'branch token', repo_token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1563
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1564
            smart_req.SmartServerResponse((b'TokenMismatch',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
1565
        # Cleanup
1566
        branch.repository.lock_write(repo_token)
1567
        branch.repository.dont_leave_lock_in_place()
1568
        branch.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1569
1570
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1571
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).
1572
1573
    def test_no_repository(self):
1574
        """Raise NoRepositoryPresent when there is a bzrdir and no repo."""
1575
        # we test this using a shared repository above the named path,
1576
        # thus checking the right search logic is used - that is, that
1577
        # its the exact path being looked at and the server is not
1578
        # searching.
1579
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1580
        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).
1581
        self.make_repository('.', shared=True)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
1582
        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).
1583
        self.assertRaises(errors.NoRepositoryPresent,
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1584
            request.execute, 'subdir')
1585
1586
6268.1.2 by Jelmer Vernooij
Initial work on Repository.add_signature_text.
1587
class TestSmartServerRepositoryAddSignatureText(tests.TestCaseWithMemoryTransport):
1588
1589
    def test_add_text(self):
1590
        backing = self.get_transport()
1591
        request = smart_repo.SmartServerRepositoryAddSignatureText(backing)
1592
        tree = self.make_branch_and_memory_tree('.')
6268.1.6 by Jelmer Vernooij
Fix add_signature_text.
1593
        write_token = tree.lock_write()
1594
        self.addCleanup(tree.unlock)
1595
        tree.add('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1596
        tree.commit("Message", rev_id=b'rev1')
6268.1.2 by Jelmer Vernooij
Initial work on Repository.add_signature_text.
1597
        tree.branch.repository.start_write_group()
6268.1.6 by Jelmer Vernooij
Fix add_signature_text.
1598
        write_group_tokens = tree.branch.repository.suspend_write_group()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1599
        self.assertEqual(None, request.execute(b'', write_token,
1600
            b'rev1', *write_group_tokens))
6268.1.6 by Jelmer Vernooij
Fix add_signature_text.
1601
        response = request.do_body('somesignature')
1602
        self.assertTrue(response.is_successful())
1603
        self.assertEqual(response.args[0], 'ok')
1604
        write_group_tokens = response.args[1:]
1605
        tree.branch.repository.resume_write_group(write_group_tokens)
1606
        tree.branch.repository.commit_write_group()
1607
        tree.unlock()
6268.1.2 by Jelmer Vernooij
Initial work on Repository.add_signature_text.
1608
        self.assertEqual("somesignature",
1609
            tree.branch.repository.get_signature_text("rev1"))
1610
1611
6280.3.2 by Jelmer Vernooij
Add smart side of RemoteRepository.all_revision_ids().
1612
class TestSmartServerRepositoryAllRevisionIds(
1613
    tests.TestCaseWithMemoryTransport):
1614
1615
    def test_empty(self):
1616
        """An empty body should be returned for an empty repository."""
1617
        backing = self.get_transport()
1618
        request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1619
        self.make_repository('.')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1620
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1621
            smart_req.SuccessfulSmartServerResponse((b"ok", ), b""),
1622
            request.execute(b''))
6280.3.2 by Jelmer Vernooij
Add smart side of RemoteRepository.all_revision_ids().
1623
1624
    def test_some_revisions(self):
1625
        """An empty body should be returned for an empty repository."""
1626
        backing = self.get_transport()
1627
        request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1628
        tree = self.make_branch_and_memory_tree('.')
1629
        tree.lock_write()
1630
        tree.add('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1631
        tree.commit(rev_id=b'origineel', message="message")
1632
        tree.commit(rev_id=b'nog-een-revisie', message="message")
6280.3.2 by Jelmer Vernooij
Add smart side of RemoteRepository.all_revision_ids().
1633
        tree.unlock()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1634
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1635
            smart_req.SuccessfulSmartServerResponse((b"ok", ),
1636
                b"origineel\nnog-een-revisie"),
1637
            request.execute(b''))
6280.3.2 by Jelmer Vernooij
Add smart side of RemoteRepository.all_revision_ids().
1638
1639
6280.4.2 by Jelmer Vernooij
Provide server side of Repository.break_lock HPSS call.
1640
class TestSmartServerRepositoryBreakLock(tests.TestCaseWithMemoryTransport):
1641
1642
    def test_lock_to_break(self):
1643
        backing = self.get_transport()
1644
        request = smart_repo.SmartServerRepositoryBreakLock(backing)
1645
        tree = self.make_branch_and_memory_tree('.')
1646
        tree.branch.repository.lock_write()
1647
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1648
            smart_req.SuccessfulSmartServerResponse((b'ok', ), None),
1649
            request.execute(b''))
6280.4.2 by Jelmer Vernooij
Provide server side of Repository.break_lock HPSS call.
1650
1651
    def test_nothing_to_break(self):
1652
        backing = self.get_transport()
1653
        request = smart_repo.SmartServerRepositoryBreakLock(backing)
1654
        tree = self.make_branch_and_memory_tree('.')
1655
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1656
            smart_req.SuccessfulSmartServerResponse((b'ok', ), None),
1657
            request.execute(b''))
6280.4.2 by Jelmer Vernooij
Provide server side of Repository.break_lock HPSS call.
1658
1659
3441.5.4 by Andrew Bennetts
Fix test failures, and add some tests for the remote graph heads RPC.
1660
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.
1661
3211.5.3 by Robert Collins
Adjust size of batch and change gzip comments to bzip2.
1662
    def test_trivial_bzipped(self):
1663
        # 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.
1664
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1665
        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.
1666
        tree = self.make_branch_and_memory_tree('.')
1667
1668
        self.assertEqual(None,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1669
            request.execute(b'', b'missing-id'))
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1670
        # 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.
1671
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1672
            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.
1673
            request.do_body('\n\n0\n'))
1674
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1675
    def test_trivial_include_missing(self):
1676
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1677
        request = smart_repo.SmartServerRepositoryGetParentMap(backing)
4190.1.3 by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls.
1678
        tree = self.make_branch_and_memory_tree('.')
1679
1680
        self.assertEqual(None,
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1681
            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.
1682
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1683
            smart_req.SuccessfulSmartServerResponse((b'ok', ),
1684
                bz2.compress(b'missing:missing-id')),
1685
            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.
1686
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.
1687
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1688
class TestSmartServerRepositoryGetRevisionGraph(
1689
    tests.TestCaseWithMemoryTransport):
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1690
1691
    def test_none_argument(self):
1692
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1693
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1694
        tree = self.make_branch_and_memory_tree('.')
1695
        tree.lock_write()
1696
        tree.add('')
1697
        r1 = tree.commit('1st commit')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1698
        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)
1699
        tree.unlock()
1700
1701
        # the lines of revision_id->revision_parent_list has no guaranteed
1702
        # 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.
1703
        lines = sorted([b' '.join([r2, r1]), r1])
1704
        response = request.execute(b'', b'')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1705
        response.body = '\n'.join(sorted(response.body.split('\n')))
1706
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
1707
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1708
            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)
1709
1710
    def test_specific_revision_argument(self):
1711
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1712
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1713
        tree = self.make_branch_and_memory_tree('.')
1714
        tree.lock_write()
1715
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1716
        rev_id_utf8 = u'\xc9'.encode('utf-8')
1717
        r1 = tree.commit('1st commit', rev_id=rev_id_utf8)
1718
        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)
1719
        tree.unlock()
1720
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1721
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), rev_id_utf8),
1722
            request.execute(b'', rev_id_utf8))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1723
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1724
    def test_no_such_revision(self):
1725
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1726
        request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
1727
        tree = self.make_branch_and_memory_tree('.')
1728
        tree.lock_write()
1729
        tree.add('')
1730
        r1 = tree.commit('1st commit')
1731
        tree.unlock()
1732
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1733
        # Note that it still returns body (of zero bytes).
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1734
        self.assertEqual(smart_req.SmartServerResponse(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1735
                (b'nosuchrevision', b'missingrevision', ), b''),
1736
                         request.execute(b'', b'missingrevision'))
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1737
1738
1739
class TestSmartServerRepositoryGetRevIdForRevno(
1740
    tests.TestCaseWithMemoryTransport):
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1741
1742
    def test_revno_found(self):
1743
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1744
        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.
1745
        tree = self.make_branch_and_memory_tree('.')
1746
        tree.lock_write()
1747
        tree.add('')
1748
        rev1_id_utf8 = u'\xc8'.encode('utf-8')
1749
        rev2_id_utf8 = u'\xc9'.encode('utf-8')
1750
        tree.commit('1st commit', rev_id=rev1_id_utf8)
1751
        tree.commit('2nd commit', rev_id=rev2_id_utf8)
1752
        tree.unlock()
1753
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1754
        self.assertEqual(smart_req.SmartServerResponse((b'ok', rev1_id_utf8)),
1755
            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.
1756
1757
    def test_known_revid_missing(self):
1758
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1759
        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.
1760
        repo = self.make_repository('.')
1761
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1762
            smart_req.FailedSmartServerResponse((b'nosuchrevision', b'ghost')),
1763
            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.
1764
1765
    def test_history_incomplete(self):
1766
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1767
        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.
1768
        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.
1769
        parent.lock_write()
1770
        parent.add([''], ['TREE_ROOT'])
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1771
        r1 = parent.commit(message='first commit')
1772
        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.
1773
        parent.unlock()
4419.2.6 by Andrew Bennetts
Add tests for server-side logic, and fix the bugs exposed by those tests.
1774
        local = self.make_branch_and_memory_tree('local', format='1.9')
1775
        local.branch.pull(parent.branch)
1776
        local.set_parent_ids([r2])
1777
        r3 = local.commit(message='local commit')
1778
        local.branch.create_clone_on_transport(
1779
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
1780
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1781
            smart_req.SmartServerResponse((b'history-incomplete', 2, r2)),
1782
            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.
1783
4476.3.68 by Andrew Bennetts
Review comments from John.
1784
6280.9.2 by Jelmer Vernooij
Add smart side.
1785
class TestSmartServerRepositoryIterRevisions(
1786
    tests.TestCaseWithMemoryTransport):
1787
1788
    def test_basic(self):
1789
        backing = self.get_transport()
1790
        request = smart_repo.SmartServerRepositoryIterRevisions(backing)
1791
        tree = self.make_branch_and_memory_tree('.', format='2a')
1792
        tree.lock_write()
1793
        tree.add('')
1794
        tree.commit('1st commit', rev_id="rev1")
1795
        tree.commit('2nd commit', rev_id="rev2")
1796
        tree.unlock()
1797
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1798
        self.assertIs(None, request.execute(b''))
6280.9.2 by Jelmer Vernooij
Add smart side.
1799
        response = request.do_body("rev1\nrev2")
1800
        self.assertTrue(response.is_successful())
1801
        # Format 2a uses serializer format 10
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1802
        self.assertEqual(response.args, (b"ok", b"10"))
6280.9.2 by Jelmer Vernooij
Add smart side.
1803
6280.9.4 by Jelmer Vernooij
use zlib instead.
1804
        self.addCleanup(tree.branch.lock_read().unlock)
1805
        entries = [zlib.compress(record.get_bytes_as("fulltext")) for record in
6280.9.2 by Jelmer Vernooij
Add smart side.
1806
            tree.branch.repository.revisions.get_record_stream(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1807
            [(b"rev1", ), (b"rev2", )], "unordered", True)]
6280.9.2 by Jelmer Vernooij
Add smart side.
1808
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1809
        contents = b"".join(response.body_stream)
6280.9.4 by Jelmer Vernooij
use zlib instead.
1810
        self.assertTrue(contents in (
1811
            "".join([entries[0], entries[1]]),
1812
            "".join([entries[1], entries[0]])))
6280.9.2 by Jelmer Vernooij
Add smart side.
1813
1814
    def test_missing(self):
1815
        backing = self.get_transport()
1816
        request = smart_repo.SmartServerRepositoryIterRevisions(backing)
1817
        tree = self.make_branch_and_memory_tree('.', format='2a')
1818
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1819
        self.assertIs(None, request.execute(b''))
1820
        response = request.do_body(b"rev1\nrev2")
6280.9.2 by Jelmer Vernooij
Add smart side.
1821
        self.assertTrue(response.is_successful())
1822
        # Format 2a uses serializer format 10
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1823
        self.assertEqual(response.args, (b"ok", b"10"))
6280.9.2 by Jelmer Vernooij
Add smart side.
1824
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1825
        contents = b"".join(response.body_stream)
1826
        self.assertEqual(contents, b"")
6280.9.2 by Jelmer Vernooij
Add smart side.
1827
1828
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1829
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1830
1831
    def make_two_commit_repo(self):
1832
        tree = self.make_branch_and_memory_tree('.')
1833
        tree.lock_write()
1834
        tree.add('')
1835
        r1 = tree.commit('1st commit')
1836
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
1837
        tree.unlock()
1838
        repo = tree.branch.repository
1839
        return repo, r1, r2
1840
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1841
1842
class TestSmartServerRepositoryGetStream(GetStreamTestBase):
1843
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1844
    def test_ancestry_of(self):
1845
        """The search argument may be a 'ancestry-of' some heads'."""
1846
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1847
        request = smart_repo.SmartServerRepositoryGetStream(backing)
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1848
        repo, r1, r2 = self.make_two_commit_repo()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1849
        fetch_spec = [b'ancestry-of', r2]
1850
        lines = b'\n'.join(fetch_spec)
1851
        request.execute(b'', repo._format.network_name())
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1852
        response = request.do_body(lines)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1853
        self.assertEqual((b'ok',), response.args)
1854
        stream_bytes = b''.join(response.body_stream)
1855
        self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1856
1857
    def test_search(self):
1858
        """The search argument may be a 'search' of some explicit keys."""
1859
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1860
        request = smart_repo.SmartServerRepositoryGetStream(backing)
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1861
        repo, r1, r2 = self.make_two_commit_repo()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1862
        fetch_spec = [b'search', r1 + b' ' + r2, b'null:', b'2']
1863
        lines = b'\n'.join(fetch_spec)
1864
        request.execute(b'', repo._format.network_name())
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1865
        response = request.do_body(lines)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1866
        self.assertEqual((b'ok',), response.args)
1867
        stream_bytes = b''.join(response.body_stream)
1868
        self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1869
5539.2.4 by Andrew Bennetts
Add some basic tests for the new verb, fix some shallow bugs.
1870
    def test_search_everything(self):
1871
        """A search of 'everything' returns a stream."""
1872
        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.
1873
        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.
1874
        repo, r1, r2 = self.make_two_commit_repo()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1875
        serialised_fetch_spec = b'everything'
1876
        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.
1877
        response = request.do_body(serialised_fetch_spec)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1878
        self.assertEqual((b'ok',), response.args)
1879
        stream_bytes = b''.join(response.body_stream)
1880
        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.
1881
4070.9.14 by Andrew Bennetts
Tweaks requested by Robert's review.
1882
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1883
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).
1884
1885
    def test_missing_revision(self):
1886
        """For a missing revision, ('no', ) is returned."""
1887
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1888
        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).
1889
        self.make_repository('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1890
        self.assertEqual(smart_req.SmartServerResponse((b'no', )),
1891
            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).
1892
1893
    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.
1894
        """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).
1895
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
1896
        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).
1897
        tree = self.make_branch_and_memory_tree('.')
1898
        tree.lock_write()
1899
        tree.add('')
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1900
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
1901
        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).
1902
        tree.unlock()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
1903
        self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1904
        self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
1905
            request.execute(b'', rev_id_utf8))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1906
1907
6280.10.20 by Jelmer Vernooij
Convert smart to zlib.
1908
class TestSmartServerRepositoryIterFilesBytes(tests.TestCaseWithTransport):
6280.10.6 by Jelmer Vernooij
Convert to iter_files_bytes_bz2.
1909
1910
    def test_single(self):
1911
        backing = self.get_transport()
6280.10.20 by Jelmer Vernooij
Convert smart to zlib.
1912
        request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
6280.10.6 by Jelmer Vernooij
Convert to iter_files_bytes_bz2.
1913
        t = self.make_branch_and_tree('.')
1914
        self.addCleanup(t.lock_write().unlock)
6855.4.1 by Jelmer Vernooij
Yet more bees.
1915
        self.build_tree_contents([("file", b"somecontents")])
1916
        t.add(["file"], [b"thefileid"])
1917
        t.commit(rev_id=b'somerev', message="add file")
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1918
        self.assertIs(None, request.execute(b''))
1919
        response = request.do_body(b"thefileid\0somerev\n")
6280.10.5 by Jelmer Vernooij
Support bz2 compression.
1920
        self.assertTrue(response.is_successful())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1921
        self.assertEqual(response.args, (b"ok", ))
1922
        self.assertEqual(b"".join(response.body_stream),
1923
            b"ok\x000\n" + zlib.compress(b"somecontents"))
6280.10.5 by Jelmer Vernooij
Support bz2 compression.
1924
6280.10.3 by Jelmer Vernooij
Fix iter_file_bytes.
1925
    def test_missing(self):
1926
        backing = self.get_transport()
6280.10.20 by Jelmer Vernooij
Convert smart to zlib.
1927
        request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
6280.10.3 by Jelmer Vernooij
Fix iter_file_bytes.
1928
        t = self.make_branch_and_tree('.')
1929
        self.addCleanup(t.lock_write().unlock)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1930
        self.assertIs(None, request.execute(b''))
1931
        response = request.do_body(b"thefileid\0revision\n")
6280.10.6 by Jelmer Vernooij
Convert to iter_files_bytes_bz2.
1932
        self.assertTrue(response.is_successful())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1933
        self.assertEqual(response.args, (b"ok", ))
1934
        self.assertEqual(b"".join(response.body_stream),
1935
            b"absent\x00thefileid\x00revision\x000\n")
6280.10.3 by Jelmer Vernooij
Fix iter_file_bytes.
1936
6280.10.2 by Jelmer Vernooij
Add Repository.iter_file_bytes.
1937
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1938
class TestSmartServerRequestHasSignatureForRevisionId(
1939
        tests.TestCaseWithMemoryTransport):
1940
1941
    def test_missing_revision(self):
1942
        """For a missing revision, NoSuchRevision is returned."""
1943
        backing = self.get_transport()
1944
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1945
            backing)
1946
        self.make_repository('.')
1947
        self.assertEqual(
1948
            smart_req.FailedSmartServerResponse(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1949
                (b'nosuchrevision', b'revid'), None),
1950
            request.execute(b'', b'revid'))
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1951
1952
    def test_missing_signature(self):
1953
        """For a missing signature, ('no', ) is returned."""
1954
        backing = self.get_transport()
1955
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1956
            backing)
1957
        tree = self.make_branch_and_memory_tree('.')
1958
        tree.lock_write()
1959
        tree.add('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1960
        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``.
1961
        tree.unlock()
1962
        self.assertTrue(tree.branch.repository.has_revision('A'))
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1963
        self.assertEqual(smart_req.SmartServerResponse((b'no', )),
1964
            request.execute(b'', b'A'))
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1965
1966
    def test_present_signature(self):
1967
        """For a present signature, ('yes', ) is returned."""
1968
        backing = self.get_transport()
1969
        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1970
            backing)
1971
        strategy = gpg.LoopbackGPGStrategy(None)
1972
        tree = self.make_branch_and_memory_tree('.')
1973
        tree.lock_write()
1974
        tree.add('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1975
        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``.
1976
        tree.branch.repository.start_write_group()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1977
        tree.branch.repository.sign_revision(b'A', strategy)
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1978
        tree.branch.repository.commit_write_group()
1979
        tree.unlock()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1980
        self.assertTrue(tree.branch.repository.has_revision(b'A'))
1981
        self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
1982
            request.execute(b'', b'A'))
6265.1.1 by Jelmer Vernooij
Add new HPSS call ``Repository.has_signature_for_revision_id``.
1983
1984
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
1985
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1986
1987
    def test_empty_revid(self):
1988
        """With an empty revid, we get only size an number and revisions"""
1989
        backing = self.get_transport()
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
        repository = self.make_repository('.')
1992
        stats = repository.gather_stats()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
1993
        expected_body = b'revisions: 0\n'
1994
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), expected_body),
1995
                         request.execute(b'', b'', b'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
1996
1997
    def test_revid_with_committers(self):
1998
        """For a revid we get more infos."""
1999
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
2000
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2001
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
2002
        tree = self.make_branch_and_memory_tree('.')
2003
        tree.lock_write()
2004
        tree.add('')
2005
        # Let's build a predictable result
2006
        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.
2007
        tree.commit('a commit', timestamp=654321.4, timezone=0,
2008
                    rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
2009
        tree.unlock()
2010
2011
        stats = tree.branch.repository.gather_stats()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2012
        expected_body = (b'firstrev: 123456.200 3600\n'
2013
                         b'latestrev: 654321.400 0\n'
2014
                         b'revisions: 2\n')
2015
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), expected_body),
2016
                         request.execute(b'', rev_id_utf8, b'no'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
2017
2018
    def test_not_empty_repository_with_committers(self):
2019
        """For a revid and requesting committers we get the whole thing."""
2020
        backing = self.get_transport()
2018.5.148 by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs.
2021
        rev_id_utf8 = u'\xc8abc'.encode('utf-8')
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2022
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
2023
        tree = self.make_branch_and_memory_tree('.')
2024
        tree.lock_write()
2025
        tree.add('')
2026
        # Let's build a predictable result
2027
        tree.commit('a commit', timestamp=123456.2, timezone=3600,
2028
                    committer='foo')
2029
        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.
2030
                    committer='bar', rev_id=rev_id_utf8)
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
2031
        tree.unlock()
2032
        stats = tree.branch.repository.gather_stats()
2033
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2034
        expected_body = (b'committers: 2\n'
2035
                         b'firstrev: 123456.200 3600\n'
2036
                         b'latestrev: 654321.400 0\n'
2037
                         b'revisions: 2\n')
2038
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), expected_body),
2039
                         request.execute(b'',
2040
                                         rev_id_utf8, b'yes'))
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
2041
6291.1.1 by Jelmer Vernooij
Cope with missing revision ids being specified to
2042
    def test_unknown_revid(self):
2043
        """An unknown revision id causes a 'nosuchrevision' error."""
2044
        backing = self.get_transport()
2045
        request = smart_repo.SmartServerRepositoryGatherStats(backing)
2046
        repository = self.make_repository('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2047
        expected_body = b'revisions: 0\n'
6291.1.1 by Jelmer Vernooij
Cope with missing revision ids being specified to
2048
        self.assertEqual(
2049
            smart_req.FailedSmartServerResponse(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2050
                (b'nosuchrevision', b'mia'), None),
2051
            request.execute(b'', b'mia', b'yes'))
6291.1.1 by Jelmer Vernooij
Cope with missing revision ids being specified to
2052
2018.10.2 by v.ladeuil+lp at free
gather_stats server side and request registration
2053
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2054
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport):
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2055
2056
    def test_is_shared(self):
2057
        """For a shared repository, ('yes', ) is returned."""
2058
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2059
        request = smart_repo.SmartServerRepositoryIsShared(backing)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2060
        self.make_repository('.', shared=True)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2061
        self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
2062
            request.execute(b'', ))
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2063
2064
    def test_is_not_shared(self):
2018.5.58 by Wouter van Heyst
Small test fixes to reflect naming and documentation
2065
        """For a shared repository, ('no', ) is returned."""
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2066
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2067
        request = smart_repo.SmartServerRepositoryIsShared(backing)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
2068
        self.make_repository('.', shared=False)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2069
        self.assertEqual(smart_req.SmartServerResponse((b'no', )),
2070
            request.execute(b'', ))
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2071
2072
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2073
class TestSmartServerRepositoryGetRevisionSignatureText(
2074
        tests.TestCaseWithMemoryTransport):
2075
2076
    def test_get_signature(self):
2077
        backing = self.get_transport()
2078
        request = smart_repo.SmartServerRepositoryGetRevisionSignatureText(
2079
            backing)
2080
        bb = self.make_branch_builder('.')
6855.4.1 by Jelmer Vernooij
Yet more bees.
2081
        bb.build_commit(rev_id=b'A')
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2082
        repo = bb.get_branch().repository
2083
        strategy = gpg.LoopbackGPGStrategy(None)
2084
        self.addCleanup(repo.lock_write().unlock)
2085
        repo.start_write_group()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2086
        repo.sign_revision(b'A', strategy)
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2087
        repo.commit_write_group()
2088
        expected_body = (
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2089
            b'-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2090
            Testament.from_revision(repo, 'A').as_short_text() +
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2091
            b'-----END PSEUDO-SIGNED CONTENT-----\n')
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2092
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2093
            smart_req.SmartServerResponse((b'ok', ), expected_body),
2094
            request.execute(b'', b'A'))
6263.3.2 by Jelmer Vernooij
Add new HPSS call 'Repository.get_revision_signature_text'.
2095
2096
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
2097
class TestSmartServerRepositoryMakeWorkingTrees(
2098
        tests.TestCaseWithMemoryTransport):
2099
2100
    def test_make_working_trees(self):
2101
        """For a repository with working trees, ('yes', ) is returned."""
2102
        backing = self.get_transport()
2103
        request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
2104
        r = self.make_repository('.')
2105
        r.set_make_working_trees(True)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2106
        self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
2107
            request.execute(b'', ))
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
2108
2109
    def test_is_not_shared(self):
2110
        """For a repository with working trees, ('no', ) is returned."""
2111
        backing = self.get_transport()
2112
        request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
2113
        r = self.make_repository('.')
2114
        r.set_make_working_trees(False)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2115
        self.assertEqual(smart_req.SmartServerResponse((b'no', )),
2116
            request.execute(b'', ))
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
2117
2118
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2119
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2120
2121
    def test_lock_write_on_unlocked_repo(self):
2122
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2123
        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.
2124
        repository = self.make_repository('.', format='knit')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2125
        response = request.execute(b'')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2126
        nonce = repository.control_files._lock.peek().get('nonce')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2127
        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
2128
        # The repository is now locked.  Verify that with a new repository
2129
        # object.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2130
        new_repo = repository.controldir.open_repository()
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2131
        self.assertRaises(errors.LockContention, new_repo.lock_write)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
2132
        # Cleanup
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2133
        request = smart_repo.SmartServerRepositoryUnlock(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2134
        response = request.execute(b'', nonce)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2135
2136
    def test_lock_write_on_locked_repo(self):
2137
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2138
        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.
2139
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
2140
        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
2141
        repository.leave_lock_in_place()
2142
        repository.unlock()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2143
        response = request.execute(b'')
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2144
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2145
            smart_req.SmartServerResponse((b'LockContention',)), response)
4327.1.10 by Vincent Ladeuil
Fix 10 more lock-related test failures.
2146
        # Cleanup
2147
        repository.lock_write(repo_token)
2148
        repository.dont_leave_lock_in_place()
2149
        repository.unlock()
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2150
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.
2151
    def test_lock_write_on_readonly_transport(self):
2152
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2153
        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.
2154
        repository = self.make_repository('.', format='knit')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2155
        response = request.execute(b'')
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
2156
        self.assertFalse(response.is_successful())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2157
        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.
2158
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2159
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
2160
class TestInsertStreamBase(tests.TestCaseWithMemoryTransport):
2161
2162
    def make_empty_byte_stream(self, repo):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2163
        byte_stream = smart_repo._stream_to_byte_stream([], repo._format)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2164
        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.
2165
2166
2167
class TestSmartServerRepositoryInsertStream(TestInsertStreamBase):
2168
2169
    def test_insert_stream_empty(self):
2170
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2171
        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.
2172
        repository = self.make_repository('.')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2173
        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.
2174
        self.assertEqual(None, response)
2175
        response = request.do_chunk(self.make_empty_byte_stream(repository))
2176
        self.assertEqual(None, response)
2177
        response = request.do_end()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2178
        self.assertEqual(smart_req.SmartServerResponse((b'ok', )), response)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2179
4144.3.1 by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.
2180
2181
class TestSmartServerRepositoryInsertStreamLocked(TestInsertStreamBase):
2182
2183
    def test_insert_stream_empty(self):
2184
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2185
        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.
2186
            backing)
2187
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
2188
        lock_token = repository.lock_write().repository_token
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2189
        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.
2190
        self.assertEqual(None, response)
2191
        response = request.do_chunk(self.make_empty_byte_stream(repository))
2192
        self.assertEqual(None, response)
2193
        response = request.do_end()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2194
        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.
2195
        repository.unlock()
2196
2197
    def test_insert_stream_with_wrong_lock_token(self):
2198
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2199
        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.
2200
            backing)
2201
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
2202
        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.
2203
        self.assertRaises(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2204
            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.
2205
        repository.unlock()
2206
2207
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2208
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2209
2210
    def test_unlock_on_locked_repo(self):
2211
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2212
        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.
2213
        repository = self.make_repository('.', format='knit')
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
2214
        token = repository.lock_write().repository_token
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2215
        repository.leave_lock_in_place()
2216
        repository.unlock()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2217
        response = request.execute(b'', token)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2218
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2219
            smart_req.SmartServerResponse((b'ok',)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2220
        # The repository is now unlocked.  Verify that with a new repository
2221
        # object.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2222
        new_repo = repository.controldir.open_repository()
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2223
        new_repo.lock_write()
2224
        new_repo.unlock()
2225
2226
    def test_unlock_on_unlocked_repo(self):
2227
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2228
        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.
2229
        repository = self.make_repository('.', format='knit')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2230
        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
2231
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2232
            smart_req.SmartServerResponse((b'TokenMismatch',)), response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
2233
2234
6280.6.2 by Jelmer Vernooij
Add HPSS calls Repository.get_physical_lock_status and Branch.get_physical_lock_status.
2235
class TestSmartServerRepositoryGetPhysicalLockStatus(
6280.6.3 by Jelmer Vernooij
Fix test.
2236
    tests.TestCaseWithTransport):
6280.6.2 by Jelmer Vernooij
Add HPSS calls Repository.get_physical_lock_status and Branch.get_physical_lock_status.
2237
6280.6.3 by Jelmer Vernooij
Fix test.
2238
    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.
2239
        backing = self.get_transport()
2240
        repo = self.make_repository('.')
6280.6.3 by Jelmer Vernooij
Fix test.
2241
        self.addCleanup(repo.lock_write().unlock)
2242
        # lock_write() doesn't necessarily actually take a physical
2243
        # lock out.
2244
        if repo.get_physical_lock_status():
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2245
            expected = b'yes'
6280.6.3 by Jelmer Vernooij
Fix test.
2246
        else:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2247
            expected = b'no'
6280.6.2 by Jelmer Vernooij
Add HPSS calls Repository.get_physical_lock_status and Branch.get_physical_lock_status.
2248
        request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2249
        request = request_class(backing)
6280.6.3 by Jelmer Vernooij
Fix test.
2250
        self.assertEqual(smart_req.SuccessfulSmartServerResponse((expected,)),
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2251
            request.execute(b'', ))
6280.6.2 by Jelmer Vernooij
Add HPSS calls Repository.get_physical_lock_status and Branch.get_physical_lock_status.
2252
6280.6.3 by Jelmer Vernooij
Fix test.
2253
    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.
2254
        backing = self.get_transport()
2255
        repo = self.make_repository('.')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2256
        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.
2257
        request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2258
        request = request_class(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2259
        self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'no',)),
2260
            request.execute(b'', ))
6280.6.2 by Jelmer Vernooij
Add HPSS calls Repository.get_physical_lock_status and Branch.get_physical_lock_status.
2261
2262
6300.1.2 by Jelmer Vernooij
Add remote side of Repository.reconcile.
2263
class TestSmartServerRepositoryReconcile(tests.TestCaseWithTransport):
2264
2265
    def test_reconcile(self):
2266
        backing = self.get_transport()
2267
        repo = self.make_repository('.')
6300.1.7 by Jelmer Vernooij
Fix test.
2268
        token = repo.lock_write().repository_token
2269
        self.addCleanup(repo.unlock)
6300.1.2 by Jelmer Vernooij
Add remote side of Repository.reconcile.
2270
        request_class = smart_repo.SmartServerRepositoryReconcile
2271
        request = request_class(backing)
6300.1.4 by Jelmer Vernooij
Add reconcile results.
2272
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2273
            (b'ok', ),
2274
             b'garbage_inventories: 0\n'
2275
             b'inconsistent_parents: 0\n'),
2276
            request.execute(b'', token))
6300.1.2 by Jelmer Vernooij
Add remote side of Repository.reconcile.
2277
2278
2692.1.1 by Andrew Bennetts
Add translate_client_path method to SmartServerRequest.
2279
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.
2280
2281
    def test_is_readonly_no(self):
2282
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2283
        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.
2284
        response = request.execute()
2285
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2286
            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.
2287
2288
    def test_is_readonly_yes(self):
2289
        backing = self.get_readonly_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2290
        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.
2291
        response = request.execute()
2292
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2293
            smart_req.SmartServerResponse((b'yes',)), response)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2294
2295
2296
class TestSmartServerRepositorySetMakeWorkingTrees(
2297
    tests.TestCaseWithMemoryTransport):
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2298
2299
    def test_set_false(self):
2300
        backing = self.get_transport()
2301
        repo = self.make_repository('.', shared=True)
2302
        repo.set_make_working_trees(True)
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'False'))
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.assertFalse(repo.make_working_trees())
2309
2310
    def test_set_true(self):
2311
        backing = self.get_transport()
2312
        repo = self.make_repository('.', shared=True)
2313
        repo.set_make_working_trees(False)
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2314
        request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2315
        request = request_class(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2316
        self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2317
            request.execute(b'', b'True'))
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2318
        repo = repo.controldir.open_repository()
4017.3.4 by Robert Collins
Create a verb for Repository.set_make_working_trees.
2319
        self.assertTrue(repo.make_working_trees())
2320
2321
6280.5.2 by Jelmer Vernooij
New HPSS call VersionedFileRepository.get_serializer_format.
2322
class TestSmartServerRepositoryGetSerializerFormat(
2323
    tests.TestCaseWithMemoryTransport):
2324
6280.5.4 by Jelmer Vernooij
Fix test name.
2325
    def test_get_serializer_format(self):
6280.5.2 by Jelmer Vernooij
New HPSS call VersionedFileRepository.get_serializer_format.
2326
        backing = self.get_transport()
2327
        repo = self.make_repository('.', format='2a')
2328
        request_class = smart_repo.SmartServerRepositoryGetSerializerFormat
2329
        request = request_class(backing)
2330
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2331
            smart_req.SuccessfulSmartServerResponse((b'ok', b'10')),
2332
            request.execute(b''))
6280.5.2 by Jelmer Vernooij
New HPSS call VersionedFileRepository.get_serializer_format.
2333
2334
6280.7.2 by Jelmer Vernooij
Add HPSS calls ``Repository.start_write_group``, ``Repository.abort_write_group`` and ``Repository.commit_write_group``.
2335
class TestSmartServerRepositoryWriteGroup(
2336
    tests.TestCaseWithMemoryTransport):
2337
2338
    def test_start_write_group(self):
2339
        backing = self.get_transport()
2340
        repo = self.make_repository('.')
2341
        lock_token = repo.lock_write().repository_token
2342
        self.addCleanup(repo.unlock)
2343
        request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2344
        request = request_class(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2345
        self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok', [])),
2346
            request.execute(b'', lock_token))
6280.7.9 by Jelmer Vernooij
test repositories with unsuspendable write groups.
2347
2348
    def test_start_write_group_unsuspendable(self):
2349
        backing = self.get_transport()
2350
        repo = self.make_repository('.', format='knit')
2351
        lock_token = repo.lock_write().repository_token
2352
        self.addCleanup(repo.unlock)
2353
        request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2354
        request = request_class(backing)
2355
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2356
            smart_req.FailedSmartServerResponse((b'UnsuspendableWriteGroup',)),
2357
            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``.
2358
2359
    def test_commit_write_group(self):
2360
        backing = self.get_transport()
2361
        repo = self.make_repository('.')
2362
        lock_token = repo.lock_write().repository_token
2363
        self.addCleanup(repo.unlock)
2364
        repo.start_write_group()
2365
        tokens = repo.suspend_write_group()
2366
        request_class = smart_repo.SmartServerRepositoryCommitWriteGroup
2367
        request = request_class(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2368
        self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2369
            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``.
2370
2371
    def test_abort_write_group(self):
2372
        backing = self.get_transport()
2373
        repo = self.make_repository('.')
2374
        lock_token = repo.lock_write().repository_token
2375
        repo.start_write_group()
2376
        tokens = repo.suspend_write_group()
2377
        self.addCleanup(repo.unlock)
2378
        request_class = smart_repo.SmartServerRepositoryAbortWriteGroup
2379
        request = request_class(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2380
        self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2381
            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``.
2382
6280.7.6 by Jelmer Vernooij
Fix remaining tests.
2383
    def test_check_write_group(self):
2384
        backing = self.get_transport()
2385
        repo = self.make_repository('.')
2386
        lock_token = repo.lock_write().repository_token
2387
        repo.start_write_group()
2388
        tokens = repo.suspend_write_group()
2389
        self.addCleanup(repo.unlock)
2390
        request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2391
        request = request_class(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2392
        self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2393
            request.execute(b'', lock_token, tokens))
6280.7.6 by Jelmer Vernooij
Fix remaining tests.
2394
2395
    def test_check_write_group_invalid(self):
2396
        backing = self.get_transport()
2397
        repo = self.make_repository('.')
2398
        lock_token = repo.lock_write().repository_token
2399
        self.addCleanup(repo.unlock)
2400
        request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2401
        request = request_class(backing)
2402
        self.assertEqual(smart_req.FailedSmartServerResponse(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2403
            (b'UnresumableWriteGroup', [b'random'],
2404
                b'Malformed write group token')),
2405
            request.execute(b'', lock_token, [b"random"]))
6280.7.6 by Jelmer Vernooij
Fix remaining tests.
2406
6280.7.2 by Jelmer Vernooij
Add HPSS calls ``Repository.start_write_group``, ``Repository.abort_write_group`` and ``Repository.commit_write_group``.
2407
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2408
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
2409
2410
    def make_repo_needing_autopacking(self, path='.'):
2411
        # Make a repo in need of autopacking.
2412
        tree = self.make_branch_and_tree('.', format='pack-0.92')
2413
        repo = tree.branch.repository
2414
        # monkey-patch the pack collection to disable autopacking
2415
        repo._pack_collection._max_pack_count = lambda count: count
2416
        for x in range(10):
2417
            tree.commit('commit %s' % x)
2418
        self.assertEqual(10, len(repo._pack_collection.names()))
2419
        del repo._pack_collection._max_pack_count
2420
        return repo
2421
2422
    def test_autopack_needed(self):
2423
        repo = self.make_repo_needing_autopacking()
4145.1.6 by Robert Collins
More test fallout, but all caught now.
2424
        repo.lock_write()
2425
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2426
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2427
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2428
            backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2429
        response = request.execute(b'')
2430
        self.assertEqual(smart_req.SmartServerResponse((b'ok',)), response)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2431
        repo._pack_collection.reload_pack_names()
2432
        self.assertEqual(1, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2433
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2434
    def test_autopack_not_needed(self):
2435
        tree = self.make_branch_and_tree('.', format='pack-0.92')
2436
        repo = tree.branch.repository
4145.1.6 by Robert Collins
More test fallout, but all caught now.
2437
        repo.lock_write()
2438
        self.addCleanup(repo.unlock)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2439
        for x in range(9):
2440
            tree.commit('commit %s' % x)
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)
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2446
        repo._pack_collection.reload_pack_names()
2447
        self.assertEqual(9, len(repo._pack_collection.names()))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2448
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2449
    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.
2450
        """A request to autopack a non-pack repo is a no-op."""
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2451
        repo = self.make_repository('.', format='knit')
2452
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2453
        request = smart_packrepo.SmartServerPackRepositoryAutopack(
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2454
            backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2455
        response = request.execute(b'')
2456
        self.assertEqual(smart_req.SmartServerResponse((b'ok',)), response)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
2457
3801.1.4 by Andrew Bennetts
Add tests for autopack RPC.
2458
4760.2.5 by Andrew Bennetts
Add some more tests.
2459
class TestSmartServerVfsGet(tests.TestCaseWithMemoryTransport):
2460
2461
    def test_unicode_path(self):
2462
        """VFS requests expect unicode paths to be escaped."""
2463
        filename = u'foo\N{INTERROBANG}'
2464
        filename_escaped = urlutils.escape(filename)
2465
        backing = self.get_transport()
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2466
        request = vfs.GetRequest(backing)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2467
        backing.put_bytes_non_atomic(filename_escaped, b'contents')
2468
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), b'contents'),
4760.2.5 by Andrew Bennetts
Add some more tests.
2469
            request.execute(filename_escaped))
2470
2471
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
2472
class TestHandlers(tests.TestCase):
2473
    """Tests for the request.request_handlers object."""
2474
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
2475
    def test_all_registrations_exist(self):
2476
        """All registered request_handlers can be found."""
2477
        # If there's a typo in a register_lazy call, this loop will fail with
2478
        # an AttributeError.
5050.78.5 by John Arbash Meinel
Merge the 2.1-client-read-reconnect-819604 (bug #819604) to bzr-2.2
2479
        for key in smart_req.request_handlers.keys():
2480
            try:
2481
                item = smart_req.request_handlers.get(key)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
2482
            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
2483
                raise AttributeError('failed to get %s: %s' % (key, e))
3526.3.1 by Andrew Bennetts
Remove registrations of defunct HPSS verbs.
2484
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2485
    def assertHandlerEqual(self, verb, handler):
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2486
        self.assertEqual(smart_req.request_handlers.get(verb), handler)
4288.1.2 by Robert Collins
Create a server verb for doing BzrDir.get_config()
2487
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
2488
    def test_registered_methods(self):
2489
        """Test that known methods are registered to the correct object."""
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2490
        self.assertHandlerEqual(b'Branch.break_lock',
6280.4.4 by Jelmer Vernooij
Add Branch.break_lock.
2491
            smart_branch.SmartServerBranchBreakLock)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2492
        self.assertHandlerEqual(b'Branch.get_config_file',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2493
            smart_branch.SmartServerBranchGetConfigFile)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2494
        self.assertHandlerEqual(b'Branch.put_config_file',
6270.1.17 by Jelmer Vernooij
s/set_config_file/put_config_file.
2495
            smart_branch.SmartServerBranchPutConfigFile)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2496
        self.assertHandlerEqual(b'Branch.get_parent',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2497
            smart_branch.SmartServerBranchGetParent)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2498
        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.
2499
            smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2500
        self.assertHandlerEqual(b'Branch.get_tags_bytes',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2501
            smart_branch.SmartServerBranchGetTagsBytes)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2502
        self.assertHandlerEqual(b'Branch.lock_write',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2503
            smart_branch.SmartServerBranchRequestLockWrite)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2504
        self.assertHandlerEqual(b'Branch.last_revision_info',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2505
            smart_branch.SmartServerBranchRequestLastRevisionInfo)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2506
        self.assertHandlerEqual(b'Branch.revision_history',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2507
            smart_branch.SmartServerRequestRevisionHistory)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2508
        self.assertHandlerEqual(b'Branch.revision_id_to_revno',
6263.1.5 by Jelmer Vernooij
Test for presence of Branch.revision_id_to_revno verb.
2509
            smart_branch.SmartServerBranchRequestRevisionIdToRevno)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2510
        self.assertHandlerEqual(b'Branch.set_config_option',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2511
            smart_branch.SmartServerBranchRequestSetConfigOption)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2512
        self.assertHandlerEqual(b'Branch.set_last_revision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2513
            smart_branch.SmartServerBranchRequestSetLastRevision)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2514
        self.assertHandlerEqual(b'Branch.set_last_revision_info',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2515
            smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2516
        self.assertHandlerEqual(b'Branch.set_last_revision_ex',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2517
            smart_branch.SmartServerBranchRequestSetLastRevisionEx)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2518
        self.assertHandlerEqual(b'Branch.set_parent_location',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2519
            smart_branch.SmartServerBranchRequestSetParentLocation)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2520
        self.assertHandlerEqual(b'Branch.unlock',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2521
            smart_branch.SmartServerBranchRequestUnlock)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2522
        self.assertHandlerEqual(b'BzrDir.destroy_branch',
6266.4.3 by Jelmer Vernooij
fix tests.
2523
            smart_dir.SmartServerBzrDirRequestDestroyBranch)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2524
        self.assertHandlerEqual(b'BzrDir.find_repository',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2525
            smart_dir.SmartServerRequestFindRepositoryV1)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2526
        self.assertHandlerEqual(b'BzrDir.find_repositoryV2',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2527
            smart_dir.SmartServerRequestFindRepositoryV2)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2528
        self.assertHandlerEqual(b'BzrDirFormat.initialize',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2529
            smart_dir.SmartServerRequestInitializeBzrDir)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2530
        self.assertHandlerEqual(b'BzrDirFormat.initialize_ex_1.16',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2531
            smart_dir.SmartServerRequestBzrDirInitializeEx)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2532
        self.assertHandlerEqual(b'BzrDir.checkout_metadir',
6305.5.10 by Jelmer Vernooij
Move to BzrDir.checkout_metadir.
2533
            smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2534
        self.assertHandlerEqual(b'BzrDir.cloning_metadir',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2535
            smart_dir.SmartServerBzrDirRequestCloningMetaDir)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2536
        self.assertHandlerEqual(b'BzrDir.get_branches',
6436.3.2 by Jelmer Vernooij
Add HPSS call for BzrDir.get_branches.
2537
            smart_dir.SmartServerBzrDirRequestGetBranches)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2538
        self.assertHandlerEqual(b'BzrDir.get_config_file',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2539
            smart_dir.SmartServerBzrDirRequestConfigFile)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2540
        self.assertHandlerEqual(b'BzrDir.open_branch',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2541
            smart_dir.SmartServerRequestOpenBranch)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2542
        self.assertHandlerEqual(b'BzrDir.open_branchV2',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2543
            smart_dir.SmartServerRequestOpenBranchV2)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2544
        self.assertHandlerEqual(b'BzrDir.open_branchV3',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2545
            smart_dir.SmartServerRequestOpenBranchV3)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2546
        self.assertHandlerEqual(b'PackRepository.autopack',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2547
            smart_packrepo.SmartServerPackRepositoryAutopack)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2548
        self.assertHandlerEqual(b'Repository.add_signature_text',
6268.1.2 by Jelmer Vernooij
Initial work on Repository.add_signature_text.
2549
            smart_repo.SmartServerRepositoryAddSignatureText)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2550
        self.assertHandlerEqual(b'Repository.all_revision_ids',
6280.3.2 by Jelmer Vernooij
Add smart side of RemoteRepository.all_revision_ids().
2551
            smart_repo.SmartServerRepositoryAllRevisionIds)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2552
        self.assertHandlerEqual(b'Repository.break_lock',
6280.4.2 by Jelmer Vernooij
Provide server side of Repository.break_lock HPSS call.
2553
            smart_repo.SmartServerRepositoryBreakLock)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2554
        self.assertHandlerEqual(b'Repository.gather_stats',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2555
            smart_repo.SmartServerRepositoryGatherStats)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2556
        self.assertHandlerEqual(b'Repository.get_parent_map',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2557
            smart_repo.SmartServerRepositoryGetParentMap)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2558
        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.
2559
            smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2560
        self.assertHandlerEqual(b'Repository.get_rev_id_for_revno',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2561
            smart_repo.SmartServerRepositoryGetRevIdForRevno)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2562
        self.assertHandlerEqual(b'Repository.get_revision_graph',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2563
            smart_repo.SmartServerRepositoryGetRevisionGraph)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2564
        self.assertHandlerEqual(b'Repository.get_revision_signature_text',
6263.3.3 by Jelmer Vernooij
Add test for presence.
2565
            smart_repo.SmartServerRepositoryGetRevisionSignatureText)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2566
        self.assertHandlerEqual(b'Repository.get_stream',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2567
            smart_repo.SmartServerRepositoryGetStream)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2568
        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.
2569
            smart_repo.SmartServerRepositoryGetStream_1_19)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2570
        self.assertHandlerEqual(b'Repository.iter_revisions',
6280.9.2 by Jelmer Vernooij
Add smart side.
2571
            smart_repo.SmartServerRepositoryIterRevisions)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2572
        self.assertHandlerEqual(b'Repository.has_revision',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2573
            smart_repo.SmartServerRequestHasRevision)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2574
        self.assertHandlerEqual(b'Repository.insert_stream',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2575
            smart_repo.SmartServerRepositoryInsertStream)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2576
        self.assertHandlerEqual(b'Repository.insert_stream_locked',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2577
            smart_repo.SmartServerRepositoryInsertStreamLocked)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2578
        self.assertHandlerEqual(b'Repository.is_shared',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2579
            smart_repo.SmartServerRepositoryIsShared)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2580
        self.assertHandlerEqual(b'Repository.iter_files_bytes',
6280.10.20 by Jelmer Vernooij
Convert smart to zlib.
2581
            smart_repo.SmartServerRepositoryIterFilesBytes)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2582
        self.assertHandlerEqual(b'Repository.lock_write',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2583
            smart_repo.SmartServerRepositoryLockWrite)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2584
        self.assertHandlerEqual(b'Repository.make_working_trees',
6263.2.1 by Jelmer Vernooij
Add hpss call ``Repository.make_working_trees``
2585
            smart_repo.SmartServerRepositoryMakeWorkingTrees)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2586
        self.assertHandlerEqual(b'Repository.pack',
6305.2.2 by Jelmer Vernooij
Add smart side of pack.
2587
            smart_repo.SmartServerRepositoryPack)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2588
        self.assertHandlerEqual(b'Repository.reconcile',
6300.1.2 by Jelmer Vernooij
Add remote side of Repository.reconcile.
2589
            smart_repo.SmartServerRepositoryReconcile)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2590
        self.assertHandlerEqual(b'Repository.tarball',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2591
            smart_repo.SmartServerRepositoryTarball)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2592
        self.assertHandlerEqual(b'Repository.unlock',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2593
            smart_repo.SmartServerRepositoryUnlock)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2594
        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``.
2595
            smart_repo.SmartServerRepositoryStartWriteGroup)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2596
        self.assertHandlerEqual(b'Repository.check_write_group',
6280.7.10 by Jelmer Vernooij
add test for existing of Repository.check_write_group.
2597
            smart_repo.SmartServerRepositoryCheckWriteGroup)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2598
        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``.
2599
            smart_repo.SmartServerRepositoryCommitWriteGroup)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2600
        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``.
2601
            smart_repo.SmartServerRepositoryAbortWriteGroup)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2602
        self.assertHandlerEqual(b'VersionedFileRepository.get_serializer_format',
6280.5.2 by Jelmer Vernooij
New HPSS call VersionedFileRepository.get_serializer_format.
2603
            smart_repo.SmartServerRepositoryGetSerializerFormat)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2604
        self.assertHandlerEqual(b'VersionedFileRepository.get_inventories',
6282.6.28 by Jelmer Vernooij
Rename VersionedFileRepository.iter_inventories to VersionedFileRepository.get_inventories.
2605
            smart_repo.SmartServerRepositoryGetInventories)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2606
        self.assertHandlerEqual(b'Transport.is_readonly',
5010.2.8 by Vincent Ladeuil
Fix test_smart.py imports.
2607
            smart_req.SmartServerIsReadonly)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2608
2609
2610
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2611
    """Tests for SmartTCPServer hooks."""
2612
2613
    def setUp(self):
2614
        super(SmartTCPServerHookTests, self).setUp()
2615
        self.server = server.SmartTCPServer(self.get_transport())
2616
2617
    def test_run_server_started_hooks(self):
2618
        """Test the server started hooks get fired properly."""
2619
        started_calls = []
2620
        server.SmartTCPServer.hooks.install_named_hook('server_started',
2621
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2622
            None)
2623
        started_ex_calls = []
2624
        server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2625
            lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2626
            None)
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2627
        self.server._sockname = ('example.com', 42)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2628
        self.server.run_server_started_hooks()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2629
        self.assertEqual(started_calls,
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2630
            [([self.get_transport().base], 'bzr://example.com:42/')])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2631
        self.assertEqual(started_ex_calls,
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2632
            [([self.get_transport().base], self.server)])
2633
2634
    def test_run_server_started_hooks_ipv6(self):
2635
        """Test that socknames can contain 4-tuples."""
2636
        self.server._sockname = ('::', 42, 0, 0)
2637
        started_calls = []
2638
        server.SmartTCPServer.hooks.install_named_hook('server_started',
2639
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2640
            None)
2641
        self.server.run_server_started_hooks()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2642
        self.assertEqual(started_calls,
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2643
                [([self.get_transport().base], 'bzr://:::42/')])
2644
2645
    def test_run_server_stopped_hooks(self):
2646
        """Test the server stopped hooks."""
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2647
        self.server._sockname = ('example.com', 42)
5611.1.2 by Jelmer Vernooij
Add some tests for the hooks.
2648
        stopped_calls = []
2649
        server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2650
            lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2651
            None)
2652
        self.server.run_server_stopped_hooks()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2653
        self.assertEqual(stopped_calls,
5611.1.3 by Jelmer Vernooij
review comments from Vincent.
2654
            [([self.get_transport().base], 'bzr://example.com:42/')])
6305.2.2 by Jelmer Vernooij
Add smart side of pack.
2655
2656
2657
class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):
2658
2659
    def test_pack(self):
2660
        backing = self.get_transport()
2661
        request = smart_repo.SmartServerRepositoryPack(backing)
2662
        tree = self.make_branch_and_memory_tree('.')
6305.2.4 by Jelmer Vernooij
Fix tests.
2663
        repo_token = tree.branch.repository.lock_write().repository_token
6305.2.2 by Jelmer Vernooij
Add smart side of pack.
2664
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2665
        self.assertIs(None, request.execute(b'', repo_token, False))
6305.2.3 by Jelmer Vernooij
Store hint in body.
2666
6305.2.2 by Jelmer Vernooij
Add smart side of pack.
2667
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2668
            smart_req.SuccessfulSmartServerResponse((b'ok', ), ),
2669
            request.do_body(b''))
6305.2.2 by Jelmer Vernooij
Add smart side of pack.
2670
6282.6.7 by Jelmer Vernooij
Add basic server side test.
2671
6282.6.28 by Jelmer Vernooij
Rename VersionedFileRepository.iter_inventories to VersionedFileRepository.get_inventories.
2672
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
6282.6.7 by Jelmer Vernooij
Add basic server side test.
2673
2674
    def _get_serialized_inventory_delta(self, repository, base_revid, revid):
6405.2.10 by Jelmer Vernooij
Fix more tests.
2675
        base_inv = repository.revision_tree(base_revid).root_inventory
2676
        inv = repository.revision_tree(revid).root_inventory
6282.6.7 by Jelmer Vernooij
Add basic server side test.
2677
        inv_delta = inv._make_delta(base_inv)
2678
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2679
        return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2680
2681
    def test_single(self):
2682
        backing = self.get_transport()
6282.6.28 by Jelmer Vernooij
Rename VersionedFileRepository.iter_inventories to VersionedFileRepository.get_inventories.
2683
        request = smart_repo.SmartServerRepositoryGetInventories(backing)
6282.6.36 by Jelmer Vernooij
Fix smart server tests.
2684
        t = self.make_branch_and_tree('.', format='2a')
6282.6.7 by Jelmer Vernooij
Add basic server side test.
2685
        self.addCleanup(t.lock_write().unlock)
6855.4.1 by Jelmer Vernooij
Yet more bees.
2686
        self.build_tree_contents([("file", b"somecontents")])
2687
        t.add(["file"], [b"thefileid"])
2688
        t.commit(rev_id=b'somerev', message="add file")
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2689
        self.assertIs(None, request.execute(b'', b'unordered'))
2690
        response = request.do_body(b"somerev\n")
6282.6.7 by Jelmer Vernooij
Add basic server side test.
2691
        self.assertTrue(response.is_successful())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2692
        self.assertEqual(response.args, (b"ok", ))
6282.6.43 by Jelmer Vernooij
Fix stream name.
2693
        stream = [('inventory-deltas', [
6282.6.37 by Jelmer Vernooij
Cope with empty results.
2694
            versionedfile.FulltextContentFactory('somerev', None, None,
2695
                self._get_serialized_inventory_delta(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2696
                    t.branch.repository, b'null:', b'somerev'))])]
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
2697
        fmt = controldir.format_registry.get('2a')().repository_format
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
2698
        self.assertEqual(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2699
            b"".join(response.body_stream),
2700
            b"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
6282.6.10 by Jelmer Vernooij
Fix smart tests.
2701
2702
    def test_empty(self):
2703
        backing = self.get_transport()
6282.6.28 by Jelmer Vernooij
Rename VersionedFileRepository.iter_inventories to VersionedFileRepository.get_inventories.
2704
        request = smart_repo.SmartServerRepositoryGetInventories(backing)
6282.6.33 by Jelmer Vernooij
Fix some tests.
2705
        t = self.make_branch_and_tree('.', format='2a')
6282.6.10 by Jelmer Vernooij
Fix smart tests.
2706
        self.addCleanup(t.lock_write().unlock)
6855.4.1 by Jelmer Vernooij
Yet more bees.
2707
        self.build_tree_contents([("file", b"somecontents")])
2708
        t.add(["file"], [b"thefileid"])
2709
        t.commit(rev_id=b'somerev', message="add file")
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2710
        self.assertIs(None, request.execute(b'', b'unordered'))
2711
        response = request.do_body(b"")
6282.6.10 by Jelmer Vernooij
Fix smart tests.
2712
        self.assertTrue(response.is_successful())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
2713
        self.assertEqual(response.args, (b"ok", ))
2714
        self.assertEqual(b"".join(response.body_stream),
2715
            b"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")