12345678910111213141516171819202122232425262728293031323334353637 |
- def testStreamInChunks(self):
- """Test StreamInChunks."""
- resume_incomplete_responses = [http_wrapper.Response(
- info={'status': http_wrapper.RESUME_INCOMPLETE,
- 'location': 'http://www.uploads.com',
- 'range': '0-{}'.format(end)},
- content='',
- request_url='http://www.uploads.com',) for end in [199, 399, 599]]
- responses = [
- self.response # Initial request in InitializeUpload().
- ] + resume_incomplete_responses + [
- self.response, # Successful request.
- ]
- # Create and configure the upload object.
- bytes_http = httplib2.Http()
- upload = transfer.Upload(
- stream=self.sample_stream,
- mime_type='text/plain',
- total_size=len(self.sample_data),
- close_stream=False,
- http=bytes_http)
- upload.strategy = transfer.RESUMABLE_UPLOAD
- # Set the chunk size so the entire stream is uploaded.
- upload.chunksize = 200
- # Mock the upload to return the sample response.
- with mock.patch.object(bytes_http,
- 'request') as make_request:
- # This side effect also checks the request body.
- make_request.side_effect = self.HttpRequestSideEffect(responses)
- # Initialization.
- upload.InitializeUpload(self.request, bytes_http)
- upload.StreamInChunks()
- # Ensure the mock was called the correct number of times.
- self.assertEquals(make_request.call_count, len(responses))
|