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('.')
143
144
self.responses = responses
145
146
self.expecting_body = False
146
_SmartClient.__init__(self, FakeMedium(fake_medium_base, self._calls))
147
_SmartClient.__init__(self, FakeMedium(self._calls), fake_medium_base)
148
149
def _get_next_response(self):
149
150
response_tuple = self.responses.pop(0)
172
173
class FakeMedium(object):
174
def __init__(self, base, client_calls):
176
self.connection = FakeConnection(client_calls)
177
self._client_calls = client_calls
180
class FakeConnection(object):
182
175
def __init__(self, client_calls):
183
176
self._remote_is_at_least_1_2 = True
184
177
self._client_calls = client_calls
200
193
self.assertTrue(result)
196
class Test_SmartClient_remote_path_from_transport(tests.TestCase):
197
"""Tests for the behaviour of _SmartClient.remote_path_from_transport."""
199
def assertRemotePath(self, expected, client_base, transport_base):
200
"""Assert that the result of _SmartClient.remote_path_from_transport
201
is the expected value for a given client_base and transport_base.
203
dummy_medium = 'dummy medium'
204
client = _SmartClient(dummy_medium, client_base)
205
transport = get_transport(transport_base)
206
result = client.remote_path_from_transport(transport)
207
self.assertEqual(expected, result)
209
def test_remote_path_from_transport(self):
210
"""_SmartClient.remote_path_from_transport calculates a URL for the
211
given transport relative to the root of the client base URL.
213
self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')
214
self.assertRemotePath(
215
'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz')
217
def test_remote_path_from_transport_http(self):
218
"""Remote paths for HTTP transports are calculated differently to other
219
transports. They are just relative to the client base, not the root
220
directory of the host.
222
for scheme in ['http:', 'https:', 'bzr+http:', 'bzr+https:']:
223
self.assertRemotePath(
224
'../xyz/', scheme + '//host/path', scheme + '//host/xyz')
225
self.assertRemotePath(
226
'xyz/', scheme + '//host/path', scheme + '//host/path/xyz')
203
229
class TestBzrDirOpenBranch(tests.TestCase):
205
231
def test_branch_present(self):
702
731
('quack/', ''))],
734
def test_get_parent_map_unexpected_response(self):
736
(('something unexpected!',), '')]
737
repo, client = self.setup_fake_client_and_repository(responses, 'path')
739
errors.UnexpectedSmartServerResponse,
740
repo.get_parent_map, ['a-revision-id'])
707
743
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
713
749
transport_path = 'empty'
714
750
repo, client = self.setup_fake_client_and_repository(
715
751
responses, transport_path)
716
result = repo.get_revision_graph(NULL_REVISION)
752
result = self.applyDeprecated(one_four, repo.get_revision_graph,
717
754
self.assertEqual([], client._calls)
718
755
self.assertEqual({}, result)
728
765
transport_path = 'sinhala'
729
766
repo, client = self.setup_fake_client_and_repository(
730
767
responses, transport_path)
731
result = repo.get_revision_graph()
768
result = self.applyDeprecated(one_four, repo.get_revision_graph)
732
769
self.assertEqual(
733
770
[('call_expecting_body', 'Repository.get_revision_graph',
734
771
('sinhala/', ''))],
748
785
transport_path = 'sinhala'
749
786
repo, client = self.setup_fake_client_and_repository(
750
787
responses, transport_path)
751
result = repo.get_revision_graph(r2)
788
result = self.applyDeprecated(one_four, repo.get_revision_graph, r2)
752
789
self.assertEqual(
753
790
[('call_expecting_body', 'Repository.get_revision_graph',
754
791
('sinhala/', r2))],
763
800
responses, transport_path)
764
801
# also check that the right revision is reported in the error
765
802
self.assertRaises(errors.NoSuchRevision,
766
repo.get_revision_graph, revid)
803
self.applyDeprecated, one_four, repo.get_revision_graph, revid)
767
804
self.assertEqual(
768
805
[('call_expecting_body', 'Repository.get_revision_graph',
769
806
('sinhala/', revid))],