2018.18.1
by Martin Pool
Add stub Repository.tarball smart method |
1 |
# Copyright (C) 2006, 2007 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 |
2692.1.18
by Andrew Bennetts
Merge from bzr.dev. |
28 |
from cStringIO import StringIO |
2018.18.2
by Martin Pool
smart method Repository.tarball actually returns the tarball |
29 |
import tarfile |
30 |
||
2692.1.2
by Andrew Bennetts
Merge from bzr.dev. |
31 |
from bzrlib import ( |
32 |
bzrdir, |
|
33 |
errors, |
|
34 |
pack, |
|
35 |
smart, |
|
36 |
tests, |
|
37 |
urlutils, |
|
38 |
)
|
|
3577.1.1
by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom. |
39 |
from bzrlib.branch import Branch, BranchReferenceFormat |
2692.1.22
by Andrew Bennetts
Reinstate imports needed to run test_smart alone. |
40 |
import bzrlib.smart.branch |
4070.2.3
by Robert Collins
Get BzrDir.cloning_metadir working. |
41 |
import bzrlib.smart.bzrdir, bzrlib.smart.bzrdir as smart_dir |
42 |
import bzrlib.smart.packrepository |
|
2692.1.22
by Andrew Bennetts
Reinstate imports needed to run test_smart alone. |
43 |
import bzrlib.smart.repository |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
44 |
from bzrlib.smart.request import ( |
45 |
FailedSmartServerResponse, |
|
46 |
SmartServerRequest, |
|
47 |
SmartServerResponse, |
|
48 |
SuccessfulSmartServerResponse, |
|
49 |
)
|
|
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
50 |
from bzrlib.tests import ( |
51 |
split_suite_by_re, |
|
52 |
)
|
|
2692.1.3
by Andrew Bennetts
Fix imports so that tests in test_smart.py can be run alone. |
53 |
from bzrlib.transport import chroot, get_transport |
2535.3.15
by Andrew Bennetts
Add KnitVersionedFile.get_stream_as_bytes, start smart implementation of RemoteRepository.get_data_stream. |
54 |
from bzrlib.util import bencode |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
55 |
|
56 |
||
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
57 |
def load_tests(standard_tests, module, loader): |
58 |
"""Multiply tests version and protocol consistency."""
|
|
59 |
# FindRepository tests.
|
|
60 |
bzrdir_mod = bzrlib.smart.bzrdir |
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
61 |
scenarios = [ |
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
62 |
("find_repository", { |
63 |
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV1}), |
|
64 |
("find_repositoryV2", { |
|
65 |
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV2}), |
|
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
66 |
("find_repositoryV3", { |
67 |
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV3}), |
|
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
68 |
]
|
69 |
to_adapt, result = split_suite_by_re(standard_tests, |
|
70 |
"TestSmartServerRequestFindRepository") |
|
71 |
v2_only, v1_and_2 = split_suite_by_re(to_adapt, |
|
72 |
"_v2") |
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
73 |
tests.multiply_tests(v1_and_2, scenarios, result) |
74 |
# The first scenario is only applicable to v1 protocols, it is deleted
|
|
75 |
# since.
|
|
76 |
tests.multiply_tests(v2_only, scenarios[1:], result) |
|
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
77 |
return result |
78 |
||
79 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
80 |
class TestCaseWithChrootedTransport(tests.TestCaseWithTransport): |
81 |
||
82 |
def setUp(self): |
|
83 |
tests.TestCaseWithTransport.setUp(self) |
|
84 |
self._chroot_server = None |
|
85 |
||
86 |
def get_transport(self, relpath=None): |
|
87 |
if self._chroot_server is None: |
|
88 |
backing_transport = tests.TestCaseWithTransport.get_transport(self) |
|
89 |
self._chroot_server = chroot.ChrootServer(backing_transport) |
|
90 |
self._chroot_server.setUp() |
|
91 |
self.addCleanup(self._chroot_server.tearDown) |
|
92 |
t = get_transport(self._chroot_server.get_url()) |
|
93 |
if relpath is not None: |
|
94 |
t = t.clone(relpath) |
|
95 |
return t |
|
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
96 |
|
97 |
||
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
98 |
class TestCaseWithSmartMedium(tests.TestCaseWithTransport): |
99 |
||
100 |
def setUp(self): |
|
101 |
super(TestCaseWithSmartMedium, self).setUp() |
|
102 |
# We're allowed to set the transport class here, so that we don't use
|
|
103 |
# the default or a parameterized class, but rather use the
|
|
104 |
# TestCaseWithTransport infrastructure to set up a smart server and
|
|
105 |
# transport.
|
|
3245.4.28
by Andrew Bennetts
Remove another XXX, and include test ID in smart server thread names. |
106 |
self.transport_server = self.make_transport_server |
107 |
||
108 |
def make_transport_server(self): |
|
109 |
return smart.server.SmartTCPServer_for_testing('-' + self.id()) |
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
110 |
|
111 |
def get_smart_medium(self): |
|
112 |
"""Get a smart medium to use in tests."""
|
|
113 |
return self.get_transport().get_smart_medium() |
|
114 |
||
115 |
||
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
116 |
class TestSmartServerResponse(tests.TestCase): |
117 |
||
118 |
def test__eq__(self): |
|
119 |
self.assertEqual(SmartServerResponse(('ok', )), |
|
120 |
SmartServerResponse(('ok', ))) |
|
121 |
self.assertEqual(SmartServerResponse(('ok', ), 'body'), |
|
122 |
SmartServerResponse(('ok', ), 'body')) |
|
123 |
self.assertNotEqual(SmartServerResponse(('ok', )), |
|
124 |
SmartServerResponse(('notok', ))) |
|
125 |
self.assertNotEqual(SmartServerResponse(('ok', ), 'body'), |
|
126 |
SmartServerResponse(('ok', ))) |
|
2018.5.41
by Robert Collins
Fix SmartServerResponse.__eq__ to handle None. |
127 |
self.assertNotEqual(None, |
128 |
SmartServerResponse(('ok', ))) |
|
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
129 |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
130 |
def test__str__(self): |
131 |
"""SmartServerResponses can be stringified."""
|
|
132 |
self.assertEqual( |
|
3691.2.6
by Martin Pool
Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions |
133 |
"<SuccessfulSmartServerResponse args=('args',) body='body'>", |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
134 |
str(SuccessfulSmartServerResponse(('args',), 'body'))) |
135 |
self.assertEqual( |
|
3691.2.6
by Martin Pool
Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions |
136 |
"<FailedSmartServerResponse args=('args',) body='body'>", |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
137 |
str(FailedSmartServerResponse(('args',), 'body'))) |
138 |
||
139 |
||
140 |
class TestSmartServerRequest(tests.TestCaseWithMemoryTransport): |
|
141 |
||
142 |
def test_translate_client_path(self): |
|
143 |
transport = self.get_transport() |
|
144 |
request = SmartServerRequest(transport, 'foo/') |
|
145 |
self.assertEqual('./', request.translate_client_path('foo/')) |
|
146 |
self.assertRaises( |
|
147 |
errors.InvalidURLJoin, request.translate_client_path, 'foo/..') |
|
148 |
self.assertRaises( |
|
149 |
errors.PathNotChild, request.translate_client_path, '/') |
|
150 |
self.assertRaises( |
|
151 |
errors.PathNotChild, request.translate_client_path, 'bar/') |
|
152 |
self.assertEqual('./baz', request.translate_client_path('foo/baz')) |
|
153 |
||
154 |
def test_transport_from_client_path(self): |
|
155 |
transport = self.get_transport() |
|
156 |
request = SmartServerRequest(transport, 'foo/') |
|
157 |
self.assertEqual( |
|
158 |
transport.base, |
|
159 |
request.transport_from_client_path('foo/').base) |
|
160 |
||
161 |
||
4070.2.3
by Robert Collins
Get BzrDir.cloning_metadir working. |
162 |
class TestSmartServerBzrDirRequestCloningMetaDir( |
163 |
tests.TestCaseWithMemoryTransport): |
|
164 |
"""Tests for BzrDir.cloning_metadir."""
|
|
165 |
||
166 |
def test_cloning_metadir(self): |
|
167 |
"""When there is a bzrdir present, the call succeeds."""
|
|
168 |
backing = self.get_transport() |
|
169 |
dir = self.make_bzrdir('.') |
|
170 |
local_result = dir.cloning_metadir() |
|
171 |
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir |
|
172 |
request = request_class(backing) |
|
173 |
expected = SuccessfulSmartServerResponse( |
|
174 |
(local_result.network_name(), |
|
175 |
local_result.repository_format.network_name(), |
|
4084.2.2
by Robert Collins
Review feedback. |
176 |
('branch', local_result.get_branch_format().network_name()))) |
4070.7.4
by Andrew Bennetts
Deal with branch references better in BzrDir.cloning_metadir RPC (changes protocol). |
177 |
self.assertEqual(expected, request.execute('', 'False')) |
178 |
||
179 |
def test_cloning_metadir_reference(self): |
|
4160.2.9
by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make |
180 |
"""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). |
181 |
backing = self.get_transport() |
182 |
referenced_branch = self.make_branch('referenced') |
|
183 |
dir = self.make_bzrdir('.') |
|
184 |
local_result = dir.cloning_metadir() |
|
185 |
reference = BranchReferenceFormat().initialize(dir, referenced_branch) |
|
186 |
reference_url = BranchReferenceFormat().get_reference(dir) |
|
187 |
# The server shouldn't try to follow the branch reference, so it's fine
|
|
188 |
# if the referenced branch isn't reachable.
|
|
189 |
backing.rename('referenced', 'moved') |
|
190 |
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir |
|
191 |
request = request_class(backing) |
|
4160.2.9
by Andrew Bennetts
Fix BzrDir.cloning_metadir RPC to fail on branch references, and make |
192 |
expected = FailedSmartServerResponse(('BranchReference',)) |
4070.2.3
by Robert Collins
Get BzrDir.cloning_metadir working. |
193 |
self.assertEqual(expected, request.execute('', 'False')) |
194 |
||
195 |
||
4017.3.2
by Robert Collins
Reduce the number of round trips required to create a repository over the network. |
196 |
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport): |
197 |
"""Tests for BzrDir.create_repository."""
|
|
198 |
||
199 |
def test_makes_repository(self): |
|
200 |
"""When there is a bzrdir present, the call succeeds."""
|
|
201 |
backing = self.get_transport() |
|
202 |
self.make_bzrdir('.') |
|
203 |
request_class = bzrlib.smart.bzrdir.SmartServerRequestCreateRepository |
|
204 |
request = request_class(backing) |
|
205 |
reference_bzrdir_format = bzrdir.format_registry.get('default')() |
|
206 |
reference_format = reference_bzrdir_format.repository_format |
|
207 |
network_name = reference_format.network_name() |
|
208 |
expected = SuccessfulSmartServerResponse( |
|
209 |
('ok', 'no', 'no', 'no', network_name)) |
|
210 |
self.assertEqual(expected, request.execute('', network_name, 'True')) |
|
211 |
||
212 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
213 |
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport): |
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
214 |
"""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. |
215 |
|
216 |
def test_no_repository(self): |
|
217 |
"""When there is no repository to be found, ('norepository', ) is returned."""
|
|
218 |
backing = self.get_transport() |
|
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
219 |
request = self._request_class(backing) |
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
220 |
self.make_bzrdir('.') |
221 |
self.assertEqual(SmartServerResponse(('norepository', )), |
|
2692.1.19
by Andrew Bennetts
Tweak for consistency suggested by John's review. |
222 |
request.execute('')) |
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
223 |
|
224 |
def test_nonshared_repository(self): |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
225 |
# nonshared repositorys only allow 'find' to return a handle when the
|
226 |
# 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. |
227 |
# the repository is at.
|
228 |
backing = self.get_transport() |
|
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
229 |
request = self._request_class(backing) |
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
230 |
result = self._make_repository_and_result() |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
231 |
self.assertEqual(result, request.execute('')) |
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
232 |
self.make_bzrdir('subdir') |
233 |
self.assertEqual(SmartServerResponse(('norepository', )), |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
234 |
request.execute('subdir')) |
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
235 |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
236 |
def _make_repository_and_result(self, shared=False, format=None): |
237 |
"""Convenience function to setup a repository.
|
|
238 |
||
239 |
:result: The SmartServerResponse to expect when opening it.
|
|
240 |
"""
|
|
241 |
repo = self.make_repository('.', shared=shared, format=format) |
|
242 |
if repo.supports_rich_root(): |
|
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
243 |
rich_root = 'yes' |
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
244 |
else: |
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
245 |
rich_root = 'no' |
2018.5.138
by Robert Collins
Merge bzr.dev. |
246 |
if repo._format.supports_tree_reference: |
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
247 |
subtrees = 'yes' |
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
248 |
else: |
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
249 |
subtrees = 'no' |
4053.1.4
by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat. |
250 |
if (smart.bzrdir.SmartServerRequestFindRepositoryV3 == |
251 |
self._request_class): |
|
252 |
return SuccessfulSmartServerResponse( |
|
253 |
('ok', '', rich_root, subtrees, 'no', |
|
254 |
repo._format.network_name())) |
|
255 |
elif (smart.bzrdir.SmartServerRequestFindRepositoryV2 == |
|
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
256 |
self._request_class): |
257 |
# All tests so far are on formats, and for non-external
|
|
258 |
# repositories.
|
|
259 |
return SuccessfulSmartServerResponse( |
|
260 |
('ok', '', rich_root, subtrees, 'no')) |
|
261 |
else: |
|
262 |
return SuccessfulSmartServerResponse(('ok', '', rich_root, subtrees)) |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
263 |
|
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
264 |
def test_shared_repository(self): |
265 |
"""When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
|
|
266 |
backing = self.get_transport() |
|
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
267 |
request = self._request_class(backing) |
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
268 |
result = self._make_repository_and_result(shared=True) |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
269 |
self.assertEqual(result, request.execute('')) |
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
270 |
self.make_bzrdir('subdir') |
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
271 |
result2 = SmartServerResponse(result.args[0:1] + ('..', ) + result.args[2:]) |
272 |
self.assertEqual(result2, |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
273 |
request.execute('subdir')) |
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
274 |
self.make_bzrdir('subdir/deeper') |
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
275 |
result3 = SmartServerResponse(result.args[0:1] + ('../..', ) + result.args[2:]) |
276 |
self.assertEqual(result3, |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
277 |
request.execute('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. |
278 |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
279 |
def test_rich_root_and_subtree_encoding(self): |
280 |
"""Test for the format attributes for rich root and subtree support."""
|
|
281 |
backing = self.get_transport() |
|
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
282 |
request = self._request_class(backing) |
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
283 |
result = self._make_repository_and_result(format='dirstate-with-subtree') |
284 |
# check the test will be valid
|
|
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
285 |
self.assertEqual('yes', result.args[2]) |
286 |
self.assertEqual('yes', result.args[3]) |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
287 |
self.assertEqual(result, request.execute('')) |
288 |
||
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
289 |
def test_supports_external_lookups_no_v2(self): |
290 |
"""Test for the supports_external_lookups attribute."""
|
|
291 |
backing = self.get_transport() |
|
292 |
request = self._request_class(backing) |
|
293 |
result = self._make_repository_and_result(format='dirstate-with-subtree') |
|
294 |
# check the test will be valid
|
|
295 |
self.assertEqual('no', result.args[4]) |
|
2692.1.24
by Andrew Bennetts
Merge from bzr.dev. |
296 |
self.assertEqual(result, request.execute('')) |
297 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
298 |
|
299 |
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport): |
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
300 |
|
301 |
def test_empty_dir(self): |
|
302 |
"""Initializing an empty dir should succeed and do it."""
|
|
303 |
backing = self.get_transport() |
|
304 |
request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing) |
|
305 |
self.assertEqual(SmartServerResponse(('ok', )), |
|
2692.1.20
by Andrew Bennetts
Tweak for consistency suggested by John's review. |
306 |
request.execute('')) |
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
307 |
made_dir = bzrdir.BzrDir.open_from_transport(backing) |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
308 |
# 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 :). |
309 |
# default formart.
|
310 |
self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree) |
|
311 |
self.assertRaises(errors.NotBranchError, made_dir.open_branch) |
|
312 |
self.assertRaises(errors.NoRepositoryPresent, made_dir.open_repository) |
|
313 |
||
314 |
def test_missing_dir(self): |
|
315 |
"""Initializing a missing directory should fail like the bzrdir api."""
|
|
316 |
backing = self.get_transport() |
|
317 |
request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing) |
|
318 |
self.assertRaises(errors.NoSuchFile, |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
319 |
request.execute, 'subdir') |
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
320 |
|
321 |
def test_initialized_dir(self): |
|
322 |
"""Initializing an extant bzrdir should fail like the bzrdir api."""
|
|
323 |
backing = self.get_transport() |
|
324 |
request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing) |
|
325 |
self.make_bzrdir('subdir') |
|
326 |
self.assertRaises(errors.FileExists, |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
327 |
request.execute, 'subdir') |
328 |
||
329 |
||
330 |
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport): |
|
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
331 |
|
332 |
def test_no_branch(self): |
|
333 |
"""When there is no branch, ('nobranch', ) is returned."""
|
|
334 |
backing = self.get_transport() |
|
335 |
request = smart.bzrdir.SmartServerRequestOpenBranch(backing) |
|
336 |
self.make_bzrdir('.') |
|
337 |
self.assertEqual(SmartServerResponse(('nobranch', )), |
|
2692.1.20
by Andrew Bennetts
Tweak for consistency suggested by John's review. |
338 |
request.execute('')) |
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
339 |
|
340 |
def test_branch(self): |
|
341 |
"""When there is a branch, 'ok' is returned."""
|
|
342 |
backing = self.get_transport() |
|
343 |
request = smart.bzrdir.SmartServerRequestOpenBranch(backing) |
|
344 |
self.make_branch('.') |
|
345 |
self.assertEqual(SmartServerResponse(('ok', '')), |
|
2692.1.20
by Andrew Bennetts
Tweak for consistency suggested by John's review. |
346 |
request.execute('')) |
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
347 |
|
348 |
def test_branch_reference(self): |
|
349 |
"""When there is a branch reference, the reference URL is returned."""
|
|
350 |
backing = self.get_transport() |
|
351 |
request = smart.bzrdir.SmartServerRequestOpenBranch(backing) |
|
352 |
branch = self.make_branch('branch') |
|
353 |
checkout = branch.create_checkout('reference',lightweight=True) |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
354 |
reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir) |
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
355 |
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location') |
356 |
self.assertEqual(SmartServerResponse(('ok', reference_url)), |
|
2692.1.20
by Andrew Bennetts
Tweak for consistency suggested by John's review. |
357 |
request.execute('reference')) |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
358 |
|
359 |
||
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. |
360 |
class TestSmartServerRequestOpenBranchV2(TestCaseWithChrootedTransport): |
361 |
||
362 |
def test_no_branch(self): |
|
363 |
"""When there is no branch, ('nobranch', ) is returned."""
|
|
364 |
backing = self.get_transport() |
|
365 |
self.make_bzrdir('.') |
|
366 |
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing) |
|
367 |
self.assertEqual(SmartServerResponse(('nobranch', )), |
|
368 |
request.execute('')) |
|
369 |
||
370 |
def test_branch(self): |
|
371 |
"""When there is a branch, 'ok' is returned."""
|
|
372 |
backing = self.get_transport() |
|
373 |
expected = self.make_branch('.')._format.network_name() |
|
374 |
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing) |
|
375 |
self.assertEqual(SuccessfulSmartServerResponse(('branch', expected)), |
|
376 |
request.execute('')) |
|
377 |
||
378 |
def test_branch_reference(self): |
|
379 |
"""When there is a branch reference, the reference URL is returned."""
|
|
380 |
backing = self.get_transport() |
|
381 |
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing) |
|
382 |
branch = self.make_branch('branch') |
|
383 |
checkout = branch.create_checkout('reference',lightweight=True) |
|
384 |
reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir) |
|
385 |
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location') |
|
386 |
self.assertEqual(SuccessfulSmartServerResponse(('ref', reference_url)), |
|
387 |
request.execute('reference')) |
|
388 |
||
4160.2.1
by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch. |
389 |
def test_stacked_branch(self): |
390 |
"""Opening a stacked branch does not open the stacked-on branch."""
|
|
391 |
trunk = self.make_branch('trunk') |
|
392 |
feature = self.make_branch('feature', format='1.9') |
|
393 |
feature.set_stacked_on_url(trunk.base) |
|
394 |
opened_branches = [] |
|
395 |
Branch.hooks.install_named_hook('open', opened_branches.append, None) |
|
396 |
backing = self.get_transport() |
|
397 |
request = smart.bzrdir.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. |
398 |
request.setup_jail() |
399 |
try: |
|
400 |
response = request.execute('feature') |
|
401 |
finally: |
|
402 |
request.teardown_jail() |
|
4160.2.1
by Andrew Bennetts
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch. |
403 |
expected_format = feature._format.network_name() |
404 |
self.assertEqual( |
|
405 |
SuccessfulSmartServerResponse(('branch', expected_format)), |
|
406 |
response) |
|
407 |
self.assertLength(1, opened_branches) |
|
408 |
||
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. |
409 |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
410 |
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport): |
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
411 |
|
412 |
def test_empty(self): |
|
413 |
"""For an empty branch, the body is empty."""
|
|
414 |
backing = self.get_transport() |
|
415 |
request = smart.branch.SmartServerRequestRevisionHistory(backing) |
|
416 |
self.make_branch('.') |
|
417 |
self.assertEqual(SmartServerResponse(('ok', ), ''), |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
418 |
request.execute('')) |
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
419 |
|
420 |
def test_not_empty(self): |
|
421 |
"""For a non-empty branch, the body is empty."""
|
|
422 |
backing = self.get_transport() |
|
423 |
request = smart.branch.SmartServerRequestRevisionHistory(backing) |
|
424 |
tree = self.make_branch_and_memory_tree('.') |
|
425 |
tree.lock_write() |
|
426 |
tree.add('') |
|
427 |
r1 = tree.commit('1st commit') |
|
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
428 |
r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8')) |
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
429 |
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. |
430 |
self.assertEqual( |
431 |
SmartServerResponse(('ok', ), ('\x00'.join([r1, r2]))), |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
432 |
request.execute('')) |
433 |
||
434 |
||
435 |
class TestSmartServerBranchRequest(tests.TestCaseWithMemoryTransport): |
|
2018.5.49
by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to |
436 |
|
437 |
def test_no_branch(self): |
|
438 |
"""When there is a bzrdir and no branch, NotBranchError is raised."""
|
|
439 |
backing = self.get_transport() |
|
440 |
request = smart.branch.SmartServerBranchRequest(backing) |
|
441 |
self.make_bzrdir('.') |
|
442 |
self.assertRaises(errors.NotBranchError, |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
443 |
request.execute, '') |
2018.5.49
by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to |
444 |
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
445 |
def test_branch_reference(self): |
446 |
"""When there is a branch reference, NotBranchError is raised."""
|
|
447 |
backing = self.get_transport() |
|
2018.5.49
by Wouter van Heyst
Refactor SmartServerBranchRequest out from SmartServerRequestRevisionHistory to |
448 |
request = smart.branch.SmartServerBranchRequest(backing) |
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
449 |
branch = self.make_branch('branch') |
450 |
checkout = branch.create_checkout('reference',lightweight=True) |
|
451 |
self.assertRaises(errors.NotBranchError, |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
452 |
request.execute, 'checkout') |
453 |
||
454 |
||
455 |
class TestSmartServerBranchRequestLastRevisionInfo(tests.TestCaseWithMemoryTransport): |
|
2018.5.50
by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method. |
456 |
|
457 |
def test_empty(self): |
|
2018.5.170
by Andrew Bennetts
Use 'null:' instead of '' to mean NULL_REVISION on the wire. |
458 |
"""For an empty branch, the result is ('ok', '0', 'null:')."""
|
2018.5.50
by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method. |
459 |
backing = self.get_transport() |
460 |
request = smart.branch.SmartServerBranchRequestLastRevisionInfo(backing) |
|
461 |
self.make_branch('.') |
|
2018.5.170
by Andrew Bennetts
Use 'null:' instead of '' to mean NULL_REVISION on the wire. |
462 |
self.assertEqual(SmartServerResponse(('ok', '0', 'null:')), |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
463 |
request.execute('')) |
2018.5.50
by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method. |
464 |
|
465 |
def test_not_empty(self): |
|
466 |
"""For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
|
|
467 |
backing = self.get_transport() |
|
468 |
request = smart.branch.SmartServerBranchRequestLastRevisionInfo(backing) |
|
469 |
tree = self.make_branch_and_memory_tree('.') |
|
470 |
tree.lock_write() |
|
471 |
tree.add('') |
|
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
472 |
rev_id_utf8 = u'\xc8'.encode('utf-8') |
2018.5.50
by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method. |
473 |
r1 = tree.commit('1st commit') |
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
474 |
r2 = tree.commit('2nd commit', rev_id=rev_id_utf8) |
2018.5.50
by Wouter van Heyst
Add SmartServerBranchRequestLastRevisionInfo method. |
475 |
tree.unlock() |
476 |
self.assertEqual( |
|
2018.5.83
by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs. |
477 |
SmartServerResponse(('ok', '2', rev_id_utf8)), |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
478 |
request.execute('')) |
479 |
||
480 |
||
481 |
class TestSmartServerBranchRequestGetConfigFile(tests.TestCaseWithMemoryTransport): |
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
482 |
|
483 |
def test_default(self): |
|
484 |
"""With no file, we get empty content."""
|
|
485 |
backing = self.get_transport() |
|
486 |
request = smart.branch.SmartServerBranchGetConfigFile(backing) |
|
487 |
branch = self.make_branch('.') |
|
488 |
# there should be no file by default
|
|
489 |
content = '' |
|
490 |
self.assertEqual(SmartServerResponse(('ok', ), content), |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
491 |
request.execute('')) |
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
492 |
|
493 |
def test_with_content(self): |
|
494 |
# SmartServerBranchGetConfigFile should return the content from
|
|
495 |
# 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 |
496 |
# perform more complex processing.
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
497 |
backing = self.get_transport() |
498 |
request = smart.branch.SmartServerBranchGetConfigFile(backing) |
|
499 |
branch = self.make_branch('.') |
|
3407.2.5
by Martin Pool
Deprecate LockableFiles.put_utf8 |
500 |
branch._transport.put_bytes('branch.conf', 'foo bar baz') |
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
501 |
self.assertEqual(SmartServerResponse(('ok', ), 'foo bar baz'), |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
502 |
request.execute('')) |
503 |
||
504 |
||
4226.2.1
by Robert Collins
Set branch config options via a smart method. |
505 |
class TestLockedBranch(tests.TestCaseWithMemoryTransport): |
506 |
||
507 |
def get_lock_tokens(self, branch): |
|
508 |
branch_token = branch.lock_write() |
|
509 |
repo_token = branch.repository.lock_write() |
|
510 |
branch.repository.unlock() |
|
511 |
return branch_token, repo_token |
|
512 |
||
513 |
||
514 |
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch): |
|
515 |
||
516 |
def test_value_name(self): |
|
517 |
branch = self.make_branch('.') |
|
518 |
request = smart.branch.SmartServerBranchRequestSetConfigOption( |
|
519 |
branch.bzrdir.root_transport) |
|
520 |
branch_token, repo_token = self.get_lock_tokens(branch) |
|
521 |
config = branch._get_config() |
|
522 |
result = request.execute('', branch_token, repo_token, 'bar', 'foo', |
|
523 |
'') |
|
524 |
self.assertEqual(SuccessfulSmartServerResponse(()), result) |
|
525 |
self.assertEqual('bar', config.get_option('foo')) |
|
526 |
||
527 |
def test_value_name_section(self): |
|
528 |
branch = self.make_branch('.') |
|
529 |
request = smart.branch.SmartServerBranchRequestSetConfigOption( |
|
530 |
branch.bzrdir.root_transport) |
|
531 |
branch_token, repo_token = self.get_lock_tokens(branch) |
|
532 |
config = branch._get_config() |
|
533 |
result = request.execute('', branch_token, repo_token, 'bar', 'foo', |
|
534 |
'gam') |
|
535 |
self.assertEqual(SuccessfulSmartServerResponse(()), result) |
|
536 |
self.assertEqual('bar', config.get_option('foo', 'gam')) |
|
537 |
||
538 |
||
539 |
class SetLastRevisionTestBase(TestLockedBranch): |
|
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
540 |
"""Base test case for verbs that implement set_last_revision."""
|
541 |
||
542 |
def setUp(self): |
|
543 |
tests.TestCaseWithMemoryTransport.setUp(self) |
|
544 |
backing_transport = self.get_transport() |
|
545 |
self.request = self.request_class(backing_transport) |
|
546 |
self.tree = self.make_branch_and_memory_tree('.') |
|
547 |
||
548 |
def lock_branch(self): |
|
4226.2.1
by Robert Collins
Set branch config options via a smart method. |
549 |
return self.get_lock_tokens(self.tree.branch) |
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
550 |
|
551 |
def unlock_branch(self): |
|
552 |
self.tree.branch.unlock() |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
553 |
|
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
554 |
def set_last_revision(self, revision_id, revno): |
555 |
branch_token, repo_token = self.lock_branch() |
|
556 |
response = self._set_last_revision( |
|
557 |
revision_id, revno, branch_token, repo_token) |
|
558 |
self.unlock_branch() |
|
559 |
return response |
|
560 |
||
561 |
def assertRequestSucceeds(self, revision_id, revno): |
|
562 |
response = self.set_last_revision(revision_id, revno) |
|
563 |
self.assertEqual(SuccessfulSmartServerResponse(('ok',)), response) |
|
564 |
||
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
565 |
|
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
566 |
class TestSetLastRevisionVerbMixin(object): |
567 |
"""Mixin test case for verbs that implement set_last_revision."""
|
|
568 |
||
569 |
def test_set_null_to_null(self): |
|
570 |
"""An empty branch can have its last revision set to 'null:'."""
|
|
571 |
self.assertRequestSucceeds('null:', 0) |
|
572 |
||
573 |
def test_NoSuchRevision(self): |
|
574 |
"""If the revision_id is not present, the verb returns NoSuchRevision.
|
|
575 |
"""
|
|
576 |
revision_id = 'non-existent revision' |
|
577 |
self.assertEqual( |
|
578 |
FailedSmartServerResponse(('NoSuchRevision', revision_id)), |
|
579 |
self.set_last_revision(revision_id, 1)) |
|
580 |
||
581 |
def make_tree_with_two_commits(self): |
|
582 |
self.tree.lock_write() |
|
583 |
self.tree.add('') |
|
584 |
rev_id_utf8 = u'\xc8'.encode('utf-8') |
|
585 |
r1 = self.tree.commit('1st commit', rev_id=rev_id_utf8) |
|
586 |
r2 = self.tree.commit('2nd commit', rev_id='rev-2') |
|
587 |
self.tree.unlock() |
|
588 |
||
589 |
def test_branch_last_revision_info_is_updated(self): |
|
590 |
"""A branch's tip can be set to a revision that is present in its
|
|
591 |
repository.
|
|
592 |
"""
|
|
593 |
# Make a branch with an empty revision history, but two revisions in
|
|
594 |
# its repository.
|
|
595 |
self.make_tree_with_two_commits() |
|
596 |
rev_id_utf8 = u'\xc8'.encode('utf-8') |
|
597 |
self.tree.branch.set_revision_history([]) |
|
598 |
self.assertEqual( |
|
599 |
(0, 'null:'), self.tree.branch.last_revision_info()) |
|
600 |
# We can update the branch to a revision that is present in the
|
|
601 |
# repository.
|
|
602 |
self.assertRequestSucceeds(rev_id_utf8, 1) |
|
603 |
self.assertEqual( |
|
604 |
(1, rev_id_utf8), self.tree.branch.last_revision_info()) |
|
605 |
||
606 |
def test_branch_last_revision_info_rewind(self): |
|
607 |
"""A branch's tip can be set to a revision that is an ancestor of the
|
|
608 |
current tip.
|
|
609 |
"""
|
|
610 |
self.make_tree_with_two_commits() |
|
611 |
rev_id_utf8 = u'\xc8'.encode('utf-8') |
|
612 |
self.assertEqual( |
|
613 |
(2, 'rev-2'), self.tree.branch.last_revision_info()) |
|
614 |
self.assertRequestSucceeds(rev_id_utf8, 1) |
|
615 |
self.assertEqual( |
|
616 |
(1, rev_id_utf8), self.tree.branch.last_revision_info()) |
|
617 |
||
3577.1.1
by Andrew Bennetts
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom. |
618 |
def test_TipChangeRejected(self): |
619 |
"""If a pre_change_branch_tip hook raises TipChangeRejected, the verb
|
|
620 |
returns TipChangeRejected.
|
|
621 |
"""
|
|
622 |
rejection_message = u'rejection message\N{INTERROBANG}' |
|
623 |
def hook_that_rejects(params): |
|
624 |
raise errors.TipChangeRejected(rejection_message) |
|
625 |
Branch.hooks.install_named_hook( |
|
626 |
'pre_change_branch_tip', hook_that_rejects, None) |
|
627 |
self.assertEqual( |
|
628 |
FailedSmartServerResponse( |
|
629 |
('TipChangeRejected', rejection_message.encode('utf-8'))), |
|
630 |
self.set_last_revision('null:', 0)) |
|
631 |
||
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
632 |
|
3441.5.6
by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests. |
633 |
class TestSmartServerBranchRequestSetLastRevision( |
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
634 |
SetLastRevisionTestBase, TestSetLastRevisionVerbMixin): |
635 |
"""Tests for Branch.set_last_revision verb."""
|
|
3441.5.6
by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests. |
636 |
|
637 |
request_class = smart.branch.SmartServerBranchRequestSetLastRevision |
|
638 |
||
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
639 |
def _set_last_revision(self, revision_id, revno, branch_token, repo_token): |
640 |
return self.request.execute( |
|
641 |
'', branch_token, repo_token, revision_id) |
|
642 |
||
643 |
||
644 |
class TestSmartServerBranchRequestSetLastRevisionInfo( |
|
645 |
SetLastRevisionTestBase, TestSetLastRevisionVerbMixin): |
|
646 |
"""Tests for Branch.set_last_revision_info verb."""
|
|
647 |
||
648 |
request_class = smart.branch.SmartServerBranchRequestSetLastRevisionInfo |
|
649 |
||
650 |
def _set_last_revision(self, revision_id, revno, branch_token, repo_token): |
|
651 |
return self.request.execute( |
|
652 |
'', branch_token, repo_token, revno, revision_id) |
|
653 |
||
654 |
def test_NoSuchRevision(self): |
|
655 |
"""Branch.set_last_revision_info does not have to return
|
|
656 |
NoSuchRevision if the revision_id is absent.
|
|
657 |
"""
|
|
658 |
raise tests.TestNotApplicable() |
|
3441.5.6
by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests. |
659 |
|
660 |
||
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. |
661 |
class TestSmartServerBranchRequestSetLastRevisionEx( |
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
662 |
SetLastRevisionTestBase, TestSetLastRevisionVerbMixin): |
663 |
"""Tests for Branch.set_last_revision_ex verb."""
|
|
3441.5.6
by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests. |
664 |
|
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. |
665 |
request_class = smart.branch.SmartServerBranchRequestSetLastRevisionEx |
3441.5.6
by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests. |
666 |
|
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
667 |
def _set_last_revision(self, revision_id, revno, branch_token, repo_token): |
668 |
return self.request.execute( |
|
669 |
'', branch_token, repo_token, revision_id, 0, 0) |
|
670 |
||
671 |
def assertRequestSucceeds(self, revision_id, revno): |
|
672 |
response = self.set_last_revision(revision_id, revno) |
|
673 |
self.assertEqual( |
|
674 |
SuccessfulSmartServerResponse(('ok', revno, revision_id)), |
|
675 |
response) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
676 |
|
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
677 |
def test_branch_last_revision_info_rewind(self): |
678 |
"""A branch's tip can be set to a revision that is an ancestor of the
|
|
679 |
current tip, but only if allow_overwrite_descendant is passed.
|
|
680 |
"""
|
|
681 |
self.make_tree_with_two_commits() |
|
3441.5.6
by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests. |
682 |
rev_id_utf8 = u'\xc8'.encode('utf-8') |
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
683 |
self.assertEqual( |
684 |
(2, 'rev-2'), self.tree.branch.last_revision_info()) |
|
685 |
# If allow_overwrite_descendant flag is 0, then trying to set the tip
|
|
686 |
# to an older revision ID has no effect.
|
|
687 |
branch_token, repo_token = self.lock_branch() |
|
688 |
response = self.request.execute( |
|
689 |
'', branch_token, repo_token, rev_id_utf8, 0, 0) |
|
690 |
self.assertEqual( |
|
691 |
SuccessfulSmartServerResponse(('ok', 2, 'rev-2')), |
|
692 |
response) |
|
693 |
self.assertEqual( |
|
694 |
(2, 'rev-2'), self.tree.branch.last_revision_info()) |
|
695 |
||
696 |
# If allow_overwrite_descendant flag is 1, then setting the tip to an
|
|
697 |
# ancestor works.
|
|
698 |
response = self.request.execute( |
|
699 |
'', branch_token, repo_token, rev_id_utf8, 0, 1) |
|
700 |
self.assertEqual( |
|
701 |
SuccessfulSmartServerResponse(('ok', 1, rev_id_utf8)), |
|
702 |
response) |
|
703 |
self.unlock_branch() |
|
704 |
self.assertEqual( |
|
705 |
(1, rev_id_utf8), self.tree.branch.last_revision_info()) |
|
706 |
||
3441.5.31
by Andrew Bennetts
Add test for allow_diverged flag. |
707 |
def make_branch_with_divergent_history(self): |
708 |
"""Make a branch with divergent history in its repo.
|
|
709 |
||
710 |
The branch's tip will be 'child-2', and the repo will also contain
|
|
711 |
'child-1', which diverges from a common base revision.
|
|
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
712 |
"""
|
713 |
self.tree.lock_write() |
|
714 |
self.tree.add('') |
|
715 |
r1 = self.tree.commit('1st commit') |
|
716 |
revno_1, revid_1 = self.tree.branch.last_revision_info() |
|
717 |
r2 = self.tree.commit('2nd commit', rev_id='child-1') |
|
3441.5.6
by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests. |
718 |
# Undo the second commit
|
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
719 |
self.tree.branch.set_last_revision_info(revno_1, revid_1) |
720 |
self.tree.set_parent_ids([revid_1]) |
|
3441.5.6
by Andrew Bennetts
Greatly simplify RemoteBranch.update_revisions. Still needs more tests. |
721 |
# Make a new second commit, child-2. child-2 has diverged from
|
722 |
# child-1.
|
|
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
723 |
new_r2 = self.tree.commit('2nd commit', rev_id='child-2') |
724 |
self.tree.unlock() |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
725 |
|
3441.5.31
by Andrew Bennetts
Add test for allow_diverged flag. |
726 |
def test_not_allow_diverged(self): |
727 |
"""If allow_diverged is not passed, then setting a divergent history
|
|
728 |
returns a Diverged error.
|
|
729 |
"""
|
|
730 |
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. |
731 |
self.assertEqual( |
3441.5.30
by Andrew Bennetts
Improve tests for all Branch.set_last_revision* verbs. |
732 |
FailedSmartServerResponse(('Diverged',)), |
733 |
self.set_last_revision('child-1', 2)) |
|
734 |
# The branch tip was not changed.
|
|
735 |
self.assertEqual('child-2', self.tree.branch.last_revision()) |
|
2892.2.1
by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it. |
736 |
|
3441.5.31
by Andrew Bennetts
Add test for allow_diverged flag. |
737 |
def test_allow_diverged(self): |
738 |
"""If allow_diverged is passed, then setting a divergent history
|
|
739 |
succeeds.
|
|
740 |
"""
|
|
741 |
self.make_branch_with_divergent_history() |
|
742 |
branch_token, repo_token = self.lock_branch() |
|
743 |
response = self.request.execute( |
|
744 |
'', branch_token, repo_token, 'child-1', 1, 0) |
|
745 |
self.assertEqual( |
|
746 |
SuccessfulSmartServerResponse(('ok', 2, 'child-1')), |
|
747 |
response) |
|
748 |
self.unlock_branch() |
|
749 |
# The branch tip was changed.
|
|
750 |
self.assertEqual('child-1', self.tree.branch.last_revision()) |
|
751 |
||
2892.2.1
by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it. |
752 |
|
4078.2.1
by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch. |
753 |
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport): |
754 |
||
755 |
def test_get_parent_none(self): |
|
756 |
base_branch = self.make_branch('base') |
|
757 |
request = smart.branch.SmartServerBranchGetParent(self.get_transport()) |
|
758 |
response = request.execute('base') |
|
759 |
self.assertEquals( |
|
4083.1.7
by Andrew Bennetts
Fix same trivial bug [(x) != (x,)] in test_remote and test_smart. |
760 |
SuccessfulSmartServerResponse(('',)), response) |
4078.2.1
by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch. |
761 |
|
762 |
def test_get_parent_something(self): |
|
763 |
base_branch = self.make_branch('base') |
|
764 |
base_branch.set_parent(self.get_url('foo')) |
|
765 |
request = smart.branch.SmartServerBranchGetParent(self.get_transport()) |
|
766 |
response = request.execute('base') |
|
767 |
self.assertEquals( |
|
4083.1.7
by Andrew Bennetts
Fix same trivial bug [(x) != (x,)] in test_remote and test_smart. |
768 |
SuccessfulSmartServerResponse(("../foo",)), |
4078.2.1
by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch. |
769 |
response) |
770 |
||
771 |
||
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. |
772 |
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport): |
773 |
# Only called when the branch format and tags match [yay factory
|
|
774 |
# methods] so only need to test straight forward cases.
|
|
775 |
||
776 |
def test_get_bytes(self): |
|
777 |
base_branch = self.make_branch('base') |
|
778 |
request = smart.branch.SmartServerBranchGetTagsBytes( |
|
779 |
self.get_transport()) |
|
780 |
response = request.execute('base') |
|
781 |
self.assertEquals( |
|
782 |
SuccessfulSmartServerResponse(('',)), response) |
|
783 |
||
784 |
||
3691.2.5
by Martin Pool
Add Branch.get_stacked_on_url rpc and tests for same |
785 |
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport): |
786 |
||
787 |
def test_get_stacked_on_url(self): |
|
788 |
base_branch = self.make_branch('base', format='1.6') |
|
789 |
stacked_branch = self.make_branch('stacked', format='1.6') |
|
790 |
# typically should be relative
|
|
791 |
stacked_branch.set_stacked_on_url('../base') |
|
792 |
request = smart.branch.SmartServerBranchRequestGetStackedOnURL( |
|
793 |
self.get_transport()) |
|
794 |
response = request.execute('stacked') |
|
795 |
self.assertEquals( |
|
796 |
SmartServerResponse(('ok', '../base')), |
|
797 |
response) |
|
798 |
||
799 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
800 |
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport): |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
801 |
|
802 |
def setUp(self): |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
803 |
tests.TestCaseWithMemoryTransport.setUp(self) |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
804 |
|
805 |
def test_lock_write_on_unlocked_branch(self): |
|
806 |
backing = self.get_transport() |
|
807 |
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. |
808 |
branch = self.make_branch('.', format='knit') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
809 |
repository = branch.repository |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
810 |
response = request.execute('') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
811 |
branch_nonce = branch.control_files._lock.peek().get('nonce') |
812 |
repository_nonce = repository.control_files._lock.peek().get('nonce') |
|
813 |
self.assertEqual( |
|
814 |
SmartServerResponse(('ok', branch_nonce, repository_nonce)), |
|
815 |
response) |
|
816 |
# The branch (and associated repository) is now locked. Verify that
|
|
817 |
# with a new branch object.
|
|
818 |
new_branch = repository.bzrdir.open_branch() |
|
819 |
self.assertRaises(errors.LockContention, new_branch.lock_write) |
|
820 |
||
821 |
def test_lock_write_on_locked_branch(self): |
|
822 |
backing = self.get_transport() |
|
823 |
request = smart.branch.SmartServerBranchRequestLockWrite(backing) |
|
824 |
branch = self.make_branch('.') |
|
825 |
branch.lock_write() |
|
826 |
branch.leave_lock_in_place() |
|
827 |
branch.unlock() |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
828 |
response = request.execute('') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
829 |
self.assertEqual( |
830 |
SmartServerResponse(('LockContention',)), response) |
|
831 |
||
832 |
def test_lock_write_with_tokens_on_locked_branch(self): |
|
833 |
backing = self.get_transport() |
|
834 |
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. |
835 |
branch = self.make_branch('.', format='knit') |
2018.5.142
by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens). |
836 |
branch_token = branch.lock_write() |
837 |
repo_token = branch.repository.lock_write() |
|
838 |
branch.repository.unlock() |
|
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
839 |
branch.leave_lock_in_place() |
840 |
branch.repository.leave_lock_in_place() |
|
841 |
branch.unlock() |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
842 |
response = request.execute('', |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
843 |
branch_token, repo_token) |
844 |
self.assertEqual( |
|
845 |
SmartServerResponse(('ok', branch_token, repo_token)), response) |
|
846 |
||
847 |
def test_lock_write_with_mismatched_tokens_on_locked_branch(self): |
|
848 |
backing = self.get_transport() |
|
849 |
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. |
850 |
branch = self.make_branch('.', format='knit') |
2018.5.142
by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens). |
851 |
branch_token = branch.lock_write() |
852 |
repo_token = branch.repository.lock_write() |
|
853 |
branch.repository.unlock() |
|
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
854 |
branch.leave_lock_in_place() |
855 |
branch.repository.leave_lock_in_place() |
|
856 |
branch.unlock() |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
857 |
response = request.execute('', |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
858 |
branch_token+'xxx', repo_token) |
859 |
self.assertEqual( |
|
860 |
SmartServerResponse(('TokenMismatch',)), response) |
|
861 |
||
862 |
def test_lock_write_on_locked_repo(self): |
|
863 |
backing = self.get_transport() |
|
864 |
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. |
865 |
branch = self.make_branch('.', format='knit') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
866 |
branch.repository.lock_write() |
867 |
branch.repository.leave_lock_in_place() |
|
868 |
branch.repository.unlock() |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
869 |
response = request.execute('') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
870 |
self.assertEqual( |
871 |
SmartServerResponse(('LockContention',)), response) |
|
872 |
||
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. |
873 |
def test_lock_write_on_readonly_transport(self): |
874 |
backing = self.get_readonly_transport() |
|
875 |
request = smart.branch.SmartServerBranchRequestLockWrite(backing) |
|
876 |
branch = self.make_branch('.') |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
877 |
root = self.get_transport().clone('/') |
878 |
path = urlutils.relative_url(root.base, self.get_transport().base) |
|
879 |
response = request.execute(path) |
|
2872.5.3
by Martin Pool
Pass back LockFailed from smart server lock methods |
880 |
error_name, lock_str, why_str = response.args |
881 |
self.assertFalse(response.is_successful()) |
|
882 |
self.assertEqual('LockFailed', error_name) |
|
2018.5.95
by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes. |
883 |
|
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
884 |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
885 |
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithMemoryTransport): |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
886 |
|
887 |
def setUp(self): |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
888 |
tests.TestCaseWithMemoryTransport.setUp(self) |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
889 |
|
890 |
def test_unlock_on_locked_branch_and_repo(self): |
|
891 |
backing = self.get_transport() |
|
892 |
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. |
893 |
branch = self.make_branch('.', format='knit') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
894 |
# Lock the branch
|
2018.5.142
by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens). |
895 |
branch_token = branch.lock_write() |
896 |
repo_token = branch.repository.lock_write() |
|
897 |
branch.repository.unlock() |
|
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
898 |
# Unlock the branch (and repo) object, leaving the physical locks
|
899 |
# in place.
|
|
900 |
branch.leave_lock_in_place() |
|
901 |
branch.repository.leave_lock_in_place() |
|
902 |
branch.unlock() |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
903 |
response = request.execute('', |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
904 |
branch_token, repo_token) |
905 |
self.assertEqual( |
|
906 |
SmartServerResponse(('ok',)), response) |
|
907 |
# The branch is now unlocked. Verify that with a new branch
|
|
908 |
# object.
|
|
909 |
new_branch = branch.bzrdir.open_branch() |
|
910 |
new_branch.lock_write() |
|
911 |
new_branch.unlock() |
|
912 |
||
913 |
def test_unlock_on_unlocked_branch_unlocked_repo(self): |
|
914 |
backing = self.get_transport() |
|
915 |
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. |
916 |
branch = self.make_branch('.', format='knit') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
917 |
response = request.execute( |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
918 |
'', 'branch token', 'repo token') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
919 |
self.assertEqual( |
920 |
SmartServerResponse(('TokenMismatch',)), response) |
|
921 |
||
922 |
def test_unlock_on_unlocked_branch_locked_repo(self): |
|
923 |
backing = self.get_transport() |
|
924 |
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. |
925 |
branch = self.make_branch('.', format='knit') |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
926 |
# Lock the repository.
|
927 |
repo_token = branch.repository.lock_write() |
|
928 |
branch.repository.leave_lock_in_place() |
|
929 |
branch.repository.unlock() |
|
930 |
# Issue branch lock_write request on the unlocked branch (with locked
|
|
931 |
# repo).
|
|
932 |
response = request.execute( |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
933 |
'', 'branch token', repo_token) |
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
934 |
self.assertEqual( |
935 |
SmartServerResponse(('TokenMismatch',)), response) |
|
936 |
||
937 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
938 |
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). |
939 |
|
940 |
def test_no_repository(self): |
|
941 |
"""Raise NoRepositoryPresent when there is a bzrdir and no repo."""
|
|
942 |
# we test this using a shared repository above the named path,
|
|
943 |
# thus checking the right search logic is used - that is, that
|
|
944 |
# its the exact path being looked at and the server is not
|
|
945 |
# searching.
|
|
946 |
backing = self.get_transport() |
|
2018.5.58
by Wouter van Heyst
Small test fixes to reflect naming and documentation |
947 |
request = smart.repository.SmartServerRepositoryRequest(backing) |
2018.5.56
by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil). |
948 |
self.make_repository('.', shared=True) |
949 |
self.make_bzrdir('subdir') |
|
950 |
self.assertRaises(errors.NoRepositoryPresent, |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
951 |
request.execute, 'subdir') |
952 |
||
953 |
||
3441.5.4
by Andrew Bennetts
Fix test failures, and add some tests for the remote graph heads RPC. |
954 |
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. |
955 |
|
3211.5.3
by Robert Collins
Adjust size of batch and change gzip comments to bzip2. |
956 |
def test_trivial_bzipped(self): |
957 |
# 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. |
958 |
backing = self.get_transport() |
959 |
request = smart.repository.SmartServerRepositoryGetParentMap(backing) |
|
960 |
tree = self.make_branch_and_memory_tree('.') |
|
961 |
||
962 |
self.assertEqual(None, |
|
2692.1.24
by Andrew Bennetts
Merge from bzr.dev. |
963 |
request.execute('', 'missing-id')) |
4190.1.3
by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls. |
964 |
# 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. |
965 |
self.assertEqual( |
3211.5.2
by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression. |
966 |
SuccessfulSmartServerResponse(('ok', ), bz2.compress('')), |
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. |
967 |
request.do_body('\n\n0\n')) |
968 |
||
4190.1.3
by Robert Collins
Allow optional inclusion of ghost data in server get_parent_map calls. |
969 |
def test_trivial_include_missing(self): |
970 |
backing = self.get_transport() |
|
971 |
request = smart.repository.SmartServerRepositoryGetParentMap(backing) |
|
972 |
tree = self.make_branch_and_memory_tree('.') |
|
973 |
||
974 |
self.assertEqual(None, |
|
975 |
request.execute('', 'missing-id', 'include-missing:')) |
|
976 |
self.assertEqual( |
|
977 |
SuccessfulSmartServerResponse(('ok', ), |
|
978 |
bz2.compress('missing:missing-id')), |
|
979 |
request.do_body('\n\n0\n')) |
|
980 |
||
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. |
981 |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
982 |
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithMemoryTransport): |
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
983 |
|
984 |
def test_none_argument(self): |
|
985 |
backing = self.get_transport() |
|
986 |
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing) |
|
987 |
tree = self.make_branch_and_memory_tree('.') |
|
988 |
tree.lock_write() |
|
989 |
tree.add('') |
|
990 |
r1 = tree.commit('1st commit') |
|
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
991 |
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) |
992 |
tree.unlock() |
993 |
||
994 |
# the lines of revision_id->revision_parent_list has no guaranteed
|
|
995 |
# order coming out of a dict, so sort both our test and response
|
|
996 |
lines = sorted([' '.join([r2, r1]), r1]) |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
997 |
response = request.execute('', '') |
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
998 |
response.body = '\n'.join(sorted(response.body.split('\n'))) |
999 |
||
2018.5.83
by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs. |
1000 |
self.assertEqual( |
1001 |
SmartServerResponse(('ok', ), '\n'.join(lines)), response) |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
1002 |
|
1003 |
def test_specific_revision_argument(self): |
|
1004 |
backing = self.get_transport() |
|
1005 |
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing) |
|
1006 |
tree = self.make_branch_and_memory_tree('.') |
|
1007 |
tree.lock_write() |
|
1008 |
tree.add('') |
|
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
1009 |
rev_id_utf8 = u'\xc9'.encode('utf-8') |
1010 |
r1 = tree.commit('1st commit', rev_id=rev_id_utf8) |
|
1011 |
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) |
1012 |
tree.unlock() |
1013 |
||
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
1014 |
self.assertEqual(SmartServerResponse(('ok', ), rev_id_utf8), |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1015 |
request.execute('', rev_id_utf8)) |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
1016 |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
1017 |
def test_no_such_revision(self): |
1018 |
backing = self.get_transport() |
|
1019 |
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing) |
|
1020 |
tree = self.make_branch_and_memory_tree('.') |
|
1021 |
tree.lock_write() |
|
1022 |
tree.add('') |
|
1023 |
r1 = tree.commit('1st commit') |
|
1024 |
tree.unlock() |
|
1025 |
||
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
1026 |
# Note that it still returns body (of zero bytes).
|
1027 |
self.assertEqual( |
|
1028 |
SmartServerResponse(('nosuchrevision', 'missingrevision', ), ''), |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1029 |
request.execute('', 'missingrevision')) |
1030 |
||
1031 |
||
4070.9.14
by Andrew Bennetts
Tweaks requested by Robert's review. |
1032 |
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport): |
1033 |
||
1034 |
def make_two_commit_repo(self): |
|
1035 |
tree = self.make_branch_and_memory_tree('.') |
|
1036 |
tree.lock_write() |
|
1037 |
tree.add('') |
|
1038 |
r1 = tree.commit('1st commit') |
|
1039 |
r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8')) |
|
1040 |
tree.unlock() |
|
1041 |
repo = tree.branch.repository |
|
1042 |
return repo, r1, r2 |
|
1043 |
||
1044 |
def test_ancestry_of(self): |
|
1045 |
"""The search argument may be a 'ancestry-of' some heads'."""
|
|
1046 |
backing = self.get_transport() |
|
1047 |
request = smart.repository.SmartServerRepositoryGetStream(backing) |
|
1048 |
repo, r1, r2 = self.make_two_commit_repo() |
|
1049 |
fetch_spec = ['ancestry-of', r2] |
|
1050 |
lines = '\n'.join(fetch_spec) |
|
1051 |
request.execute('', repo._format.network_name()) |
|
1052 |
response = request.do_body(lines) |
|
1053 |
self.assertEqual(('ok',), response.args) |
|
1054 |
stream_bytes = ''.join(response.body_stream) |
|
1055 |
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1') |
|
1056 |
||
1057 |
def test_search(self): |
|
1058 |
"""The search argument may be a 'search' of some explicit keys."""
|
|
1059 |
backing = self.get_transport() |
|
1060 |
request = smart.repository.SmartServerRepositoryGetStream(backing) |
|
1061 |
repo, r1, r2 = self.make_two_commit_repo() |
|
1062 |
fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2'] |
|
1063 |
lines = '\n'.join(fetch_spec) |
|
1064 |
request.execute('', repo._format.network_name()) |
|
1065 |
response = request.do_body(lines) |
|
1066 |
self.assertEqual(('ok',), response.args) |
|
1067 |
stream_bytes = ''.join(response.body_stream) |
|
1068 |
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1') |
|
1069 |
||
1070 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1071 |
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). |
1072 |
|
1073 |
def test_missing_revision(self): |
|
1074 |
"""For a missing revision, ('no', ) is returned."""
|
|
1075 |
backing = self.get_transport() |
|
1076 |
request = smart.repository.SmartServerRequestHasRevision(backing) |
|
1077 |
self.make_repository('.') |
|
1078 |
self.assertEqual(SmartServerResponse(('no', )), |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1079 |
request.execute('', 'revid')) |
2018.5.56
by Robert Collins
Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil). |
1080 |
|
1081 |
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. |
1082 |
"""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). |
1083 |
backing = self.get_transport() |
1084 |
request = smart.repository.SmartServerRequestHasRevision(backing) |
|
1085 |
tree = self.make_branch_and_memory_tree('.') |
|
1086 |
tree.lock_write() |
|
1087 |
tree.add('') |
|
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
1088 |
rev_id_utf8 = u'\xc8abc'.encode('utf-8') |
1089 |
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). |
1090 |
tree.unlock() |
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
1091 |
self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8)) |
2018.5.158
by Andrew Bennetts
Return 'yes'/'no' rather than 'ok'/'no' from the Repository.has_revision smart command. |
1092 |
self.assertEqual(SmartServerResponse(('yes', )), |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1093 |
request.execute('', rev_id_utf8)) |
1094 |
||
1095 |
||
1096 |
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport): |
|
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1097 |
|
1098 |
def test_empty_revid(self): |
|
1099 |
"""With an empty revid, we get only size an number and revisions"""
|
|
1100 |
backing = self.get_transport() |
|
1101 |
request = smart.repository.SmartServerRepositoryGatherStats(backing) |
|
1102 |
repository = self.make_repository('.') |
|
1103 |
stats = repository.gather_stats() |
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
1104 |
expected_body = 'revisions: 0\n' |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1105 |
self.assertEqual(SmartServerResponse(('ok', ), expected_body), |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1106 |
request.execute('', '', 'no')) |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1107 |
|
1108 |
def test_revid_with_committers(self): |
|
1109 |
"""For a revid we get more infos."""
|
|
1110 |
backing = self.get_transport() |
|
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
1111 |
rev_id_utf8 = u'\xc8abc'.encode('utf-8') |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1112 |
request = smart.repository.SmartServerRepositoryGatherStats(backing) |
1113 |
tree = self.make_branch_and_memory_tree('.') |
|
1114 |
tree.lock_write() |
|
1115 |
tree.add('') |
|
1116 |
# Let's build a predictable result
|
|
1117 |
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. |
1118 |
tree.commit('a commit', timestamp=654321.4, timezone=0, |
1119 |
rev_id=rev_id_utf8) |
|
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1120 |
tree.unlock() |
1121 |
||
1122 |
stats = tree.branch.repository.gather_stats() |
|
1123 |
expected_body = ('firstrev: 123456.200 3600\n' |
|
1124 |
'latestrev: 654321.400 0\n' |
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
1125 |
'revisions: 2\n') |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1126 |
self.assertEqual(SmartServerResponse(('ok', ), expected_body), |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1127 |
request.execute('', |
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
1128 |
rev_id_utf8, 'no')) |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1129 |
|
1130 |
def test_not_empty_repository_with_committers(self): |
|
1131 |
"""For a revid and requesting committers we get the whole thing."""
|
|
1132 |
backing = self.get_transport() |
|
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
1133 |
rev_id_utf8 = u'\xc8abc'.encode('utf-8') |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1134 |
request = smart.repository.SmartServerRepositoryGatherStats(backing) |
1135 |
tree = self.make_branch_and_memory_tree('.') |
|
1136 |
tree.lock_write() |
|
1137 |
tree.add('') |
|
1138 |
# Let's build a predictable result
|
|
1139 |
tree.commit('a commit', timestamp=123456.2, timezone=3600, |
|
1140 |
committer='foo') |
|
1141 |
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. |
1142 |
committer='bar', rev_id=rev_id_utf8) |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1143 |
tree.unlock() |
1144 |
stats = tree.branch.repository.gather_stats() |
|
1145 |
||
1146 |
expected_body = ('committers: 2\n' |
|
1147 |
'firstrev: 123456.200 3600\n' |
|
1148 |
'latestrev: 654321.400 0\n' |
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
1149 |
'revisions: 2\n') |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1150 |
self.assertEqual(SmartServerResponse(('ok', ), expected_body), |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1151 |
request.execute('', |
2018.5.148
by Andrew Bennetts
Fix all the DeprecationWarnings in test_smart caused by unicode revision IDs. |
1152 |
rev_id_utf8, 'yes')) |
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1153 |
|
1154 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1155 |
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport): |
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
1156 |
|
1157 |
def test_is_shared(self): |
|
1158 |
"""For a shared repository, ('yes', ) is returned."""
|
|
1159 |
backing = self.get_transport() |
|
1160 |
request = smart.repository.SmartServerRepositoryIsShared(backing) |
|
1161 |
self.make_repository('.', shared=True) |
|
1162 |
self.assertEqual(SmartServerResponse(('yes', )), |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1163 |
request.execute('', )) |
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
1164 |
|
1165 |
def test_is_not_shared(self): |
|
2018.5.58
by Wouter van Heyst
Small test fixes to reflect naming and documentation |
1166 |
"""For a shared repository, ('no', ) is returned."""
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
1167 |
backing = self.get_transport() |
1168 |
request = smart.repository.SmartServerRepositoryIsShared(backing) |
|
1169 |
self.make_repository('.', shared=False) |
|
1170 |
self.assertEqual(SmartServerResponse(('no', )), |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1171 |
request.execute('', )) |
1172 |
||
1173 |
||
1174 |
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport): |
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1175 |
|
1176 |
def test_lock_write_on_unlocked_repo(self): |
|
1177 |
backing = self.get_transport() |
|
1178 |
request = smart.repository.SmartServerRepositoryLockWrite(backing) |
|
3015.2.12
by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories. |
1179 |
repository = self.make_repository('.', format='knit') |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1180 |
response = request.execute('') |
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1181 |
nonce = repository.control_files._lock.peek().get('nonce') |
1182 |
self.assertEqual(SmartServerResponse(('ok', nonce)), response) |
|
1183 |
# The repository is now locked. Verify that with a new repository
|
|
1184 |
# object.
|
|
1185 |
new_repo = repository.bzrdir.open_repository() |
|
1186 |
self.assertRaises(errors.LockContention, new_repo.lock_write) |
|
1187 |
||
1188 |
def test_lock_write_on_locked_repo(self): |
|
1189 |
backing = self.get_transport() |
|
1190 |
request = smart.repository.SmartServerRepositoryLockWrite(backing) |
|
3015.2.12
by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories. |
1191 |
repository = self.make_repository('.', format='knit') |
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1192 |
repository.lock_write() |
1193 |
repository.leave_lock_in_place() |
|
1194 |
repository.unlock() |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1195 |
response = request.execute('') |
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1196 |
self.assertEqual( |
1197 |
SmartServerResponse(('LockContention',)), response) |
|
1198 |
||
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. |
1199 |
def test_lock_write_on_readonly_transport(self): |
1200 |
backing = self.get_readonly_transport() |
|
1201 |
request = smart.repository.SmartServerRepositoryLockWrite(backing) |
|
3015.2.12
by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories. |
1202 |
repository = self.make_repository('.', format='knit') |
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. |
1203 |
response = request.execute('') |
2872.5.3
by Martin Pool
Pass back LockFailed from smart server lock methods |
1204 |
self.assertFalse(response.is_successful()) |
1205 |
self.assertEqual('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. |
1206 |
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1207 |
|
4144.3.1
by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error. |
1208 |
class TestInsertStreamBase(tests.TestCaseWithMemoryTransport): |
1209 |
||
1210 |
def make_empty_byte_stream(self, repo): |
|
1211 |
byte_stream = smart.repository._stream_to_byte_stream([], repo._format) |
|
1212 |
return ''.join(byte_stream) |
|
1213 |
||
1214 |
||
1215 |
class TestSmartServerRepositoryInsertStream(TestInsertStreamBase): |
|
1216 |
||
1217 |
def test_insert_stream_empty(self): |
|
1218 |
backing = self.get_transport() |
|
1219 |
request = smart.repository.SmartServerRepositoryInsertStream(backing) |
|
1220 |
repository = self.make_repository('.') |
|
1221 |
response = request.execute('', '') |
|
1222 |
self.assertEqual(None, response) |
|
1223 |
response = request.do_chunk(self.make_empty_byte_stream(repository)) |
|
1224 |
self.assertEqual(None, response) |
|
1225 |
response = request.do_end() |
|
1226 |
self.assertEqual(SmartServerResponse(('ok', )), response) |
|
1227 |
||
1228 |
||
1229 |
class TestSmartServerRepositoryInsertStreamLocked(TestInsertStreamBase): |
|
1230 |
||
1231 |
def test_insert_stream_empty(self): |
|
1232 |
backing = self.get_transport() |
|
1233 |
request = smart.repository.SmartServerRepositoryInsertStreamLocked( |
|
1234 |
backing) |
|
1235 |
repository = self.make_repository('.', format='knit') |
|
1236 |
lock_token = repository.lock_write() |
|
1237 |
response = request.execute('', '', lock_token) |
|
1238 |
self.assertEqual(None, response) |
|
1239 |
response = request.do_chunk(self.make_empty_byte_stream(repository)) |
|
1240 |
self.assertEqual(None, response) |
|
1241 |
response = request.do_end() |
|
1242 |
self.assertEqual(SmartServerResponse(('ok', )), response) |
|
1243 |
repository.unlock() |
|
1244 |
||
1245 |
def test_insert_stream_with_wrong_lock_token(self): |
|
1246 |
backing = self.get_transport() |
|
1247 |
request = smart.repository.SmartServerRepositoryInsertStreamLocked( |
|
1248 |
backing) |
|
1249 |
repository = self.make_repository('.', format='knit') |
|
1250 |
lock_token = repository.lock_write() |
|
1251 |
self.assertRaises( |
|
1252 |
errors.TokenMismatch, request.execute, '', '', 'wrong-token') |
|
1253 |
repository.unlock() |
|
1254 |
||
1255 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1256 |
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport): |
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1257 |
|
1258 |
def setUp(self): |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1259 |
tests.TestCaseWithMemoryTransport.setUp(self) |
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1260 |
|
1261 |
def test_unlock_on_locked_repo(self): |
|
1262 |
backing = self.get_transport() |
|
1263 |
request = smart.repository.SmartServerRepositoryUnlock(backing) |
|
3015.2.12
by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories. |
1264 |
repository = self.make_repository('.', format='knit') |
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1265 |
token = repository.lock_write() |
1266 |
repository.leave_lock_in_place() |
|
1267 |
repository.unlock() |
|
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1268 |
response = request.execute('', token) |
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1269 |
self.assertEqual( |
1270 |
SmartServerResponse(('ok',)), response) |
|
1271 |
# The repository is now unlocked. Verify that with a new repository
|
|
1272 |
# object.
|
|
1273 |
new_repo = repository.bzrdir.open_repository() |
|
1274 |
new_repo.lock_write() |
|
1275 |
new_repo.unlock() |
|
1276 |
||
1277 |
def test_unlock_on_unlocked_repo(self): |
|
1278 |
backing = self.get_transport() |
|
1279 |
request = smart.repository.SmartServerRepositoryUnlock(backing) |
|
3015.2.12
by Robert Collins
Make test_smart use specific formats as needed to exercise locked and unlocked repositories. |
1280 |
repository = self.make_repository('.', format='knit') |
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1281 |
response = request.execute('', 'some token') |
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1282 |
self.assertEqual( |
1283 |
SmartServerResponse(('TokenMismatch',)), response) |
|
1284 |
||
1285 |
||
2692.1.1
by Andrew Bennetts
Add translate_client_path method to SmartServerRequest. |
1286 |
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. |
1287 |
|
1288 |
def test_is_readonly_no(self): |
|
1289 |
backing = self.get_transport() |
|
1290 |
request = smart.request.SmartServerIsReadonly(backing) |
|
1291 |
response = request.execute() |
|
1292 |
self.assertEqual( |
|
1293 |
SmartServerResponse(('no',)), response) |
|
1294 |
||
1295 |
def test_is_readonly_yes(self): |
|
1296 |
backing = self.get_readonly_transport() |
|
1297 |
request = smart.request.SmartServerIsReadonly(backing) |
|
1298 |
response = request.execute() |
|
1299 |
self.assertEqual( |
|
1300 |
SmartServerResponse(('yes',)), response) |
|
1301 |
||
1302 |
||
4017.3.4
by Robert Collins
Create a verb for Repository.set_make_working_trees. |
1303 |
class TestSmartServerRepositorySetMakeWorkingTrees(tests.TestCaseWithMemoryTransport): |
1304 |
||
1305 |
def test_set_false(self): |
|
1306 |
backing = self.get_transport() |
|
1307 |
repo = self.make_repository('.', shared=True) |
|
1308 |
repo.set_make_working_trees(True) |
|
1309 |
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees |
|
1310 |
request = request_class(backing) |
|
1311 |
self.assertEqual(SuccessfulSmartServerResponse(('ok',)), |
|
1312 |
request.execute('', 'False')) |
|
1313 |
repo = repo.bzrdir.open_repository() |
|
1314 |
self.assertFalse(repo.make_working_trees()) |
|
1315 |
||
1316 |
def test_set_true(self): |
|
1317 |
backing = self.get_transport() |
|
1318 |
repo = self.make_repository('.', shared=True) |
|
1319 |
repo.set_make_working_trees(False) |
|
1320 |
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees |
|
1321 |
request = request_class(backing) |
|
1322 |
self.assertEqual(SuccessfulSmartServerResponse(('ok',)), |
|
1323 |
request.execute('', 'True')) |
|
1324 |
repo = repo.bzrdir.open_repository() |
|
1325 |
self.assertTrue(repo.make_working_trees()) |
|
1326 |
||
1327 |
||
3801.1.4
by Andrew Bennetts
Add tests for autopack RPC. |
1328 |
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport): |
1329 |
||
1330 |
def make_repo_needing_autopacking(self, path='.'): |
|
1331 |
# Make a repo in need of autopacking.
|
|
1332 |
tree = self.make_branch_and_tree('.', format='pack-0.92') |
|
1333 |
repo = tree.branch.repository |
|
1334 |
# monkey-patch the pack collection to disable autopacking
|
|
1335 |
repo._pack_collection._max_pack_count = lambda count: count |
|
1336 |
for x in range(10): |
|
1337 |
tree.commit('commit %s' % x) |
|
1338 |
self.assertEqual(10, len(repo._pack_collection.names())) |
|
1339 |
del repo._pack_collection._max_pack_count |
|
1340 |
return repo |
|
1341 |
||
1342 |
def test_autopack_needed(self): |
|
1343 |
repo = self.make_repo_needing_autopacking() |
|
4145.1.6
by Robert Collins
More test fallout, but all caught now. |
1344 |
repo.lock_write() |
1345 |
self.addCleanup(repo.unlock) |
|
3801.1.4
by Andrew Bennetts
Add tests for autopack RPC. |
1346 |
backing = self.get_transport() |
1347 |
request = smart.packrepository.SmartServerPackRepositoryAutopack( |
|
1348 |
backing) |
|
1349 |
response = request.execute('') |
|
1350 |
self.assertEqual(SmartServerResponse(('ok',)), response) |
|
1351 |
repo._pack_collection.reload_pack_names() |
|
1352 |
self.assertEqual(1, len(repo._pack_collection.names())) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
1353 |
|
3801.1.4
by Andrew Bennetts
Add tests for autopack RPC. |
1354 |
def test_autopack_not_needed(self): |
1355 |
tree = self.make_branch_and_tree('.', format='pack-0.92') |
|
1356 |
repo = tree.branch.repository |
|
4145.1.6
by Robert Collins
More test fallout, but all caught now. |
1357 |
repo.lock_write() |
1358 |
self.addCleanup(repo.unlock) |
|
3801.1.4
by Andrew Bennetts
Add tests for autopack RPC. |
1359 |
for x in range(9): |
1360 |
tree.commit('commit %s' % x) |
|
1361 |
backing = self.get_transport() |
|
1362 |
request = smart.packrepository.SmartServerPackRepositoryAutopack( |
|
1363 |
backing) |
|
1364 |
response = request.execute('') |
|
1365 |
self.assertEqual(SmartServerResponse(('ok',)), response) |
|
1366 |
repo._pack_collection.reload_pack_names() |
|
1367 |
self.assertEqual(9, len(repo._pack_collection.names())) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
1368 |
|
3801.1.4
by Andrew Bennetts
Add tests for autopack RPC. |
1369 |
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. |
1370 |
"""A request to autopack a non-pack repo is a no-op."""
|
3801.1.4
by Andrew Bennetts
Add tests for autopack RPC. |
1371 |
repo = self.make_repository('.', format='knit') |
1372 |
backing = self.get_transport() |
|
1373 |
request = smart.packrepository.SmartServerPackRepositoryAutopack( |
|
1374 |
backing) |
|
1375 |
response = request.execute('') |
|
3801.1.20
by Andrew Bennetts
Return ('ok',) rather than an error the autopack RPC is used on a non-pack repo. |
1376 |
self.assertEqual(SmartServerResponse(('ok',)), response) |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
1377 |
|
3801.1.4
by Andrew Bennetts
Add tests for autopack RPC. |
1378 |
|
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
1379 |
class TestHandlers(tests.TestCase): |
1380 |
"""Tests for the request.request_handlers object."""
|
|
1381 |
||
3526.3.1
by Andrew Bennetts
Remove registrations of defunct HPSS verbs. |
1382 |
def test_all_registrations_exist(self): |
1383 |
"""All registered request_handlers can be found."""
|
|
1384 |
# If there's a typo in a register_lazy call, this loop will fail with
|
|
1385 |
# an AttributeError.
|
|
1386 |
for key, item in smart.request.request_handlers.iteritems(): |
|
1387 |
pass
|
|
1388 |
||
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
1389 |
def test_registered_methods(self): |
1390 |
"""Test that known methods are registered to the correct object."""
|
|
1391 |
self.assertEqual( |
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
1392 |
smart.request.request_handlers.get('Branch.get_config_file'), |
1393 |
smart.branch.SmartServerBranchGetConfigFile) |
|
1394 |
self.assertEqual( |
|
4078.2.1
by Robert Collins
Add a Branch.get_parent remote call for RemoteBranch. |
1395 |
smart.request.request_handlers.get('Branch.get_parent'), |
1396 |
smart.branch.SmartServerBranchGetParent) |
|
1397 |
self.assertEqual( |
|
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. |
1398 |
smart.request.request_handlers.get('Branch.get_tags_bytes'), |
1399 |
smart.branch.SmartServerBranchGetTagsBytes) |
|
1400 |
self.assertEqual( |
|
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
1401 |
smart.request.request_handlers.get('Branch.lock_write'), |
1402 |
smart.branch.SmartServerBranchRequestLockWrite) |
|
1403 |
self.assertEqual( |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
1404 |
smart.request.request_handlers.get('Branch.last_revision_info'), |
1405 |
smart.branch.SmartServerBranchRequestLastRevisionInfo) |
|
1406 |
self.assertEqual( |
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
1407 |
smart.request.request_handlers.get('Branch.revision_history'), |
1408 |
smart.branch.SmartServerRequestRevisionHistory) |
|
1409 |
self.assertEqual( |
|
4226.2.1
by Robert Collins
Set branch config options via a smart method. |
1410 |
smart.request.request_handlers.get('Branch.set_config_option'), |
1411 |
smart.branch.SmartServerBranchRequestSetConfigOption) |
|
1412 |
self.assertEqual( |
|
2018.5.77
by Wouter van Heyst
Fix typo in request_handlers registration of Branch.set_last_revision, and test that registration |
1413 |
smart.request.request_handlers.get('Branch.set_last_revision'), |
1414 |
smart.branch.SmartServerBranchRequestSetLastRevision) |
|
1415 |
self.assertEqual( |
|
2892.2.1
by Andrew Bennetts
Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it. |
1416 |
smart.request.request_handlers.get('Branch.set_last_revision_info'), |
1417 |
smart.branch.SmartServerBranchRequestSetLastRevisionInfo) |
|
1418 |
self.assertEqual( |
|
2018.5.79
by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations. |
1419 |
smart.request.request_handlers.get('Branch.unlock'), |
1420 |
smart.branch.SmartServerBranchRequestUnlock) |
|
1421 |
self.assertEqual( |
|
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
1422 |
smart.request.request_handlers.get('BzrDir.find_repository'), |
3221.3.2
by Robert Collins
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for |
1423 |
smart.bzrdir.SmartServerRequestFindRepositoryV1) |
1424 |
self.assertEqual( |
|
1425 |
smart.request.request_handlers.get('BzrDir.find_repositoryV2'), |
|
1426 |
smart.bzrdir.SmartServerRequestFindRepositoryV2) |
|
2018.5.34
by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository. |
1427 |
self.assertEqual( |
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
1428 |
smart.request.request_handlers.get('BzrDirFormat.initialize'), |
1429 |
smart.bzrdir.SmartServerRequestInitializeBzrDir) |
|
1430 |
self.assertEqual( |
|
4070.2.3
by Robert Collins
Get BzrDir.cloning_metadir working. |
1431 |
smart.request.request_handlers.get('BzrDir.cloning_metadir'), |
1432 |
smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir) |
|
1433 |
self.assertEqual( |
|
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
1434 |
smart.request.request_handlers.get('BzrDir.open_branch'), |
1435 |
smart.bzrdir.SmartServerRequestOpenBranch) |
|
2018.5.40
by Robert Collins
Implement a remote Repository.has_revision method. |
1436 |
self.assertEqual( |
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. |
1437 |
smart.request.request_handlers.get('BzrDir.open_branchV2'), |
1438 |
smart.bzrdir.SmartServerRequestOpenBranchV2) |
|
1439 |
self.assertEqual( |
|
3801.1.4
by Andrew Bennetts
Add tests for autopack RPC. |
1440 |
smart.request.request_handlers.get('PackRepository.autopack'), |
1441 |
smart.packrepository.SmartServerPackRepositoryAutopack) |
|
1442 |
self.assertEqual( |
|
2018.10.2
by v.ladeuil+lp at free
gather_stats server side and request registration |
1443 |
smart.request.request_handlers.get('Repository.gather_stats'), |
1444 |
smart.repository.SmartServerRepositoryGatherStats) |
|
1445 |
self.assertEqual( |
|
3172.5.6
by Robert Collins
Create new smart server verb Repository.get_parent_map. |
1446 |
smart.request.request_handlers.get('Repository.get_parent_map'), |
1447 |
smart.repository.SmartServerRepositoryGetParentMap) |
|
1448 |
self.assertEqual( |
|
2535.3.69
by Andrew Bennetts
Add check for Repository.stream_knit_data_for_revisions to TestHandlers.test_registered_methods. |
1449 |
smart.request.request_handlers.get( |
1450 |
'Repository.get_revision_graph'), |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
1451 |
smart.repository.SmartServerRepositoryGetRevisionGraph) |
1452 |
self.assertEqual( |
|
4144.3.1
by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error. |
1453 |
smart.request.request_handlers.get('Repository.get_stream'), |
1454 |
smart.repository.SmartServerRepositoryGetStream) |
|
1455 |
self.assertEqual( |
|
2018.5.40
by Robert Collins
Implement a remote Repository.has_revision method. |
1456 |
smart.request.request_handlers.get('Repository.has_revision'), |
1457 |
smart.repository.SmartServerRequestHasRevision) |
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
1458 |
self.assertEqual( |
4144.3.1
by Andrew Bennetts
Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error. |
1459 |
smart.request.request_handlers.get('Repository.insert_stream'), |
1460 |
smart.repository.SmartServerRepositoryInsertStream) |
|
1461 |
self.assertEqual( |
|
1462 |
smart.request.request_handlers.get('Repository.insert_stream_locked'), |
|
1463 |
smart.repository.SmartServerRepositoryInsertStreamLocked) |
|
1464 |
self.assertEqual( |
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
1465 |
smart.request.request_handlers.get('Repository.is_shared'), |
1466 |
smart.repository.SmartServerRepositoryIsShared) |
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1467 |
self.assertEqual( |
1468 |
smart.request.request_handlers.get('Repository.lock_write'), |
|
1469 |
smart.repository.SmartServerRepositoryLockWrite) |
|
1470 |
self.assertEqual( |
|
2535.3.69
by Andrew Bennetts
Add check for Repository.stream_knit_data_for_revisions to TestHandlers.test_registered_methods. |
1471 |
smart.request.request_handlers.get('Repository.tarball'), |
1472 |
smart.repository.SmartServerRepositoryTarball) |
|
1473 |
self.assertEqual( |
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
1474 |
smart.request.request_handlers.get('Repository.unlock'), |
1475 |
smart.repository.SmartServerRepositoryUnlock) |
|
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. |
1476 |
self.assertEqual( |
1477 |
smart.request.request_handlers.get('Transport.is_readonly'), |
|
1478 |
smart.request.SmartServerIsReadonly) |