Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def download_file(client, destination_path=None, overwrite=True, timeout=None):

with open(destination_path, 'wb') as stream:
download = client.download_file(timeout=timeout)
download_content = download.readall()
stream.write(download_content)
download.readinto(stream)


def exists(cmd, client, timeout=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import tempfile
import unittest
from types import SimpleNamespace
from unittest import mock

from azure.cli.command_modules.storage.operations.fs_file import download_file


class TestStorageFsFileOperations(unittest.TestCase):

def test_download_file_streams_content_to_destination(self):
download = mock.Mock()

def _write_to_stream(target_stream):
return target_stream.write(b'hello world')

download.readinto.side_effect = _write_to_stream

client = mock.Mock()
client.get_file_properties.return_value = SimpleNamespace(name='dir/test.txt')
client.download_file.return_value = download

with tempfile.TemporaryDirectory() as temp_dir:
download_file(client, destination_path=temp_dir)

with open(os.path.join(temp_dir, 'test.txt'), 'rb') as downloaded_file:
self.assertEqual(downloaded_file.read(), b'hello world')

download.readinto.assert_called_once()
download.readall.assert_not_called()
Loading