/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-20 07:16:50 UTC
  • mfrom: (3431.3.11 bug-230550)
  • Revision ID: pqm@pqm.ubuntu.com-20080520071650-9vbizb6v6ji8k1jy
Fix spurious "No repository present" errors when accessing branches
        in shared repos via bzr+http.

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
 
from bzrlib.transport.remote import RemoteTransport
 
51
from bzrlib.transport.remote import RemoteTransport, RemoteTCPTransport
52
52
 
53
53
 
54
54
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
144
144
        self.responses = []
145
145
        self._calls = []
146
146
        self.expecting_body = False
147
 
        _SmartClient.__init__(self, FakeMedium(self._calls), fake_medium_base)
 
147
        _SmartClient.__init__(self, FakeMedium(self._calls, fake_medium_base))
148
148
 
149
149
    def add_success_response(self, *args):
150
150
        self.responses.append(('success', args, None))
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
 
    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
 
192
        self.base = base
192
193
 
193
194
    def disconnect(self):
194
195
        self._client_calls.append(('disconnect medium',))
208
209
        self.assertTrue(result)
209
210
 
210
211
 
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."""
213
214
 
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.
217
219
        """
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)
223
 
        
 
224
 
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.
227
228
        """
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')
231
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
        
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.
236
249
        """
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/')
242
255
 
243
256
 
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')