46
46
from bzrlib.smart import server, medium
47
47
from bzrlib.smart.client import _SmartClient
48
48
from bzrlib.symbol_versioning import one_four
49
from bzrlib.transport import get_transport
49
from bzrlib.transport import get_transport, http
50
50
from bzrlib.transport.memory import MemoryTransport
51
from bzrlib.transport.remote import RemoteTransport
51
from bzrlib.transport.remote import RemoteTransport, RemoteTCPTransport
54
54
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
184
184
return result[1], FakeProtocol(result[2], self)
187
class FakeMedium(object):
187
class FakeMedium(medium.SmartClientMedium):
189
def __init__(self, client_calls):
189
def __init__(self, client_calls, base):
190
190
self._remote_is_at_least_1_2 = True
191
191
self._client_calls = client_calls
193
194
def disconnect(self):
194
195
self._client_calls.append(('disconnect medium',))
208
209
self.assertTrue(result)
211
class Test_SmartClient_remote_path_from_transport(tests.TestCase):
212
"""Tests for the behaviour of _SmartClient.remote_path_from_transport."""
212
class Test_ClientMedium_remote_path_from_transport(tests.TestCase):
213
"""Tests for the behaviour of client_medium.remote_path_from_transport."""
214
215
def assertRemotePath(self, expected, client_base, transport_base):
215
"""Assert that the result of _SmartClient.remote_path_from_transport
216
is the expected value for a given client_base and transport_base.
216
"""Assert that the result of
217
SmartClientMedium.remote_path_from_transport is the expected value for
218
a given client_base and transport_base.
218
dummy_medium = 'dummy medium'
219
client = _SmartClient(dummy_medium, client_base)
220
client_medium = medium.SmartClientMedium(client_base)
220
221
transport = get_transport(transport_base)
221
result = client.remote_path_from_transport(transport)
222
result = client_medium.remote_path_from_transport(transport)
222
223
self.assertEqual(expected, result)
224
225
def test_remote_path_from_transport(self):
225
"""_SmartClient.remote_path_from_transport calculates a URL for the
226
given transport relative to the root of the client base URL.
226
"""SmartClientMedium.remote_path_from_transport calculates a URL for
227
the given transport relative to the root of the client base URL.
228
229
self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')
229
230
self.assertRemotePath(
230
231
'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz')
233
def assertRemotePathHTTP(self, expected, transport_base, relpath):
234
"""Assert that the result of
235
HttpTransportBase.remote_path_from_transport is the expected value for
236
a given transport_base and relpath of that transport. (Note that
237
HttpTransportBase is a subclass of SmartClientMedium)
239
base_transport = get_transport(transport_base)
240
client_medium = base_transport.get_smart_medium()
241
cloned_transport = base_transport.clone(relpath)
242
result = client_medium.remote_path_from_transport(cloned_transport)
243
self.assertEqual(expected, result)
232
245
def test_remote_path_from_transport_http(self):
233
246
"""Remote paths for HTTP transports are calculated differently to other
234
247
transports. They are just relative to the client base, not the root
235
248
directory of the host.
237
250
for scheme in ['http:', 'https:', 'bzr+http:', 'bzr+https:']:
238
self.assertRemotePath(
239
'../xyz/', scheme + '//host/path', scheme + '//host/xyz')
240
self.assertRemotePath(
241
'xyz/', scheme + '//host/path', scheme + '//host/path/xyz')
251
self.assertRemotePathHTTP(
252
'../xyz/', scheme + '//host/path', '../xyz/')
253
self.assertRemotePathHTTP(
254
'xyz/', scheme + '//host/path', 'xyz/')
244
257
class TestBzrDirOpenBranch(tests.TestCase):
291
304
def test_url_quoting_of_path(self):
292
305
# Relpaths on the wire should not be URL-escaped. So "~" should be
293
306
# transmitted as "~", not "%7E".
294
transport = RemoteTransport('bzr://localhost/~hello/')
307
transport = RemoteTCPTransport('bzr://localhost/~hello/')
295
308
client = FakeClient(transport.base)
296
309
client.add_success_response('ok', '')
297
310
client.add_success_response('ok', '', 'no', 'no', 'no')