~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

(lifeless) Teach BzrDir.find_bzrdirs to handle PermissionDenied errors.
 (Marius Kruger) (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
from bzrlib.transport import (
55
55
    get_transport,
56
56
    memory,
 
57
    pathfilter,
57
58
    )
58
59
from bzrlib.transport.http._urllib import HttpTransport_urllib
59
60
from bzrlib.transport.nosmart import NoSmartTransportDecorator
807
808
        self.assertEqualBzrdirs([baz, foo, bar],
808
809
                                bzrdir.BzrDir.find_bzrdirs(transport))
809
810
 
 
811
    def make_fake_permission_denied_transport(self, transport, paths):
 
812
        """Create a transport that raises PermissionDenied for some paths."""
 
813
        def filter(path):
 
814
            if path in paths:
 
815
                raise errors.PermissionDenied(path)
 
816
            return path
 
817
        path_filter_server = pathfilter.PathFilteringServer(transport, filter)
 
818
        path_filter_server.start_server()
 
819
        self.addCleanup(path_filter_server.stop_server)
 
820
        path_filter_transport = pathfilter.PathFilteringTransport(
 
821
            path_filter_server, '.')
 
822
        return (path_filter_server, path_filter_transport)
 
823
 
 
824
    def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
 
825
        """Check that each branch url ends with the given suffix."""
 
826
        for actual_bzrdir in actual_bzrdirs:
 
827
            self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
 
828
 
 
829
    def test_find_bzrdirs_permission_denied(self):
 
830
        foo, bar, baz = self.make_foo_bar_baz()
 
831
        transport = get_transport(self.get_url())
 
832
        path_filter_server, path_filter_transport = \
 
833
            self.make_fake_permission_denied_transport(transport, ['foo'])
 
834
        # local transport
 
835
        self.assertBranchUrlsEndWith('/baz/',
 
836
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
 
837
        # smart server
 
838
        smart_transport = self.make_smart_server('.',
 
839
            backing_server=path_filter_server)
 
840
        self.assertBranchUrlsEndWith('/baz/',
 
841
            bzrdir.BzrDir.find_bzrdirs(smart_transport))
 
842
 
810
843
    def test_find_bzrdirs_list_current(self):
811
844
        def list_current(transport):
812
845
            return [s for s in transport.list_dir('') if s != 'baz']
817
850
                                bzrdir.BzrDir.find_bzrdirs(transport,
818
851
                                    list_current=list_current))
819
852
 
820
 
 
821
853
    def test_find_bzrdirs_evaluate(self):
822
854
        def evaluate(bzrdir):
823
855
            try: