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