89
86
_qualified_prefix='http+pycurl',)))
90
87
tests.multiply_tests(t_tests, transport_scenarios, result)
89
protocol_scenarios = [
90
('HTTP/1.0', dict(_protocol_version='HTTP/1.0')),
91
('HTTP/1.1', dict(_protocol_version='HTTP/1.1')),
94
# some tests are parametrized by the protocol version only
95
p_tests, remaining_tests = tests.split_suite_by_condition(
96
remaining_tests, tests.condition_isinstance((
99
tests.multiply_tests(p_tests, protocol_scenarios, result)
92
101
# each implementation tested with each HTTP version
93
102
tp_tests, remaining_tests = tests.split_suite_by_condition(
94
103
remaining_tests, tests.condition_isinstance((
104
113
TestSpecificRequestHandler,
106
protocol_scenarios = [
107
('HTTP/1.0', dict(_protocol_version='HTTP/1.0')),
108
('HTTP/1.1', dict(_protocol_version='HTTP/1.1')),
110
115
tp_scenarios = tests.multiply_scenarios(transport_scenarios,
111
116
protocol_scenarios)
112
117
tests.multiply_tests(tp_tests, tp_scenarios, result)
1334
1336
t = self._transport(self.new_server.get_url())
1335
1337
self.assertEqual('0123456789', t.get('a').read())
1337
def test_read_redirected_bundle_from_url(self):
1338
from bzrlib.bundle import read_bundle_from_url
1339
url = self.old_transport.abspath('bundle')
1340
bundle = self.applyDeprecated(deprecated_in((1, 12, 0)),
1341
read_bundle_from_url, url)
1342
# If read_bundle_from_url was successful we get an empty bundle
1343
self.assertEqual([], bundle.revisions)
1346
1340
class RedirectedRequest(_urllib2_wrappers.Request):
1347
1341
"""Request following redirections. """
1966
1960
# We override at class level because constructors may propagate the
1967
1961
# bound method and render instance overriding ineffective (an
1968
1962
# alternative would be to define a specific ui factory instead...)
1969
self.orig_report_activity = self._transport._report_activity
1970
self._transport._report_activity = report_activity
1973
self._transport._report_activity = self.orig_report_activity
1974
self.server.stop_server()
1975
tests.TestCase.tearDown(self)
1963
self.overrideAttr(self._transport, '_report_activity', report_activity)
1964
self.addCleanup(self.server.stop_server)
1977
1966
def get_transport(self):
1978
1967
return self._transport(self.server.get_url())
2095
2084
class TestActivity(tests.TestCase, TestActivityMixin):
2097
2086
def setUp(self):
2098
tests.TestCase.setUp(self)
2099
self.server = self._activity_server(self._protocol_version)
2100
self.server.start_server()
2101
self.activities = {}
2102
def report_activity(t, bytes, direction):
2103
count = self.activities.get(direction, 0)
2105
self.activities[direction] = count
2107
# We override at class level because constructors may propagate the
2108
# bound method and render instance overriding ineffective (an
2109
# alternative would be to define a specific ui factory instead...)
2110
self.orig_report_activity = self._transport._report_activity
2111
self._transport._report_activity = report_activity
2114
self._transport._report_activity = self.orig_report_activity
2115
self.server.stop_server()
2116
tests.TestCase.tearDown(self)
2087
TestActivityMixin.setUp(self)
2119
2090
class TestNoReportActivity(tests.TestCase, TestActivityMixin):
2092
# Unlike TestActivity, we are really testing ReportingFileSocket and
2093
# ReportingSocket, so we don't need all the parametrization. Since
2094
# ReportingFileSocket and ReportingSocket are wrappers, it's easier to
2095
# test them through their use by the transport than directly (that's a
2096
# bit less clean but far more simpler and effective).
2097
_activity_server = ActivityHTTPServer
2098
_protocol_version = 'HTTP/1.1'
2121
2100
def setUp(self):
2122
tests.TestCase.setUp(self)
2123
# Unlike TestActivity, we are really testing ReportingFileSocket and
2124
# ReportingSocket, so we don't need all the parametrization. Since
2125
# ReportingFileSocket and ReportingSocket are wrappers, it's easier to
2126
# test them through their use by the transport than directly (that's a
2127
# bit less clean but far more simpler and effective).
2128
self.server = ActivityHTTPServer('HTTP/1.1')
2129
self._transport=_urllib.HttpTransport_urllib
2131
self.server.start_server()
2133
# We override at class level because constructors may propagate the
2134
# bound method and render instance overriding ineffective (an
2135
# alternative would be to define a specific ui factory instead...)
2136
self.orig_report_activity = self._transport._report_activity
2137
self._transport._report_activity = None
2140
self._transport._report_activity = self.orig_report_activity
2141
self.server.stop_server()
2142
tests.TestCase.tearDown(self)
2101
self._transport =_urllib.HttpTransport_urllib
2102
TestActivityMixin.setUp(self)
2144
2104
def assertActivitiesMatch(self):
2145
2105
# Nothing to check here
2156
2116
_transport = _urllib.HttpTransport_urllib
2158
2118
def create_transport_readonly_server(self):
2159
return self._auth_server()
2119
return self._auth_server(protocol_version=self._protocol_version)
2161
2121
def create_transport_secondary_server(self):
2162
2122
"""Create the secondary server redirecting to the primary server"""
2163
2123
new = self.get_readonly_server()
2165
redirecting = http_utils.HTTPServerRedirecting()
2125
redirecting = http_utils.HTTPServerRedirecting(
2126
protocol_version=self._protocol_version)
2166
2127
redirecting.redirect_to(new.host, new.port)
2167
2128
return redirecting