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