test_drive_object.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:onedrive-e 作者: tobecontinued 项目源码 文件源码
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())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号