@mock.patch('google.auth.transport.requests.AuthorizedSession')
def _download_to_file_helper(self, fake_session_factory, use_chunks=False):
    blob_name = 'blob-name'
    fake_transport = self._mock_download_transport()
    fake_session_factory.return_value = fake_transport
    client = mock.Mock(_credentials=_make_credentials(), spec=['_credentials'])
    bucket = _Bucket(client)
    media_link = 'http://example.com/media/'
    properties = {'mediaLink': media_link}
    blob = self._make_one(blob_name, bucket=bucket, properties=properties)
    if use_chunks:
        blob._CHUNK_SIZE_MULTIPLE = 1
        blob.chunk_size = 3
    else:
        single_chunk_response = self._mock_requests_response(http_client.OK, {'content-length': '6', 'content-range': 'bytes 0-5/6'}, content=b'abcdef')
        fake_transport.request.side_effect = [single_chunk_response]
    file_obj = io.BytesIO()
    blob.download_to_file(file_obj)
    self.assertEqual(file_obj.getvalue(), b'abcdef')
    if use_chunks:
        self._check_session_mocks(client, fake_session_factory, media_link)
    else:
        fake_session_factory.assert_called_once_with(client._credentials)
        fake_transport.request.assert_called_once_with('GET', media_link, data=None, headers={})
@mock.patch('google.auth.transport.requests.AuthorizedSession')
def _download_to_file_helper(self, fake_session_factory, use_chunks=False):
    blob_name = 'blob-name'
    fake_transport = self._mock_download_transport()
    fake_session_factory.return_value = fake_transport
    client = mock.Mock(_credentials=_make_credentials(), spec=['_credentials'])
    bucket = _Bucket(client)
    media_link = 'http://example.com/media/'
    properties = {'mediaLink': media_link}
    blob = self._make_one(blob_name, bucket=bucket, properties=properties)
    if use_chunks:
        blob._CHUNK_SIZE_MULTIPLE = 1
        blob.chunk_size = 3
    else:
        single_chunk_response = self._mock_requests_response(http_client.OK, {'content-length': '6', 'content-range': 'bytes 0-5/6'}, content=b'abcdef')
        fake_transport.request.side_effect = [single_chunk_response]
    file_obj = io.BytesIO()
    blob.download_to_file(file_obj)
    self.assertEqual(file_obj.getvalue(), b'abcdef')
    if use_chunks:
        self._check_session_mocks(client, fake_session_factory, media_link)
    else:
        fake_session_factory.assert_called_once_with(client._credentials)
        fake_transport.request.assert_called_once_with('GET', media_link, data=None, headers={})