bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
3407.2.2
by Martin Pool
 Remove special case in RemoteBranchLockableFiles for branch.conf  | 
1  | 
# Copyright (C) 2006, 2007, 2008 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  | 
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
49  | 
from bzrlib.transport import get_transport, http  | 
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
50  | 
from bzrlib.transport.memory import MemoryTransport  | 
| 
3431.3.1
by Andrew Bennetts
 First rough cut of a fix for bug #230550, by adding .base to SmartClientMedia rather than relying on other objects to track this accurately while reusing client media.  | 
51  | 
from bzrlib.transport.remote import RemoteTransport, RemoteTCPTransport  | 
| 
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  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
135  | 
def __init__(self, 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
 | 
| 
3297.3.3
by Andrew Bennetts
 SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.  | 
139  | 
            back to callers.  A special case is if the response-tuple is
 | 
140  | 
            'unknown verb', then a UnknownSmartMethod will be raised for that
 | 
|
141  | 
            call, using the second element of the tuple as the verb in the
 | 
|
142  | 
            exception.
 | 
|
| 
2018.5.59
by Robert Collins
 Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).  | 
143  | 
        """
 | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
144  | 
self.responses = []  | 
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
145  | 
self._calls = []  | 
| 
2535.3.68
by Andrew Bennetts
 Backwards compatibility for new smart method.  | 
146  | 
self.expecting_body = False  | 
| 
3431.3.2
by Andrew Bennetts
 Remove 'base' from _SmartClient entirely, now that the medium has it.  | 
147  | 
_SmartClient.__init__(self, FakeMedium(self._calls, fake_medium_base))  | 
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
148  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
149  | 
def add_success_response(self, *args):  | 
150  | 
self.responses.append(('success', args, None))  | 
|
151  | 
||
152  | 
def add_success_response_with_body(self, body, *args):  | 
|
153  | 
self.responses.append(('success', args, body))  | 
|
154  | 
||
155  | 
def add_error_response(self, *args):  | 
|
156  | 
self.responses.append(('error', args))  | 
|
157  | 
||
158  | 
def add_unknown_method_response(self, verb):  | 
|
159  | 
self.responses.append(('unknown', verb))  | 
|
160  | 
||
| 
3297.3.3
by Andrew Bennetts
 SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.  | 
161  | 
def _get_next_response(self):  | 
162  | 
response_tuple = self.responses.pop(0)  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
163  | 
if response_tuple[0] == 'unknown':  | 
164  | 
raise errors.UnknownSmartMethod(response_tuple[1])  | 
|
165  | 
elif response_tuple[0] == 'error':  | 
|
166  | 
raise errors.ErrorFromSmartServer(response_tuple[1])  | 
|
| 
3297.3.3
by Andrew Bennetts
 SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.  | 
167  | 
return response_tuple  | 
168  | 
||
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
169  | 
def call(self, method, *args):  | 
170  | 
self._calls.append(('call', method, args))  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
171  | 
return self._get_next_response()[1]  | 
| 
2018.5.59
by Robert Collins
 Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).  | 
172  | 
|
| 
2018.5.153
by Andrew Bennetts
 Rename call2 to call_expecting_body, and other small changes prompted by review.  | 
173  | 
def call_expecting_body(self, method, *args):  | 
174  | 
self._calls.append(('call_expecting_body', method, args))  | 
|
| 
3297.3.3
by Andrew Bennetts
 SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.  | 
175  | 
result = self._get_next_response()  | 
| 
2535.3.68
by Andrew Bennetts
 Backwards compatibility for new smart method.  | 
176  | 
self.expecting_body = True  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
177  | 
return result[1], FakeProtocol(result[2], self)  | 
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
178  | 
|
| 
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.  | 
179  | 
def call_with_body_bytes_expecting_body(self, method, args, body):  | 
180  | 
self._calls.append(('call_with_body_bytes_expecting_body', method,  | 
|
181  | 
args, body))  | 
|
| 
3297.3.3
by Andrew Bennetts
 SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.  | 
182  | 
result = self._get_next_response()  | 
| 
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.  | 
183  | 
self.expecting_body = True  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
184  | 
return result[1], FakeProtocol(result[2], self)  | 
| 
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.  | 
185  | 
|
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
186  | 
|
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
187  | 
class FakeMedium(medium.SmartClientMedium):  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
188  | 
|
| 
3431.3.1
by Andrew Bennetts
 First rough cut of a fix for bug #230550, by adding .base to SmartClientMedia rather than relying on other objects to track this accurately while reusing client media.  | 
189  | 
def __init__(self, client_calls, base):  | 
| 
3453.4.1
by Andrew Bennetts
 Better infrastructure on SmartClientMedium for tracking the remote version.  | 
190  | 
medium.SmartClientMedium.__init__(self, base)  | 
| 
3213.1.2
by Andrew Bennetts
 Add test for reconnection if get_parent_map is unknown by the server.  | 
191  | 
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.  | 
192  | 
|
193  | 
def disconnect(self):  | 
|
| 
3213.1.2
by Andrew Bennetts
 Add test for reconnection if get_parent_map is unknown by the server.  | 
194  | 
self._client_calls.append(('disconnect medium',))  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
195  | 
|
196  | 
||
| 
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.  | 
197  | 
class TestVfsHas(tests.TestCase):  | 
198  | 
||
199  | 
def test_unicode_path(self):  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
200  | 
client = FakeClient('/')  | 
201  | 
client.add_success_response('yes',)  | 
|
| 
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.  | 
202  | 
transport = RemoteTransport('bzr://localhost/', _client=client)  | 
203  | 
filename = u'/hell\u00d8'.encode('utf8')  | 
|
204  | 
result = transport.has(filename)  | 
|
205  | 
self.assertEqual(  | 
|
206  | 
[('call', 'has', (filename,))],  | 
|
207  | 
client._calls)  | 
|
208  | 
self.assertTrue(result)  | 
|
209  | 
||
210  | 
||
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
211  | 
class Test_ClientMedium_remote_path_from_transport(tests.TestCase):  | 
212  | 
"""Tests for the behaviour of client_medium.remote_path_from_transport."""  | 
|
| 
3313.3.3
by Andrew Bennetts
 Add tests for _SmartClient.remote_path_for_transport.  | 
213  | 
|
214  | 
def assertRemotePath(self, expected, client_base, transport_base):  | 
|
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
215  | 
"""Assert that the result of  | 
216  | 
        SmartClientMedium.remote_path_from_transport is the expected value for
 | 
|
217  | 
        a given client_base and transport_base.
 | 
|
| 
3313.3.3
by Andrew Bennetts
 Add tests for _SmartClient.remote_path_for_transport.  | 
218  | 
        """
 | 
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
219  | 
client_medium = medium.SmartClientMedium(client_base)  | 
| 
3313.3.3
by Andrew Bennetts
 Add tests for _SmartClient.remote_path_for_transport.  | 
220  | 
transport = get_transport(transport_base)  | 
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
221  | 
result = client_medium.remote_path_from_transport(transport)  | 
| 
3313.3.3
by Andrew Bennetts
 Add tests for _SmartClient.remote_path_for_transport.  | 
222  | 
self.assertEqual(expected, result)  | 
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
223  | 
|
| 
3313.3.3
by Andrew Bennetts
 Add tests for _SmartClient.remote_path_for_transport.  | 
224  | 
def test_remote_path_from_transport(self):  | 
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
225  | 
"""SmartClientMedium.remote_path_from_transport calculates a URL for  | 
226  | 
        the given transport relative to the root of the client base URL.
 | 
|
| 
3313.3.3
by Andrew Bennetts
 Add tests for _SmartClient.remote_path_for_transport.  | 
227  | 
        """
 | 
228  | 
self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')  | 
|
229  | 
self.assertRemotePath(  | 
|
230  | 
'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz')  | 
|
231  | 
||
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
232  | 
def assertRemotePathHTTP(self, expected, transport_base, relpath):  | 
233  | 
"""Assert that the result of  | 
|
234  | 
        HttpTransportBase.remote_path_from_transport is the expected value for
 | 
|
235  | 
        a given transport_base and relpath of that transport.  (Note that
 | 
|
236  | 
        HttpTransportBase is a subclass of SmartClientMedium)
 | 
|
237  | 
        """
 | 
|
238  | 
base_transport = get_transport(transport_base)  | 
|
239  | 
client_medium = base_transport.get_smart_medium()  | 
|
240  | 
cloned_transport = base_transport.clone(relpath)  | 
|
241  | 
result = client_medium.remote_path_from_transport(cloned_transport)  | 
|
242  | 
self.assertEqual(expected, result)  | 
|
243  | 
||
| 
3313.3.3
by Andrew Bennetts
 Add tests for _SmartClient.remote_path_for_transport.  | 
244  | 
def test_remote_path_from_transport_http(self):  | 
245  | 
"""Remote paths for HTTP transports are calculated differently to other  | 
|
246  | 
        transports.  They are just relative to the client base, not the root
 | 
|
247  | 
        directory of the host.
 | 
|
248  | 
        """
 | 
|
249  | 
for scheme in ['http:', 'https:', 'bzr+http:', 'bzr+https:']:  | 
|
| 
3431.3.11
by Andrew Bennetts
 Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.  | 
250  | 
self.assertRemotePathHTTP(  | 
251  | 
'../xyz/', scheme + '//host/path', '../xyz/')  | 
|
252  | 
self.assertRemotePathHTTP(  | 
|
253  | 
'xyz/', scheme + '//host/path', 'xyz/')  | 
|
| 
3313.3.3
by Andrew Bennetts
 Add tests for _SmartClient.remote_path_for_transport.  | 
254  | 
|
255  | 
||
| 
3453.4.1
by Andrew Bennetts
 Better infrastructure on SmartClientMedium for tracking the remote version.  | 
256  | 
class Test_ClientMedium_remote_is_at_least(tests.TestCase):  | 
257  | 
"""Tests for the behaviour of client_medium.remote_is_at_least."""  | 
|
258  | 
||
259  | 
def test_initially_unlimited(self):  | 
|
260  | 
"""A fresh medium assumes that the remote side supports all  | 
|
261  | 
        versions.
 | 
|
262  | 
        """
 | 
|
263  | 
client_medium = medium.SmartClientMedium('dummy base')  | 
|
| 
3453.4.10
by Andrew Bennetts
 Change _is_remote_at_least to _is_remote_before.  | 
264  | 
self.assertFalse(client_medium._is_remote_before((99, 99)))  | 
| 
3453.4.1
by Andrew Bennetts
 Better infrastructure on SmartClientMedium for tracking the remote version.  | 
265  | 
|
| 
3453.4.9
by Andrew Bennetts
 Rename _remote_is_not to _remember_remote_is_before.  | 
266  | 
def test__remember_remote_is_before(self):  | 
267  | 
"""Calling _remember_remote_is_before ratchets down the known remote  | 
|
268  | 
        version.
 | 
|
269  | 
        """
 | 
|
| 
3453.4.1
by Andrew Bennetts
 Better infrastructure on SmartClientMedium for tracking the remote version.  | 
270  | 
client_medium = medium.SmartClientMedium('dummy base')  | 
271  | 
        # Mark the remote side as being less than 1.6.  The remote side may
 | 
|
272  | 
        # still be 1.5.
 | 
|
| 
3453.4.9
by Andrew Bennetts
 Rename _remote_is_not to _remember_remote_is_before.  | 
273  | 
client_medium._remember_remote_is_before((1, 6))  | 
| 
3453.4.10
by Andrew Bennetts
 Change _is_remote_at_least to _is_remote_before.  | 
274  | 
self.assertTrue(client_medium._is_remote_before((1, 6)))  | 
275  | 
self.assertFalse(client_medium._is_remote_before((1, 5)))  | 
|
| 
3453.4.9
by Andrew Bennetts
 Rename _remote_is_not to _remember_remote_is_before.  | 
276  | 
        # Calling _remember_remote_is_before again with a lower value works.
 | 
277  | 
client_medium._remember_remote_is_before((1, 5))  | 
|
| 
3453.4.10
by Andrew Bennetts
 Change _is_remote_at_least to _is_remote_before.  | 
278  | 
self.assertTrue(client_medium._is_remote_before((1, 5)))  | 
| 
3453.4.9
by Andrew Bennetts
 Rename _remote_is_not to _remember_remote_is_before.  | 
279  | 
        # You cannot call _remember_remote_is_before with a larger value.
 | 
| 
3453.4.1
by Andrew Bennetts
 Better infrastructure on SmartClientMedium for tracking the remote version.  | 
280  | 
self.assertRaises(  | 
| 
3453.4.9
by Andrew Bennetts
 Rename _remote_is_not to _remember_remote_is_before.  | 
281  | 
AssertionError, client_medium._remember_remote_is_before, (1, 9))  | 
| 
3453.4.1
by Andrew Bennetts
 Better infrastructure on SmartClientMedium for tracking the remote version.  | 
282  | 
|
283  | 
||
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
284  | 
class TestBzrDirOpenBranch(tests.TestCase):  | 
285  | 
||
286  | 
def test_branch_present(self):  | 
|
287  | 
transport = MemoryTransport()  | 
|
288  | 
transport.mkdir('quack')  | 
|
289  | 
transport = transport.clone('quack')  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
290  | 
client = FakeClient(transport.base)  | 
291  | 
client.add_success_response('ok', '')  | 
|
292  | 
client.add_success_response('ok', '', 'no', 'no', 'no')  | 
|
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
293  | 
bzrdir = RemoteBzrDir(transport, _client=client)  | 
294  | 
result = bzrdir.open_branch()  | 
|
295  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
296  | 
[('call', 'BzrDir.open_branch', ('quack/',)),  | 
| 
3221.3.3
by Robert Collins
 * Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so  | 
297  | 
('call', 'BzrDir.find_repositoryV2', ('quack/',))],  | 
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
298  | 
client._calls)  | 
299  | 
self.assertIsInstance(result, RemoteBranch)  | 
|
300  | 
self.assertEqual(bzrdir, result.bzrdir)  | 
|
301  | 
||
302  | 
def test_branch_missing(self):  | 
|
303  | 
transport = MemoryTransport()  | 
|
304  | 
transport.mkdir('quack')  | 
|
305  | 
transport = transport.clone('quack')  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
306  | 
client = FakeClient(transport.base)  | 
307  | 
client.add_error_response('nobranch')  | 
|
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
308  | 
bzrdir = RemoteBzrDir(transport, _client=client)  | 
309  | 
self.assertRaises(errors.NotBranchError, bzrdir.open_branch)  | 
|
310  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
311  | 
[('call', 'BzrDir.open_branch', ('quack/',))],  | 
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
312  | 
client._calls)  | 
313  | 
||
| 
3211.4.1
by Robert Collins
 * ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,  | 
314  | 
def test__get_tree_branch(self):  | 
315  | 
        # _get_tree_branch is a form of open_branch, but it should only ask for
 | 
|
316  | 
        # branch opening, not any other network requests.
 | 
|
317  | 
calls = []  | 
|
318  | 
def open_branch():  | 
|
319  | 
calls.append("Called")  | 
|
320  | 
return "a-branch"  | 
|
321  | 
transport = MemoryTransport()  | 
|
322  | 
        # no requests on the network - catches other api calls being made.
 | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
323  | 
client = FakeClient(transport.base)  | 
| 
3211.4.1
by Robert Collins
 * ``RemoteBzrDir._get_tree_branch`` no longer triggers ``_ensure_real``,  | 
324  | 
bzrdir = RemoteBzrDir(transport, _client=client)  | 
325  | 
        # patch the open_branch call to record that it was called.
 | 
|
326  | 
bzrdir.open_branch = open_branch  | 
|
327  | 
self.assertEqual((None, "a-branch"), bzrdir._get_tree_branch())  | 
|
328  | 
self.assertEqual(["Called"], calls)  | 
|
329  | 
self.assertEqual([], client._calls)  | 
|
330  | 
||
| 
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.  | 
331  | 
def test_url_quoting_of_path(self):  | 
332  | 
        # Relpaths on the wire should not be URL-escaped.  So "~" should be
 | 
|
333  | 
        # transmitted as "~", not "%7E".
 | 
|
| 
3431.3.1
by Andrew Bennetts
 First rough cut of a fix for bug #230550, by adding .base to SmartClientMedia rather than relying on other objects to track this accurately while reusing client media.  | 
334  | 
transport = RemoteTCPTransport('bzr://localhost/~hello/')  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
335  | 
client = FakeClient(transport.base)  | 
336  | 
client.add_success_response('ok', '')  | 
|
337  | 
client.add_success_response('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.  | 
338  | 
bzrdir = RemoteBzrDir(transport, _client=client)  | 
339  | 
result = bzrdir.open_branch()  | 
|
340  | 
self.assertEqual(  | 
|
341  | 
[('call', 'BzrDir.open_branch', ('~hello/',)),  | 
|
| 
3221.3.3
by Robert Collins
 * Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so  | 
342  | 
('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.  | 
343  | 
client._calls)  | 
344  | 
||
| 
3221.3.3
by Robert Collins
 * Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so  | 
345  | 
def check_open_repository(self, rich_root, subtrees, external_lookup='no'):  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
346  | 
transport = MemoryTransport()  | 
347  | 
transport.mkdir('quack')  | 
|
348  | 
transport = transport.clone('quack')  | 
|
| 
2018.5.118
by Robert Collins
 Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.  | 
349  | 
if rich_root:  | 
| 
2018.5.166
by Andrew Bennetts
 Small changes in response to Aaron's review.  | 
350  | 
rich_response = 'yes'  | 
| 
2018.5.118
by Robert Collins
 Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.  | 
351  | 
else:  | 
| 
2018.5.166
by Andrew Bennetts
 Small changes in response to Aaron's review.  | 
352  | 
rich_response = 'no'  | 
| 
2018.5.118
by Robert Collins
 Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.  | 
353  | 
if subtrees:  | 
| 
2018.5.166
by Andrew Bennetts
 Small changes in response to Aaron's review.  | 
354  | 
subtree_response = 'yes'  | 
| 
2018.5.118
by Robert Collins
 Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.  | 
355  | 
else:  | 
| 
2018.5.166
by Andrew Bennetts
 Small changes in response to Aaron's review.  | 
356  | 
subtree_response = 'no'  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
357  | 
client = FakeClient(transport.base)  | 
358  | 
client.add_success_response(  | 
|
359  | 
'ok', '', rich_response, subtree_response, external_lookup)  | 
|
| 
2018.5.118
by Robert Collins
 Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.  | 
360  | 
bzrdir = RemoteBzrDir(transport, _client=client)  | 
361  | 
result = bzrdir.open_repository()  | 
|
362  | 
self.assertEqual(  | 
|
| 
3221.3.3
by Robert Collins
 * Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so  | 
363  | 
[('call', 'BzrDir.find_repositoryV2', ('quack/',))],  | 
| 
2018.5.118
by Robert Collins
 Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.  | 
364  | 
client._calls)  | 
365  | 
self.assertIsInstance(result, RemoteRepository)  | 
|
366  | 
self.assertEqual(bzrdir, result.bzrdir)  | 
|
367  | 
self.assertEqual(rich_root, result._format.rich_root_data)  | 
|
| 
2018.5.138
by Robert Collins
 Merge bzr.dev.  | 
368  | 
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.  | 
369  | 
|
370  | 
def test_open_repository_sets_format_attributes(self):  | 
|
371  | 
self.check_open_repository(True, True)  | 
|
372  | 
self.check_open_repository(False, True)  | 
|
373  | 
self.check_open_repository(True, False)  | 
|
374  | 
self.check_open_repository(False, False)  | 
|
| 
3221.3.3
by Robert Collins
 * Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so  | 
375  | 
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.  | 
376  | 
|
| 
2432.3.2
by Andrew Bennetts
 Add test, and tidy implementation.  | 
377  | 
def test_old_server(self):  | 
378  | 
"""RemoteBzrDirFormat should fail to probe if the server version is too  | 
|
379  | 
        old.
 | 
|
380  | 
        """
 | 
|
381  | 
self.assertRaises(errors.NotBranchError,  | 
|
382  | 
RemoteBzrDirFormat.probe_transport, OldServerTransport())  | 
|
383  | 
||
384  | 
||
| 
3297.3.3
by Andrew Bennetts
 SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.  | 
385  | 
class TestBzrDirOpenRepository(tests.TestCase):  | 
386  | 
||
387  | 
def test_backwards_compat_1_2(self):  | 
|
388  | 
transport = MemoryTransport()  | 
|
389  | 
transport.mkdir('quack')  | 
|
390  | 
transport = transport.clone('quack')  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
391  | 
client = FakeClient(transport.base)  | 
392  | 
client.add_unknown_method_response('RemoteRepository.find_repositoryV2')  | 
|
393  | 
client.add_success_response('ok', '', 'no', 'no')  | 
|
| 
3297.3.3
by Andrew Bennetts
 SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod. Callers no longer need to do their own ad hoc unknown smart method error detection.  | 
394  | 
bzrdir = RemoteBzrDir(transport, _client=client)  | 
395  | 
repo = bzrdir.open_repository()  | 
|
396  | 
self.assertEqual(  | 
|
397  | 
[('call', 'BzrDir.find_repositoryV2', ('quack/',)),  | 
|
398  | 
('call', 'BzrDir.find_repository', ('quack/',))],  | 
|
399  | 
client._calls)  | 
|
400  | 
||
401  | 
||
| 
2432.3.2
by Andrew Bennetts
 Add test, and tidy implementation.  | 
402  | 
class OldSmartClient(object):  | 
403  | 
"""A fake smart client for test_old_version that just returns a version one  | 
|
404  | 
    response to the 'hello' (query version) command.
 | 
|
405  | 
    """
 | 
|
406  | 
||
407  | 
def get_request(self):  | 
|
408  | 
input_file = StringIO('ok\x011\n')  | 
|
409  | 
output_file = StringIO()  | 
|
410  | 
client_medium = medium.SmartSimplePipesClientMedium(  | 
|
411  | 
input_file, output_file)  | 
|
412  | 
return medium.SmartClientStreamMediumRequest(client_medium)  | 
|
413  | 
||
| 
3241.1.1
by Andrew Bennetts
 Shift protocol version querying from RemoteBzrDirFormat into SmartClientMedium.  | 
414  | 
def protocol_version(self):  | 
415  | 
return 1  | 
|
416  | 
||
| 
2432.3.2
by Andrew Bennetts
 Add test, and tidy implementation.  | 
417  | 
|
418  | 
class OldServerTransport(object):  | 
|
419  | 
"""A fake transport for test_old_server that reports it's smart server  | 
|
420  | 
    protocol version as version one.
 | 
|
421  | 
    """
 | 
|
422  | 
||
423  | 
def __init__(self):  | 
|
424  | 
self.base = 'fake:'  | 
|
425  | 
||
426  | 
def get_smart_client(self):  | 
|
427  | 
return OldSmartClient()  | 
|
428  | 
||
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
429  | 
|
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
430  | 
class TestBranchLastRevisionInfo(tests.TestCase):  | 
431  | 
||
432  | 
def test_empty_branch(self):  | 
|
433  | 
        # in an empty branch we decode the response properly
 | 
|
434  | 
transport = MemoryTransport()  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
435  | 
client = FakeClient(transport.base)  | 
436  | 
client.add_success_response('ok', '0', 'null:')  | 
|
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
437  | 
transport.mkdir('quack')  | 
438  | 
transport = transport.clone('quack')  | 
|
439  | 
        # we do not want bzrdir to make any remote calls
 | 
|
440  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
441  | 
branch = RemoteBranch(bzrdir, None, _client=client)  | 
|
442  | 
result = branch.last_revision_info()  | 
|
443  | 
||
444  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
445  | 
[('call', 'Branch.last_revision_info', ('quack/',))],  | 
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
446  | 
client._calls)  | 
447  | 
self.assertEqual((0, NULL_REVISION), result)  | 
|
448  | 
||
449  | 
def test_non_empty_branch(self):  | 
|
450  | 
        # 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.  | 
451  | 
revid = u'\xc8'.encode('utf8')  | 
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
452  | 
transport = MemoryTransport()  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
453  | 
client = FakeClient(transport.base)  | 
454  | 
client.add_success_response('ok', '2', revid)  | 
|
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
455  | 
transport.mkdir('kwaak')  | 
456  | 
transport = transport.clone('kwaak')  | 
|
457  | 
        # we do not want bzrdir to make any remote calls
 | 
|
458  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
459  | 
branch = RemoteBranch(bzrdir, None, _client=client)  | 
|
460  | 
result = branch.last_revision_info()  | 
|
461  | 
||
462  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
463  | 
[('call', 'Branch.last_revision_info', ('kwaak/',))],  | 
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
464  | 
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.  | 
465  | 
self.assertEqual((2, revid), result)  | 
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
466  | 
|
467  | 
||
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
468  | 
class TestBranchSetLastRevision(tests.TestCase):  | 
469  | 
||
470  | 
def test_set_empty(self):  | 
|
471  | 
        # set_revision_history([]) is translated to calling
 | 
|
472  | 
        # Branch.set_last_revision(path, '') on the wire.
 | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
473  | 
transport = MemoryTransport()  | 
474  | 
transport.mkdir('branch')  | 
|
475  | 
transport = transport.clone('branch')  | 
|
476  | 
||
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
477  | 
client = FakeClient(transport.base)  | 
478  | 
        # lock_write
 | 
|
479  | 
client.add_success_response('ok', 'branch token', 'repo token')  | 
|
480  | 
        # set_last_revision
 | 
|
481  | 
client.add_success_response('ok')  | 
|
482  | 
        # unlock
 | 
|
483  | 
client.add_success_response('ok')  | 
|
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
484  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
485  | 
branch = RemoteBranch(bzrdir, None, _client=client)  | 
|
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
486  | 
        # This is a hack to work around the problem that RemoteBranch currently
 | 
487  | 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 | 
|
488  | 
branch._ensure_real = lambda: None  | 
|
489  | 
branch.lock_write()  | 
|
490  | 
client._calls = []  | 
|
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
491  | 
result = branch.set_revision_history([])  | 
492  | 
self.assertEqual(  | 
|
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
493  | 
[('call', 'Branch.set_last_revision',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
494  | 
('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.  | 
495  | 
client._calls)  | 
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
496  | 
branch.unlock()  | 
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
497  | 
self.assertEqual(None, result)  | 
498  | 
||
499  | 
def test_set_nonempty(self):  | 
|
500  | 
        # set_revision_history([rev-id1, ..., rev-idN]) is translated to calling
 | 
|
501  | 
        # Branch.set_last_revision(path, rev-idN) on the wire.
 | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
502  | 
transport = MemoryTransport()  | 
503  | 
transport.mkdir('branch')  | 
|
504  | 
transport = transport.clone('branch')  | 
|
505  | 
||
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
506  | 
client = FakeClient(transport.base)  | 
507  | 
        # lock_write
 | 
|
508  | 
client.add_success_response('ok', 'branch token', 'repo token')  | 
|
509  | 
        # set_last_revision
 | 
|
510  | 
client.add_success_response('ok')  | 
|
511  | 
        # unlock
 | 
|
512  | 
client.add_success_response('ok')  | 
|
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
513  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
514  | 
branch = RemoteBranch(bzrdir, None, _client=client)  | 
|
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
515  | 
        # This is a hack to work around the problem that RemoteBranch currently
 | 
516  | 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 | 
|
517  | 
branch._ensure_real = lambda: None  | 
|
518  | 
        # Lock the branch, reset the record of remote calls.
 | 
|
519  | 
branch.lock_write()  | 
|
520  | 
client._calls = []  | 
|
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
521  | 
|
522  | 
result = branch.set_revision_history(['rev-id1', 'rev-id2'])  | 
|
523  | 
self.assertEqual(  | 
|
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
524  | 
[('call', 'Branch.set_last_revision',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
525  | 
('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.  | 
526  | 
client._calls)  | 
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
527  | 
branch.unlock()  | 
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
528  | 
self.assertEqual(None, result)  | 
529  | 
||
530  | 
def test_no_such_revision(self):  | 
|
531  | 
transport = MemoryTransport()  | 
|
532  | 
transport.mkdir('branch')  | 
|
533  | 
transport = transport.clone('branch')  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
534  | 
        # A response of 'NoSuchRevision' is translated into an exception.
 | 
535  | 
client = FakeClient(transport.base)  | 
|
536  | 
        # lock_write
 | 
|
537  | 
client.add_success_response('ok', 'branch token', 'repo token')  | 
|
538  | 
        # set_last_revision
 | 
|
539  | 
client.add_error_response('NoSuchRevision', 'rev-id')  | 
|
540  | 
        # unlock
 | 
|
541  | 
client.add_success_response('ok')  | 
|
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
542  | 
|
543  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
| 
3533.3.1
by Andrew Bennetts
 Remove duplication of error translation in bzrlib/remote.py.  | 
544  | 
repo = RemoteRepository(bzrdir, None, _client=client)  | 
545  | 
branch = RemoteBranch(bzrdir, repo, _client=client)  | 
|
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
546  | 
branch._ensure_real = lambda: None  | 
547  | 
branch.lock_write()  | 
|
548  | 
client._calls = []  | 
|
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
549  | 
|
550  | 
self.assertRaises(  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
551  | 
errors.NoSuchRevision, branch.set_revision_history, ['rev-id'])  | 
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
552  | 
branch.unlock()  | 
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
553  | 
|
| 
3577.1.1
by Andrew Bennetts
 Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.  | 
554  | 
def test_tip_change_rejected(self):  | 
555  | 
"""TipChangeRejected responses cause a TipChangeRejected exception to  | 
|
556  | 
        be raised.
 | 
|
557  | 
        """
 | 
|
558  | 
transport = MemoryTransport()  | 
|
559  | 
transport.mkdir('branch')  | 
|
560  | 
transport = transport.clone('branch')  | 
|
561  | 
client = FakeClient(transport.base)  | 
|
562  | 
        # lock_write
 | 
|
563  | 
client.add_success_response('ok', 'branch token', 'repo token')  | 
|
564  | 
        # set_last_revision
 | 
|
565  | 
rejection_msg_unicode = u'rejection message\N{INTERROBANG}'  | 
|
566  | 
rejection_msg_utf8 = rejection_msg_unicode.encode('utf8')  | 
|
567  | 
client.add_error_response('TipChangeRejected', rejection_msg_utf8)  | 
|
568  | 
        # unlock
 | 
|
569  | 
client.add_success_response('ok')  | 
|
570  | 
||
571  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
572  | 
repo = RemoteRepository(bzrdir, None, _client=client)  | 
|
573  | 
branch = RemoteBranch(bzrdir, repo, _client=client)  | 
|
574  | 
branch._ensure_real = lambda: None  | 
|
575  | 
branch.lock_write()  | 
|
576  | 
self.addCleanup(branch.unlock)  | 
|
577  | 
client._calls = []  | 
|
578  | 
||
579  | 
        # The 'TipChangeRejected' error response triggered by calling
 | 
|
580  | 
        # set_revision_history causes a TipChangeRejected exception.
 | 
|
581  | 
err = self.assertRaises(  | 
|
582  | 
errors.TipChangeRejected, branch.set_revision_history, ['rev-id'])  | 
|
583  | 
        # The UTF-8 message from the response has been decoded into a unicode
 | 
|
584  | 
        # object.
 | 
|
585  | 
self.assertIsInstance(err.msg, unicode)  | 
|
586  | 
self.assertEqual(rejection_msg_unicode, err.msg)  | 
|
587  | 
||
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
588  | 
|
| 
2892.2.1
by Andrew Bennetts
 Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.  | 
589  | 
class TestBranchSetLastRevisionInfo(tests.TestCase):  | 
590  | 
||
| 
3297.4.2
by Andrew Bennetts
 Add backwards compatibility for servers older than 1.4.  | 
591  | 
def test_set_last_revision_info(self):  | 
| 
2892.2.1
by Andrew Bennetts
 Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.  | 
592  | 
        # set_last_revision_info(num, 'rev-id') is translated to calling
 | 
593  | 
        # Branch.set_last_revision_info(num, 'rev-id') on the wire.
 | 
|
| 
3297.4.1
by Andrew Bennetts
 Merge 'Add Branch.set_last_revision_info smart method'.  | 
594  | 
transport = MemoryTransport()  | 
595  | 
transport.mkdir('branch')  | 
|
596  | 
transport = transport.clone('branch')  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
597  | 
client = FakeClient(transport.base)  | 
598  | 
        # lock_write
 | 
|
599  | 
client.add_success_response('ok', 'branch token', 'repo token')  | 
|
600  | 
        # set_last_revision
 | 
|
601  | 
client.add_success_response('ok')  | 
|
602  | 
        # unlock
 | 
|
603  | 
client.add_success_response('ok')  | 
|
| 
2892.2.1
by Andrew Bennetts
 Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.  | 
604  | 
|
605  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
606  | 
branch = RemoteBranch(bzrdir, None, _client=client)  | 
|
607  | 
        # This is a hack to work around the problem that RemoteBranch currently
 | 
|
608  | 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 | 
|
609  | 
branch._ensure_real = lambda: None  | 
|
610  | 
        # Lock the branch, reset the record of remote calls.
 | 
|
611  | 
branch.lock_write()  | 
|
612  | 
client._calls = []  | 
|
613  | 
result = branch.set_last_revision_info(1234, 'a-revision-id')  | 
|
614  | 
self.assertEqual(  | 
|
615  | 
[('call', 'Branch.set_last_revision_info',  | 
|
| 
3297.4.1
by Andrew Bennetts
 Merge 'Add Branch.set_last_revision_info smart method'.  | 
616  | 
('branch/', 'branch token', 'repo token',  | 
| 
2892.2.1
by Andrew Bennetts
 Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.  | 
617  | 
'1234', 'a-revision-id'))],  | 
618  | 
client._calls)  | 
|
619  | 
self.assertEqual(None, result)  | 
|
620  | 
||
621  | 
def test_no_such_revision(self):  | 
|
622  | 
        # A response of 'NoSuchRevision' is translated into an exception.
 | 
|
623  | 
transport = MemoryTransport()  | 
|
624  | 
transport.mkdir('branch')  | 
|
625  | 
transport = transport.clone('branch')  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
626  | 
client = FakeClient(transport.base)  | 
627  | 
        # lock_write
 | 
|
628  | 
client.add_success_response('ok', 'branch token', 'repo token')  | 
|
629  | 
        # set_last_revision
 | 
|
630  | 
client.add_error_response('NoSuchRevision', 'revid')  | 
|
631  | 
        # unlock
 | 
|
632  | 
client.add_success_response('ok')  | 
|
| 
2892.2.1
by Andrew Bennetts
 Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.  | 
633  | 
|
634  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
| 
3533.3.1
by Andrew Bennetts
 Remove duplication of error translation in bzrlib/remote.py.  | 
635  | 
repo = RemoteRepository(bzrdir, None, _client=client)  | 
636  | 
branch = RemoteBranch(bzrdir, repo, _client=client)  | 
|
| 
2892.2.1
by Andrew Bennetts
 Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.  | 
637  | 
        # This is a hack to work around the problem that RemoteBranch currently
 | 
638  | 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 | 
|
639  | 
branch._ensure_real = lambda: None  | 
|
640  | 
        # Lock the branch, reset the record of remote calls.
 | 
|
641  | 
branch.lock_write()  | 
|
642  | 
client._calls = []  | 
|
643  | 
||
644  | 
self.assertRaises(  | 
|
645  | 
errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')  | 
|
646  | 
branch.unlock()  | 
|
647  | 
||
| 
3297.4.2
by Andrew Bennetts
 Add backwards compatibility for servers older than 1.4.  | 
648  | 
def lock_remote_branch(self, branch):  | 
649  | 
"""Trick a RemoteBranch into thinking it is locked."""  | 
|
650  | 
branch._lock_mode = 'w'  | 
|
651  | 
branch._lock_count = 2  | 
|
652  | 
branch._lock_token = 'branch token'  | 
|
653  | 
branch._repo_lock_token = 'repo token'  | 
|
654  | 
||
655  | 
def test_backwards_compatibility(self):  | 
|
656  | 
"""If the server does not support the Branch.set_last_revision_info  | 
|
657  | 
        verb (which is new in 1.4), then the client falls back to VFS methods.
 | 
|
658  | 
        """
 | 
|
659  | 
        # This test is a little messy.  Unlike most tests in this file, it
 | 
|
660  | 
        # doesn't purely test what a Remote* object sends over the wire, and
 | 
|
661  | 
        # how it reacts to responses from the wire.  It instead relies partly
 | 
|
662  | 
        # on asserting that the RemoteBranch will call
 | 
|
663  | 
        # self._real_branch.set_last_revision_info(...).
 | 
|
664  | 
||
665  | 
        # First, set up our RemoteBranch with a FakeClient that raises
 | 
|
666  | 
        # UnknownSmartMethod, and a StubRealBranch that logs how it is called.
 | 
|
667  | 
transport = MemoryTransport()  | 
|
668  | 
transport.mkdir('branch')  | 
|
669  | 
transport = transport.clone('branch')  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
670  | 
client = FakeClient(transport.base)  | 
671  | 
client.add_unknown_method_response('Branch.set_last_revision_info')  | 
|
| 
3297.4.2
by Andrew Bennetts
 Add backwards compatibility for servers older than 1.4.  | 
672  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
673  | 
branch = RemoteBranch(bzrdir, None, _client=client)  | 
|
674  | 
class StubRealBranch(object):  | 
|
675  | 
def __init__(self):  | 
|
676  | 
self.calls = []  | 
|
677  | 
def set_last_revision_info(self, revno, revision_id):  | 
|
678  | 
self.calls.append(  | 
|
679  | 
('set_last_revision_info', revno, revision_id))  | 
|
| 
3441.5.5
by Andrew Bennetts
 Some small tweaks and comments.  | 
680  | 
def _clear_cached_state(self):  | 
681  | 
                pass
 | 
|
| 
3297.4.2
by Andrew Bennetts
 Add backwards compatibility for servers older than 1.4.  | 
682  | 
real_branch = StubRealBranch()  | 
683  | 
branch._real_branch = real_branch  | 
|
684  | 
self.lock_remote_branch(branch)  | 
|
685  | 
||
686  | 
        # Call set_last_revision_info, and verify it behaved as expected.
 | 
|
687  | 
result = branch.set_last_revision_info(1234, 'a-revision-id')  | 
|
688  | 
self.assertEqual(  | 
|
689  | 
[('call', 'Branch.set_last_revision_info',  | 
|
690  | 
('branch/', 'branch token', 'repo token',  | 
|
691  | 
'1234', 'a-revision-id')),],  | 
|
692  | 
client._calls)  | 
|
693  | 
self.assertEqual(  | 
|
694  | 
[('set_last_revision_info', 1234, 'a-revision-id')],  | 
|
695  | 
real_branch.calls)  | 
|
696  | 
||
| 
3245.4.53
by Andrew Bennetts
 Add some missing 'raise' statements to test_remote.  | 
697  | 
def test_unexpected_error(self):  | 
698  | 
        # A response of 'NoSuchRevision' is translated into an exception.
 | 
|
699  | 
transport = MemoryTransport()  | 
|
700  | 
transport.mkdir('branch')  | 
|
701  | 
transport = transport.clone('branch')  | 
|
702  | 
client = FakeClient(transport.base)  | 
|
703  | 
        # lock_write
 | 
|
704  | 
client.add_success_response('ok', 'branch token', 'repo token')  | 
|
705  | 
        # set_last_revision
 | 
|
706  | 
client.add_error_response('UnexpectedError')  | 
|
707  | 
        # unlock
 | 
|
708  | 
client.add_success_response('ok')  | 
|
709  | 
||
710  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
| 
3533.3.1
by Andrew Bennetts
 Remove duplication of error translation in bzrlib/remote.py.  | 
711  | 
repo = RemoteRepository(bzrdir, None, _client=client)  | 
712  | 
branch = RemoteBranch(bzrdir, repo, _client=client)  | 
|
| 
3245.4.53
by Andrew Bennetts
 Add some missing 'raise' statements to test_remote.  | 
713  | 
        # This is a hack to work around the problem that RemoteBranch currently
 | 
714  | 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 | 
|
715  | 
branch._ensure_real = lambda: None  | 
|
716  | 
        # Lock the branch, reset the record of remote calls.
 | 
|
717  | 
branch.lock_write()  | 
|
718  | 
client._calls = []  | 
|
719  | 
||
720  | 
err = self.assertRaises(  | 
|
721  | 
errors.ErrorFromSmartServer,  | 
|
722  | 
branch.set_last_revision_info, 123, 'revid')  | 
|
723  | 
self.assertEqual(('UnexpectedError',), err.error_tuple)  | 
|
724  | 
branch.unlock()  | 
|
725  | 
||
| 
3577.1.1
by Andrew Bennetts
 Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.  | 
726  | 
def test_tip_change_rejected(self):  | 
727  | 
"""TipChangeRejected responses cause a TipChangeRejected exception to  | 
|
728  | 
        be raised.
 | 
|
729  | 
        """
 | 
|
730  | 
transport = MemoryTransport()  | 
|
731  | 
transport.mkdir('branch')  | 
|
732  | 
transport = transport.clone('branch')  | 
|
733  | 
client = FakeClient(transport.base)  | 
|
734  | 
        # lock_write
 | 
|
735  | 
client.add_success_response('ok', 'branch token', 'repo token')  | 
|
736  | 
        # set_last_revision
 | 
|
737  | 
client.add_error_response('TipChangeRejected', 'rejection message')  | 
|
738  | 
        # unlock
 | 
|
739  | 
client.add_success_response('ok')  | 
|
740  | 
||
741  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
742  | 
repo = RemoteRepository(bzrdir, None, _client=client)  | 
|
743  | 
branch = RemoteBranch(bzrdir, repo, _client=client)  | 
|
744  | 
        # This is a hack to work around the problem that RemoteBranch currently
 | 
|
745  | 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 | 
|
746  | 
branch._ensure_real = lambda: None  | 
|
747  | 
        # Lock the branch, reset the record of remote calls.
 | 
|
748  | 
branch.lock_write()  | 
|
749  | 
self.addCleanup(branch.unlock)  | 
|
750  | 
client._calls = []  | 
|
751  | 
||
752  | 
        # The 'TipChangeRejected' error response triggered by calling
 | 
|
753  | 
        # set_last_revision_info causes a TipChangeRejected exception.
 | 
|
754  | 
err = self.assertRaises(  | 
|
755  | 
errors.TipChangeRejected,  | 
|
756  | 
branch.set_last_revision_info, 123, 'revid')  | 
|
757  | 
self.assertEqual('rejection message', err.msg)  | 
|
758  | 
||
| 
2892.2.1
by Andrew Bennetts
 Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.  | 
759  | 
|
| 
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.  | 
760  | 
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):  | 
| 
3408.3.1
by Martin Pool
 Remove erroneous handling of branch.conf for RemoteBranch  | 
761  | 
"""Getting the branch configuration should use an abstract method not vfs.  | 
| 
2018.5.59
by Robert Collins
 Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).  | 
762  | 
    """
 | 
763  | 
||
764  | 
def test_get_branch_conf(self):  | 
|
| 
3408.3.1
by Martin Pool
 Remove erroneous handling of branch.conf for RemoteBranch  | 
765  | 
raise tests.KnownFailure('branch.conf is not retrieved by get_config_file')  | 
| 
3407.2.10
by Martin Pool
 Merge trunk  | 
766  | 
        ## # We should see that branch.get_config() does a single rpc to get the
 | 
767  | 
        ## # remote configuration file, abstracting away where that is stored on
 | 
|
768  | 
        ## # the server.  However at the moment it always falls back to using the
 | 
|
769  | 
        ## # vfs, and this would need some changes in config.py.
 | 
|
| 
3408.3.1
by Martin Pool
 Remove erroneous handling of branch.conf for RemoteBranch  | 
770  | 
|
| 
3407.2.10
by Martin Pool
 Merge trunk  | 
771  | 
        ## # in an empty branch we decode the response properly
 | 
772  | 
        ## client = FakeClient([(('ok', ), '# config file body')], self.get_url())
 | 
|
773  | 
        ## # we need to make a real branch because the remote_branch.control_files
 | 
|
774  | 
        ## # will trigger _ensure_real.
 | 
|
775  | 
        ## branch = self.make_branch('quack')
 | 
|
776  | 
        ## transport = branch.bzrdir.root_transport
 | 
|
777  | 
        ## # we do not want bzrdir to make any remote calls
 | 
|
778  | 
        ## bzrdir = RemoteBzrDir(transport, _client=False)
 | 
|
779  | 
        ## branch = RemoteBranch(bzrdir, None, _client=client)
 | 
|
780  | 
        ## config = branch.get_config()
 | 
|
781  | 
        ## self.assertEqual(
 | 
|
782  | 
        ##     [('call_expecting_body', 'Branch.get_config_file', ('quack/',))],
 | 
|
783  | 
        ##     client._calls)
 | 
|
| 
2018.5.59
by Robert Collins
 Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).  | 
784  | 
|
785  | 
||
| 
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.  | 
786  | 
class TestBranchLockWrite(tests.TestCase):  | 
787  | 
||
788  | 
def test_lock_write_unlockable(self):  | 
|
789  | 
transport = MemoryTransport()  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
790  | 
client = FakeClient(transport.base)  | 
791  | 
client.add_error_response('UnlockableTransport')  | 
|
| 
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.  | 
792  | 
transport.mkdir('quack')  | 
793  | 
transport = transport.clone('quack')  | 
|
794  | 
        # we do not want bzrdir to make any remote calls
 | 
|
795  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
| 
3533.3.1
by Andrew Bennetts
 Remove duplication of error translation in bzrlib/remote.py.  | 
796  | 
repo = RemoteRepository(bzrdir, None, _client=client)  | 
797  | 
branch = RemoteBranch(bzrdir, repo, _client=client)  | 
|
| 
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.  | 
798  | 
self.assertRaises(errors.UnlockableTransport, branch.lock_write)  | 
799  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
800  | 
[('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.  | 
801  | 
client._calls)  | 
802  | 
||
803  | 
||
| 
2466.2.2
by Andrew Bennetts
 Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.  | 
804  | 
class TestTransportIsReadonly(tests.TestCase):  | 
805  | 
||
806  | 
def test_true(self):  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
807  | 
client = FakeClient()  | 
808  | 
client.add_success_response('yes')  | 
|
| 
2466.2.2
by Andrew Bennetts
 Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.  | 
809  | 
transport = RemoteTransport('bzr://example.com/', medium=False,  | 
810  | 
_client=client)  | 
|
811  | 
self.assertEqual(True, transport.is_readonly())  | 
|
812  | 
self.assertEqual(  | 
|
813  | 
[('call', 'Transport.is_readonly', ())],  | 
|
814  | 
client._calls)  | 
|
815  | 
||
816  | 
def test_false(self):  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
817  | 
client = FakeClient()  | 
818  | 
client.add_success_response('no')  | 
|
| 
2466.2.2
by Andrew Bennetts
 Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.  | 
819  | 
transport = RemoteTransport('bzr://example.com/', medium=False,  | 
820  | 
_client=client)  | 
|
821  | 
self.assertEqual(False, transport.is_readonly())  | 
|
822  | 
self.assertEqual(  | 
|
823  | 
[('call', 'Transport.is_readonly', ())],  | 
|
824  | 
client._calls)  | 
|
825  | 
||
826  | 
def test_error_from_old_server(self):  | 
|
827  | 
"""bzr 0.15 and earlier servers don't recognise the is_readonly verb.  | 
|
828  | 
        
 | 
|
829  | 
        Clients should treat it as a "no" response, because is_readonly is only
 | 
|
830  | 
        advisory anyway (a transport could be read-write, but then the
 | 
|
831  | 
        underlying filesystem could be readonly anyway).
 | 
|
832  | 
        """
 | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
833  | 
client = FakeClient()  | 
834  | 
client.add_unknown_method_response('Transport.is_readonly')  | 
|
| 
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.  | 
835  | 
transport = RemoteTransport('bzr://example.com/', medium=False,  | 
836  | 
_client=client)  | 
|
837  | 
self.assertEqual(False, transport.is_readonly())  | 
|
838  | 
self.assertEqual(  | 
|
839  | 
[('call', 'Transport.is_readonly', ())],  | 
|
840  | 
client._calls)  | 
|
841  | 
||
| 
2466.2.2
by Andrew Bennetts
 Add tests for RemoteTransport.is_readonly in the style of the other remote object tests.  | 
842  | 
|
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
843  | 
class TestRemoteRepository(tests.TestCase):  | 
| 
2018.18.9
by Martin Pool
 remote Repository.tarball builds a temporary directory and tars that  | 
844  | 
"""Base for testing RemoteRepository protocol usage.  | 
845  | 
    
 | 
|
846  | 
    These tests contain frozen requests and responses.  We want any changes to 
 | 
|
847  | 
    what is sent or expected to be require a thoughtful update to these tests
 | 
|
848  | 
    because they might break compatibility with different-versioned servers.
 | 
|
849  | 
    """
 | 
|
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
850  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
851  | 
def setup_fake_client_and_repository(self, transport_path):  | 
| 
2018.18.7
by Martin Pool
 (broken) Start addng client proxy test for Repository.tarball  | 
852  | 
"""Create the fake client and repository for testing with.  | 
853  | 
        
 | 
|
854  | 
        There's no real server here; we just have canned responses sent
 | 
|
855  | 
        back one by one.
 | 
|
856  | 
        
 | 
|
857  | 
        :param transport_path: Path below the root of the MemoryTransport
 | 
|
858  | 
            where the repository will be created.
 | 
|
859  | 
        """
 | 
|
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
860  | 
transport = MemoryTransport()  | 
861  | 
transport.mkdir(transport_path)  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
862  | 
client = FakeClient(transport.base)  | 
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
863  | 
transport = transport.clone(transport_path)  | 
864  | 
        # we do not want bzrdir to make any remote calls
 | 
|
865  | 
bzrdir = RemoteBzrDir(transport, _client=False)  | 
|
866  | 
repo = RemoteRepository(bzrdir, None, _client=client)  | 
|
867  | 
return repo, client  | 
|
868  | 
||
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
869  | 
|
| 
2018.12.2
by Andrew Bennetts
 Remove some duplicate code in test_remote  | 
870  | 
class TestRepositoryGatherStats(TestRemoteRepository):  | 
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
871  | 
|
872  | 
def test_revid_none(self):  | 
|
873  | 
        # ('ok',), body with revisions and size
 | 
|
874  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
875  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
876  | 
client.add_success_response_with_body(  | 
|
877  | 
'revisions: 2\nsize: 18\n', 'ok')  | 
|
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
878  | 
result = repo.gather_stats(None)  | 
879  | 
self.assertEqual(  | 
|
| 
2018.5.153
by Andrew Bennetts
 Rename call2 to call_expecting_body, and other small changes prompted by review.  | 
880  | 
[('call_expecting_body', 'Repository.gather_stats',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
881  | 
('quack/','','no'))],  | 
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
882  | 
client._calls)  | 
883  | 
self.assertEqual({'revisions': 2, 'size': 18}, result)  | 
|
884  | 
||
885  | 
def test_revid_no_committers(self):  | 
|
886  | 
        # ('ok',), body without committers
 | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
887  | 
body = ('firstrev: 123456.300 3600\n'  | 
888  | 
'latestrev: 654231.400 0\n'  | 
|
889  | 
'revisions: 2\n'  | 
|
890  | 
'size: 18\n')  | 
|
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
891  | 
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.  | 
892  | 
revid = u'\xc8'.encode('utf8')  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
893  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
894  | 
client.add_success_response_with_body(body, 'ok')  | 
|
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
895  | 
result = repo.gather_stats(revid)  | 
896  | 
self.assertEqual(  | 
|
| 
2018.5.153
by Andrew Bennetts
 Rename call2 to call_expecting_body, and other small changes prompted by review.  | 
897  | 
[('call_expecting_body', 'Repository.gather_stats',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
898  | 
('quick/', revid, 'no'))],  | 
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
899  | 
client._calls)  | 
900  | 
self.assertEqual({'revisions': 2, 'size': 18,  | 
|
901  | 
'firstrev': (123456.300, 3600),  | 
|
902  | 
'latestrev': (654231.400, 0),},  | 
|
903  | 
result)  | 
|
904  | 
||
905  | 
def test_revid_with_committers(self):  | 
|
906  | 
        # ('ok',), body with committers
 | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
907  | 
body = ('committers: 128\n'  | 
908  | 
'firstrev: 123456.300 3600\n'  | 
|
909  | 
'latestrev: 654231.400 0\n'  | 
|
910  | 
'revisions: 2\n'  | 
|
911  | 
'size: 18\n')  | 
|
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
912  | 
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.  | 
913  | 
revid = u'\xc8'.encode('utf8')  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
914  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
915  | 
client.add_success_response_with_body(body, 'ok')  | 
|
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
916  | 
result = repo.gather_stats(revid, True)  | 
917  | 
self.assertEqual(  | 
|
| 
2018.5.153
by Andrew Bennetts
 Rename call2 to call_expecting_body, and other small changes prompted by review.  | 
918  | 
[('call_expecting_body', 'Repository.gather_stats',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
919  | 
('buick/', revid, 'yes'))],  | 
| 
2018.10.3
by v.ladeuil+lp at free
 more tests for gather_stats  | 
920  | 
client._calls)  | 
921  | 
self.assertEqual({'revisions': 2, 'size': 18,  | 
|
922  | 
'committers': 128,  | 
|
923  | 
'firstrev': (123456.300, 3600),  | 
|
924  | 
'latestrev': (654231.400, 0),},  | 
|
925  | 
result)  | 
|
926  | 
||
927  | 
||
| 
3172.5.4
by Robert Collins
 Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.  | 
928  | 
class TestRepositoryGetGraph(TestRemoteRepository):  | 
929  | 
||
930  | 
def test_get_graph(self):  | 
|
| 
3172.5.8
by Robert Collins
 Review feedback.  | 
931  | 
        # get_graph returns a graph with the repository as the
 | 
932  | 
        # parents_provider.
 | 
|
| 
3172.5.4
by Robert Collins
 Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.  | 
933  | 
transport_path = 'quack'  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
934  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
| 
3172.5.4
by Robert Collins
 Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.  | 
935  | 
graph = repo.get_graph()  | 
| 
3441.5.24
by Andrew Bennetts
 Remove RemoteGraph experiment.  | 
936  | 
self.assertEqual(graph._parents_provider, repo)  | 
| 
3172.5.4
by Robert Collins
 Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.  | 
937  | 
|
938  | 
||
939  | 
class TestRepositoryGetParentMap(TestRemoteRepository):  | 
|
940  | 
||
941  | 
def test_get_parent_map_caching(self):  | 
|
942  | 
        # get_parent_map returns from cache until unlock()
 | 
|
943  | 
        # setup a reponse with two revisions
 | 
|
944  | 
r1 = u'\u0e33'.encode('utf8')  | 
|
945  | 
r2 = u'\u0dab'.encode('utf8')  | 
|
946  | 
lines = [' '.join([r2, r1]), r1]  | 
|
| 
3211.5.2
by Robert Collins
 Change RemoteRepository.get_parent_map to use bz2 not gzip for compression.  | 
947  | 
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.  | 
948  | 
|
949  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
950  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
951  | 
client.add_success_response_with_body(encoded_body, 'ok')  | 
|
952  | 
client.add_success_response_with_body(encoded_body, 'ok')  | 
|
| 
3172.5.4
by Robert Collins
 Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.  | 
953  | 
repo.lock_read()  | 
954  | 
graph = repo.get_graph()  | 
|
955  | 
parents = graph.get_parent_map([r2])  | 
|
956  | 
self.assertEqual({r2: (r1,)}, parents)  | 
|
957  | 
        # locking and unlocking deeper should not reset
 | 
|
958  | 
repo.lock_read()  | 
|
959  | 
repo.unlock()  | 
|
960  | 
parents = graph.get_parent_map([r1])  | 
|
| 
3172.5.6
by Robert Collins
 Create new smart server verb Repository.get_parent_map.  | 
961  | 
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.  | 
962  | 
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.  | 
963  | 
[('call_with_body_bytes_expecting_body',  | 
964  | 
'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.  | 
965  | 
client._calls)  | 
966  | 
repo.unlock()  | 
|
967  | 
        # now we call again, and it should use the second response.
 | 
|
968  | 
repo.lock_read()  | 
|
969  | 
graph = repo.get_graph()  | 
|
| 
3172.5.6
by Robert Collins
 Create new smart server verb Repository.get_parent_map.  | 
970  | 
parents = graph.get_parent_map([r1])  | 
971  | 
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.  | 
972  | 
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.  | 
973  | 
[('call_with_body_bytes_expecting_body',  | 
974  | 
'Repository.get_parent_map', ('quack/', r2), '\n\n0'),  | 
|
975  | 
('call_with_body_bytes_expecting_body',  | 
|
976  | 
'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.  | 
977  | 
            ],
 | 
978  | 
client._calls)  | 
|
979  | 
repo.unlock()  | 
|
980  | 
||
| 
3213.1.2
by Andrew Bennetts
 Add test for reconnection if get_parent_map is unknown by the server.  | 
981  | 
def test_get_parent_map_reconnects_if_unknown_method(self):  | 
982  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
983  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
984  | 
client.add_unknown_method_response('Repository,get_parent_map')  | 
|
985  | 
client.add_success_response_with_body('', 'ok')  | 
|
| 
3453.4.10
by Andrew Bennetts
 Change _is_remote_at_least to _is_remote_before.  | 
986  | 
self.assertFalse(client._medium._is_remote_before((1, 2)))  | 
| 
3213.1.2
by Andrew Bennetts
 Add test for reconnection if get_parent_map is unknown by the server.  | 
987  | 
rev_id = 'revision-id'  | 
| 
3297.3.5
by Andrew Bennetts
 Suppress a deprecation warning.  | 
988  | 
expected_deprecations = [  | 
989  | 
            'bzrlib.remote.RemoteRepository.get_revision_graph was deprecated '
 | 
|
990  | 
'in version 1.4.']  | 
|
991  | 
parents = self.callDeprecated(  | 
|
992  | 
expected_deprecations, repo.get_parent_map, [rev_id])  | 
|
| 
3213.1.2
by Andrew Bennetts
 Add test for reconnection if get_parent_map is unknown by the server.  | 
993  | 
self.assertEqual(  | 
| 
3213.1.8
by Andrew Bennetts
 Merge from bzr.dev.  | 
994  | 
[('call_with_body_bytes_expecting_body',  | 
995  | 
'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.  | 
996  | 
('disconnect medium',),  | 
997  | 
('call_expecting_body', 'Repository.get_revision_graph',  | 
|
998  | 
('quack/', ''))],  | 
|
999  | 
client._calls)  | 
|
| 
3389.1.2
by Andrew Bennetts
 Add test for the bug John found.  | 
1000  | 
        # The medium is now marked as being connected to an older server
 | 
| 
3453.4.10
by Andrew Bennetts
 Change _is_remote_at_least to _is_remote_before.  | 
1001  | 
self.assertTrue(client._medium._is_remote_before((1, 2)))  | 
| 
3389.1.2
by Andrew Bennetts
 Add test for the bug John found.  | 
1002  | 
|
1003  | 
def test_get_parent_map_fallback_parentless_node(self):  | 
|
1004  | 
"""get_parent_map falls back to get_revision_graph on old servers. The  | 
|
1005  | 
        results from get_revision_graph are tweaked to match the get_parent_map
 | 
|
1006  | 
        API.
 | 
|
1007  | 
||
| 
3389.1.3
by Andrew Bennetts
 Remove XXX from test description.  | 
1008  | 
        Specifically, a {key: ()} result from get_revision_graph means "no
 | 
| 
3389.1.2
by Andrew Bennetts
 Add test for the bug John found.  | 
1009  | 
        parents" for that key, which in get_parent_map results should be
 | 
| 
3389.1.3
by Andrew Bennetts
 Remove XXX from test description.  | 
1010  | 
        represented as {key: ('null:',)}.
 | 
| 
3389.1.2
by Andrew Bennetts
 Add test for the bug John found.  | 
1011  | 
|
1012  | 
        This is the test for https://bugs.launchpad.net/bzr/+bug/214894
 | 
|
1013  | 
        """
 | 
|
1014  | 
rev_id = 'revision-id'  | 
|
1015  | 
transport_path = 'quack'  | 
|
| 
3245.4.40
by Andrew Bennetts
 Merge from bzr.dev.  | 
1016  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1017  | 
client.add_success_response_with_body(rev_id, 'ok')  | 
|
| 
3453.4.9
by Andrew Bennetts
 Rename _remote_is_not to _remember_remote_is_before.  | 
1018  | 
client._medium._remember_remote_is_before((1, 2))  | 
| 
3389.1.2
by Andrew Bennetts
 Add test for the bug John found.  | 
1019  | 
expected_deprecations = [  | 
1020  | 
            'bzrlib.remote.RemoteRepository.get_revision_graph was deprecated '
 | 
|
1021  | 
'in version 1.4.']  | 
|
1022  | 
parents = self.callDeprecated(  | 
|
1023  | 
expected_deprecations, repo.get_parent_map, [rev_id])  | 
|
1024  | 
self.assertEqual(  | 
|
1025  | 
[('call_expecting_body', 'Repository.get_revision_graph',  | 
|
1026  | 
('quack/', ''))],  | 
|
1027  | 
client._calls)  | 
|
1028  | 
self.assertEqual({rev_id: ('null:',)}, parents)  | 
|
| 
3213.1.2
by Andrew Bennetts
 Add test for reconnection if get_parent_map is unknown by the server.  | 
1029  | 
|
| 
3297.2.3
by Andrew Bennetts
 Test the code path that the typo is on.  | 
1030  | 
def test_get_parent_map_unexpected_response(self):  | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1031  | 
repo, client = self.setup_fake_client_and_repository('path')  | 
1032  | 
client.add_success_response('something unexpected!')  | 
|
| 
3297.2.3
by Andrew Bennetts
 Test the code path that the typo is on.  | 
1033  | 
self.assertRaises(  | 
1034  | 
errors.UnexpectedSmartServerResponse,  | 
|
1035  | 
repo.get_parent_map, ['a-revision-id'])  | 
|
| 
3213.1.2
by Andrew Bennetts
 Add test for reconnection if get_parent_map is unknown by the server.  | 
1036  | 
|
| 
3172.5.4
by Robert Collins
 Implement get_parent_map for RemoteRepository with caching, based on get_revision_graph.  | 
1037  | 
|
| 
2018.5.68
by Wouter van Heyst
 Merge RemoteRepository.gather_stats.  | 
1038  | 
class TestRepositoryGetRevisionGraph(TestRemoteRepository):  | 
1039  | 
||
1040  | 
def test_null_revision(self):  | 
|
1041  | 
        # a null revision has the predictable result {}, we should have no wire
 | 
|
1042  | 
        # traffic when calling it with this argument
 | 
|
1043  | 
transport_path = 'empty'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1044  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1045  | 
client.add_success_response('notused')  | 
|
| 
3287.6.4
by Robert Collins
 Fix up deprecation warnings for get_revision_graph.  | 
1046  | 
result = self.applyDeprecated(one_four, repo.get_revision_graph,  | 
1047  | 
NULL_REVISION)  | 
|
| 
2018.5.68
by Wouter van Heyst
 Merge RemoteRepository.gather_stats.  | 
1048  | 
self.assertEqual([], client._calls)  | 
1049  | 
self.assertEqual({}, result)  | 
|
1050  | 
||
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1051  | 
def test_none_revision(self):  | 
1052  | 
        # 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.  | 
1053  | 
r1 = u'\u0e33'.encode('utf8')  | 
1054  | 
r2 = u'\u0dab'.encode('utf8')  | 
|
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1055  | 
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.  | 
1056  | 
encoded_body = '\n'.join(lines)  | 
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1057  | 
|
1058  | 
transport_path = 'sinhala'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1059  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1060  | 
client.add_success_response_with_body(encoded_body, 'ok')  | 
|
| 
3287.6.4
by Robert Collins
 Fix up deprecation warnings for get_revision_graph.  | 
1061  | 
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)  | 
1062  | 
self.assertEqual(  | 
| 
2018.5.153
by Andrew Bennetts
 Rename call2 to call_expecting_body, and other small changes prompted by review.  | 
1063  | 
[('call_expecting_body', 'Repository.get_revision_graph',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1064  | 
('sinhala/', ''))],  | 
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1065  | 
client._calls)  | 
| 
2625.8.1
by Robert Collins
 LIBRARY API BREAKS:  | 
1066  | 
self.assertEqual({r1: (), r2: (r1, )}, result)  | 
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1067  | 
|
1068  | 
def test_specific_revision(self):  | 
|
1069  | 
        # with a specific revision we want the graph for that
 | 
|
1070  | 
        # 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.  | 
1071  | 
r11 = u'\u0e33'.encode('utf8')  | 
1072  | 
r12 = u'\xc9'.encode('utf8')  | 
|
1073  | 
r2 = u'\u0dab'.encode('utf8')  | 
|
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1074  | 
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.  | 
1075  | 
encoded_body = '\n'.join(lines)  | 
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1076  | 
|
1077  | 
transport_path = 'sinhala'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1078  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1079  | 
client.add_success_response_with_body(encoded_body, 'ok')  | 
|
| 
3287.6.4
by Robert Collins
 Fix up deprecation warnings for get_revision_graph.  | 
1080  | 
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)  | 
1081  | 
self.assertEqual(  | 
| 
2018.5.153
by Andrew Bennetts
 Rename call2 to call_expecting_body, and other small changes prompted by review.  | 
1082  | 
[('call_expecting_body', 'Repository.get_revision_graph',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1083  | 
('sinhala/', r2))],  | 
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1084  | 
client._calls)  | 
| 
2625.8.1
by Robert Collins
 LIBRARY API BREAKS:  | 
1085  | 
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)  | 
1086  | 
|
1087  | 
def test_no_such_revision(self):  | 
|
1088  | 
revid = '123'  | 
|
1089  | 
transport_path = 'sinhala'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1090  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1091  | 
client.add_error_response('nosuchrevision', revid)  | 
|
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1092  | 
        # 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  | 
1093  | 
self.assertRaises(errors.NoSuchRevision,  | 
| 
3287.6.4
by Robert Collins
 Fix up deprecation warnings for get_revision_graph.  | 
1094  | 
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)  | 
1095  | 
self.assertEqual(  | 
| 
2018.5.153
by Andrew Bennetts
 Rename call2 to call_expecting_body, and other small changes prompted by review.  | 
1096  | 
[('call_expecting_body', 'Repository.get_revision_graph',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1097  | 
('sinhala/', revid))],  | 
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1098  | 
client._calls)  | 
1099  | 
||
| 
3245.4.53
by Andrew Bennetts
 Add some missing 'raise' statements to test_remote.  | 
1100  | 
def test_unexpected_error(self):  | 
1101  | 
revid = '123'  | 
|
1102  | 
transport_path = 'sinhala'  | 
|
1103  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
|
1104  | 
client.add_error_response('AnUnexpectedError')  | 
|
1105  | 
e = self.assertRaises(errors.ErrorFromSmartServer,  | 
|
1106  | 
self.applyDeprecated, one_four, repo.get_revision_graph, revid)  | 
|
1107  | 
self.assertEqual(('AnUnexpectedError',), e.error_tuple)  | 
|
1108  | 
||
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
1109  | 
|
1110  | 
class TestRepositoryIsShared(TestRemoteRepository):  | 
|
1111  | 
||
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
1112  | 
def test_is_shared(self):  | 
1113  | 
        # ('yes', ) for Repository.is_shared -> 'True'.
 | 
|
1114  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1115  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1116  | 
client.add_success_response('yes')  | 
|
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
1117  | 
result = repo.is_shared()  | 
1118  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1119  | 
[('call', 'Repository.is_shared', ('quack/',))],  | 
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
1120  | 
client._calls)  | 
1121  | 
self.assertEqual(True, result)  | 
|
1122  | 
||
1123  | 
def test_is_not_shared(self):  | 
|
1124  | 
        # ('no', ) for Repository.is_shared -> 'False'.
 | 
|
1125  | 
transport_path = 'qwack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1126  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1127  | 
client.add_success_response('no')  | 
|
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
1128  | 
result = repo.is_shared()  | 
1129  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1130  | 
[('call', 'Repository.is_shared', ('qwack/',))],  | 
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
1131  | 
client._calls)  | 
1132  | 
self.assertEqual(False, result)  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
1133  | 
|
1134  | 
||
1135  | 
class TestRepositoryLockWrite(TestRemoteRepository):  | 
|
1136  | 
||
1137  | 
def test_lock_write(self):  | 
|
1138  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1139  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1140  | 
client.add_success_response('ok', 'a token')  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
1141  | 
result = repo.lock_write()  | 
1142  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1143  | 
[('call', 'Repository.lock_write', ('quack/', ''))],  | 
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
1144  | 
client._calls)  | 
1145  | 
self.assertEqual('a token', result)  | 
|
1146  | 
||
1147  | 
def test_lock_write_already_locked(self):  | 
|
1148  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1149  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1150  | 
client.add_error_response('LockContention')  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
1151  | 
self.assertRaises(errors.LockContention, repo.lock_write)  | 
1152  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1153  | 
[('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.  | 
1154  | 
client._calls)  | 
1155  | 
||
1156  | 
def test_lock_write_unlockable(self):  | 
|
1157  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1158  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1159  | 
client.add_error_response('UnlockableTransport')  | 
|
| 
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.  | 
1160  | 
self.assertRaises(errors.UnlockableTransport, repo.lock_write)  | 
1161  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1162  | 
[('call', 'Repository.lock_write', ('quack/', ''))],  | 
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
1163  | 
client._calls)  | 
1164  | 
||
1165  | 
||
1166  | 
class TestRepositoryUnlock(TestRemoteRepository):  | 
|
1167  | 
||
1168  | 
def test_unlock(self):  | 
|
1169  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1170  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1171  | 
client.add_success_response('ok', 'a token')  | 
|
1172  | 
client.add_success_response('ok')  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
1173  | 
repo.lock_write()  | 
1174  | 
repo.unlock()  | 
|
1175  | 
self.assertEqual(  | 
|
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1176  | 
[('call', 'Repository.lock_write', ('quack/', '')),  | 
1177  | 
('call', 'Repository.unlock', ('quack/', 'a token'))],  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
1178  | 
client._calls)  | 
1179  | 
||
1180  | 
def test_unlock_wrong_token(self):  | 
|
1181  | 
        # If somehow the token is wrong, unlock will raise TokenMismatch.
 | 
|
1182  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1183  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1184  | 
client.add_success_response('ok', 'a token')  | 
|
1185  | 
client.add_error_response('TokenMismatch')  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
1186  | 
repo.lock_write()  | 
1187  | 
self.assertRaises(errors.TokenMismatch, repo.unlock)  | 
|
1188  | 
||
1189  | 
||
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
1190  | 
class TestRepositoryHasRevision(TestRemoteRepository):  | 
1191  | 
||
1192  | 
def test_none(self):  | 
|
1193  | 
        # repo.has_revision(None) should not cause any traffic.
 | 
|
1194  | 
transport_path = 'quack'  | 
|
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1195  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
1196  | 
|
1197  | 
        # The null revision is always there, so has_revision(None) == True.
 | 
|
| 
3172.3.3
by Robert Collins
 Missed one occurence of None -> NULL_REVISION.  | 
1198  | 
self.assertEqual(True, repo.has_revision(NULL_REVISION))  | 
| 
2018.14.1
by Andrew Bennetts
 Update to current hpss branch? Fix lots of test failures.  | 
1199  | 
|
1200  | 
        # The remote repo shouldn't be accessed.
 | 
|
1201  | 
self.assertEqual([], client._calls)  | 
|
| 
2018.18.7
by Martin Pool
 (broken) Start addng client proxy test for Repository.tarball  | 
1202  | 
|
1203  | 
||
1204  | 
class TestRepositoryTarball(TestRemoteRepository):  | 
|
1205  | 
||
| 
2018.18.9
by Martin Pool
 remote Repository.tarball builds a temporary directory and tars that  | 
1206  | 
    # This is a canned tarball reponse we can validate against
 | 
| 
2018.18.18
by Martin Pool
 reformat  | 
1207  | 
tarball_content = (  | 
| 
2018.18.23
by Martin Pool
 review cleanups  | 
1208  | 
        'QlpoOTFBWSZTWdGkj3wAAWF/k8aQACBIB//A9+8cIX/v33AACEAYABAECEACNz'
 | 
1209  | 
        'JqsgJJFPTSnk1A3qh6mTQAAAANPUHkagkSTEkaA09QaNAAAGgAAAcwCYCZGAEY'
 | 
|
1210  | 
        'mJhMJghpiaYBUkKammSHqNMZQ0NABkNAeo0AGneAevnlwQoGzEzNVzaYxp/1Uk'
 | 
|
1211  | 
        'xXzA1CQX0BJMZZLcPBrluJir5SQyijWHYZ6ZUtVqqlYDdB2QoCwa9GyWwGYDMA'
 | 
|
1212  | 
        'OQYhkpLt/OKFnnlT8E0PmO8+ZNSo2WWqeCzGB5fBXZ3IvV7uNJVE7DYnWj6qwB'
 | 
|
1213  | 
        'k5DJDIrQ5OQHHIjkS9KqwG3mc3t+F1+iujb89ufyBNIKCgeZBWrl5cXxbMGoMs'
 | 
|
1214  | 
        'c9JuUkg5YsiVcaZJurc6KLi6yKOkgCUOlIlOpOoXyrTJjK8ZgbklReDdwGmFgt'
 | 
|
1215  | 
        'dkVsAIslSVCd4AtACSLbyhLHryfb14PKegrVDba+U8OL6KQtzdM5HLjAc8/p6n'
 | 
|
1216  | 
        '0lgaWU8skgO7xupPTkyuwheSckejFLK5T4ZOo0Gda9viaIhpD1Qn7JqqlKAJqC'
 | 
|
1217  | 
        'QplPKp2nqBWAfwBGaOwVrz3y1T+UZZNismXHsb2Jq18T+VaD9k4P8DqE3g70qV'
 | 
|
1218  | 
        'JLurpnDI6VS5oqDDPVbtVjMxMxMg4rzQVipn2Bv1fVNK0iq3Gl0hhnnHKm/egy'
 | 
|
1219  | 
        'nWQ7QH/F3JFOFCQ0aSPfA='
 | 
|
1220  | 
).decode('base64')  | 
|
| 
2018.18.9
by Martin Pool
 remote Repository.tarball builds a temporary directory and tars that  | 
1221  | 
|
| 
2018.18.7
by Martin Pool
 (broken) Start addng client proxy test for Repository.tarball  | 
1222  | 
def test_repository_tarball(self):  | 
| 
2018.18.9
by Martin Pool
 remote Repository.tarball builds a temporary directory and tars that  | 
1223  | 
        # Test that Repository.tarball generates the right operations
 | 
| 
2018.18.7
by Martin Pool
 (broken) Start addng client proxy test for Repository.tarball  | 
1224  | 
transport_path = 'repo'  | 
| 
2018.18.14
by Martin Pool
 merge hpss again; restore incorrectly removed RemoteRepository.break_lock  | 
1225  | 
expected_calls = [('call_expecting_body', 'Repository.tarball',  | 
| 
3104.4.2
by Andrew Bennetts
 All tests passing.  | 
1226  | 
('repo/', 'bz2',),),  | 
| 
2018.18.7
by Martin Pool
 (broken) Start addng client proxy test for Repository.tarball  | 
1227  | 
            ]
 | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1228  | 
repo, client = self.setup_fake_client_and_repository(transport_path)  | 
1229  | 
client.add_success_response_with_body(self.tarball_content, 'ok')  | 
|
| 
2018.18.7
by Martin Pool
 (broken) Start addng client proxy test for Repository.tarball  | 
1230  | 
        # Now actually ask for the tarball
 | 
| 
3245.4.24
by Andrew Bennetts
 Consistently raise errors from the server as ErrorFromSmartServer exceptions.  | 
1231  | 
tarball_file = repo._get_tarball('bz2')  | 
| 
2018.18.25
by Martin Pool
 Repository.tarball fixes for python2.4  | 
1232  | 
try:  | 
1233  | 
self.assertEqual(expected_calls, client._calls)  | 
|
1234  | 
self.assertEqual(self.tarball_content, tarball_file.read())  | 
|
1235  | 
finally:  | 
|
1236  | 
tarball_file.close()  | 
|
| 
2018.18.9
by Martin Pool
 remote Repository.tarball builds a temporary directory and tars that  | 
1237  | 
|
1238  | 
||
1239  | 
class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):  | 
|
1240  | 
"""RemoteRepository.copy_content_into optimizations"""  | 
|
1241  | 
||
| 
2018.18.10
by Martin Pool
 copy_content_into from Remote repositories by using temporary directories on both ends.  | 
1242  | 
def test_copy_content_remote_to_local(self):  | 
1243  | 
self.transport_server = server.SmartTCPServer_for_testing  | 
|
1244  | 
src_repo = self.make_repository('repo1')  | 
|
1245  | 
src_repo = repository.Repository.open(self.get_url('repo1'))  | 
|
1246  | 
        # At the moment the tarball-based copy_content_into can't write back
 | 
|
1247  | 
        # into a smart server.  It would be good if it could upload the
 | 
|
1248  | 
        # tarball; once that works we'd have to create repositories of
 | 
|
1249  | 
        # different formats. -- mbp 20070410
 | 
|
1250  | 
dest_url = self.get_vfs_only_url('repo2')  | 
|
1251  | 
dest_bzrdir = BzrDir.create(dest_url)  | 
|
1252  | 
dest_repo = dest_bzrdir.create_repository()  | 
|
1253  | 
self.assertFalse(isinstance(dest_repo, RemoteRepository))  | 
|
1254  | 
self.assertTrue(isinstance(src_repo, RemoteRepository))  | 
|
1255  | 
src_repo.copy_content_into(dest_repo)  | 
|
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1256  | 
|
1257  | 
||
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1258  | 
class TestErrorTranslationBase(tests.TestCaseWithMemoryTransport):  | 
1259  | 
"""Base class for unit tests for bzrlib.remote._translate_error."""  | 
|
1260  | 
||
1261  | 
def translateTuple(self, error_tuple, **context):  | 
|
1262  | 
"""Call _translate_error with an ErrorFromSmartServer built from the  | 
|
1263  | 
        given error_tuple.
 | 
|
1264  | 
||
1265  | 
        :param error_tuple: A tuple of a smart server response, as would be
 | 
|
1266  | 
            passed to an ErrorFromSmartServer.
 | 
|
1267  | 
        :kwargs context: context items to call _translate_error with.
 | 
|
1268  | 
||
1269  | 
        :returns: The error raised by _translate_error.
 | 
|
1270  | 
        """
 | 
|
1271  | 
        # Raise the ErrorFromSmartServer before passing it as an argument,
 | 
|
1272  | 
        # because _translate_error may need to re-raise it with a bare 'raise'
 | 
|
1273  | 
        # statement.
 | 
|
1274  | 
server_error = errors.ErrorFromSmartServer(error_tuple)  | 
|
1275  | 
translated_error = self.translateErrorFromSmartServer(  | 
|
1276  | 
server_error, **context)  | 
|
1277  | 
return translated_error  | 
|
1278  | 
||
1279  | 
def translateErrorFromSmartServer(self, error_object, **context):  | 
|
1280  | 
"""Like translateTuple, but takes an already constructed  | 
|
1281  | 
        ErrorFromSmartServer rather than a tuple.
 | 
|
1282  | 
        """
 | 
|
1283  | 
try:  | 
|
1284  | 
raise error_object  | 
|
1285  | 
except errors.ErrorFromSmartServer, server_error:  | 
|
1286  | 
translated_error = self.assertRaises(  | 
|
1287  | 
errors.BzrError, remote._translate_error, server_error,  | 
|
1288  | 
**context)  | 
|
1289  | 
return translated_error  | 
|
1290  | 
||
1291  | 
||
1292  | 
class TestErrorTranslationSuccess(TestErrorTranslationBase):  | 
|
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1293  | 
"""Unit tests for bzrlib.remote._translate_error.  | 
1294  | 
    
 | 
|
1295  | 
    Given an ErrorFromSmartServer (which has an error tuple from a smart
 | 
|
1296  | 
    server) and some context, _translate_error raises more specific errors from
 | 
|
1297  | 
    bzrlib.errors.
 | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1298  | 
|
1299  | 
    This test case covers the cases where _translate_error succeeds in
 | 
|
1300  | 
    translating an ErrorFromSmartServer to something better.  See
 | 
|
1301  | 
    TestErrorTranslationRobustness for other cases.
 | 
|
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1302  | 
    """
 | 
1303  | 
||
1304  | 
def test_NoSuchRevision(self):  | 
|
1305  | 
branch = self.make_branch('')  | 
|
1306  | 
revid = 'revid'  | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1307  | 
translated_error = self.translateTuple(  | 
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1308  | 
('NoSuchRevision', revid), branch=branch)  | 
1309  | 
expected_error = errors.NoSuchRevision(branch, revid)  | 
|
1310  | 
self.assertEqual(expected_error, translated_error)  | 
|
1311  | 
||
1312  | 
def test_nosuchrevision(self):  | 
|
1313  | 
repository = self.make_repository('')  | 
|
1314  | 
revid = 'revid'  | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1315  | 
translated_error = self.translateTuple(  | 
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1316  | 
('nosuchrevision', revid), repository=repository)  | 
1317  | 
expected_error = errors.NoSuchRevision(repository, revid)  | 
|
1318  | 
self.assertEqual(expected_error, translated_error)  | 
|
1319  | 
||
1320  | 
def test_nobranch(self):  | 
|
1321  | 
bzrdir = self.make_bzrdir('')  | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1322  | 
translated_error = self.translateTuple(('nobranch',), bzrdir=bzrdir)  | 
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1323  | 
expected_error = errors.NotBranchError(path=bzrdir.root_transport.base)  | 
1324  | 
self.assertEqual(expected_error, translated_error)  | 
|
1325  | 
||
1326  | 
def test_LockContention(self):  | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1327  | 
translated_error = self.translateTuple(('LockContention',))  | 
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1328  | 
expected_error = errors.LockContention('(remote lock)')  | 
1329  | 
self.assertEqual(expected_error, translated_error)  | 
|
1330  | 
||
1331  | 
def test_UnlockableTransport(self):  | 
|
1332  | 
bzrdir = self.make_bzrdir('')  | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1333  | 
translated_error = self.translateTuple(  | 
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1334  | 
('UnlockableTransport',), bzrdir=bzrdir)  | 
1335  | 
expected_error = errors.UnlockableTransport(bzrdir.root_transport)  | 
|
1336  | 
self.assertEqual(expected_error, translated_error)  | 
|
1337  | 
||
1338  | 
def test_LockFailed(self):  | 
|
1339  | 
lock = 'str() of a server lock'  | 
|
1340  | 
why = 'str() of why'  | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1341  | 
translated_error = self.translateTuple(('LockFailed', lock, why))  | 
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1342  | 
expected_error = errors.LockFailed(lock, why)  | 
1343  | 
self.assertEqual(expected_error, translated_error)  | 
|
1344  | 
||
1345  | 
def test_TokenMismatch(self):  | 
|
1346  | 
token = 'a lock token'  | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1347  | 
translated_error = self.translateTuple(('TokenMismatch',), token=token)  | 
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1348  | 
expected_error = errors.TokenMismatch(token, '(remote token)')  | 
1349  | 
self.assertEqual(expected_error, translated_error)  | 
|
1350  | 
||
1351  | 
def test_Diverged(self):  | 
|
1352  | 
branch = self.make_branch('a')  | 
|
1353  | 
other_branch = self.make_branch('b')  | 
|
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1354  | 
translated_error = self.translateTuple(  | 
| 
3533.3.3
by Andrew Bennetts
 Add unit tests for bzrlib.remote._translate_error.  | 
1355  | 
('Diverged',), branch=branch, other_branch=other_branch)  | 
1356  | 
expected_error = errors.DivergedBranches(branch, other_branch)  | 
|
1357  | 
self.assertEqual(expected_error, translated_error)  | 
|
1358  | 
||
1359  | 
||
| 
3533.3.4
by Andrew Bennetts
 Add tests for _translate_error's robustness.  | 
1360  | 
class TestErrorTranslationRobustness(TestErrorTranslationBase):  | 
1361  | 
"""Unit tests for bzrlib.remote._translate_error's robustness.  | 
|
1362  | 
    
 | 
|
1363  | 
    TestErrorTranslationSuccess is for cases where _translate_error can
 | 
|
1364  | 
    translate successfully.  This class about how _translate_err behaves when
 | 
|
1365  | 
    it fails to translate: it re-raises the original error.
 | 
|
1366  | 
    """
 | 
|
1367  | 
||
1368  | 
def test_unrecognised_server_error(self):  | 
|
1369  | 
"""If the error code from the server is not recognised, the original  | 
|
1370  | 
        ErrorFromSmartServer is propagated unmodified.
 | 
|
1371  | 
        """
 | 
|
1372  | 
error_tuple = ('An unknown error tuple',)  | 
|
1373  | 
server_error = errors.ErrorFromSmartServer(error_tuple)  | 
|
1374  | 
translated_error = self.translateErrorFromSmartServer(server_error)  | 
|
1375  | 
self.assertEqual(server_error, translated_error)  | 
|
1376  | 
||
1377  | 
def test_context_missing_a_key(self):  | 
|
1378  | 
"""In case of a bug in the client, or perhaps an unexpected response  | 
|
1379  | 
        from a server, _translate_error returns the original error tuple from
 | 
|
1380  | 
        the server and mutters a warning.
 | 
|
1381  | 
        """
 | 
|
1382  | 
        # To translate a NoSuchRevision error _translate_error needs a 'branch'
 | 
|
1383  | 
        # in the context dict.  So let's give it an empty context dict instead
 | 
|
1384  | 
        # to exercise its error recovery.
 | 
|
1385  | 
empty_context = {}  | 
|
1386  | 
error_tuple = ('NoSuchRevision', 'revid')  | 
|
1387  | 
server_error = errors.ErrorFromSmartServer(error_tuple)  | 
|
1388  | 
translated_error = self.translateErrorFromSmartServer(server_error)  | 
|
1389  | 
self.assertEqual(server_error, translated_error)  | 
|
1390  | 
        # In addition to re-raising ErrorFromSmartServer, some debug info has
 | 
|
1391  | 
        # been muttered to the log file for developer to look at.
 | 
|
1392  | 
self.assertContainsRe(  | 
|
1393  | 
self._get_log(keep_log_file=True),  | 
|
1394  | 
"Missing key 'branch' in context")  | 
|
1395  |