~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Vincent Ladeuil
  • Date: 2007-04-26 09:01:46 UTC
  • mfrom: (2420.2.2 bzr.http.auth)
  • mto: This revision was merged to the branch mainline in revision 2463.
  • Revision ID: v.ladeuil+lp@free.fr-20070426090146-jbwl0muvk76wlw6c
Merge spiv modifications

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
These are proxy objects which act on remote objects by sending messages
20
20
through a smart client.  The proxies are to be created when attempting to open
21
21
the object given a transport that supports smartserver rpc operations. 
 
22
 
 
23
These tests correspond to tests.test_smart, which exercises the server side.
22
24
"""
23
25
 
24
26
from cStringIO import StringIO
25
27
 
26
28
from bzrlib import (
 
29
    bzrdir,
27
30
    errors,
28
31
    remote,
 
32
    repository,
29
33
    tests,
30
34
    )
31
35
from bzrlib.branch import Branch
37
41
    RemoteRepository,
38
42
    )
39
43
from bzrlib.revision import NULL_REVISION
40
 
from bzrlib.smart import server
 
44
from bzrlib.smart import server, medium
41
45
from bzrlib.smart.client import _SmartClient
42
46
from bzrlib.transport.memory import MemoryTransport
43
47
 
203
207
        self.check_open_repository(True, False)
204
208
        self.check_open_repository(False, False)
205
209
 
 
210
    def test_old_server(self):
 
211
        """RemoteBzrDirFormat should fail to probe if the server version is too
 
212
        old.
 
213
        """
 
214
        self.assertRaises(errors.NotBranchError,
 
215
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
 
216
 
 
217
 
 
218
class OldSmartClient(object):
 
219
    """A fake smart client for test_old_version that just returns a version one
 
220
    response to the 'hello' (query version) command.
 
221
    """
 
222
 
 
223
    def get_request(self):
 
224
        input_file = StringIO('ok\x011\n')
 
225
        output_file = StringIO()
 
226
        client_medium = medium.SmartSimplePipesClientMedium(
 
227
            input_file, output_file)
 
228
        return medium.SmartClientStreamMediumRequest(client_medium)
 
229
 
 
230
 
 
231
class OldServerTransport(object):
 
232
    """A fake transport for test_old_server that reports it's smart server
 
233
    protocol version as version one.
 
234
    """
 
235
 
 
236
    def __init__(self):
 
237
        self.base = 'fake:'
 
238
 
 
239
    def get_smart_client(self):
 
240
        return OldSmartClient()
 
241
 
206
242
 
207
243
class TestBranchLastRevisionInfo(tests.TestCase):
208
244
 
369
405
 
370
406
 
371
407
class TestRemoteRepository(tests.TestCase):
 
408
    """Base for testing RemoteRepository protocol usage.
 
409
    
 
410
    These tests contain frozen requests and responses.  We want any changes to 
 
411
    what is sent or expected to be require a thoughtful update to these tests
 
412
    because they might break compatibility with different-versioned servers.
 
413
    """
372
414
 
373
415
    def setup_fake_client_and_repository(self, responses, transport_path):
374
 
        """Create the fake client and repository for testing with."""
 
416
        """Create the fake client and repository for testing with.
 
417
        
 
418
        There's no real server here; we just have canned responses sent
 
419
        back one by one.
 
420
        
 
421
        :param transport_path: Path below the root of the MemoryTransport
 
422
            where the repository will be created.
 
423
        """
375
424
        client = FakeClient(responses)
376
425
        transport = MemoryTransport()
377
426
        transport.mkdir(transport_path)
609
658
 
610
659
        # The remote repo shouldn't be accessed.
611
660
        self.assertEqual([], client._calls)
 
661
 
 
662
 
 
663
class TestRepositoryTarball(TestRemoteRepository):
 
664
 
 
665
    # This is a canned tarball reponse we can validate against
 
666
    tarball_content = (
 
667
        'QlpoOTFBWSZTWdGkj3wAAWF/k8aQACBIB//A9+8cIX/v33AACEAYABAECEACNz'
 
668
        'JqsgJJFPTSnk1A3qh6mTQAAAANPUHkagkSTEkaA09QaNAAAGgAAAcwCYCZGAEY'
 
669
        'mJhMJghpiaYBUkKammSHqNMZQ0NABkNAeo0AGneAevnlwQoGzEzNVzaYxp/1Uk'
 
670
        'xXzA1CQX0BJMZZLcPBrluJir5SQyijWHYZ6ZUtVqqlYDdB2QoCwa9GyWwGYDMA'
 
671
        'OQYhkpLt/OKFnnlT8E0PmO8+ZNSo2WWqeCzGB5fBXZ3IvV7uNJVE7DYnWj6qwB'
 
672
        'k5DJDIrQ5OQHHIjkS9KqwG3mc3t+F1+iujb89ufyBNIKCgeZBWrl5cXxbMGoMs'
 
673
        'c9JuUkg5YsiVcaZJurc6KLi6yKOkgCUOlIlOpOoXyrTJjK8ZgbklReDdwGmFgt'
 
674
        'dkVsAIslSVCd4AtACSLbyhLHryfb14PKegrVDba+U8OL6KQtzdM5HLjAc8/p6n'
 
675
        '0lgaWU8skgO7xupPTkyuwheSckejFLK5T4ZOo0Gda9viaIhpD1Qn7JqqlKAJqC'
 
676
        'QplPKp2nqBWAfwBGaOwVrz3y1T+UZZNismXHsb2Jq18T+VaD9k4P8DqE3g70qV'
 
677
        'JLurpnDI6VS5oqDDPVbtVjMxMxMg4rzQVipn2Bv1fVNK0iq3Gl0hhnnHKm/egy'
 
678
        'nWQ7QH/F3JFOFCQ0aSPfA='
 
679
        ).decode('base64')
 
680
 
 
681
    def test_repository_tarball(self):
 
682
        # Test that Repository.tarball generates the right operations
 
683
        transport_path = 'repo'
 
684
        expected_responses = [(('ok',), self.tarball_content),
 
685
            ]
 
686
        expected_calls = [('call_expecting_body', 'Repository.tarball',
 
687
                           ('///repo/', 'bz2',),),
 
688
            ]
 
689
        remote_repo, client = self.setup_fake_client_and_repository(
 
690
            expected_responses, transport_path)
 
691
        # Now actually ask for the tarball
 
692
        tarball_file = remote_repo._get_tarball('bz2')
 
693
        try:
 
694
            self.assertEqual(expected_calls, client._calls)
 
695
            self.assertEqual(self.tarball_content, tarball_file.read())
 
696
        finally:
 
697
            tarball_file.close()
 
698
 
 
699
    def test_sprout_uses_tarball(self):
 
700
        # RemoteRepository.sprout should try to use the
 
701
        # tarball command rather than accessing all the files
 
702
        transport_path = 'srcrepo'
 
703
        expected_responses = [(('ok',), self.tarball_content),
 
704
            ]
 
705
        expected_calls = [('call2', 'Repository.tarball', ('///srcrepo/', 'bz2',),),
 
706
            ]
 
707
        remote_repo, client = self.setup_fake_client_and_repository(
 
708
            expected_responses, transport_path)
 
709
        # make a regular local repository to receive the results
 
710
        dest_transport = MemoryTransport()
 
711
        dest_transport.mkdir('destrepo')
 
712
        bzrdir_format = bzrdir.format_registry.make_bzrdir('default')
 
713
        dest_bzrdir = bzrdir_format.initialize_on_transport(dest_transport)
 
714
        # try to copy...
 
715
        remote_repo.sprout(dest_bzrdir)
 
716
 
 
717
 
 
718
class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):
 
719
    """RemoteRepository.copy_content_into optimizations"""
 
720
 
 
721
    def test_copy_content_remote_to_local(self):
 
722
        self.transport_server = server.SmartTCPServer_for_testing
 
723
        src_repo = self.make_repository('repo1')
 
724
        src_repo = repository.Repository.open(self.get_url('repo1'))
 
725
        # At the moment the tarball-based copy_content_into can't write back
 
726
        # into a smart server.  It would be good if it could upload the
 
727
        # tarball; once that works we'd have to create repositories of
 
728
        # different formats. -- mbp 20070410
 
729
        dest_url = self.get_vfs_only_url('repo2')
 
730
        dest_bzrdir = BzrDir.create(dest_url)
 
731
        dest_repo = dest_bzrdir.create_repository()
 
732
        self.assertFalse(isinstance(dest_repo, RemoteRepository))
 
733
        self.assertTrue(isinstance(src_repo, RemoteRepository))
 
734
        src_repo.copy_content_into(dest_repo)