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