~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

(Andrew Bennetts) Fix incompatibility with < 0.16 smart servers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
from bzrlib.smart import server, medium
45
45
from bzrlib.smart.client import _SmartClient
46
46
from bzrlib.transport.memory import MemoryTransport
 
47
from bzrlib.transport.remote import RemoteTransport
47
48
 
48
49
 
49
50
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
60
61
        self.transport.disconnect()
61
62
        tests.TestCaseWithTransport.tearDown(self)
62
63
 
63
 
    def test_is_readonly(self):
64
 
        # XXX: this is a poor way to test RemoteTransport, but currently there's
65
 
        # no easy way to substitute in a fake client on a transport like we can
66
 
        # with RemoteBzrDir/Branch/Repository.
67
 
        self.assertEqual(self.transport.is_readonly(), False)
68
 
 
69
64
    def test_create_remote_bzrdir(self):
70
65
        b = remote.RemoteBzrDir(self.transport)
71
66
        self.assertIsInstance(b, BzrDir)
104
99
        self.assertIsInstance(d, BzrDir)
105
100
 
106
101
 
107
 
class ReadonlyRemoteTransportTests(tests.TestCaseWithTransport):
108
 
 
109
 
    def setUp(self):
110
 
        self.transport_server = server.ReadonlySmartTCPServer_for_testing
111
 
        super(ReadonlyRemoteTransportTests, self).setUp()
112
 
 
113
 
    def test_is_readonly_yes(self):
114
 
        # XXX: this is a poor way to test RemoteTransport, but currently there's
115
 
        # no easy way to substitute in a fake client on a transport like we can
116
 
        # with RemoteBzrDir/Branch/Repository.
117
 
        transport = self.get_readonly_transport()
118
 
        self.assertEqual(transport.is_readonly(), True)
119
 
 
120
 
 
121
102
class FakeProtocol(object):
122
103
    """Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
123
104
 
404
385
            client._calls)
405
386
 
406
387
 
 
388
class TestTransportIsReadonly(tests.TestCase):
 
389
 
 
390
    def test_true(self):
 
391
        client = FakeClient([(('yes',), '')])
 
392
        transport = RemoteTransport('bzr://example.com/', medium=False,
 
393
                                    _client=client)
 
394
        self.assertEqual(True, transport.is_readonly())
 
395
        self.assertEqual(
 
396
            [('call', 'Transport.is_readonly', ())],
 
397
            client._calls)
 
398
 
 
399
    def test_false(self):
 
400
        client = FakeClient([(('no',), '')])
 
401
        transport = RemoteTransport('bzr://example.com/', medium=False,
 
402
                                    _client=client)
 
403
        self.assertEqual(False, transport.is_readonly())
 
404
        self.assertEqual(
 
405
            [('call', 'Transport.is_readonly', ())],
 
406
            client._calls)
 
407
 
 
408
    def test_error_from_old_server(self):
 
409
        """bzr 0.15 and earlier servers don't recognise the is_readonly verb.
 
410
        
 
411
        Clients should treat it as a "no" response, because is_readonly is only
 
412
        advisory anyway (a transport could be read-write, but then the
 
413
        underlying filesystem could be readonly anyway).
 
414
        """
 
415
        client = FakeClient([(
 
416
            ('error', "Generic bzr smart protocol error: "
 
417
                      "bad request 'Transport.is_readonly'"), '')])
 
418
        transport = RemoteTransport('bzr://example.com/', medium=False,
 
419
                                    _client=client)
 
420
        self.assertEqual(False, transport.is_readonly())
 
421
        self.assertEqual(
 
422
            [('call', 'Transport.is_readonly', ())],
 
423
            client._calls)
 
424
 
 
425
 
407
426
class TestRemoteRepository(tests.TestCase):
408
427
    """Base for testing RemoteRepository protocol usage.
409
428