transfer_test_8.py 1.4 KB

123456789101112131415161718192021222324252627282930
  1. def testGetRange(self):
  2. for (start_byte, end_byte) in [(0, 25), (5, 15), (0, 0), (25, 25)]:
  3. bytes_http = object()
  4. http = object()
  5. download_stream = six.StringIO()
  6. download = transfer.Download.FromStream(download_stream,
  7. total_size=26,
  8. auto_transfer=False)
  9. download.bytes_http = bytes_http
  10. base_url = 'https://part.one/'
  11. with mock.patch.object(http_wrapper, 'MakeRequest',
  12. autospec=True) as make_request:
  13. make_request.return_value = http_wrapper.Response(
  14. info={
  15. 'content-range': 'bytes %d-%d/26' %
  16. (start_byte, end_byte),
  17. 'status': http_client.OK,
  18. },
  19. content=string.ascii_lowercase[start_byte:end_byte + 1],
  20. request_url=base_url,
  21. )
  22. request = http_wrapper.Request(url='https://part.one/')
  23. download.InitializeDownload(request, http=http)
  24. download.GetRange(start_byte, end_byte)
  25. self.assertEqual(1, make_request.call_count)
  26. received_request = make_request.call_args[0][1]
  27. self.assertEqual(base_url, received_request.url)
  28. self.assertRangeAndContentRangeCompatible(
  29. received_request, make_request.return_value)