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
49
50
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
60
61
self.transport.disconnect()
61
62
tests.TestCaseWithTransport.tearDown(self)
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)
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)
107
class ReadonlyRemoteTransportTests(tests.TestCaseWithTransport):
110
self.transport_server = server.ReadonlySmartTCPServer_for_testing
111
super(ReadonlyRemoteTransportTests, self).setUp()
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)
121
102
class FakeProtocol(object):
122
103
"""Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
388
class TestTransportIsReadonly(tests.TestCase):
391
client = FakeClient([(('yes',), '')])
392
transport = RemoteTransport('bzr://example.com/', medium=False,
394
self.assertEqual(True, transport.is_readonly())
396
[('call', 'Transport.is_readonly', ())],
399
def test_false(self):
400
client = FakeClient([(('no',), '')])
401
transport = RemoteTransport('bzr://example.com/', medium=False,
403
self.assertEqual(False, transport.is_readonly())
405
[('call', 'Transport.is_readonly', ())],
408
def test_error_from_old_server(self):
409
"""bzr 0.15 and earlier servers don't recognise the is_readonly verb.
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).
415
client = FakeClient([(
416
('error', "Generic bzr smart protocol error: "
417
"bad request 'Transport.is_readonly'"), '')])
418
transport = RemoteTransport('bzr://example.com/', medium=False,
420
self.assertEqual(False, transport.is_readonly())
422
[('call', 'Transport.is_readonly', ())],
407
426
class TestRemoteRepository(tests.TestCase):
408
427
"""Base for testing RemoteRepository protocol usage.