bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
1 |
# Copyright (C) 2006, 2007 Canonical Ltd
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Tests for remote bzrdir/branch/repo/etc
|
|
18 |
||
19 |
These are proxy objects which act on remote objects by sending messages
|
|
20 |
through a smart client. The proxies are to be created when attempting to open
|
|
21 |
the object given a transport that supports smartserver rpc operations.
|
|
|
2018.18.7
by Martin Pool
(broken) Start addng client proxy test for Repository.tarball |
22 |
|
23 |
These tests correspond to tests.test_smart, which exercises the server side.
|
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
24 |
"""
|
25 |
||
|
3211.5.2
by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression. |
26 |
import bz2 |
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
27 |
from cStringIO import StringIO |
28 |
||
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
29 |
from bzrlib import ( |
30 |
errors, |
|
|
3184.1.9
by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of |
31 |
graph, |
|
2535.3.39
by Andrew Bennetts
Tidy some XXXs. |
32 |
pack, |
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
33 |
remote, |
|
2018.18.9
by Martin Pool
remote Repository.tarball builds a temporary directory and tars that |
34 |
repository, |
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
35 |
tests, |
36 |
)
|
|
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
37 |
from bzrlib.branch import Branch |
38 |
from bzrlib.bzrdir import BzrDir, BzrDirFormat |
|
39 |
from bzrlib.remote import ( |
|
40 |
RemoteBranch, |
|
41 |
RemoteBzrDir, |
|
42 |
RemoteBzrDirFormat, |
|
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
43 |
RemoteRepository, |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
44 |
)
|
45 |
from bzrlib.revision import NULL_REVISION |
|
|
2432.3.2
by Andrew Bennetts
Add test, and tidy implementation. |
46 |
from bzrlib.smart import server, medium |
|
2018.5.159
by Andrew Bennetts
Rename SmartClient to _SmartClient. |
47 |
from bzrlib.smart.client import _SmartClient |
|
3287.6.4
by Robert Collins
Fix up deprecation warnings for get_revision_graph. |
48 |
from bzrlib.symbol_versioning import one_four |
|
3313.3.3
by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport. |
49 |
from bzrlib.transport import get_transport |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
50 |
from bzrlib.transport.memory import MemoryTransport |
|
2466.2.2
by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests. |
51 |
from bzrlib.transport.remote import RemoteTransport |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
52 |
|
|
2018.5.24
by Andrew Bennetts
Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts) |
53 |
|
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
54 |
class BasicRemoteObjectTests(tests.TestCaseWithTransport): |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
55 |
|
56 |
def setUp(self): |
|
|
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. |
57 |
self.transport_server = server.SmartTCPServer_for_testing |
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
58 |
super(BasicRemoteObjectTests, self).setUp() |
59 |
self.transport = self.get_transport() |
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
60 |
# make a branch that can be opened over the smart transport
|
|
1752.2.31
by Martin Pool
[broken] some support for write operations over hpss |
61 |
self.local_wt = BzrDir.create_standalone_workingtree('.') |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
62 |
|
|
2018.5.171
by Andrew Bennetts
Disconnect RemoteTransports in some tests to avoid tripping up test_strace with leftover threads from previous tests. |
63 |
def tearDown(self): |
64 |
self.transport.disconnect() |
|
65 |
tests.TestCaseWithTransport.tearDown(self) |
|
66 |
||
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
67 |
def test_create_remote_bzrdir(self): |
68 |
b = remote.RemoteBzrDir(self.transport) |
|
69 |
self.assertIsInstance(b, BzrDir) |
|
70 |
||
71 |
def test_open_remote_branch(self): |
|
|
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
72 |
# open a standalone branch in the working directory
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
73 |
b = remote.RemoteBzrDir(self.transport) |
74 |
branch = b.open_branch() |
|
|
2018.5.163
by Andrew Bennetts
Deal with various review comments from Robert. |
75 |
self.assertIsInstance(branch, Branch) |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
76 |
|
|
1752.2.31
by Martin Pool
[broken] some support for write operations over hpss |
77 |
def test_remote_repository(self): |
78 |
b = BzrDir.open_from_transport(self.transport) |
|
79 |
repo = b.open_repository() |
|
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
80 |
revid = u'\xc823123123'.encode('utf8') |
|
2018.5.40
by Robert Collins
Implement a remote Repository.has_revision method. |
81 |
self.assertFalse(repo.has_revision(revid)) |
82 |
self.local_wt.commit(message='test commit', rev_id=revid) |
|
83 |
self.assertTrue(repo.has_revision(revid)) |
|
|
1752.2.31
by Martin Pool
[broken] some support for write operations over hpss |
84 |
|
85 |
def test_remote_branch_revision_history(self): |
|
86 |
b = BzrDir.open_from_transport(self.transport).open_branch() |
|
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
87 |
self.assertEqual([], b.revision_history()) |
88 |
r1 = self.local_wt.commit('1st commit') |
|
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
89 |
r2 = self.local_wt.commit('1st commit', rev_id=u'\xc8'.encode('utf8')) |
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
90 |
self.assertEqual([r1, r2], b.revision_history()) |
|
1752.2.31
by Martin Pool
[broken] some support for write operations over hpss |
91 |
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
92 |
def test_find_correct_format(self): |
|
2018.5.20
by Andrew Bennetts
Move bzrlib/transport/smart/_smart.py to bzrlib/transport/remote.py and rename SmartTransport to RemoteTransport (Robert Collins, Andrew Bennetts) |
93 |
"""Should open a RemoteBzrDir over a RemoteTransport""" |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
94 |
fmt = BzrDirFormat.find_format(self.transport) |
|
2018.5.169
by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property. |
95 |
self.assertTrue(RemoteBzrDirFormat |
96 |
in BzrDirFormat._control_server_formats) |
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
97 |
self.assertIsInstance(fmt, remote.RemoteBzrDirFormat) |
98 |
||
99 |
def test_open_detected_smart_format(self): |
|
100 |
fmt = BzrDirFormat.find_format(self.transport) |
|
101 |
d = fmt.open(self.transport) |
|
102 |
self.assertIsInstance(d, BzrDir) |
|
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
103 |
|
|
2477.1.1
by Martin Pool
Add RemoteBranch repr |
104 |
def test_remote_branch_repr(self): |
105 |
b = BzrDir.open_from_transport(self.transport).open_branch() |
|
106 |
self.assertStartsWith(str(b), 'RemoteBranch(') |
|
107 |
||
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
108 |
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
109 |
class FakeProtocol(object): |
110 |
"""Lookalike SmartClientRequestProtocolOne allowing body reading tests.""" |
|
111 |
||
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
112 |
def __init__(self, body, fake_client): |
|
2535.4.2
by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming. |
113 |
self.body = body |
114 |
self._body_buffer = None |
|
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
115 |
self._fake_client = fake_client |
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
116 |
|
117 |
def read_body_bytes(self, count=-1): |
|
|
2535.4.2
by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming. |
118 |
if self._body_buffer is None: |
119 |
self._body_buffer = StringIO(self.body) |
|
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
120 |
bytes = self._body_buffer.read(count) |
121 |
if self._body_buffer.tell() == len(self._body_buffer.getvalue()): |
|
122 |
self._fake_client.expecting_body = False |
|
123 |
return bytes |
|
124 |
||
125 |
def cancel_read_body(self): |
|
126 |
self._fake_client.expecting_body = False |
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
127 |
|
|
2535.4.2
by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming. |
128 |
def read_streamed_body(self): |
129 |
return self.body |
|
130 |
||
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
131 |
|
|
2018.5.159
by Andrew Bennetts
Rename SmartClient to _SmartClient. |
132 |
class FakeClient(_SmartClient): |
133 |
"""Lookalike for _SmartClient allowing testing.""" |
|
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
134 |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
135 |
def __init__(self, responses, fake_medium_base='fake base'): |
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
136 |
"""Create a FakeClient. |
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
137 |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
138 |
:param responses: A list of response-tuple, body-data pairs to be sent
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
139 |
back to callers.
|
140 |
"""
|
|
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
141 |
self.responses = responses |
142 |
self._calls = [] |
|
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
143 |
self.expecting_body = False |
|
3313.2.1
by Andrew Bennetts
Change _SmartClient's API to accept a medium and a base, rather than a _SharedConnection. |
144 |
_SmartClient.__init__(self, FakeMedium(self._calls), fake_medium_base) |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
145 |
|
146 |
def call(self, method, *args): |
|
147 |
self._calls.append(('call', method, args)) |
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
148 |
return self.responses.pop(0)[0] |
149 |
||
|
2018.5.153
by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review. |
150 |
def call_expecting_body(self, method, *args): |
151 |
self._calls.append(('call_expecting_body', method, args)) |
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
152 |
result = self.responses.pop(0) |
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
153 |
self.expecting_body = True |
154 |
return result[0], FakeProtocol(result[1], self) |
|
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
155 |
|
|
3184.1.10
by Robert Collins
Change the smart server verb for Repository.stream_revisions_chunked to use SearchResults as the request mechanism for downloads. |
156 |
def call_with_body_bytes_expecting_body(self, method, args, body): |
157 |
self._calls.append(('call_with_body_bytes_expecting_body', method, |
|
158 |
args, body)) |
|
159 |
result = self.responses.pop(0) |
|
160 |
self.expecting_body = True |
|
161 |
return result[0], FakeProtocol(result[1], self) |
|
162 |
||
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
163 |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
164 |
class FakeMedium(object): |
165 |
||
|
3213.1.2
by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server. |
166 |
def __init__(self, client_calls): |
|
3213.1.1
by Andrew Bennetts
Recover (by reconnecting) if the server turns out not to understand the new requests in 1.2 that send bodies. |
167 |
self._remote_is_at_least_1_2 = True |
|
3213.1.2
by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server. |
168 |
self._client_calls = client_calls |
|
3213.1.1
by Andrew Bennetts
Recover (by reconnecting) if the server turns out not to understand the new requests in 1.2 that send bodies. |
169 |
|
170 |
def disconnect(self): |
|
|
3213.1.2
by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server. |
171 |
self._client_calls.append(('disconnect medium',)) |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
172 |
|
173 |
||
|
3192.2.1
by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier. |
174 |
class TestVfsHas(tests.TestCase): |
175 |
||
176 |
def test_unicode_path(self): |
|
177 |
client = FakeClient([(('yes',), )], '/') |
|
178 |
transport = RemoteTransport('bzr://localhost/', _client=client) |
|
179 |
filename = u'/hell\u00d8'.encode('utf8') |
|
180 |
result = transport.has(filename) |
|
181 |
self.assertEqual( |
|
182 |
[('call', 'has', (filename,))], |
|
183 |
client._calls) |
|
184 |
self.assertTrue(result) |
|
185 |
||
186 |
||
|
3313.3.3
by Andrew Bennetts
Add tests for _SmartClient.remote_path_for_transport. |
187 |
class Test_SmartClient_remote_path_from_transport(tests.TestCase): |
188 |
"""Tests for the behaviour of _SmartClient.remote_path_from_transport.""" |
|
189 |
||
190 |
def assertRemotePath(self, expected, client_base, transport_base): |
|
191 |
"""Assert that the result of _SmartClient.remote_path_from_transport |
|
192 |
is the expected value for a given client_base and transport_base.
|
|
193 |
"""
|
|
194 |
dummy_medium = 'dummy medium' |
|
195 |
client = _SmartClient(dummy_medium, client_base) |
|
196 |
transport = get_transport(transport_base) |
|
197 |
result = client.remote_path_from_transport(transport) |
|
198 |
self.assertEqual(expected, result) |
|
199 |
||
200 |
def test_remote_path_from_transport(self): |
|
201 |
"""_SmartClient.remote_path_from_transport calculates a URL for the |
|
202 |
given transport relative to the root of the client base URL.
|
|
203 |
"""
|
|
204 |
self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz') |
|
205 |
self.assertRemotePath( |
|
206 |
'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz') |
|
207 |
||
208 |
def test_remote_path_from_transport_http(self): |
|
209 |
"""Remote paths for HTTP transports are calculated differently to other |
|
210 |
transports. They are just relative to the client base, not the root
|
|
211 |
directory of the host.
|
|
212 |
"""
|
|
213 |
for scheme in ['http:', 'https:', 'bzr+http:', 'bzr+https:']: |
|
214 |
self.assertRemotePath( |
|
215 |
'../xyz/', scheme + '//host/path', scheme + '//host/xyz') |
|
216 |
self.assertRemotePath( |
|
217 |
'xyz/', scheme + '//host/path', scheme + '//host/path/xyz') |
|
218 |
||
219 |
||
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
220 |
class TestBzrDirOpenBranch(tests.TestCase): |
221 |
||
222 |
def test_branch_present(self): |
|
223 |
transport = MemoryTransport() |
|
224 |
transport.mkdir('quack') |
|
225 |
transport = transport.clone('quack') |
|
|
3221.3.3
by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so |
226 |
client = FakeClient([(('ok', ''), ), (('ok', '', 'no', 'no', 'no'), )], |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
227 |
transport.base) |
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
228 |
bzrdir = RemoteBzrDir(transport, _client=client) |
229 |
result = bzrdir.open_branch() |
|
230 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
231 |
[('call', 'BzrDir.open_branch', ('quack/',)), |
|
3221.3.3
by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so |
232 |
('call', 'BzrDir.find_repositoryV2', ('quack/',))], |
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
233 |
client._calls) |
234 |
self.assertIsInstance(result, RemoteBranch) |
|
235 |
self.assertEqual(bzrdir, result.bzrdir) |
|
236 |
||
237 |
def test_branch_missing(self): |
|
238 |
transport = MemoryTransport() |
|
239 |
transport.mkdir('quack') |
|
240 |
transport = transport.clone('quack') |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
241 |
client = FakeClient([(('nobranch',), )], transport.base) |
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
242 |
bzrdir = RemoteBzrDir(transport, _client=client) |
243 |
self.assertRaises(errors.NotBranchError, bzrdir.open_branch) |
|
244 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
245 |
[('call', 'BzrDir.open_branch', ('quack/',))], |
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
246 |
client._calls) |
247 |
||
|
3211.4.1
by Robert Collins
* ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``, |
248 |
def test__get_tree_branch(self): |
249 |
# _get_tree_branch is a form of open_branch, but it should only ask for
|
|
250 |
# branch opening, not any other network requests.
|
|
251 |
calls = [] |
|
252 |
def open_branch(): |
|
253 |
calls.append("Called") |
|
254 |
return "a-branch" |
|
255 |
transport = MemoryTransport() |
|
256 |
# no requests on the network - catches other api calls being made.
|
|
257 |
client = FakeClient([], transport.base) |
|
258 |
bzrdir = RemoteBzrDir(transport, _client=client) |
|
259 |
# patch the open_branch call to record that it was called.
|
|
260 |
bzrdir.open_branch = open_branch |
|
261 |
self.assertEqual((None, "a-branch"), bzrdir._get_tree_branch()) |
|
262 |
self.assertEqual(["Called"], calls) |
|
263 |
self.assertEqual([], client._calls) |
|
264 |
||
|
3192.2.1
by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier. |
265 |
def test_url_quoting_of_path(self): |
266 |
# Relpaths on the wire should not be URL-escaped. So "~" should be
|
|
267 |
# transmitted as "~", not "%7E".
|
|
268 |
transport = RemoteTransport('bzr://localhost/~hello/') |
|
|
3221.3.3
by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so |
269 |
client = FakeClient([(('ok', ''), ), (('ok', '', 'no', 'no', 'no'), )], |
|
3192.2.1
by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier. |
270 |
transport.base) |
271 |
bzrdir = RemoteBzrDir(transport, _client=client) |
|
272 |
result = bzrdir.open_branch() |
|
273 |
self.assertEqual( |
|
274 |
[('call', 'BzrDir.open_branch', ('~hello/',)), |
|
|
3221.3.3
by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so |
275 |
('call', 'BzrDir.find_repositoryV2', ('~hello/',))], |
|
3192.2.1
by Andrew Bennetts
Don't transmit URL-escaped relpaths in the smart protocol, which is back to how things worked in bzr 1.1 and earlier. |
276 |
client._calls) |
277 |
||
|
3221.3.3
by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so |
278 |
def check_open_repository(self, rich_root, subtrees, external_lookup='no'): |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
279 |
transport = MemoryTransport() |
280 |
transport.mkdir('quack') |
|
281 |
transport = transport.clone('quack') |
|
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
282 |
if rich_root: |
|
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
283 |
rich_response = 'yes' |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
284 |
else: |
|
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
285 |
rich_response = 'no' |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
286 |
if subtrees: |
|
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
287 |
subtree_response = 'yes' |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
288 |
else: |
|
2018.5.166
by Andrew Bennetts
Small changes in response to Aaron's review. |
289 |
subtree_response = 'no' |
|
3221.3.3
by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so |
290 |
client = FakeClient( |
291 |
[(('ok', '', rich_response, subtree_response, external_lookup), ),], |
|
292 |
transport.base) |
|
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
293 |
bzrdir = RemoteBzrDir(transport, _client=client) |
294 |
result = bzrdir.open_repository() |
|
295 |
self.assertEqual( |
|
|
3221.3.3
by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so |
296 |
[('call', 'BzrDir.find_repositoryV2', ('quack/',))], |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
297 |
client._calls) |
298 |
self.assertIsInstance(result, RemoteRepository) |
|
299 |
self.assertEqual(bzrdir, result.bzrdir) |
|
300 |
self.assertEqual(rich_root, result._format.rich_root_data) |
|
|
2018.5.138
by Robert Collins
Merge bzr.dev. |
301 |
self.assertEqual(subtrees, result._format.supports_tree_reference) |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
302 |
|
303 |
def test_open_repository_sets_format_attributes(self): |
|
304 |
self.check_open_repository(True, True) |
|
305 |
self.check_open_repository(False, True) |
|
306 |
self.check_open_repository(True, False) |
|
307 |
self.check_open_repository(False, False) |
|
|
3221.3.3
by Robert Collins
* Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so |
308 |
self.check_open_repository(False, False, 'yes') |
|
2018.5.118
by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference. |
309 |
|
|
2432.3.2
by Andrew Bennetts
Add test, and tidy implementation. |
310 |
def test_old_server(self): |
311 |
"""RemoteBzrDirFormat should fail to probe if the server version is too |
|
312 |
old.
|
|
313 |
"""
|
|
314 |
self.assertRaises(errors.NotBranchError, |
|
315 |
RemoteBzrDirFormat.probe_transport, OldServerTransport()) |
|
316 |
||
317 |
||
318 |
class OldSmartClient(object): |
|
319 |
"""A fake smart client for test_old_version that just returns a version one |
|
320 |
response to the 'hello' (query version) command.
|
|
321 |
"""
|
|
322 |
||
323 |
def get_request(self): |
|
324 |
input_file = StringIO('ok\x011\n') |
|
325 |
output_file = StringIO() |
|
326 |
client_medium = medium.SmartSimplePipesClientMedium( |
|
327 |
input_file, output_file) |
|
328 |
return medium.SmartClientStreamMediumRequest(client_medium) |
|
329 |
||
|
3241.1.1
by Andrew Bennetts
Shift protocol version querying from RemoteBzrDirFormat into SmartClientMedium. |
330 |
def protocol_version(self): |
331 |
return 1 |
|
332 |
||
|
2432.3.2
by Andrew Bennetts
Add test, and tidy implementation. |
333 |
|
334 |
class OldServerTransport(object): |
|
335 |
"""A fake transport for test_old_server that reports it's smart server |
|
336 |
protocol version as version one.
|
|
337 |
"""
|
|
338 |
||
339 |
def __init__(self): |
|
340 |
self.base = 'fake:' |
|
341 |
||
342 |
def get_smart_client(self): |
|
343 |
return OldSmartClient() |
|
344 |
||
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
345 |
|
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
346 |
class TestBranchLastRevisionInfo(tests.TestCase): |
347 |
||
348 |
def test_empty_branch(self): |
|
349 |
# in an empty branch we decode the response properly
|
|
350 |
transport = MemoryTransport() |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
351 |
client = FakeClient([(('ok', '0', 'null:'), )], transport.base) |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
352 |
transport.mkdir('quack') |
353 |
transport = transport.clone('quack') |
|
354 |
# we do not want bzrdir to make any remote calls
|
|
355 |
bzrdir = RemoteBzrDir(transport, _client=False) |
|
356 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
357 |
result = branch.last_revision_info() |
|
358 |
||
359 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
360 |
[('call', 'Branch.last_revision_info', ('quack/',))], |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
361 |
client._calls) |
362 |
self.assertEqual((0, NULL_REVISION), result) |
|
363 |
||
364 |
def test_non_empty_branch(self): |
|
365 |
# in a non-empty branch we also decode the response properly
|
|
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
366 |
revid = u'\xc8'.encode('utf8') |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
367 |
transport = MemoryTransport() |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
368 |
client = FakeClient([(('ok', '2', revid), )], transport.base) |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
369 |
transport.mkdir('kwaak') |
370 |
transport = transport.clone('kwaak') |
|
371 |
# we do not want bzrdir to make any remote calls
|
|
372 |
bzrdir = RemoteBzrDir(transport, _client=False) |
|
373 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
374 |
result = branch.last_revision_info() |
|
375 |
||
376 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
377 |
[('call', 'Branch.last_revision_info', ('kwaak/',))], |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
378 |
client._calls) |
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
379 |
self.assertEqual((2, revid), result) |
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
380 |
|
381 |
||
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
382 |
class TestBranchSetLastRevision(tests.TestCase): |
383 |
||
384 |
def test_set_empty(self): |
|
385 |
# set_revision_history([]) is translated to calling
|
|
386 |
# Branch.set_last_revision(path, '') on the wire.
|
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
387 |
transport = MemoryTransport() |
388 |
transport.mkdir('branch') |
|
389 |
transport = transport.clone('branch') |
|
390 |
||
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
391 |
client = FakeClient([ |
392 |
# lock_write
|
|
393 |
(('ok', 'branch token', 'repo token'), ), |
|
394 |
# set_last_revision
|
|
395 |
(('ok',), ), |
|
396 |
# unlock
|
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
397 |
(('ok',), )], |
398 |
transport.base) |
|
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
399 |
bzrdir = RemoteBzrDir(transport, _client=False) |
400 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
401 |
# This is a hack to work around the problem that RemoteBranch currently
|
402 |
# unnecessarily invokes _ensure_real upon a call to lock_write.
|
|
403 |
branch._ensure_real = lambda: None |
|
404 |
branch.lock_write() |
|
405 |
client._calls = [] |
|
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
406 |
result = branch.set_revision_history([]) |
407 |
self.assertEqual( |
|
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
408 |
[('call', 'Branch.set_last_revision', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
409 |
('branch/', 'branch token', 'repo token', 'null:'))], |
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
410 |
client._calls) |
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
411 |
branch.unlock() |
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
412 |
self.assertEqual(None, result) |
413 |
||
414 |
def test_set_nonempty(self): |
|
415 |
# set_revision_history([rev-id1, ..., rev-idN]) is translated to calling
|
|
416 |
# Branch.set_last_revision(path, rev-idN) on the wire.
|
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
417 |
transport = MemoryTransport() |
418 |
transport.mkdir('branch') |
|
419 |
transport = transport.clone('branch') |
|
420 |
||
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
421 |
client = FakeClient([ |
422 |
# lock_write
|
|
423 |
(('ok', 'branch token', 'repo token'), ), |
|
424 |
# set_last_revision
|
|
425 |
(('ok',), ), |
|
426 |
# unlock
|
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
427 |
(('ok',), )], |
428 |
transport.base) |
|
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
429 |
bzrdir = RemoteBzrDir(transport, _client=False) |
430 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
431 |
# This is a hack to work around the problem that RemoteBranch currently
|
432 |
# unnecessarily invokes _ensure_real upon a call to lock_write.
|
|
433 |
branch._ensure_real = lambda: None |
|
434 |
# Lock the branch, reset the record of remote calls.
|
|
435 |
branch.lock_write() |
|
436 |
client._calls = [] |
|
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
437 |
|
438 |
result = branch.set_revision_history(['rev-id1', 'rev-id2']) |
|
439 |
self.assertEqual( |
|
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
440 |
[('call', 'Branch.set_last_revision', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
441 |
('branch/', 'branch token', 'repo token', 'rev-id2'))], |
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
442 |
client._calls) |
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
443 |
branch.unlock() |
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
444 |
self.assertEqual(None, result) |
445 |
||
446 |
def test_no_such_revision(self): |
|
447 |
# A response of 'NoSuchRevision' is translated into an exception.
|
|
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
448 |
client = FakeClient([ |
449 |
# lock_write
|
|
450 |
(('ok', 'branch token', 'repo token'), ), |
|
451 |
# set_last_revision
|
|
452 |
(('NoSuchRevision', 'rev-id'), ), |
|
453 |
# unlock
|
|
454 |
(('ok',), )]) |
|
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
455 |
transport = MemoryTransport() |
456 |
transport.mkdir('branch') |
|
457 |
transport = transport.clone('branch') |
|
458 |
||
459 |
bzrdir = RemoteBzrDir(transport, _client=False) |
|
460 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
461 |
branch._ensure_real = lambda: None |
462 |
branch.lock_write() |
|
463 |
client._calls = [] |
|
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
464 |
|
465 |
self.assertRaises( |
|
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
466 |
errors.NoSuchRevision, branch.set_revision_history, ['rev-id']) |
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
467 |
branch.unlock() |
|
2018.12.3
by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it. |
468 |
|
469 |
||
|
2018.5.169
by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property. |
470 |
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport): |
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
471 |
"""Test branch.control_files api munging... |
472 |
||
|
2018.5.169
by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property. |
473 |
We special case RemoteBranch.control_files.get('branch.conf') to
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
474 |
call a specific API so that RemoteBranch's can intercept configuration
|
475 |
file reading, allowing them to signal to the client about things like
|
|
476 |
'email is configured for commits'.
|
|
477 |
"""
|
|
478 |
||
479 |
def test_get_branch_conf(self): |
|
480 |
# in an empty branch we decode the response properly
|
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
481 |
client = FakeClient([(('ok', ), 'config file body')], self.get_url()) |
|
2018.5.169
by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property. |
482 |
# we need to make a real branch because the remote_branch.control_files
|
483 |
# will trigger _ensure_real.
|
|
484 |
branch = self.make_branch('quack') |
|
485 |
transport = branch.bzrdir.root_transport |
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
486 |
# we do not want bzrdir to make any remote calls
|
487 |
bzrdir = RemoteBzrDir(transport, _client=False) |
|
488 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
489 |
result = branch.control_files.get('branch.conf') |
|
490 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
491 |
[('call_expecting_body', 'Branch.get_config_file', ('quack/',))], |
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
492 |
client._calls) |
493 |
self.assertEqual('config file body', result.read()) |
|
494 |
||
495 |
||
|
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. |
496 |
class TestBranchLockWrite(tests.TestCase): |
497 |
||
498 |
def test_lock_write_unlockable(self): |
|
499 |
transport = MemoryTransport() |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
500 |
client = FakeClient([(('UnlockableTransport', ), '')], transport.base) |
|
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. |
501 |
transport.mkdir('quack') |
502 |
transport = transport.clone('quack') |
|
503 |
# we do not want bzrdir to make any remote calls
|
|
504 |
bzrdir = RemoteBzrDir(transport, _client=False) |
|
505 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
506 |
self.assertRaises(errors.UnlockableTransport, branch.lock_write) |
|
507 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
508 |
[('call', 'Branch.lock_write', ('quack/', '', ''))], |
|
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. |
509 |
client._calls) |
510 |
||
511 |
||
|
2466.2.2
by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests. |
512 |
class TestTransportIsReadonly(tests.TestCase): |
513 |
||
514 |
def test_true(self): |
|
515 |
client = FakeClient([(('yes',), '')]) |
|
516 |
transport = RemoteTransport('bzr://example.com/', medium=False, |
|
517 |
_client=client) |
|
518 |
self.assertEqual(True, transport.is_readonly()) |
|
519 |
self.assertEqual( |
|
520 |
[('call', 'Transport.is_readonly', ())], |
|
521 |
client._calls) |
|
522 |
||
523 |
def test_false(self): |
|
524 |
client = FakeClient([(('no',), '')]) |
|
525 |
transport = RemoteTransport('bzr://example.com/', medium=False, |
|
526 |
_client=client) |
|
527 |
self.assertEqual(False, transport.is_readonly()) |
|
528 |
self.assertEqual( |
|
529 |
[('call', 'Transport.is_readonly', ())], |
|
530 |
client._calls) |
|
531 |
||
532 |
def test_error_from_old_server(self): |
|
533 |
"""bzr 0.15 and earlier servers don't recognise the is_readonly verb. |
|
534 |
|
|
535 |
Clients should treat it as a "no" response, because is_readonly is only
|
|
536 |
advisory anyway (a transport could be read-write, but then the
|
|
537 |
underlying filesystem could be readonly anyway).
|
|
538 |
"""
|
|
539 |
client = FakeClient([( |
|
540 |
('error', "Generic bzr smart protocol error: " |
|
541 |
"bad request 'Transport.is_readonly'"), '')]) |
|
542 |
transport = RemoteTransport('bzr://example.com/', medium=False, |
|
543 |
_client=client) |
|
544 |
self.assertEqual(False, transport.is_readonly()) |
|
545 |
self.assertEqual( |
|
546 |
[('call', 'Transport.is_readonly', ())], |
|
547 |
client._calls) |
|
548 |
||
|
2471.2.1
by Andrew Bennetts
Fix trivial incompatibility with bzr 0.11 servers, which give a slightly different error to bzr 0.15 servers. |
549 |
def test_error_from_old_0_11_server(self): |
550 |
"""Same as test_error_from_old_server, but with the slightly different |
|
551 |
error message from bzr 0.11 servers.
|
|
552 |
"""
|
|
553 |
client = FakeClient([( |
|
554 |
('error', "Generic bzr smart protocol error: " |
|
555 |
"bad request u'Transport.is_readonly'"), '')]) |
|
556 |
transport = RemoteTransport('bzr://example.com/', medium=False, |
|
557 |
_client=client) |
|
558 |
self.assertEqual(False, transport.is_readonly()) |
|
559 |
self.assertEqual( |
|
560 |
[('call', 'Transport.is_readonly', ())], |
|
561 |
client._calls) |
|
562 |
||
|
2466.2.2
by Andrew Bennetts
Add tests for RemoteTransport.is_readonly in the style of the other remote object tests. |
563 |
|
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
564 |
class TestRemoteRepository(tests.TestCase): |
|
2018.18.9
by Martin Pool
remote Repository.tarball builds a temporary directory and tars that |
565 |
"""Base for testing RemoteRepository protocol usage. |
566 |
|
|
567 |
These tests contain frozen requests and responses. We want any changes to
|
|
568 |
what is sent or expected to be require a thoughtful update to these tests
|
|
569 |
because they might break compatibility with different-versioned servers.
|
|
570 |
"""
|
|
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
571 |
|
572 |
def setup_fake_client_and_repository(self, responses, transport_path): |
|
|
2018.18.7
by Martin Pool
(broken) Start addng client proxy test for Repository.tarball |
573 |
"""Create the fake client and repository for testing with. |
574 |
|
|
575 |
There's no real server here; we just have canned responses sent
|
|
576 |
back one by one.
|
|
577 |
|
|
578 |
:param transport_path: Path below the root of the MemoryTransport
|
|
579 |
where the repository will be created.
|
|
580 |
"""
|
|
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
581 |
transport = MemoryTransport() |
582 |
transport.mkdir(transport_path) |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
583 |
client = FakeClient(responses, transport.base) |
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
584 |
transport = transport.clone(transport_path) |
585 |
# we do not want bzrdir to make any remote calls
|
|
586 |
bzrdir = RemoteBzrDir(transport, _client=False) |
|
587 |
repo = RemoteRepository(bzrdir, None, _client=client) |
|
588 |
return repo, client |
|
589 |
||
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
590 |
|
|
2018.12.2
by Andrew Bennetts
Remove some duplicate code in test_remote |
591 |
class TestRepositoryGatherStats(TestRemoteRepository): |
|
2018.10.3
by v.ladeuil+lp at free
more tests for gather_stats |
592 |
|
593 |
def test_revid_none(self): |
|
594 |
# ('ok',), body with revisions and size
|
|
595 |
responses = [(('ok', ), 'revisions: 2\nsize: 18\n')] |
|
596 |
transport_path = 'quack' |
|
597 |
repo, client = self.setup_fake_client_and_repository( |
|
598 |
responses, transport_path) |
|
599 |
result = repo.gather_stats(None) |
|
600 |
self.assertEqual( |
|
|
2018.5.153
by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review. |
601 |
[('call_expecting_body', 'Repository.gather_stats', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
602 |
('quack/','','no'))], |
|
2018.10.3
by v.ladeuil+lp at free
more tests for gather_stats |
603 |
client._calls) |
604 |
self.assertEqual({'revisions': 2, 'size': 18}, result) |
|
605 |
||
606 |
def test_revid_no_committers(self): |
|
607 |
# ('ok',), body without committers
|
|
608 |
responses = [(('ok', ), |
|
609 |
'firstrev: 123456.300 3600\n' |
|
610 |
'latestrev: 654231.400 0\n' |
|
611 |
'revisions: 2\n' |
|
612 |
'size: 18\n')] |
|
613 |
transport_path = 'quick' |
|
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
614 |
revid = u'\xc8'.encode('utf8') |
|
2018.10.3
by v.ladeuil+lp at free
more tests for gather_stats |
615 |
repo, client = self.setup_fake_client_and_repository( |
616 |
responses, transport_path) |
|
617 |
result = repo.gather_stats(revid) |
|
618 |
self.assertEqual( |
|
|
2018.5.153
by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review. |
619 |
[('call_expecting_body', 'Repository.gather_stats', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
620 |
('quick/', revid, 'no'))], |
|
2018.10.3
by v.ladeuil+lp at free
more tests for gather_stats |
621 |
client._calls) |
622 |
self.assertEqual({'revisions': 2, 'size': 18, |
|
623 |
'firstrev': (123456.300, 3600), |
|
624 |
'latestrev': (654231.400, 0),}, |
|
625 |
result) |
|
626 |
||
627 |
def test_revid_with_committers(self): |
|
628 |
# ('ok',), body with committers
|
|
629 |
responses = [(('ok', ), |
|
630 |
'committers: 128\n' |
|
631 |
'firstrev: 123456.300 3600\n' |
|
632 |
'latestrev: 654231.400 0\n' |
|
633 |
'revisions: 2\n' |
|
634 |
'size: 18\n')] |
|
635 |
transport_path = 'buick' |
|
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
636 |
revid = u'\xc8'.encode('utf8') |
|
2018.10.3
by v.ladeuil+lp at free
more tests for gather_stats |
637 |
repo, client = self.setup_fake_client_and_repository( |
638 |
responses, transport_path) |
|
639 |
result = repo.gather_stats(revid, True) |
|
640 |
self.assertEqual( |
|
|
2018.5.153
by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review. |
641 |
[('call_expecting_body', 'Repository.gather_stats', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
642 |
('buick/', revid, 'yes'))], |
|
2018.10.3
by v.ladeuil+lp at free
more tests for gather_stats |
643 |
client._calls) |
644 |
self.assertEqual({'revisions': 2, 'size': 18, |
|
645 |
'committers': 128, |
|
646 |
'firstrev': (123456.300, 3600), |
|
647 |
'latestrev': (654231.400, 0),}, |
|
648 |
result) |
|
649 |
||
650 |
||
|
3172.5.4
by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph. |
651 |
class TestRepositoryGetGraph(TestRemoteRepository): |
652 |
||
653 |
def test_get_graph(self): |
|
|
3172.5.8
by Robert Collins
Review feedback. |
654 |
# get_graph returns a graph with the repository as the
|
655 |
# parents_provider.
|
|
|
3172.5.4
by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph. |
656 |
responses = [] |
657 |
transport_path = 'quack' |
|
658 |
repo, client = self.setup_fake_client_and_repository( |
|
659 |
responses, transport_path) |
|
660 |
graph = repo.get_graph() |
|
661 |
self.assertEqual(graph._parents_provider, repo) |
|
662 |
||
663 |
||
664 |
class TestRepositoryGetParentMap(TestRemoteRepository): |
|
665 |
||
666 |
def test_get_parent_map_caching(self): |
|
667 |
# get_parent_map returns from cache until unlock()
|
|
668 |
# setup a reponse with two revisions
|
|
669 |
r1 = u'\u0e33'.encode('utf8') |
|
670 |
r2 = u'\u0dab'.encode('utf8') |
|
671 |
lines = [' '.join([r2, r1]), r1] |
|
|
3211.5.2
by Robert Collins
Change RemoteRepository.get_parent_map to use bz2 not gzip for compression. |
672 |
encoded_body = bz2.compress('\n'.join(lines)) |
|
3172.5.4
by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph. |
673 |
responses = [(('ok', ), encoded_body), (('ok', ), encoded_body)] |
674 |
||
675 |
transport_path = 'quack' |
|
676 |
repo, client = self.setup_fake_client_and_repository( |
|
677 |
responses, transport_path) |
|
678 |
repo.lock_read() |
|
679 |
graph = repo.get_graph() |
|
680 |
parents = graph.get_parent_map([r2]) |
|
681 |
self.assertEqual({r2: (r1,)}, parents) |
|
682 |
# locking and unlocking deeper should not reset
|
|
683 |
repo.lock_read() |
|
684 |
repo.unlock() |
|
685 |
parents = graph.get_parent_map([r1]) |
|
|
3172.5.6
by Robert Collins
Create new smart server verb Repository.get_parent_map. |
686 |
self.assertEqual({r1: (NULL_REVISION,)}, parents) |
|
3172.5.4
by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph. |
687 |
self.assertEqual( |
|
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. |
688 |
[('call_with_body_bytes_expecting_body', |
689 |
'Repository.get_parent_map', ('quack/', r2), '\n\n0')], |
|
|
3172.5.4
by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph. |
690 |
client._calls) |
691 |
repo.unlock() |
|
692 |
# now we call again, and it should use the second response.
|
|
693 |
repo.lock_read() |
|
694 |
graph = repo.get_graph() |
|
|
3172.5.6
by Robert Collins
Create new smart server verb Repository.get_parent_map. |
695 |
parents = graph.get_parent_map([r1]) |
696 |
self.assertEqual({r1: (NULL_REVISION,)}, parents) |
|
|
3172.5.4
by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph. |
697 |
self.assertEqual( |
|
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. |
698 |
[('call_with_body_bytes_expecting_body', |
699 |
'Repository.get_parent_map', ('quack/', r2), '\n\n0'), |
|
700 |
('call_with_body_bytes_expecting_body', |
|
701 |
'Repository.get_parent_map', ('quack/', r1), '\n\n0'), |
|
|
3172.5.4
by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph. |
702 |
],
|
703 |
client._calls) |
|
704 |
repo.unlock() |
|
705 |
||
|
3213.1.2
by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server. |
706 |
def test_get_parent_map_reconnects_if_unknown_method(self): |
707 |
error_msg = ( |
|
708 |
"Generic bzr smart protocol error: "
|
|
709 |
"bad request 'Repository.get_parent_map'") |
|
710 |
responses = [ |
|
711 |
(('error', error_msg), ''), |
|
712 |
(('ok',), '')] |
|
713 |
transport_path = 'quack' |
|
714 |
repo, client = self.setup_fake_client_and_repository( |
|
715 |
responses, transport_path) |
|
716 |
rev_id = 'revision-id' |
|
717 |
parents = repo.get_parent_map([rev_id]) |
|
718 |
self.assertEqual( |
|
|
3213.1.8
by Andrew Bennetts
Merge from bzr.dev. |
719 |
[('call_with_body_bytes_expecting_body', |
720 |
'Repository.get_parent_map', ('quack/', rev_id), '\n\n0'), |
|
|
3213.1.2
by Andrew Bennetts
Add test for reconnection if get_parent_map is unknown by the server. |
721 |
('disconnect medium',), |
722 |
('call_expecting_body', 'Repository.get_revision_graph', |
|
723 |
('quack/', ''))], |
|
724 |
client._calls) |
|
725 |
||
726 |
||
|
3172.5.4
by Robert Collins
Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph. |
727 |
|
|
2018.5.68
by Wouter van Heyst
Merge RemoteRepository.gather_stats. |
728 |
class TestRepositoryGetRevisionGraph(TestRemoteRepository): |
729 |
||
730 |
def test_null_revision(self): |
|
731 |
# a null revision has the predictable result {}, we should have no wire
|
|
732 |
# traffic when calling it with this argument
|
|
733 |
responses = [(('notused', ), '')] |
|
734 |
transport_path = 'empty' |
|
735 |
repo, client = self.setup_fake_client_and_repository( |
|
736 |
responses, transport_path) |
|
|
3287.6.4
by Robert Collins
Fix up deprecation warnings for get_revision_graph. |
737 |
result = self.applyDeprecated(one_four, repo.get_revision_graph, |
738 |
NULL_REVISION) |
|
|
2018.5.68
by Wouter van Heyst
Merge RemoteRepository.gather_stats. |
739 |
self.assertEqual([], client._calls) |
740 |
self.assertEqual({}, result) |
|
741 |
||
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
742 |
def test_none_revision(self): |
743 |
# with none we want the entire graph
|
|
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
744 |
r1 = u'\u0e33'.encode('utf8') |
745 |
r2 = u'\u0dab'.encode('utf8') |
|
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
746 |
lines = [' '.join([r2, r1]), r1] |
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
747 |
encoded_body = '\n'.join(lines) |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
748 |
|
749 |
responses = [(('ok', ), encoded_body)] |
|
750 |
transport_path = 'sinhala' |
|
751 |
repo, client = self.setup_fake_client_and_repository( |
|
752 |
responses, transport_path) |
|
|
3287.6.4
by Robert Collins
Fix up deprecation warnings for get_revision_graph. |
753 |
result = self.applyDeprecated(one_four, repo.get_revision_graph) |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
754 |
self.assertEqual( |
|
2018.5.153
by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review. |
755 |
[('call_expecting_body', 'Repository.get_revision_graph', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
756 |
('sinhala/', ''))], |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
757 |
client._calls) |
|
2625.8.1
by Robert Collins
LIBRARY API BREAKS: |
758 |
self.assertEqual({r1: (), r2: (r1, )}, result) |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
759 |
|
760 |
def test_specific_revision(self): |
|
761 |
# with a specific revision we want the graph for that
|
|
762 |
# with none we want the entire graph
|
|
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
763 |
r11 = u'\u0e33'.encode('utf8') |
764 |
r12 = u'\xc9'.encode('utf8') |
|
765 |
r2 = u'\u0dab'.encode('utf8') |
|
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
766 |
lines = [' '.join([r2, r11, r12]), r11, r12] |
|
2018.5.106
by Andrew Bennetts
Update tests in test_remote to use utf-8 byte strings for revision IDs, rather than unicode strings. |
767 |
encoded_body = '\n'.join(lines) |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
768 |
|
769 |
responses = [(('ok', ), encoded_body)] |
|
770 |
transport_path = 'sinhala' |
|
771 |
repo, client = self.setup_fake_client_and_repository( |
|
772 |
responses, transport_path) |
|
|
3287.6.4
by Robert Collins
Fix up deprecation warnings for get_revision_graph. |
773 |
result = self.applyDeprecated(one_four, repo.get_revision_graph, r2) |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
774 |
self.assertEqual( |
|
2018.5.153
by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review. |
775 |
[('call_expecting_body', 'Repository.get_revision_graph', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
776 |
('sinhala/', r2))], |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
777 |
client._calls) |
|
2625.8.1
by Robert Collins
LIBRARY API BREAKS: |
778 |
self.assertEqual({r11: (), r12: (), r2: (r11, r12), }, result) |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
779 |
|
780 |
def test_no_such_revision(self): |
|
781 |
revid = '123' |
|
782 |
responses = [(('nosuchrevision', revid), '')] |
|
783 |
transport_path = 'sinhala' |
|
784 |
repo, client = self.setup_fake_client_and_repository( |
|
785 |
responses, transport_path) |
|
786 |
# also check that the right revision is reported in the error
|
|
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
787 |
self.assertRaises(errors.NoSuchRevision, |
|
3287.6.4
by Robert Collins
Fix up deprecation warnings for get_revision_graph. |
788 |
self.applyDeprecated, one_four, repo.get_revision_graph, revid) |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
789 |
self.assertEqual( |
|
2018.5.153
by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review. |
790 |
[('call_expecting_body', 'Repository.get_revision_graph', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
791 |
('sinhala/', revid))], |
|
2018.5.67
by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins) |
792 |
client._calls) |
793 |
||
794 |
||
795 |
class TestRepositoryIsShared(TestRemoteRepository): |
|
796 |
||
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
797 |
def test_is_shared(self): |
798 |
# ('yes', ) for Repository.is_shared -> 'True'.
|
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
799 |
responses = [(('yes', ), )] |
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
800 |
transport_path = 'quack' |
801 |
repo, client = self.setup_fake_client_and_repository( |
|
802 |
responses, transport_path) |
|
803 |
result = repo.is_shared() |
|
804 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
805 |
[('call', 'Repository.is_shared', ('quack/',))], |
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
806 |
client._calls) |
807 |
self.assertEqual(True, result) |
|
808 |
||
809 |
def test_is_not_shared(self): |
|
810 |
# ('no', ) for Repository.is_shared -> 'False'.
|
|
|
2018.5.59
by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil). |
811 |
responses = [(('no', ), )] |
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
812 |
transport_path = 'qwack' |
813 |
repo, client = self.setup_fake_client_and_repository( |
|
814 |
responses, transport_path) |
|
815 |
result = repo.is_shared() |
|
816 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
817 |
[('call', 'Repository.is_shared', ('qwack/',))], |
|
2018.5.57
by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). |
818 |
client._calls) |
819 |
self.assertEqual(False, result) |
|
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
820 |
|
821 |
||
822 |
class TestRepositoryLockWrite(TestRemoteRepository): |
|
823 |
||
824 |
def test_lock_write(self): |
|
825 |
responses = [(('ok', 'a token'), '')] |
|
826 |
transport_path = 'quack' |
|
827 |
repo, client = self.setup_fake_client_and_repository( |
|
828 |
responses, transport_path) |
|
829 |
result = repo.lock_write() |
|
830 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
831 |
[('call', 'Repository.lock_write', ('quack/', ''))], |
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
832 |
client._calls) |
833 |
self.assertEqual('a token', result) |
|
834 |
||
835 |
def test_lock_write_already_locked(self): |
|
836 |
responses = [(('LockContention', ), '')] |
|
837 |
transport_path = 'quack' |
|
838 |
repo, client = self.setup_fake_client_and_repository( |
|
839 |
responses, transport_path) |
|
840 |
self.assertRaises(errors.LockContention, repo.lock_write) |
|
841 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
842 |
[('call', 'Repository.lock_write', ('quack/', ''))], |
|
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. |
843 |
client._calls) |
844 |
||
845 |
def test_lock_write_unlockable(self): |
|
846 |
responses = [(('UnlockableTransport', ), '')] |
|
847 |
transport_path = 'quack' |
|
848 |
repo, client = self.setup_fake_client_and_repository( |
|
849 |
responses, transport_path) |
|
850 |
self.assertRaises(errors.UnlockableTransport, repo.lock_write) |
|
851 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
852 |
[('call', 'Repository.lock_write', ('quack/', ''))], |
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
853 |
client._calls) |
854 |
||
855 |
||
856 |
class TestRepositoryUnlock(TestRemoteRepository): |
|
857 |
||
858 |
def test_unlock(self): |
|
859 |
responses = [(('ok', 'a token'), ''), |
|
860 |
(('ok',), '')] |
|
861 |
transport_path = 'quack' |
|
862 |
repo, client = self.setup_fake_client_and_repository( |
|
863 |
responses, transport_path) |
|
864 |
repo.lock_write() |
|
865 |
repo.unlock() |
|
866 |
self.assertEqual( |
|
|
3104.4.2
by Andrew Bennetts
All tests passing. |
867 |
[('call', 'Repository.lock_write', ('quack/', '')), |
868 |
('call', 'Repository.unlock', ('quack/', 'a token'))], |
|
|
2018.5.78
by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the |
869 |
client._calls) |
870 |
||
871 |
def test_unlock_wrong_token(self): |
|
872 |
# If somehow the token is wrong, unlock will raise TokenMismatch.
|
|
873 |
responses = [(('ok', 'a token'), ''), |
|
874 |
(('TokenMismatch',), '')] |
|
875 |
transport_path = 'quack' |
|
876 |
repo, client = self.setup_fake_client_and_repository( |
|
877 |
responses, transport_path) |
|
878 |
repo.lock_write() |
|
879 |
self.assertRaises(errors.TokenMismatch, repo.unlock) |
|
880 |
||
881 |
||
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
882 |
class TestRepositoryHasRevision(TestRemoteRepository): |
883 |
||
884 |
def test_none(self): |
|
885 |
# repo.has_revision(None) should not cause any traffic.
|
|
886 |
transport_path = 'quack' |
|
887 |
responses = None |
|
888 |
repo, client = self.setup_fake_client_and_repository( |
|
889 |
responses, transport_path) |
|
890 |
||
891 |
# The null revision is always there, so has_revision(None) == True.
|
|
|
3172.3.3
by Robert Collins
Missed one occurence of None -> NULL_REVISION. |
892 |
self.assertEqual(True, repo.has_revision(NULL_REVISION)) |
|
2018.14.1
by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures. |
893 |
|
894 |
# The remote repo shouldn't be accessed.
|
|
895 |
self.assertEqual([], client._calls) |
|
|
2018.18.7
by Martin Pool
(broken) Start addng client proxy test for Repository.tarball |
896 |
|
897 |
||
898 |
class TestRepositoryTarball(TestRemoteRepository): |
|
899 |
||
|
2018.18.9
by Martin Pool
remote Repository.tarball builds a temporary directory and tars that |
900 |
# This is a canned tarball reponse we can validate against
|
|
2018.18.18
by Martin Pool
reformat |
901 |
tarball_content = ( |
|
2018.18.23
by Martin Pool
review cleanups |
902 |
'QlpoOTFBWSZTWdGkj3wAAWF/k8aQACBIB//A9+8cIX/v33AACEAYABAECEACNz'
|
903 |
'JqsgJJFPTSnk1A3qh6mTQAAAANPUHkagkSTEkaA09QaNAAAGgAAAcwCYCZGAEY'
|
|
904 |
'mJhMJghpiaYBUkKammSHqNMZQ0NABkNAeo0AGneAevnlwQoGzEzNVzaYxp/1Uk'
|
|
905 |
'xXzA1CQX0BJMZZLcPBrluJir5SQyijWHYZ6ZUtVqqlYDdB2QoCwa9GyWwGYDMA'
|
|
906 |
'OQYhkpLt/OKFnnlT8E0PmO8+ZNSo2WWqeCzGB5fBXZ3IvV7uNJVE7DYnWj6qwB'
|
|
907 |
'k5DJDIrQ5OQHHIjkS9KqwG3mc3t+F1+iujb89ufyBNIKCgeZBWrl5cXxbMGoMs'
|
|
908 |
'c9JuUkg5YsiVcaZJurc6KLi6yKOkgCUOlIlOpOoXyrTJjK8ZgbklReDdwGmFgt'
|
|
909 |
'dkVsAIslSVCd4AtACSLbyhLHryfb14PKegrVDba+U8OL6KQtzdM5HLjAc8/p6n'
|
|
910 |
'0lgaWU8skgO7xupPTkyuwheSckejFLK5T4ZOo0Gda9viaIhpD1Qn7JqqlKAJqC'
|
|
911 |
'QplPKp2nqBWAfwBGaOwVrz3y1T+UZZNismXHsb2Jq18T+VaD9k4P8DqE3g70qV'
|
|
912 |
'JLurpnDI6VS5oqDDPVbtVjMxMxMg4rzQVipn2Bv1fVNK0iq3Gl0hhnnHKm/egy'
|
|
913 |
'nWQ7QH/F3JFOFCQ0aSPfA='
|
|
914 |
).decode('base64') |
|
|
2018.18.9
by Martin Pool
remote Repository.tarball builds a temporary directory and tars that |
915 |
|
|
2018.18.7
by Martin Pool
(broken) Start addng client proxy test for Repository.tarball |
916 |
def test_repository_tarball(self): |
|
2018.18.9
by Martin Pool
remote Repository.tarball builds a temporary directory and tars that |
917 |
# Test that Repository.tarball generates the right operations
|
|
2018.18.7
by Martin Pool
(broken) Start addng client proxy test for Repository.tarball |
918 |
transport_path = 'repo' |
|
2018.18.9
by Martin Pool
remote Repository.tarball builds a temporary directory and tars that |
919 |
expected_responses = [(('ok',), self.tarball_content), |
|
2018.18.7
by Martin Pool
(broken) Start addng client proxy test for Repository.tarball |
920 |
]
|
|
2018.18.14
by Martin Pool
merge hpss again; restore incorrectly removed RemoteRepository.break_lock |
921 |
expected_calls = [('call_expecting_body', 'Repository.tarball', |
|
3104.4.2
by Andrew Bennetts
All tests passing. |
922 |
('repo/', 'bz2',),), |
|
2018.18.7
by Martin Pool
(broken) Start addng client proxy test for Repository.tarball |
923 |
]
|
924 |
remote_repo, client = self.setup_fake_client_and_repository( |
|
925 |
expected_responses, transport_path) |
|
926 |
# Now actually ask for the tarball
|
|
|
2018.18.25
by Martin Pool
Repository.tarball fixes for python2.4 |
927 |
tarball_file = remote_repo._get_tarball('bz2') |
928 |
try: |
|
929 |
self.assertEqual(expected_calls, client._calls) |
|
930 |
self.assertEqual(self.tarball_content, tarball_file.read()) |
|
931 |
finally: |
|
932 |
tarball_file.close() |
|
|
2018.18.9
by Martin Pool
remote Repository.tarball builds a temporary directory and tars that |
933 |
|
934 |
||
935 |
class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport): |
|
936 |
"""RemoteRepository.copy_content_into optimizations""" |
|
937 |
||
|
2018.18.10
by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends. |
938 |
def test_copy_content_remote_to_local(self): |
939 |
self.transport_server = server.SmartTCPServer_for_testing |
|
940 |
src_repo = self.make_repository('repo1') |
|
941 |
src_repo = repository.Repository.open(self.get_url('repo1')) |
|
942 |
# At the moment the tarball-based copy_content_into can't write back
|
|
943 |
# into a smart server. It would be good if it could upload the
|
|
944 |
# tarball; once that works we'd have to create repositories of
|
|
945 |
# different formats. -- mbp 20070410
|
|
946 |
dest_url = self.get_vfs_only_url('repo2') |
|
947 |
dest_bzrdir = BzrDir.create(dest_url) |
|
948 |
dest_repo = dest_bzrdir.create_repository() |
|
949 |
self.assertFalse(isinstance(dest_repo, RemoteRepository)) |
|
950 |
self.assertTrue(isinstance(src_repo, RemoteRepository)) |
|
951 |
src_repo.copy_content_into(dest_repo) |
|
|
2535.3.39
by Andrew Bennetts
Tidy some XXXs. |
952 |
|
953 |
||
|
2535.3.49
by Andrew Bennetts
Rename 'Repository.fetch_revisions' smart request to 'Repository.stream_knit_data_for_revisions'. |
954 |
class TestRepositoryStreamKnitData(TestRemoteRepository): |
|
2535.3.39
by Andrew Bennetts
Tidy some XXXs. |
955 |
|
956 |
def make_pack_file(self, records): |
|
957 |
pack_file = StringIO() |
|
958 |
pack_writer = pack.ContainerWriter(pack_file.write) |
|
959 |
pack_writer.begin() |
|
960 |
for bytes, names in records: |
|
961 |
pack_writer.add_bytes_record(bytes, names) |
|
962 |
pack_writer.end() |
|
963 |
pack_file.seek(0) |
|
964 |
return pack_file |
|
965 |
||
|
2535.4.2
by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming. |
966 |
def make_pack_stream(self, records): |
|
2535.4.18
by Andrew Bennetts
Use pack.ContainerSerialiser to remove some nasty cruft. |
967 |
pack_serialiser = pack.ContainerSerialiser() |
968 |
yield pack_serialiser.begin() |
|
|
2535.4.2
by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming. |
969 |
for bytes, names in records: |
|
2535.4.18
by Andrew Bennetts
Use pack.ContainerSerialiser to remove some nasty cruft. |
970 |
yield pack_serialiser.bytes_record(bytes, names) |
971 |
yield pack_serialiser.end() |
|
|
2535.4.2
by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming. |
972 |
|
|
2535.3.39
by Andrew Bennetts
Tidy some XXXs. |
973 |
def test_bad_pack_from_server(self): |
|
2535.3.50
by Andrew Bennetts
Use tuple names in data streams rather than concatenated strings. |
974 |
"""A response with invalid data (e.g. it has a record with multiple |
975 |
names) triggers an exception.
|
|
976 |
|
|
977 |
Not all possible errors will be caught at this stage, but obviously
|
|
978 |
malformed data should be.
|
|
979 |
"""
|
|
980 |
record = ('bytes', [('name1',), ('name2',)]) |
|
|
2535.4.2
by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming. |
981 |
pack_stream = self.make_pack_stream([record]) |
982 |
responses = [(('ok',), pack_stream), ] |
|
|
2535.3.39
by Andrew Bennetts
Tidy some XXXs. |
983 |
transport_path = 'quack' |
984 |
repo, client = self.setup_fake_client_and_repository( |
|
985 |
responses, transport_path) |
|
|
3184.1.9
by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of |
986 |
search = graph.SearchResult(set(['revid']), set(), 1, set(['revid'])) |
987 |
stream = repo.get_data_stream_for_search(search) |
|
|
2535.3.39
by Andrew Bennetts
Tidy some XXXs. |
988 |
self.assertRaises(errors.SmartProtocolError, list, stream) |
989 |
||
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
990 |
def test_backwards_compatibility(self): |
991 |
"""If the server doesn't recognise this request, fallback to VFS.""" |
|
992 |
error_msg = ( |
|
993 |
"Generic bzr smart protocol error: "
|
|
|
2535.4.29
by Andrew Bennetts
Add a new smart method, Repository.stream_revisions_chunked, rather than changing the behaviour of an existing method. |
994 |
"bad request 'Repository.stream_revisions_chunked'") |
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
995 |
responses = [ |
996 |
(('error', error_msg), '')] |
|
997 |
repo, client = self.setup_fake_client_and_repository( |
|
998 |
responses, 'path') |
|
999 |
self.mock_called = False |
|
1000 |
repo._real_repository = MockRealRepository(self) |
|
|
3184.1.9
by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of |
1001 |
search = graph.SearchResult(set(['revid']), set(), 1, set(['revid'])) |
1002 |
repo.get_data_stream_for_search(search) |
|
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
1003 |
self.assertTrue(self.mock_called) |
1004 |
self.failIf(client.expecting_body, |
|
1005 |
"The protocol has been left in an unclean state that will cause "
|
|
1006 |
"TooManyConcurrentRequests errors.") |
|
1007 |
||
1008 |
||
1009 |
class MockRealRepository(object): |
|
1010 |
"""Helper class for TestRepositoryStreamKnitData.test_unknown_method.""" |
|
1011 |
||
1012 |
def __init__(self, test): |
|
1013 |
self.test = test |
|
1014 |
||
|
3184.1.9
by Robert Collins
* ``Repository.get_data_stream`` is now deprecated in favour of |
1015 |
def get_data_stream_for_search(self, search): |
1016 |
self.test.assertEqual(set(['revid']), search.get_keys()) |
|
|
2535.3.68
by Andrew Bennetts
Backwards compatibility for new smart method. |
1017 |
self.test.mock_called = True |
1018 |
||
1019 |