~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-05-20 00:42:19 UTC
  • mto: This revision was merged to the branch mainline in revision 3439.
  • Revision ID: andrew.bennetts@canonical.com-20080520004219-11umu8ynx5c39bqg
Push remote_path_from_transport logic into SmartClientMedium, removing special-casing of bzr+http from _SmartClient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
52
52
 
184
184
        return result[1], FakeProtocol(result[2], self)
185
185
 
186
186
 
187
 
class FakeMedium(object):
 
187
class FakeMedium(medium.SmartClientMedium):
188
188
 
189
189
    def __init__(self, client_calls, base):
190
190
        self._remote_is_at_least_1_2 = True
209
209
        self.assertTrue(result)
210
210
 
211
211
 
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."""
214
214
 
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.
218
219
        """
219
 
        class DummyMedium(object):
220
 
            base = client_base
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)
225
 
        
 
224
 
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.
229
228
        """
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
232
 
 
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)
 
238
        """
 
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)
 
244
        
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.
238
249
        """
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/')
244
255
 
245
256
 
246
257
class TestBzrDirOpenBranch(tests.TestCase):