139
140
self.responses = responses
141
142
self.expecting_body = False
142
_SmartClient.__init__(self, FakeMedium(fake_medium_base))
143
_SmartClient.__init__(self, FakeMedium(fake_medium_base, self._calls))
144
145
def call(self, method, *args):
145
146
self._calls.append(('call', method, args))
162
163
class FakeMedium(object):
164
def __init__(self, base):
165
def __init__(self, base, client_calls):
167
self.connection = FakeConnection(client_calls)
168
self._client_calls = client_calls
171
class FakeConnection(object):
173
def __init__(self, client_calls):
174
self._remote_is_at_least_1_2 = True
175
self._client_calls = client_calls
177
def disconnect(self):
178
self._client_calls.append(('disconnect medium',))
168
181
class TestVfsHas(tests.TestCase):
206
219
[('call', 'BzrDir.open_branch', ('quack/',))],
222
def test__get_tree_branch(self):
223
# _get_tree_branch is a form of open_branch, but it should only ask for
224
# branch opening, not any other network requests.
227
calls.append("Called")
229
transport = MemoryTransport()
230
# no requests on the network - catches other api calls being made.
231
client = FakeClient([], transport.base)
232
bzrdir = RemoteBzrDir(transport, _client=client)
233
# patch the open_branch call to record that it was called.
234
bzrdir.open_branch = open_branch
235
self.assertEqual((None, "a-branch"), bzrdir._get_tree_branch())
236
self.assertEqual(["Called"], calls)
237
self.assertEqual([], client._calls)
209
239
def test_url_quoting_of_path(self):
210
240
# Relpaths on the wire should not be URL-escaped. So "~" should be
211
241
# transmitted as "~", not "%7E".
608
638
r1 = u'\u0e33'.encode('utf8')
609
639
r2 = u'\u0dab'.encode('utf8')
610
640
lines = [' '.join([r2, r1]), r1]
611
encoded_body = '\n'.join(lines)
641
encoded_body = bz2.compress('\n'.join(lines))
612
642
responses = [(('ok', ), encoded_body), (('ok', ), encoded_body)]
614
644
transport_path = 'quack'
624
654
parents = graph.get_parent_map([r1])
625
655
self.assertEqual({r1: (NULL_REVISION,)}, parents)
626
656
self.assertEqual(
627
[('call_expecting_body', 'Repository.get_parent_map',
657
[('call_with_body_bytes_expecting_body',
658
'Repository.get_parent_map', ('quack/', r2), '\n\n0')],
631
661
# now we call again, and it should use the second response.
634
664
parents = graph.get_parent_map([r1])
635
665
self.assertEqual({r1: (NULL_REVISION,)}, parents)
636
666
self.assertEqual(
637
[('call_expecting_body', 'Repository.get_parent_map',
639
('call_expecting_body', 'Repository.get_parent_map',
667
[('call_with_body_bytes_expecting_body',
668
'Repository.get_parent_map', ('quack/', r2), '\n\n0'),
669
('call_with_body_bytes_expecting_body',
670
'Repository.get_parent_map', ('quack/', r1), '\n\n0'),
675
def test_get_parent_map_reconnects_if_unknown_method(self):
677
"Generic bzr smart protocol error: "
678
"bad request 'Repository.get_parent_map'")
680
(('error', error_msg), ''),
682
transport_path = 'quack'
683
repo, client = self.setup_fake_client_and_repository(
684
responses, transport_path)
685
rev_id = 'revision-id'
686
parents = repo.get_parent_map([rev_id])
688
[('call_with_body_bytes_expecting_body',
689
'Repository.get_parent_map', ('quack/', rev_id), '\n\n0'),
690
('disconnect medium',),
691
('call_expecting_body', 'Repository.get_revision_graph',
646
697
class TestRepositoryGetRevisionGraph(TestRemoteRepository):