def test_download_large_file(self):
self.drive.config = drive_config.DriveConfig({'max_get_size_bytes': 2})
in_data = b'12345'
output = io.BytesIO()
expected_ranges = ['0-1', '2-3', '4-4']
with requests_mock.Mocker() as mock:
def callback(request, context):
self.assertIn('Range', request.headers)
r = expected_ranges.pop(0)
self.assertEqual('bytes=' + r, request.headers['Range'])
f, t = request.headers['Range'].split('=', 1)[1].split('-')
context.status_code = codes.partial
return in_data[int(f): int(t) + 1]
mock.get(self.drive.get_item_uri(item_id='123', item_path=None) + '/content', content=callback)
self.drive.download_file(file=output, size=len(in_data), item_id='123')
self.assertEqual(in_data, output.getvalue())
评论列表
文章目录