~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Martin Pool
  • Date: 2010-08-13 08:09:53 UTC
  • mto: (5050.17.6 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: mbp@sourcefrog.net-20100813080953-c00cm9l3qgu2flj9
Remove spuriously-resurrected test

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
24
import sys
25
25
 
26
26
from bzrlib import (
 
27
    branch,
27
28
    bzrdir,
28
29
    errors,
29
30
    help_topics,
36
37
    )
37
38
import bzrlib.branch
38
39
from bzrlib.errors import (NotBranchError,
 
40
                           NoColocatedBranchSupport,
39
41
                           UnknownFormatError,
40
42
                           UnsupportedFormatError,
41
43
                           )
50
52
    http_utils,
51
53
    )
52
54
from bzrlib.tests.test_http import TestWithTransport_pycurl
53
 
from bzrlib.transport import get_transport
 
55
from bzrlib.transport import (
 
56
    get_transport,
 
57
    memory,
 
58
    pathfilter,
 
59
    )
54
60
from bzrlib.transport.http._urllib import HttpTransport_urllib
55
 
from bzrlib.transport.memory import MemoryServer
56
61
from bzrlib.transport.nosmart import NoSmartTransportDecorator
57
62
from bzrlib.transport.readonly import ReadonlyTransportDecorator
58
63
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
145
150
        new = topics.get_detail('current-formats')
146
151
        rest = topics.get_detail('other-formats')
147
152
        experimental, deprecated = rest.split('Deprecated formats')
148
 
        self.assertContainsRe(new, 'bzr help formats')
 
153
        self.assertContainsRe(new, 'formats-help')
149
154
        self.assertContainsRe(new,
150
155
                ':knit:\n    \(native\) \(default\) Format using knits\n')
151
156
        self.assertContainsRe(experimental,
204
209
        """See BzrDir.open_repository."""
205
210
        return SampleRepository(self)
206
211
 
207
 
    def create_branch(self):
 
212
    def create_branch(self, name=None):
208
213
        """See BzrDir.create_branch."""
 
214
        if name is not None:
 
215
            raise NoColocatedBranchSupport(self)
209
216
        return SampleBranch(self)
210
217
 
211
218
    def create_workingtree(self):
354
361
 
355
362
    def test_create_branch_convenience_root(self):
356
363
        """Creating a branch at the root of a fs should work."""
357
 
        self.vfs_transport_factory = MemoryServer
 
364
        self.vfs_transport_factory = memory.MemoryServer
358
365
        # outside a repo the default convenience output is a repo+branch_tree
359
366
        format = bzrdir.format_registry.make_bzrdir('knit')
360
367
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
466
473
        # Make stackable source branch with an unstackable repo format.
467
474
        source_bzrdir = self.make_bzrdir('source')
468
475
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
469
 
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(source_bzrdir)
 
476
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
 
477
            source_bzrdir)
470
478
        # Make a directory with a default stacking policy
471
479
        parent_bzrdir = self.make_bzrdir('parent')
472
480
        stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
565
573
 
566
574
    def setUp(self):
567
575
        super(ChrootedTests, self).setUp()
568
 
        if not self.vfs_transport_factory == MemoryServer:
 
576
        if not self.vfs_transport_factory == memory.MemoryServer:
569
577
            self.transport_readonly_server = http_server.HttpServer
570
578
 
571
579
    def local_branch_path(self, branch):
801
809
        self.assertEqualBzrdirs([baz, foo, bar],
802
810
                                bzrdir.BzrDir.find_bzrdirs(transport))
803
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
 
804
844
    def test_find_bzrdirs_list_current(self):
805
845
        def list_current(transport):
806
846
            return [s for s in transport.list_dir('') if s != 'baz']
811
851
                                bzrdir.BzrDir.find_bzrdirs(transport,
812
852
                                    list_current=list_current))
813
853
 
814
 
 
815
854
    def test_find_bzrdirs_evaluate(self):
816
855
        def evaluate(bzrdir):
817
856
            try:
850
889
        self.assertEqual(bar.root_transport.base, branches[1].base)
851
890
 
852
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
 
853
907
class TestMeta1DirFormat(TestCaseWithTransport):
854
908
    """Tests specific to the meta1 dir format."""
855
909
 
1049
1103
 
1050
1104
    def setUp(self):
1051
1105
        super(NonLocalTests, self).setUp()
1052
 
        self.vfs_transport_factory = MemoryServer
 
1106
        self.vfs_transport_factory = memory.MemoryServer
1053
1107
 
1054
1108
    def test_create_branch_convenience(self):
1055
1109
        # outside a repo the default convenience output is a repo+branch_tree
1105
1159
    """
1106
1160
 
1107
1161
    def create_transport_readonly_server(self):
 
1162
        # We don't set the http protocol version, relying on the default
1108
1163
        return http_utils.HTTPServerRedirecting()
1109
1164
 
1110
1165
    def create_transport_secondary_server(self):
 
1166
        # We don't set the http protocol version, relying on the default
1111
1167
        return http_utils.HTTPServerRedirecting()
1112
1168
 
1113
1169
    def setUp(self):
1152
1208
    _transport = HttpTransport_urllib
1153
1209
 
1154
1210
    def _qualified_url(self, host, port):
1155
 
        return 'http+urllib://%s:%s' % (host, port)
 
1211
        result = 'http+urllib://%s:%s' % (host, port)
 
1212
        self.permit_url(result)
 
1213
        return result
1156
1214
 
1157
1215
 
1158
1216
 
1162
1220
    """Tests redirections for pycurl implementation"""
1163
1221
 
1164
1222
    def _qualified_url(self, host, port):
1165
 
        return 'http+pycurl://%s:%s' % (host, port)
 
1223
        result = 'http+pycurl://%s:%s' % (host, port)
 
1224
        self.permit_url(result)
 
1225
        return result
1166
1226
 
1167
1227
 
1168
1228
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
1172
1232
    _transport = NoSmartTransportDecorator
1173
1233
 
1174
1234
    def _qualified_url(self, host, port):
1175
 
        return 'nosmart+http://%s:%s' % (host, port)
 
1235
        result = 'nosmart+http://%s:%s' % (host, port)
 
1236
        self.permit_url(result)
 
1237
        return result
1176
1238
 
1177
1239
 
1178
1240
class TestHTTPRedirections_readonly(TestHTTPRedirections,
1182
1244
    _transport = ReadonlyTransportDecorator
1183
1245
 
1184
1246
    def _qualified_url(self, host, port):
1185
 
        return 'readonly+http://%s:%s' % (host, port)
 
1247
        result = 'readonly+http://%s:%s' % (host, port)
 
1248
        self.permit_url(result)
 
1249
        return result
1186
1250
 
1187
1251
 
1188
1252
class TestDotBzrHidden(TestCaseWithTransport):
1325
1389
        url = transport.base
1326
1390
        err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
1327
1391
        self.assertEqual('fail', err._preformatted_string)
 
1392
 
 
1393
    def test_post_repo_init(self):
 
1394
        from bzrlib.bzrdir import RepoInitHookParams
 
1395
        calls = []
 
1396
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
 
1397
            calls.append, None)
 
1398
        self.make_repository('foo')
 
1399
        self.assertLength(1, calls)
 
1400
        params = calls[0]
 
1401
        self.assertIsInstance(params, RepoInitHookParams)
 
1402
        self.assertTrue(hasattr(params, 'bzrdir'))
 
1403
        self.assertTrue(hasattr(params, 'repository'))