

def test_206_single_range(self):
    fr = FakeResponse(206, {
        'Content-Length': '8',
        'Content-Type': 'application/lunch',
        'Content-Range': 'bytes 1-8/10',
    }, 'andwiche')
    doc_iters = http_response_to_document_iters(fr)
    (first_byte, last_byte, length, headers, body) = next(doc_iters)
    self.assertEqual(first_byte, 1)
    self.assertEqual(last_byte, 8)
    self.assertEqual(length, 10)
    header_dict = HeaderKeyDict(headers)
    self.assertEqual(header_dict.get('Content-Length'), '8')
    self.assertEqual(header_dict.get('Content-Type'), 'application/lunch')
    self.assertEqual(body.read(), 'andwiche')
    self.assertRaises(StopIteration, next, doc_iters)
    fr = FakeResponse(206, {
        'Transfer-Encoding': 'chunked',
        'Content-Type': 'application/lunch',
        'Content-Range': 'bytes 1-8/10',
    }, 'andwiche')
    doc_iters = http_response_to_document_iters(fr)
    (first_byte, last_byte, length, headers, body) = next(doc_iters)
    self.assertEqual(first_byte, 1)
    self.assertEqual(last_byte, 8)
    self.assertEqual(length, 10)
    header_dict = HeaderKeyDict(headers)
    self.assertEqual(header_dict.get('Content-Type'), 'application/lunch')
    self.assertEqual(body.read(), 'andwiche')
    self.assertRaises(StopIteration, next, doc_iters)

dataset/ETHPy150Open openstack/swift/test/unit/common/test_request_helpers.py TestHTTPResponseToDocumentIters.test_206_single_range/original