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
51
from bzrlib.transport.remote import RemoteTransport, RemoteTCPTransport
209
209
self.assertTrue(result)
212
class Test_SmartClient_remote_path_from_transport(tests.TestCase):
213
"""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."""
215
215
def assertRemotePath(self, expected, client_base, transport_base):
216
"""Assert that the result of _SmartClient.remote_path_from_transport
217
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.
219
class DummyMedium(object):
221
client = _SmartClient(DummyMedium())
220
client_medium = medium.SmartClientMedium(client_base)
222
221
transport = get_transport(transport_base)
223
result = client.remote_path_from_transport(transport)
222
result = client_medium.remote_path_from_transport(transport)
224
223
self.assertEqual(expected, result)
226
225
def test_remote_path_from_transport(self):
227
"""_SmartClient.remote_path_from_transport calculates a URL for the
228
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.
230
229
self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')
231
230
self.assertRemotePath(
232
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)
234
245
def test_remote_path_from_transport_http(self):
235
246
"""Remote paths for HTTP transports are calculated differently to other
236
247
transports. They are just relative to the client base, not the root
237
248
directory of the host.
239
250
for scheme in ['http:', 'https:', 'bzr+http:', 'bzr+https:']:
240
self.assertRemotePath(
241
'../xyz/', scheme + '//host/path', scheme + '//host/xyz')
242
self.assertRemotePath(
243
'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/')
246
257
class TestBzrDirOpenBranch(tests.TestCase):