transfer_test_9.py 1.2 KB

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