34
from bzrlib.tests.HttpServer import (
39
from bzrlib.tests.HTTPTestUtil import (
40
BadProtocolRequestHandler,
41
BadStatusRequestHandler,
42
InvalidStatusRequestHandler,
43
TestCaseWithWebserver,
34
46
from bzrlib.transport import (
38
50
from bzrlib.transport.http import (
40
BadProtocolRequestHandler,
41
BadStatusRequestHandler,
43
InvalidStatusRequestHandler,
46
54
from bzrlib.transport.http._urllib import HttpTransport_urllib
47
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
50
57
class FakeManager (object):
99
106
def test_http_impl_urls(self):
100
107
"""There are servers which ask for particular clients to connect"""
108
server = HttpServer_PyCurl()
102
from bzrlib.transport.http._pycurl import HttpServer_PyCurl
103
server = HttpServer_PyCurl()
106
url = server.get_url()
107
self.assertTrue(url.startswith('http+pycurl://'))
110
except DependencyNotPresent:
111
raise TestSkipped('pycurl not present')
111
url = server.get_url()
112
self.assertTrue(url.startswith('http+pycurl://'))
114
117
class TestHttpConnections(object):
364
367
# """Tests BadProtocolServer for pycurl implementation"""
370
class TestRangesServer(object):
371
"""Tests range requests against a server.
373
This MUST be used by daughter classes that also inherit from
374
TestCaseWithWebserver.
376
We can't inherit directly from TestCaseWithWebserver or the
377
test framework will try to create an instance which cannot
378
run, its implementation being incomplete.
382
TestCaseWithWebserver.setUp(self)
383
transport = self.get_transport()
384
if transport.is_readonly():
385
file('a', 'w').write('0123456789')
387
transport.put_bytes('a', '0123456789')
389
def test_single_range(self):
390
server = self.get_readonly_server()
391
t = self._transport(server.get_url())
392
content = t.readv(_file_10, )
394
self.assertRaises(errors.InvalidRange, out.read, 20)
397
self.assertEqual(_single_range_response[2], out.read(100))
399
def test_single_range_no_content(self):
400
out = self.get_response(_single_range_no_content_type)
401
self.assertIsInstance(out, response.HttpRangeResponse)
403
self.assertRaises(errors.InvalidRange, out.read, 20)
406
self.assertEqual(_single_range_no_content_type[2], out.read(100))
408
def test_multi_range(self):
409
out = self.get_response(_multipart_range_response)
410
self.assertIsInstance(out, response.HttpMultipartRangeResponse)
412
# Just make sure we can read the right contents
419
def test_multi_squid_range(self):
420
out = self.get_response(_multipart_squid_range_response)
421
self.assertIsInstance(out, response.HttpMultipartRangeResponse)
423
# Just make sure we can read the right contents
430
def test_full_text_no_content_type(self):
431
# We should not require Content-Type for a full response
432
a_response = _full_text_response
433
headers = http._extract_headers(a_response[1], 'http://foo')
434
del headers['Content-Type']
435
out = response.handle_response('http://foo', a_response[0], headers,
436
StringIO(a_response[2]))
437
self.assertEqual(_full_text_response[2], out.read())
439
def test_missing_content_range(self):
440
a_response = _single_range_response
441
headers = http._extract_headers(a_response[1], 'http://nocontent')
442
del headers['Content-Range']
443
self.assertRaises(errors.InvalidHttpResponse,
444
response.handle_response, 'http://nocontent', a_response[0],
445
headers, StringIO(a_response[2]))