45
45
from bzrlib.revision import NULL_REVISION
46
46
from bzrlib.smart import server, medium
47
47
from bzrlib.smart.client import _SmartClient
48
from bzrlib.symbol_versioning import one_four
49
from bzrlib.transport import get_transport
48
50
from bzrlib.transport.memory import MemoryTransport
49
51
from bzrlib.transport.remote import RemoteTransport
55
57
self.transport_server = server.SmartTCPServer_for_testing
56
58
super(BasicRemoteObjectTests, self).setUp()
57
59
self.transport = self.get_transport()
58
self.client = self.transport.get_smart_client()
59
60
# make a branch that can be opened over the smart transport
60
61
self.local_wt = BzrDir.create_standalone_workingtree('.')
140
141
self.responses = responses
142
143
self.expecting_body = False
143
_SmartClient.__init__(self, FakeMedium(fake_medium_base, self._calls))
144
_SmartClient.__init__(self, FakeMedium(self._calls), fake_medium_base)
145
146
def call(self, method, *args):
146
147
self._calls.append(('call', method, args))
163
164
class FakeMedium(object):
165
def __init__(self, base, client_calls):
167
self.connection = FakeConnection(client_calls)
168
self._client_calls = client_calls
171
class FakeConnection(object):
173
166
def __init__(self, client_calls):
174
167
self._remote_is_at_least_1_2 = True
175
168
self._client_calls = client_calls
191
184
self.assertTrue(result)
187
class Test_SmartClient_remote_path_from_transport(tests.TestCase):
188
"""Tests for the behaviour of _SmartClient.remote_path_from_transport."""
190
def assertRemotePath(self, expected, client_base, transport_base):
191
"""Assert that the result of _SmartClient.remote_path_from_transport
192
is the expected value for a given client_base and transport_base.
194
dummy_medium = 'dummy medium'
195
client = _SmartClient(dummy_medium, client_base)
196
transport = get_transport(transport_base)
197
result = client.remote_path_from_transport(transport)
198
self.assertEqual(expected, result)
200
def test_remote_path_from_transport(self):
201
"""_SmartClient.remote_path_from_transport calculates a URL for the
202
given transport relative to the root of the client base URL.
204
self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')
205
self.assertRemotePath(
206
'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz')
208
def test_remote_path_from_transport_http(self):
209
"""Remote paths for HTTP transports are calculated differently to other
210
transports. They are just relative to the client base, not the root
211
directory of the host.
213
for scheme in ['http:', 'https:', 'bzr+http:', 'bzr+https:']:
214
self.assertRemotePath(
215
'../xyz/', scheme + '//host/path', scheme + '//host/xyz')
216
self.assertRemotePath(
217
'xyz/', scheme + '//host/path', scheme + '//host/path/xyz')
194
220
class TestBzrDirOpenBranch(tests.TestCase):
196
222
def test_branch_present(self):
705
734
transport_path = 'empty'
706
735
repo, client = self.setup_fake_client_and_repository(
707
736
responses, transport_path)
708
result = repo.get_revision_graph(NULL_REVISION)
737
result = self.applyDeprecated(one_four, repo.get_revision_graph,
709
739
self.assertEqual([], client._calls)
710
740
self.assertEqual({}, result)
720
750
transport_path = 'sinhala'
721
751
repo, client = self.setup_fake_client_and_repository(
722
752
responses, transport_path)
723
result = repo.get_revision_graph()
753
result = self.applyDeprecated(one_four, repo.get_revision_graph)
724
754
self.assertEqual(
725
755
[('call_expecting_body', 'Repository.get_revision_graph',
726
756
('sinhala/', ''))],
740
770
transport_path = 'sinhala'
741
771
repo, client = self.setup_fake_client_and_repository(
742
772
responses, transport_path)
743
result = repo.get_revision_graph(r2)
773
result = self.applyDeprecated(one_four, repo.get_revision_graph, r2)
744
774
self.assertEqual(
745
775
[('call_expecting_body', 'Repository.get_revision_graph',
746
776
('sinhala/', r2))],
755
785
responses, transport_path)
756
786
# also check that the right revision is reported in the error
757
787
self.assertRaises(errors.NoSuchRevision,
758
repo.get_revision_graph, revid)
788
self.applyDeprecated, one_four, repo.get_revision_graph, revid)
759
789
self.assertEqual(
760
790
[('call_expecting_body', 'Repository.get_revision_graph',
761
791
('sinhala/', revid))],