def _initiate_resumable_helper(self, size=None, extra_headers=None, chunk_size=None, num_retries=None):
    from google.resumable_media.requests import ResumableUpload
    bucket = mock.Mock(path='/b/whammy', spec=[u'path'])
    blob = self._make_one(u'blob-name', bucket=bucket)
    blob.metadata = {'rook': 'takes knight'}
    blob.chunk_size = (3 * blob._CHUNK_SIZE_MULTIPLE)
    self.assertIsNotNone(blob.chunk_size)
    object_metadata = blob._get_writable_metadata()
    blob._get_writable_metadata = mock.Mock(return_value=object_metadata, spec=[])
    resumable_url = 'http://test.invalid?upload_id=hey-you'
    response_headers = {'location': resumable_url}
    fake_transport = self._mock_transport(http_client.OK, response_headers)
    blob._make_transport = mock.Mock(return_value=fake_transport, spec=[])
    client = mock.sentinel.client
    data = b'hello hallo halo hi-low'
    stream = io.BytesIO(data)
    content_type = u'text/plain'
    (upload, transport) = blob._initiate_resumable_upload(client, stream, content_type, size, num_retries, extra_headers=extra_headers, chunk_size=chunk_size)
    self.assertIsInstance(upload, ResumableUpload)
    upload_url = (('https://www.googleapis.com/upload/storage/v1' + bucket.path) + '/o?uploadType=resumable')
    self.assertEqual(upload.upload_url, upload_url)
    if (extra_headers is None):
        self.assertEqual(upload._headers, {})
    else:
        self.assertEqual(upload._headers, extra_headers)
        self.assertIsNot(upload._headers, extra_headers)
    self.assertFalse(upload.finished)
    if (chunk_size is None):
        self.assertEqual(upload._chunk_size, blob.chunk_size)
    else:
        self.assertNotEqual(blob.chunk_size, chunk_size)
        self.assertEqual(upload._chunk_size, chunk_size)
    self.assertIs(upload._stream, stream)
    if (size is None):
        self.assertIsNone(upload._total_bytes)
    else:
        self.assertEqual(upload._total_bytes, size)
    self.assertEqual(upload._content_type, content_type)
    self.assertEqual(upload.resumable_url, resumable_url)
    retry_strategy = upload._retry_strategy
    self.assertEqual(retry_strategy.max_sleep, 64.0)
    if (num_retries is None):
        self.assertEqual(retry_strategy.max_cumulative_retry, 600.0)
        self.assertIsNone(retry_strategy.max_retries)
    else:
        self.assertIsNone(retry_strategy.max_cumulative_retry)
        self.assertEqual(retry_strategy.max_retries, num_retries)
    self.assertIs(transport, fake_transport)
    self.assertEqual(stream.tell(), 0)
    blob._get_writable_metadata.assert_called_once_with()
    blob._make_transport.assert_called_once_with(client)
    payload = json.dumps(object_metadata).encode('utf-8')
    expected_headers = {'content-type': 'application/json; charset=UTF-8', 'x-upload-content-type': content_type}
    if (size is not None):
        expected_headers['x-upload-content-length'] = str(size)
    if (extra_headers is not None):
        expected_headers.update(extra_headers)
    fake_transport.request.assert_called_once_with('POST', upload_url, data=payload, headers=expected_headers)
def _initiate_resumable_helper(self, size=None, extra_headers=None, chunk_size=None, num_retries=None):
    from google.resumable_media.requests import ResumableUpload
    bucket = mock.Mock(path='/b/whammy', spec=[u'path'])
    blob = self._make_one(u'blob-name', bucket=bucket)
    blob.metadata = {'rook': 'takes knight'}
    blob.chunk_size = (3 * blob._CHUNK_SIZE_MULTIPLE)
    self.assertIsNotNone(blob.chunk_size)
    object_metadata = blob._get_writable_metadata()
    blob._get_writable_metadata = mock.Mock(return_value=object_metadata, spec=[])
    resumable_url = 'http://test.invalid?upload_id=hey-you'
    response_headers = {'location': resumable_url}
    fake_transport = self._mock_transport(http_client.OK, response_headers)
    blob._make_transport = mock.Mock(return_value=fake_transport, spec=[])
    client = mock.sentinel.client
    data = b'hello hallo halo hi-low'
    stream = io.BytesIO(data)
    content_type = u'text/plain'
    (upload, transport) = blob._initiate_resumable_upload(client, stream, content_type, size, num_retries, extra_headers=extra_headers, chunk_size=chunk_size)
    self.assertIsInstance(upload, ResumableUpload)
    upload_url = (('https://www.googleapis.com/upload/storage/v1' + bucket.path) + '/o?uploadType=resumable')
    self.assertEqual(upload.upload_url, upload_url)
    if (extra_headers is None):
        self.assertEqual(upload._headers, {})
    else:
        self.assertEqual(upload._headers, extra_headers)
        self.assertIsNot(upload._headers, extra_headers)
    self.assertFalse(upload.finished)
    if (chunk_size is None):
        self.assertEqual(upload._chunk_size, blob.chunk_size)
    else:
        self.assertNotEqual(blob.chunk_size, chunk_size)
        self.assertEqual(upload._chunk_size, chunk_size)
    self.assertIs(upload._stream, stream)
    if (size is None):
        self.assertIsNone(upload._total_bytes)
    else:
        self.assertEqual(upload._total_bytes, size)
    self.assertEqual(upload._content_type, content_type)
    self.assertEqual(upload.resumable_url, resumable_url)
    retry_strategy = upload._retry_strategy
    self.assertEqual(retry_strategy.max_sleep, 64.0)
    if (num_retries is None):
        self.assertEqual(retry_strategy.max_cumulative_retry, 600.0)
        self.assertIsNone(retry_strategy.max_retries)
    else:
        self.assertIsNone(retry_strategy.max_cumulative_retry)
        self.assertEqual(retry_strategy.max_retries, num_retries)
    self.assertIs(transport, fake_transport)
    self.assertEqual(stream.tell(), 0)
    blob._get_writable_metadata.assert_called_once_with()
    blob._make_transport.assert_called_once_with(client)
    payload = json.dumps(object_metadata).encode('utf-8')
    expected_headers = {'content-type': 'application/json; charset=UTF-8', 'x-upload-content-type': content_type}
    if (size is not None):
        expected_headers['x-upload-content-length'] = str(size)
    if (extra_headers is not None):
        expected_headers.update(extra_headers)
    fake_transport.request.assert_called_once_with('POST', upload_url, data=payload, headers=expected_headers)