/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-04-07 10:34:57 UTC
  • mfrom: (3344 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3349.
  • Revision ID: andrew.bennetts@canonical.com-20080407103457-ro4t95pd3imwt0zw
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
50
52
 
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('.')
61
62
 
143
144
        self.responses = responses
144
145
        self._calls = []
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)
147
148
 
148
149
    def _get_next_response(self):
149
150
        response_tuple = self.responses.pop(0)
171
172
 
172
173
class FakeMedium(object):
173
174
 
174
 
    def __init__(self, base, client_calls):
175
 
        self.base = base
176
 
        self.connection = FakeConnection(client_calls)
177
 
        self._client_calls = client_calls
178
 
 
179
 
 
180
 
class FakeConnection(object):
181
 
 
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)
201
194
 
202
195
 
 
196
class Test_SmartClient_remote_path_from_transport(tests.TestCase):
 
197
    """Tests for the behaviour of _SmartClient.remote_path_from_transport."""
 
198
 
 
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.
 
202
        """
 
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)
 
208
        
 
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.
 
212
        """
 
213
        self.assertRemotePath('xyz/', 'bzr://host/path', 'bzr://host/xyz')
 
214
        self.assertRemotePath(
 
215
            'path/xyz/', 'bzr://host/path', 'bzr://host/path/xyz')
 
216
 
 
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.
 
221
        """
 
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')
 
227
 
 
228
 
203
229
class TestBzrDirOpenBranch(tests.TestCase):
204
230
 
205
231
    def test_branch_present(self):
328
354
            input_file, output_file)
329
355
        return medium.SmartClientStreamMediumRequest(client_medium)
330
356
 
 
357
    def protocol_version(self):
 
358
        return 1
 
359
 
331
360
 
332
361
class OldServerTransport(object):
333
362
    """A fake transport for test_old_server that reports it's smart server
702
731
              ('quack/', ''))],
703
732
            client._calls)
704
733
 
 
734
    def test_get_parent_map_unexpected_response(self):
 
735
        responses = [
 
736
            (('something unexpected!',), '')]
 
737
        repo, client = self.setup_fake_client_and_repository(responses, 'path')
 
738
        self.assertRaises(
 
739
            errors.UnexpectedSmartServerResponse,
 
740
            repo.get_parent_map, ['a-revision-id'])
705
741
 
706
742
 
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,
 
753
            NULL_REVISION)
717
754
        self.assertEqual([], client._calls)
718
755
        self.assertEqual({}, result)
719
756
 
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))],