~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

Merge cleanup into texinfo

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import sys
25
25
 
26
26
from bzrlib import (
 
27
    branch,
27
28
    bzrdir,
28
29
    errors,
29
30
    help_topics,
54
55
from bzrlib.transport import (
55
56
    get_transport,
56
57
    memory,
 
58
    pathfilter,
57
59
    )
58
60
from bzrlib.transport.http._urllib import HttpTransport_urllib
59
61
from bzrlib.transport.nosmart import NoSmartTransportDecorator
807
809
        self.assertEqualBzrdirs([baz, foo, bar],
808
810
                                bzrdir.BzrDir.find_bzrdirs(transport))
809
811
 
 
812
    def make_fake_permission_denied_transport(self, transport, paths):
 
813
        """Create a transport that raises PermissionDenied for some paths."""
 
814
        def filter(path):
 
815
            if path in paths:
 
816
                raise errors.PermissionDenied(path)
 
817
            return path
 
818
        path_filter_server = pathfilter.PathFilteringServer(transport, filter)
 
819
        path_filter_server.start_server()
 
820
        self.addCleanup(path_filter_server.stop_server)
 
821
        path_filter_transport = pathfilter.PathFilteringTransport(
 
822
            path_filter_server, '.')
 
823
        return (path_filter_server, path_filter_transport)
 
824
 
 
825
    def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
 
826
        """Check that each branch url ends with the given suffix."""
 
827
        for actual_bzrdir in actual_bzrdirs:
 
828
            self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
 
829
 
 
830
    def test_find_bzrdirs_permission_denied(self):
 
831
        foo, bar, baz = self.make_foo_bar_baz()
 
832
        transport = get_transport(self.get_url())
 
833
        path_filter_server, path_filter_transport = \
 
834
            self.make_fake_permission_denied_transport(transport, ['foo'])
 
835
        # local transport
 
836
        self.assertBranchUrlsEndWith('/baz/',
 
837
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
 
838
        # smart server
 
839
        smart_transport = self.make_smart_server('.',
 
840
            backing_server=path_filter_server)
 
841
        self.assertBranchUrlsEndWith('/baz/',
 
842
            bzrdir.BzrDir.find_bzrdirs(smart_transport))
 
843
 
810
844
    def test_find_bzrdirs_list_current(self):
811
845
        def list_current(transport):
812
846
            return [s for s in transport.list_dir('') if s != 'baz']
817
851
                                bzrdir.BzrDir.find_bzrdirs(transport,
818
852
                                    list_current=list_current))
819
853
 
820
 
 
821
854
    def test_find_bzrdirs_evaluate(self):
822
855
        def evaluate(bzrdir):
823
856
            try:
856
889
        self.assertEqual(bar.root_transport.base, branches[1].base)
857
890
 
858
891
 
 
892
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
 
893
 
 
894
    def test_find_bzrdirs_missing_repo(self):
 
895
        transport = get_transport(self.get_url())
 
896
        arepo = self.make_repository('arepo', shared=True)
 
897
        abranch_url = arepo.user_url + '/abranch'
 
898
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
 
899
        transport.delete_tree('arepo/.bzr')
 
900
        self.assertRaises(errors.NoRepositoryPresent,
 
901
            branch.Branch.open, abranch_url)
 
902
        self.make_branch('baz')
 
903
        for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
 
904
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
 
905
 
 
906
 
859
907
class TestMeta1DirFormat(TestCaseWithTransport):
860
908
    """Tests specific to the meta1 dir format."""
861
909
 
1111
1159
    """
1112
1160
 
1113
1161
    def create_transport_readonly_server(self):
 
1162
        # We don't set the http protocol version, relying on the default
1114
1163
        return http_utils.HTTPServerRedirecting()
1115
1164
 
1116
1165
    def create_transport_secondary_server(self):
 
1166
        # We don't set the http protocol version, relying on the default
1117
1167
        return http_utils.HTTPServerRedirecting()
1118
1168
 
1119
1169
    def setUp(self):