~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

Merge tarball branch that's already with PQM, resolving conflicts.

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
401
405
 
402
406
 
403
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
    """
404
414
 
405
415
    def setup_fake_client_and_repository(self, responses, transport_path):
406
 
        """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
        """
407
424
        client = FakeClient(responses)
408
425
        transport = MemoryTransport()
409
426
        transport.mkdir(transport_path)
641
658
 
642
659
        # The remote repo shouldn't be accessed.
643
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)