/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_bzrdir.py

1st cut merge of bzr.dev r3907

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006, 2007 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
5
5
# the Free Software Foundation; either version 2 of the License, or
30
30
    errors,
31
31
    help_topics,
32
32
    repository,
 
33
    osutils,
33
34
    symbol_versioning,
34
35
    urlutils,
35
36
    win32utils,
47
48
    TestSkipped,
48
49
    test_sftp_transport
49
50
    )
50
 
from bzrlib.tests.http_server import HttpServer
51
 
from bzrlib.tests.http_utils import (
52
 
    TestCaseWithTwoWebservers,
53
 
    HTTPServerRedirecting,
 
51
from bzrlib.tests import(
 
52
    http_server,
 
53
    http_utils,
54
54
    )
55
55
from bzrlib.tests.test_http import TestWithTransport_pycurl
56
56
from bzrlib.transport import get_transport
57
57
from bzrlib.transport.http._urllib import HttpTransport_urllib
58
58
from bzrlib.transport.memory import MemoryServer
 
59
from bzrlib.transport.nosmart import NoSmartTransportDecorator
 
60
from bzrlib.transport.readonly import ReadonlyTransportDecorator
59
61
from bzrlib.repofmt import knitrepo, weaverepo
60
62
 
61
63
 
138
140
        
139
141
    def test_help_topic(self):
140
142
        topics = help_topics.HelpTopicRegistry()
141
 
        topics.register('formats', self.make_format_registry().help_topic, 
142
 
                        'Directory formats')
143
 
        topic = topics.get_detail('formats')
144
 
        new, rest = topic.split('Experimental formats')
 
143
        registry = self.make_format_registry()
 
144
        topics.register('current-formats', registry.help_topic, 
 
145
                        'Current formats')
 
146
        topics.register('other-formats', registry.help_topic, 
 
147
                        'Other formats')
 
148
        new = topics.get_detail('current-formats')
 
149
        rest = topics.get_detail('other-formats')
145
150
        experimental, deprecated = rest.split('Deprecated formats')
146
 
        self.assertContainsRe(new, 'These formats can be used')
 
151
        self.assertContainsRe(new, 'bzr help formats')
147
152
        self.assertContainsRe(new, 
148
153
                ':knit:\n    \(native\) \(default\) Format using knits\n')
149
154
        self.assertContainsRe(experimental, 
441
446
        self.assertEqual(parent_bzrdir.root_transport.base,
442
447
                         repo_policy._stack_on_pwd)
443
448
 
444
 
    def prepare_default_stacking(self):
 
449
    def prepare_default_stacking(self, child_format='1.6'):
445
450
        parent_bzrdir = self.make_bzrdir('.')
446
 
        child_branch = self.make_branch('child', format='development1')
 
451
        child_branch = self.make_branch('child', format=child_format)
447
452
        parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
448
453
        new_child_transport = parent_bzrdir.transport.clone('child2')
449
454
        return child_branch, new_child_transport
460
465
        self.assertEqual(child_branch.base,
461
466
                         new_child.open_branch().get_stacked_on_url())
462
467
 
 
468
    def test_clone_ignores_policy_for_unsupported_formats(self):
 
469
        child_branch, new_child_transport = self.prepare_default_stacking(
 
470
            child_format='pack-0.92')
 
471
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
 
472
        self.assertRaises(errors.UnstackableBranchFormat,
 
473
                          new_child.open_branch().get_stacked_on_url)
 
474
 
 
475
    def test_sprout_ignores_policy_for_unsupported_formats(self):
 
476
        child_branch, new_child_transport = self.prepare_default_stacking(
 
477
            child_format='pack-0.92')
 
478
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
 
479
        self.assertRaises(errors.UnstackableBranchFormat,
 
480
                          new_child.open_branch().get_stacked_on_url)
 
481
 
 
482
    def test_sprout_upgrades_format_if_stacked_specified(self):
 
483
        child_branch, new_child_transport = self.prepare_default_stacking(
 
484
            child_format='pack-0.92')
 
485
        new_child = child_branch.bzrdir.sprout(new_child_transport.base,
 
486
                                               stacked=True)
 
487
        self.assertEqual(child_branch.bzrdir.root_transport.base,
 
488
                         new_child.open_branch().get_stacked_on_url())
 
489
        repo = new_child.open_repository()
 
490
        self.assertTrue(repo._format.supports_external_lookups)
 
491
        self.assertFalse(repo.supports_rich_root())
 
492
 
 
493
    def test_clone_on_transport_upgrades_format_if_stacked_on_specified(self):
 
494
        child_branch, new_child_transport = self.prepare_default_stacking(
 
495
            child_format='pack-0.92')
 
496
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport,
 
497
            stacked_on=child_branch.bzrdir.root_transport.base)
 
498
        self.assertEqual(child_branch.bzrdir.root_transport.base,
 
499
                         new_child.open_branch().get_stacked_on_url())
 
500
        repo = new_child.open_repository()
 
501
        self.assertTrue(repo._format.supports_external_lookups)
 
502
        self.assertFalse(repo.supports_rich_root())
 
503
 
 
504
    def test_sprout_upgrades_to_rich_root_format_if_needed(self):
 
505
        child_branch, new_child_transport = self.prepare_default_stacking(
 
506
            child_format='rich-root-pack')
 
507
        new_child = child_branch.bzrdir.sprout(new_child_transport.base,
 
508
                                               stacked=True)
 
509
        repo = new_child.open_repository()
 
510
        self.assertTrue(repo._format.supports_external_lookups)
 
511
        self.assertTrue(repo.supports_rich_root())
 
512
 
463
513
    def test_add_fallback_repo_handles_absolute_urls(self):
464
 
        stack_on = self.make_branch('stack_on', format='development1')
465
 
        repo = self.make_repository('repo', format='development1')
 
514
        stack_on = self.make_branch('stack_on', format='1.6')
 
515
        repo = self.make_repository('repo', format='1.6')
466
516
        policy = bzrdir.UseExistingRepository(repo, stack_on.base)
467
517
        policy._add_fallback(repo)
468
518
 
469
519
    def test_add_fallback_repo_handles_relative_urls(self):
470
 
        stack_on = self.make_branch('stack_on', format='development1')
471
 
        repo = self.make_repository('repo', format='development1')
 
520
        stack_on = self.make_branch('stack_on', format='1.6')
 
521
        repo = self.make_repository('repo', format='1.6')
472
522
        policy = bzrdir.UseExistingRepository(repo, '.', stack_on.base)
473
523
        policy._add_fallback(repo)
474
524
 
475
525
    def test_configure_relative_branch_stacking_url(self):
476
 
        stack_on = self.make_branch('stack_on', format='development1')
477
 
        stacked = self.make_branch('stack_on/stacked', format='development1')
 
526
        stack_on = self.make_branch('stack_on', format='1.6')
 
527
        stacked = self.make_branch('stack_on/stacked', format='1.6')
478
528
        policy = bzrdir.UseExistingRepository(stacked.repository,
479
529
            '.', stack_on.base)
480
530
        policy.configure_branch(stacked)
481
531
        self.assertEqual('..', stacked.get_stacked_on_url())
482
532
 
483
533
    def test_relative_branch_stacking_to_absolute(self):
484
 
        stack_on = self.make_branch('stack_on', format='development1')
485
 
        stacked = self.make_branch('stack_on/stacked', format='development1')
 
534
        stack_on = self.make_branch('stack_on', format='1.6')
 
535
        stacked = self.make_branch('stack_on/stacked', format='1.6')
486
536
        policy = bzrdir.UseExistingRepository(stacked.repository,
487
537
            '.', self.get_readonly_url('stack_on'))
488
538
        policy.configure_branch(stacked)
501
551
    def setUp(self):
502
552
        super(ChrootedTests, self).setUp()
503
553
        if not self.vfs_transport_factory == MemoryServer:
504
 
            self.transport_readonly_server = HttpServer
 
554
            self.transport_readonly_server = http_server.HttpServer
505
555
 
506
556
    def local_branch_path(self, branch):
507
557
         return os.path.realpath(urlutils.local_path_from_url(branch.base))
532
582
        self.assertEqual(os.path.realpath('topdir'),
533
583
                         self.local_branch_path(branch))
534
584
        self.assertEqual(
535
 
            os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
 
585
            osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
536
586
            repo.bzrdir.transport.local_abspath('repository'))
537
587
        self.assertEqual(relpath, 'foo')
538
588
 
545
595
        self.assertEqual(os.path.realpath('branch'),
546
596
                         self.local_branch_path(branch))
547
597
        self.assertEqual(
548
 
            os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
 
598
            osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
549
599
            repo.bzrdir.transport.local_abspath('repository'))
550
600
        self.assertEqual(relpath, 'foo')
551
601
 
557
607
        self.assertEqual(tree, None)
558
608
        self.assertEqual(branch, None)
559
609
        self.assertEqual(
560
 
            os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
 
610
            osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
561
611
            repo.bzrdir.transport.local_abspath('repository'))
562
612
        self.assertEqual(relpath, '')
563
613
 
572
622
        self.assertEqual(os.path.realpath('shared/branch'),
573
623
                         self.local_branch_path(branch))
574
624
        self.assertEqual(
575
 
            os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
 
625
            osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
576
626
            repo.bzrdir.transport.local_abspath('repository'))
577
627
        self.assertEqual(relpath, '')
578
628
 
587
637
        self.assertEqual(os.path.realpath('foo'),
588
638
                         self.local_branch_path(branch))
589
639
        self.assertEqual(
590
 
            os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
 
640
            osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
591
641
            repo.bzrdir.transport.local_abspath('repository'))
592
642
        self.assertEqual(relpath, 'bar')
593
643
 
600
650
        self.assertEqual(tree, None)
601
651
        self.assertEqual(branch, None)
602
652
        self.assertEqual(
603
 
            os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
 
653
            osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
604
654
            repo.bzrdir.transport.local_abspath('repository'))
605
655
        self.assertEqual(relpath, 'baz')
606
656
 
1018
1068
                              workingtree.WorkingTreeFormat3)
1019
1069
 
1020
1070
 
1021
 
class TestHTTPRedirectionLoop(object):
1022
 
    """Test redirection loop between two http servers.
 
1071
class TestHTTPRedirections(object):
 
1072
    """Test redirection between two http servers.
1023
1073
 
1024
1074
    This MUST be used by daughter classes that also inherit from
1025
1075
    TestCaseWithTwoWebservers.
1029
1079
    run, its implementation being incomplete. 
1030
1080
    """
1031
1081
 
1032
 
    # Should be defined by daughter classes to ensure redirection
1033
 
    # still use the same transport implementation (not currently
1034
 
    # enforced as it's a bit tricky to get right (see the FIXME
1035
 
    # in BzrDir.open_from_transport for the unique use case so
1036
 
    # far)
1037
 
    _qualifier = None
1038
 
 
1039
1082
    def create_transport_readonly_server(self):
1040
 
        return HTTPServerRedirecting()
 
1083
        return http_utils.HTTPServerRedirecting()
1041
1084
 
1042
1085
    def create_transport_secondary_server(self):
1043
 
        return HTTPServerRedirecting()
 
1086
        return http_utils.HTTPServerRedirecting()
1044
1087
 
1045
1088
    def setUp(self):
1046
 
        # Both servers redirect to each server creating a loop
1047
 
        super(TestHTTPRedirectionLoop, self).setUp()
 
1089
        super(TestHTTPRedirections, self).setUp()
1048
1090
        # The redirections will point to the new server
1049
1091
        self.new_server = self.get_readonly_server()
1050
1092
        # The requests to the old server will be redirected
1051
1093
        self.old_server = self.get_secondary_server()
1052
1094
        # Configure the redirections
1053
1095
        self.old_server.redirect_to(self.new_server.host, self.new_server.port)
 
1096
 
 
1097
    def test_loop(self):
 
1098
        # Both servers redirect to each other creating a loop
1054
1099
        self.new_server.redirect_to(self.old_server.host, self.old_server.port)
1055
 
 
1056
 
    def _qualified_url(self, host, port):
1057
 
        return 'http+%s://%s:%s' % (self._qualifier, host, port)
1058
 
 
1059
 
    def test_loop(self):
1060
1100
        # Starting from either server should loop
1061
 
        old_url = self._qualified_url(self.old_server.host, 
 
1101
        old_url = self._qualified_url(self.old_server.host,
1062
1102
                                      self.old_server.port)
1063
1103
        oldt = self._transport(old_url)
1064
1104
        self.assertRaises(errors.NotBranchError,
1065
1105
                          bzrdir.BzrDir.open_from_transport, oldt)
1066
 
        new_url = self._qualified_url(self.new_server.host, 
 
1106
        new_url = self._qualified_url(self.new_server.host,
1067
1107
                                      self.new_server.port)
1068
1108
        newt = self._transport(new_url)
1069
1109
        self.assertRaises(errors.NotBranchError,
1070
1110
                          bzrdir.BzrDir.open_from_transport, newt)
1071
1111
 
1072
 
 
1073
 
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
1074
 
                                  TestCaseWithTwoWebservers):
 
1112
    def test_qualifier_preserved(self):
 
1113
        wt = self.make_branch_and_tree('branch')
 
1114
        old_url = self._qualified_url(self.old_server.host,
 
1115
                                      self.old_server.port)
 
1116
        start = self._transport(old_url).clone('branch')
 
1117
        bdir = bzrdir.BzrDir.open_from_transport(start)
 
1118
        # Redirection should preserve the qualifier, hence the transport class
 
1119
        # itself.
 
1120
        self.assertIsInstance(bdir.root_transport, type(start))
 
1121
 
 
1122
 
 
1123
class TestHTTPRedirections_urllib(TestHTTPRedirections,
 
1124
                                  http_utils.TestCaseWithTwoWebservers):
1075
1125
    """Tests redirections for urllib implementation"""
1076
1126
 
1077
 
    _qualifier = 'urllib'
1078
1127
    _transport = HttpTransport_urllib
1079
1128
 
 
1129
    def _qualified_url(self, host, port):
 
1130
        return 'http+urllib://%s:%s' % (host, port)
 
1131
 
1080
1132
 
1081
1133
 
1082
1134
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
1083
 
                                  TestHTTPRedirectionLoop,
1084
 
                                  TestCaseWithTwoWebservers):
 
1135
                                  TestHTTPRedirections,
 
1136
                                  http_utils.TestCaseWithTwoWebservers):
1085
1137
    """Tests redirections for pycurl implementation"""
1086
1138
 
1087
 
    _qualifier = 'pycurl'
 
1139
    def _qualified_url(self, host, port):
 
1140
        return 'http+pycurl://%s:%s' % (host, port)
 
1141
 
 
1142
 
 
1143
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
 
1144
                                  http_utils.TestCaseWithTwoWebservers):
 
1145
    """Tests redirections for the nosmart decorator"""
 
1146
 
 
1147
    _transport = NoSmartTransportDecorator
 
1148
 
 
1149
    def _qualified_url(self, host, port):
 
1150
        return 'nosmart+http://%s:%s' % (host, port)
 
1151
 
 
1152
 
 
1153
class TestHTTPRedirections_readonly(TestHTTPRedirections,
 
1154
                                    http_utils.TestCaseWithTwoWebservers):
 
1155
    """Tests redirections for readonly decoratror"""
 
1156
 
 
1157
    _transport = ReadonlyTransportDecorator
 
1158
 
 
1159
    def _qualified_url(self, host, port):
 
1160
        return 'readonly+http://%s:%s' % (host, port)
1088
1161
 
1089
1162
 
1090
1163
class TestDotBzrHidden(TestCaseWithTransport):
1138
1211
    def open_branch(self, unsupported=False):
1139
1212
        return self.test_branch
1140
1213
 
1141
 
    def cloning_metadir(self):
 
1214
    def cloning_metadir(self, require_stacking=False):
1142
1215
        return _TestBzrDirFormat()
1143
1216
 
1144
1217
 
1148
1221
    def __init__(self, *args, **kwargs):
1149
1222
        super(_TestBranch, self).__init__(*args, **kwargs)
1150
1223
        self.calls = []
1151
 
    
 
1224
        self._parent = None
 
1225
 
1152
1226
    def sprout(self, *args, **kwargs):
1153
1227
        self.calls.append('sprout')
 
1228
        return _TestBranch()
 
1229
 
 
1230
    def copy_content_into(self, destination, revision_id=None):
 
1231
        self.calls.append('copy_content_into')
 
1232
 
 
1233
    def get_parent(self):
 
1234
        return self._parent
 
1235
 
 
1236
    def set_parent(self, parent):
 
1237
        self._parent = parent
1154
1238
 
1155
1239
 
1156
1240
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1181
1265
        result = source_bzrdir.sprout(target_url, recurse='no')
1182
1266
 
1183
1267
        # The bzrdir called the branch's sprout method.
1184
 
        self.assertEqual(['sprout'], source_bzrdir.test_branch.calls)
1185
 
        
 
1268
        self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
 
1269
 
 
1270
    def test_sprout_parent(self):
 
1271
        grandparent_tree = self.make_branch('grandparent')
 
1272
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
 
1273
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
 
1274
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')