65
if features.pycurl.available():
65
66
from bzrlib.transport.http._pycurl import PyCurlTransport
67
except errors.DependencyNotPresent:
68
pycurl_present = False
71
69
def load_tests(standard_tests, module, loader):
84
82
_server=http_server.HttpServer_urllib,
85
83
_qualified_prefix='http+urllib',)),
85
if features.pycurl.available():
88
86
transport_scenarios.append(
89
87
('pycurl', dict(_transport=PyCurlTransport,
90
88
_server=http_server.HttpServer_PyCurl,
156
154
activity_scenarios.append(
157
155
('urllib,https', dict(_activity_server=ActivityHTTPSServer,
158
156
_transport=_urllib.HttpTransport_urllib,)),)
157
if features.pycurl.available():
160
158
activity_scenarios.append(
161
159
('pycurl,http', dict(_activity_server=ActivityHTTPServer,
162
160
_transport=PyCurlTransport,)),)
220
218
def get_url(self):
221
219
return '%s://%s:%s/' % (self.scheme, self.host, self.port)
221
def start_server(self):
224
222
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
225
223
self._sock.bind(('127.0.0.1', 0))
226
224
self.host, self.port = self._sock.getsockname()
309
307
server = http_server.HttpServer(BogusRequestHandler)
311
self.assertRaises(httplib.UnknownProtocol, server.setUp)
309
self.assertRaises(httplib.UnknownProtocol, server.start_server)
314
312
self.fail('HTTP Server creation did not raise UnknownProtocol')
316
314
def test_force_invalid_protocol(self):
317
315
server = http_server.HttpServer(protocol_version='HTTP/0.1')
319
self.assertRaises(httplib.UnknownProtocol, server.setUp)
317
self.assertRaises(httplib.UnknownProtocol, server.start_server)
322
320
self.fail('HTTP Server creation did not raise UnknownProtocol')
324
322
def test_server_start_and_stop(self):
325
323
server = http_server.HttpServer()
324
server.start_server()
328
326
self.assertTrue(server._http_running)
331
329
self.assertFalse(server._http_running)
333
331
def test_create_http_server_one_zero(self):
376
374
"""Test case to inherit from if pycurl is present"""
378
376
def _get_pycurl_maybe(self):
380
from bzrlib.transport.http._pycurl import PyCurlTransport
381
return PyCurlTransport
382
except errors.DependencyNotPresent:
383
raise tests.TestSkipped('pycurl not present')
377
self.requireFeature(features.pycurl)
378
return PyCurlTransport
385
380
_transport = property(_get_pycurl_maybe)
433
428
def test_http_impl_urls(self):
434
429
"""There are servers which ask for particular clients to connect"""
435
430
server = self._server()
431
server.start_server()
438
433
url = server.get_url()
439
434
self.assertTrue(url.startswith('%s://' % self._qualified_prefix))
444
439
class TestHttps_pycurl(TestWithTransport_pycurl, tests.TestCase):
453
448
https by supplying a fake version_info that do not
459
raise tests.TestSkipped('pycurl not present')
451
self.requireFeature(features.pycurl)
452
# Import the module locally now that we now it's available.
453
pycurl = features.pycurl.module
461
455
version_info_orig = pycurl.version_info
463
# Now that we have pycurl imported, we can fake its version_info
464
# This was taken from a windows pycurl without SSL
466
pycurl.version_info = lambda : (2,
474
('ftp', 'gopher', 'telnet',
475
'dict', 'ldap', 'http', 'file'),
479
self.assertRaises(errors.DependencyNotPresent, self._transport,
480
'https://launchpad.net')
482
# Restore the right function
483
457
pycurl.version_info = version_info_orig
458
self.addCleanup(restore)
460
# Fake the pycurl version_info This was taken from a windows pycurl
461
# without SSL (thanks to bialix)
462
pycurl.version_info = lambda : (2,
470
('ftp', 'gopher', 'telnet',
471
'dict', 'ldap', 'http', 'file'),
475
self.assertRaises(errors.DependencyNotPresent, self._transport,
476
'https://launchpad.net')
486
479
class TestHTTPConnections(http_utils.TestCaseWithWebserver):
603
596
protocol_version=self._protocol_version)
605
598
def _testing_pycurl(self):
606
return pycurl_present and self._transport == PyCurlTransport
599
# TODO: This is duplicated for lots of the classes in this file
600
return (features.pycurl.available()
601
and self._transport == PyCurlTransport)
609
604
class WallRequestHandler(http_server.TestingHTTPRequestHandler):
718
713
_req_handler_class = BadProtocolRequestHandler
721
if pycurl_present and self._transport == PyCurlTransport:
716
if self._testing_pycurl():
722
717
raise tests.TestNotApplicable(
723
718
"pycurl doesn't check the protocol version")
724
719
super(TestBadProtocolServer, self).setUp()
768
763
self.assertEqual(None, server.host)
769
764
self.assertEqual(None, server.port)
771
def test_setUp_and_tearDown(self):
766
def test_setUp_and_stop(self):
772
767
server = RecordingServer(expect_body_tail=None)
768
server.start_server()
775
770
self.assertNotEqual(None, server.host)
776
771
self.assertNotEqual(None, server.port)
779
774
self.assertEqual(None, server.host)
780
775
self.assertEqual(None, server.port)
1187
1182
self._old_env = {}
1189
1184
def _testing_pycurl(self):
1190
return pycurl_present and self._transport == PyCurlTransport
1185
# TODO: This is duplicated for lots of the classes in this file
1186
return (features.pycurl.available()
1187
and self._transport == PyCurlTransport)
1192
1189
def create_transport_secondary_server(self):
1193
1190
"""Creates an http server that will serve files with
1391
1388
def setUp(self):
1392
if pycurl_present and self._transport == PyCurlTransport:
1389
if (features.pycurl.available()
1390
and self._transport == PyCurlTransport):
1393
1391
raise tests.TestNotApplicable(
1394
1392
"pycurl doesn't redirect silently annymore")
1395
1393
super(TestHTTPSilentRedirections, self).setUp()
1507
1505
return self._auth_server(protocol_version=self._protocol_version)
1509
1507
def _testing_pycurl(self):
1510
return pycurl_present and self._transport == PyCurlTransport
1508
# TODO: This is duplicated for lots of the classes in this file
1509
return (features.pycurl.available()
1510
and self._transport == PyCurlTransport)
1512
1512
def get_user_url(self, user, password):
1513
1513
"""Build an url embedding user and password"""
1964
1964
def setUp(self):
1965
1965
tests.TestCase.setUp(self)
1966
1966
self.server = self._activity_server(self._protocol_version)
1967
self.server.start_server()
1968
1968
self.activities = {}
1969
1969
def report_activity(t, bytes, direction):
1970
1970
count = self.activities.get(direction, 0)
2105
2105
def setUp(self):
2106
2106
tests.TestCase.setUp(self)
2107
2107
self.server = self._activity_server(self._protocol_version)
2108
self.server.start_server()
2109
2109
self.activities = {}
2110
2110
def report_activity(t, bytes, direction):
2111
2111
count = self.activities.get(direction, 0)
2136
2136
self.server = ActivityHTTPServer('HTTP/1.1')
2137
2137
self._transport=_urllib.HttpTransport_urllib
2139
self.server.start_server()
2141
2141
# We override at class level because constructors may propagate the
2142
2142
# bound method and render instance overriding ineffective (an