def _do_resumable_helper(self, use_size=False, num_retries=None):
    bucket = mock.Mock(path='/b/yesterday', spec=[u'path'])
    blob = self._make_one(u'blob-name', bucket=bucket)
    blob.chunk_size = blob._CHUNK_SIZE_MULTIPLE
    self.assertIsNotNone(blob.chunk_size)
    data = ((b'<html>' + (b'A' * blob.chunk_size)) + b'</html>')
    total_bytes = len(data)
    if use_size:
        size = total_bytes
    else:
        size = None
    resumable_url = 'http://test.invalid?upload_id=and-then-there-was-1'
    headers1 = {'location': resumable_url}
    headers2 = {'range': 'bytes=0-{:d}'.format((blob.chunk_size - 1))}
    (fake_transport, responses) = self._make_resumable_transport(headers1, headers2, {}, total_bytes)
    blob._make_transport = mock.Mock(return_value=fake_transport, spec=[])
    client = mock.sentinel.client
    stream = io.BytesIO(data)
    content_type = u'text/html'
    response = blob._do_resumable_upload(client, stream, content_type, size, num_retries)
    self.assertIs(response, responses[2])
    self.assertEqual(stream.tell(), total_bytes)
    blob._make_transport.assert_called_once_with(client)
    call0 = self._do_resumable_upload_call0(blob, content_type, size=size)
    call1 = self._do_resumable_upload_call1(blob, content_type, data, resumable_url, size=size)
    call2 = self._do_resumable_upload_call2(blob, content_type, data, resumable_url, total_bytes)
    self.assertEqual(fake_transport.request.mock_calls, [call0, call1, call2])
def _do_resumable_helper(self, use_size=False, num_retries=None):
    bucket = mock.Mock(path='/b/yesterday', spec=[u'path'])
    blob = self._make_one(u'blob-name', bucket=bucket)
    blob.chunk_size = blob._CHUNK_SIZE_MULTIPLE
    self.assertIsNotNone(blob.chunk_size)
    data = ((b'<html>' + (b'A' * blob.chunk_size)) + b'</html>')
    total_bytes = len(data)
    if use_size:
        size = total_bytes
    else:
        size = None
    resumable_url = 'http://test.invalid?upload_id=and-then-there-was-1'
    headers1 = {'location': resumable_url}
    headers2 = {'range': 'bytes=0-{:d}'.format((blob.chunk_size - 1))}
    (fake_transport, responses) = self._make_resumable_transport(headers1, headers2, {}, total_bytes)
    blob._make_transport = mock.Mock(return_value=fake_transport, spec=[])
    client = mock.sentinel.client
    stream = io.BytesIO(data)
    content_type = u'text/html'
    response = blob._do_resumable_upload(client, stream, content_type, size, num_retries)
    self.assertIs(response, responses[2])
    self.assertEqual(stream.tell(), total_bytes)
    blob._make_transport.assert_called_once_with(client)
    call0 = self._do_resumable_upload_call0(blob, content_type, size=size)
    call1 = self._do_resumable_upload_call1(blob, content_type, data, resumable_url, size=size)
    call2 = self._do_resumable_upload_call2(blob, content_type, data, resumable_url, total_bytes)
    self.assertEqual(fake_transport.request.mock_calls, [call0, call1, call2])