~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Mark Hammond
  • Date: 2008-12-28 05:21:23 UTC
  • mfrom: (3920 +trunk)
  • mto: (3932.1.1 prepare-1.11)
  • mto: This revision was merged to the branch mainline in revision 3937.
  • Revision ID: mhammond@skippinet.com.au-20081228052123-f78xs5sbdkotshwf
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    TestSkipped,
49
49
    test_sftp_transport
50
50
    )
51
 
from bzrlib.tests.http_server import HttpServer
52
 
from bzrlib.tests.http_utils import (
53
 
    TestCaseWithTwoWebservers,
54
 
    HTTPServerRedirecting,
 
51
from bzrlib.tests import(
 
52
    http_server,
 
53
    http_utils,
55
54
    )
56
55
from bzrlib.tests.test_http import TestWithTransport_pycurl
57
56
from bzrlib.transport import get_transport
58
57
from bzrlib.transport.http._urllib import HttpTransport_urllib
59
58
from bzrlib.transport.memory import MemoryServer
 
59
from bzrlib.transport.nosmart import NoSmartTransportDecorator
 
60
from bzrlib.transport.readonly import ReadonlyTransportDecorator
60
61
from bzrlib.repofmt import knitrepo, weaverepo
61
62
 
62
63
 
139
140
        
140
141
    def test_help_topic(self):
141
142
        topics = help_topics.HelpTopicRegistry()
142
 
        topics.register('formats', self.make_format_registry().help_topic, 
143
 
                        'Directory formats')
144
 
        topic = topics.get_detail('formats')
145
 
        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')
146
150
        experimental, deprecated = rest.split('Deprecated formats')
147
 
        self.assertContainsRe(new, 'These formats can be used')
 
151
        self.assertContainsRe(new, 'bzr help formats')
148
152
        self.assertContainsRe(new, 
149
153
                ':knit:\n    \(native\) \(default\) Format using knits\n')
150
154
        self.assertContainsRe(experimental, 
547
551
    def setUp(self):
548
552
        super(ChrootedTests, self).setUp()
549
553
        if not self.vfs_transport_factory == MemoryServer:
550
 
            self.transport_readonly_server = HttpServer
 
554
            self.transport_readonly_server = http_server.HttpServer
551
555
 
552
556
    def local_branch_path(self, branch):
553
557
         return os.path.realpath(urlutils.local_path_from_url(branch.base))
1064
1068
                              workingtree.WorkingTreeFormat3)
1065
1069
 
1066
1070
 
1067
 
class TestHTTPRedirectionLoop(object):
1068
 
    """Test redirection loop between two http servers.
 
1071
class TestHTTPRedirections(object):
 
1072
    """Test redirection between two http servers.
1069
1073
 
1070
1074
    This MUST be used by daughter classes that also inherit from
1071
1075
    TestCaseWithTwoWebservers.
1075
1079
    run, its implementation being incomplete. 
1076
1080
    """
1077
1081
 
1078
 
    # Should be defined by daughter classes to ensure redirection
1079
 
    # still use the same transport implementation (not currently
1080
 
    # enforced as it's a bit tricky to get right (see the FIXME
1081
 
    # in BzrDir.open_from_transport for the unique use case so
1082
 
    # far)
1083
 
    _qualifier = None
1084
 
 
1085
1082
    def create_transport_readonly_server(self):
1086
 
        return HTTPServerRedirecting()
 
1083
        return http_utils.HTTPServerRedirecting()
1087
1084
 
1088
1085
    def create_transport_secondary_server(self):
1089
 
        return HTTPServerRedirecting()
 
1086
        return http_utils.HTTPServerRedirecting()
1090
1087
 
1091
1088
    def setUp(self):
1092
 
        # Both servers redirect to each server creating a loop
1093
 
        super(TestHTTPRedirectionLoop, self).setUp()
 
1089
        super(TestHTTPRedirections, self).setUp()
1094
1090
        # The redirections will point to the new server
1095
1091
        self.new_server = self.get_readonly_server()
1096
1092
        # The requests to the old server will be redirected
1097
1093
        self.old_server = self.get_secondary_server()
1098
1094
        # Configure the redirections
1099
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
1100
1099
        self.new_server.redirect_to(self.old_server.host, self.old_server.port)
1101
 
 
1102
 
    def _qualified_url(self, host, port):
1103
 
        return 'http+%s://%s:%s' % (self._qualifier, host, port)
1104
 
 
1105
 
    def test_loop(self):
1106
1100
        # Starting from either server should loop
1107
 
        old_url = self._qualified_url(self.old_server.host, 
 
1101
        old_url = self._qualified_url(self.old_server.host,
1108
1102
                                      self.old_server.port)
1109
1103
        oldt = self._transport(old_url)
1110
1104
        self.assertRaises(errors.NotBranchError,
1111
1105
                          bzrdir.BzrDir.open_from_transport, oldt)
1112
 
        new_url = self._qualified_url(self.new_server.host, 
 
1106
        new_url = self._qualified_url(self.new_server.host,
1113
1107
                                      self.new_server.port)
1114
1108
        newt = self._transport(new_url)
1115
1109
        self.assertRaises(errors.NotBranchError,
1116
1110
                          bzrdir.BzrDir.open_from_transport, newt)
1117
1111
 
1118
 
 
1119
 
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
1120
 
                                  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):
1121
1125
    """Tests redirections for urllib implementation"""
1122
1126
 
1123
 
    _qualifier = 'urllib'
1124
1127
    _transport = HttpTransport_urllib
1125
1128
 
 
1129
    def _qualified_url(self, host, port):
 
1130
        return 'http+urllib://%s:%s' % (host, port)
 
1131
 
1126
1132
 
1127
1133
 
1128
1134
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
1129
 
                                  TestHTTPRedirectionLoop,
1130
 
                                  TestCaseWithTwoWebservers):
 
1135
                                  TestHTTPRedirections,
 
1136
                                  http_utils.TestCaseWithTwoWebservers):
1131
1137
    """Tests redirections for pycurl implementation"""
1132
1138
 
1133
 
    _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)
1134
1161
 
1135
1162
 
1136
1163
class TestDotBzrHidden(TestCaseWithTransport):