/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: Canonical.com Patch Queue Manager
  • Date: 2010-01-14 00:01:32 UTC
  • mfrom: (4957.1.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100114000132-3p3rabnonjw3gzqb
(jam) Merge bzr.stable, bringing in bug fixes #175839, #504390

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from cStringIO import StringIO
28
28
 
29
29
from bzrlib import (
 
30
    branch,
30
31
    bzrdir,
31
32
    config,
32
33
    errors,
36
37
    pack,
37
38
    remote,
38
39
    repository,
39
 
    smart,
40
40
    tests,
41
41
    treebuilder,
42
42
    urlutils,
61
61
    condition_isinstance,
62
62
    split_suite_by_condition,
63
63
    multiply_tests,
64
 
    KnownFailure,
65
64
    )
66
 
from bzrlib.transport import get_transport, http
 
65
from bzrlib.transport import get_transport
67
66
from bzrlib.transport.memory import MemoryTransport
68
67
from bzrlib.transport.remote import (
69
68
    RemoteTransport,
474
473
        self.assertFinished(client)
475
474
 
476
475
 
 
476
class TestBzrDirOpen(TestRemote):
 
477
 
 
478
    def make_fake_client_and_transport(self, path='quack'):
 
479
        transport = MemoryTransport()
 
480
        transport.mkdir(path)
 
481
        transport = transport.clone(path)
 
482
        client = FakeClient(transport.base)
 
483
        return client, transport
 
484
 
 
485
    def test_absent(self):
 
486
        client, transport = self.make_fake_client_and_transport()
 
487
        client.add_expected_call(
 
488
            'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
 
489
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
 
490
                remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
 
491
        self.assertFinished(client)
 
492
 
 
493
    def test_present_without_workingtree(self):
 
494
        client, transport = self.make_fake_client_and_transport()
 
495
        client.add_expected_call(
 
496
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
 
497
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
498
            _client=client, _force_probe=True)
 
499
        self.assertIsInstance(bd, RemoteBzrDir)
 
500
        self.assertFalse(bd.has_workingtree())
 
501
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
 
502
        self.assertFinished(client)
 
503
 
 
504
    def test_present_with_workingtree(self):
 
505
        client, transport = self.make_fake_client_and_transport()
 
506
        client.add_expected_call(
 
507
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
 
508
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
509
            _client=client, _force_probe=True)
 
510
        self.assertIsInstance(bd, RemoteBzrDir)
 
511
        self.assertTrue(bd.has_workingtree())
 
512
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
 
513
        self.assertFinished(client)
 
514
 
 
515
    def test_backwards_compat(self):
 
516
        client, transport = self.make_fake_client_and_transport()
 
517
        client.add_expected_call(
 
518
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
 
519
        client.add_expected_call(
 
520
            'BzrDir.open', ('quack/',), 'success', ('yes',))
 
521
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
522
            _client=client, _force_probe=True)
 
523
        self.assertIsInstance(bd, RemoteBzrDir)
 
524
        self.assertFinished(client)
 
525
 
 
526
 
477
527
class TestBzrDirOpenBranch(TestRemote):
478
528
 
479
529
    def test_backwards_compat(self):
689
739
        # fallback all the way to the first version.
690
740
        reference_format = self.get_repo_format()
691
741
        network_name = reference_format.network_name()
692
 
        client = FakeClient('bzr://example.com/')
 
742
        server_url = 'bzr://example.com/'
 
743
        self.permit_url(server_url)
 
744
        client = FakeClient(server_url)
693
745
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
694
746
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
695
747
        client.add_success_response('ok', '', 'no', 'no')
701
753
            reference_format.get_format_string(), 'ok')
702
754
        # PackRepository wants to do a stat
703
755
        client.add_success_response('stat', '0', '65535')
704
 
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
 
756
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
705
757
            _client=client)
706
758
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
707
759
            _client=client)
721
773
        # fallback to find_repositoryV2
722
774
        reference_format = self.get_repo_format()
723
775
        network_name = reference_format.network_name()
724
 
        client = FakeClient('bzr://example.com/')
 
776
        server_url = 'bzr://example.com/'
 
777
        self.permit_url(server_url)
 
778
        client = FakeClient(server_url)
725
779
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
726
780
        client.add_success_response('ok', '', 'no', 'no', 'no')
727
781
        # A real repository instance will be created to determine the network
732
786
            reference_format.get_format_string(), 'ok')
733
787
        # PackRepository wants to do a stat
734
788
        client.add_success_response('stat', '0', '65535')
735
 
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
 
789
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
736
790
            _client=client)
737
791
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
738
792
            _client=client)
1727
1781
        return repo, client
1728
1782
 
1729
1783
 
 
1784
def remoted_description(format):
 
1785
    return 'Remote: ' + format.get_format_description()
 
1786
 
 
1787
 
 
1788
class TestBranchFormat(tests.TestCase):
 
1789
 
 
1790
    def test_get_format_description(self):
 
1791
        remote_format = RemoteBranchFormat()
 
1792
        real_format = branch.BranchFormat.get_default_format()
 
1793
        remote_format._network_name = real_format.network_name()
 
1794
        self.assertEqual(remoted_description(real_format),
 
1795
            remote_format.get_format_description())
 
1796
 
 
1797
 
1730
1798
class TestRepositoryFormat(TestRemoteRepository):
1731
1799
 
1732
1800
    def test_fast_delta(self):
1739
1807
        false_format._network_name = false_name
1740
1808
        self.assertEqual(False, false_format.fast_deltas)
1741
1809
 
 
1810
    def test_get_format_description(self):
 
1811
        remote_repo_format = RemoteRepositoryFormat()
 
1812
        real_format = repository.RepositoryFormat.get_default_format()
 
1813
        remote_repo_format._network_name = real_format.network_name()
 
1814
        self.assertEqual(remoted_description(real_format),
 
1815
            remote_repo_format.get_format_description())
 
1816
 
1742
1817
 
1743
1818
class TestRepositoryGatherStats(TestRemoteRepository):
1744
1819
 
1999
2074
    def test_allows_new_revisions(self):
2000
2075
        """get_parent_map's results can be updated by commit."""
2001
2076
        smart_server = server.SmartTCPServer_for_testing()
2002
 
        smart_server.setUp()
2003
 
        self.addCleanup(smart_server.tearDown)
 
2077
        self.start_server(smart_server)
2004
2078
        self.make_branch('branch')
2005
2079
        branch = Branch.open(smart_server.get_url() + '/branch')
2006
2080
        tree = branch.create_checkout('tree', lightweight=True)
2819
2893
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2820
2894
        # been muttered to the log file for developer to look at.
2821
2895
        self.assertContainsRe(
2822
 
            self._get_log(keep_log_file=True),
 
2896
            self.get_log(),
2823
2897
            "Missing key 'branch' in context")
2824
2898
 
2825
2899
    def test_path_missing(self):
2833
2907
        self.assertEqual(server_error, translated_error)
2834
2908
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2835
2909
        # been muttered to the log file for developer to look at.
2836
 
        self.assertContainsRe(
2837
 
            self._get_log(keep_log_file=True), "Missing key 'path' in context")
 
2910
        self.assertContainsRe(self.get_log(), "Missing key 'path' in context")
2838
2911
 
2839
2912
 
2840
2913
class TestStacking(tests.TestCaseWithTransport):
2859
2932
        stacked_branch.set_stacked_on_url('../base')
2860
2933
        # start a server looking at this
2861
2934
        smart_server = server.SmartTCPServer_for_testing()
2862
 
        smart_server.setUp()
2863
 
        self.addCleanup(smart_server.tearDown)
 
2935
        self.start_server(smart_server)
2864
2936
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
2865
2937
        # can get its branch and repository
2866
2938
        remote_branch = remote_bzrdir.open_branch()
2969
3041
            local_tree.commit('more local changes are better')
2970
3042
            branch = Branch.open(self.get_url('tree3'))
2971
3043
            branch.lock_read()
 
3044
            self.addCleanup(branch.unlock)
2972
3045
            return None, branch
2973
3046
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered',
2974
3047
            branch_factory=make_stacked_stacked)
3021
3094
        # Create a smart server that publishes whatever the backing VFS server
3022
3095
        # does.
3023
3096
        self.smart_server = server.SmartTCPServer_for_testing()
3024
 
        self.smart_server.setUp(self.get_server())
3025
 
        self.addCleanup(self.smart_server.tearDown)
 
3097
        self.start_server(self.smart_server, self.get_server())
3026
3098
        # Log all HPSS calls into self.hpss_calls.
3027
3099
        _SmartClient.hooks.install_named_hook(
3028
3100
            'call', self.capture_hpss_call, None)