~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Alexander Belchenko
  • Date: 2008-02-16 10:03:17 UTC
  • mfrom: (3224 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3230.
  • Revision ID: bialix@ukr.net-20080216100317-xg1hdw306evlgt94
merge bzr.dev; update for 1.3; $BZR_LOG used in trace.py module (again), not in the main bzr script (req. by Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
These tests correspond to tests.test_smart, which exercises the server side.
24
24
"""
25
25
 
 
26
import bz2
26
27
from cStringIO import StringIO
27
28
 
28
29
from bzrlib import (
139
140
        self.responses = responses
140
141
        self._calls = []
141
142
        self.expecting_body = False
142
 
        _SmartClient.__init__(self, FakeMedium(fake_medium_base))
 
143
        _SmartClient.__init__(self, FakeMedium(fake_medium_base, self._calls))
143
144
 
144
145
    def call(self, method, *args):
145
146
        self._calls.append(('call', method, args))
161
162
 
162
163
class FakeMedium(object):
163
164
 
164
 
    def __init__(self, base):
 
165
    def __init__(self, base, client_calls):
165
166
        self.base = base
 
167
        self.connection = FakeConnection(client_calls)
 
168
        self._client_calls = client_calls
 
169
 
 
170
 
 
171
class FakeConnection(object):
 
172
 
 
173
    def __init__(self, client_calls):
 
174
        self._remote_is_at_least_1_2 = True
 
175
        self._client_calls = client_calls
 
176
 
 
177
    def disconnect(self):
 
178
        self._client_calls.append(('disconnect medium',))
166
179
 
167
180
 
168
181
class TestVfsHas(tests.TestCase):
206
219
            [('call', 'BzrDir.open_branch', ('quack/',))],
207
220
            client._calls)
208
221
 
 
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.
 
225
        calls = []
 
226
        def open_branch():
 
227
            calls.append("Called")
 
228
            return "a-branch"
 
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)
 
238
 
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)]
613
643
 
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',
628
 
             ('quack/', r2))],
 
657
            [('call_with_body_bytes_expecting_body',
 
658
              'Repository.get_parent_map', ('quack/', r2), '\n\n0')],
629
659
            client._calls)
630
660
        repo.unlock()
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',
638
 
              ('quack/', r2)),
639
 
             ('call_expecting_body', 'Repository.get_parent_map',
640
 
              ('quack/', r1))
 
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'),
641
671
            ],
642
672
            client._calls)
643
673
        repo.unlock()
644
674
 
 
675
    def test_get_parent_map_reconnects_if_unknown_method(self):
 
676
        error_msg = (
 
677
            "Generic bzr smart protocol error: "
 
678
            "bad request 'Repository.get_parent_map'")
 
679
        responses = [
 
680
            (('error', error_msg), ''),
 
681
            (('ok',), '')]
 
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])
 
687
        self.assertEqual(
 
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',
 
692
              ('quack/', ''))],
 
693
            client._calls)
 
694
 
 
695
 
645
696
 
646
697
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
647
698