403
407
class TestRemoteRepository(tests.TestCase):
408
"""Base for testing RemoteRepository protocol usage.
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.
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.
418
There's no real server here; we just have canned responses sent
421
:param transport_path: Path below the root of the MemoryTransport
422
where the repository will be created.
407
424
client = FakeClient(responses)
408
425
transport = MemoryTransport()
409
426
transport.mkdir(transport_path)
642
659
# The remote repo shouldn't be accessed.
643
660
self.assertEqual([], client._calls)
663
class TestRepositoryTarball(TestRemoteRepository):
665
# This is a canned tarball reponse we can validate against
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='
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),
686
expected_calls = [('call_expecting_body', 'Repository.tarball',
687
('///repo/', 'bz2',),),
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')
694
self.assertEqual(expected_calls, client._calls)
695
self.assertEqual(self.tarball_content, tarball_file.read())
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),
705
expected_calls = [('call2', 'Repository.tarball', ('///srcrepo/', 'bz2',),),
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)
715
remote_repo.sprout(dest_bzrdir)
718
class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):
719
"""RemoteRepository.copy_content_into optimizations"""
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)