365
365
# TestBadProtocolServer,
366
366
# TestCaseWithWebserver):
367
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]))