summaryrefslogtreecommitdiffstats
path: root/multivimbroker
diff options
context:
space:
mode:
authorEthan Lynn <ethanlynnl@vmware.com>2018-03-25 22:25:11 -0700
committerEthan Lynn <ethanlynnl@vmware.com>2018-03-25 22:25:36 -0700
commitcd363b6f336f181b01bbf4fbb9c0a8c1da3ab00a (patch)
tree7ea17c44e9c57f05799905a14657f32187b92b49 /multivimbroker
parente5bc47a68acf51a4feab1337bc59ac3e36cdd7c1 (diff)
Add test_download_file_from_http_success
Add test_download_file_from_http_success to fileutil.py Change-Id: I980202084422fd440f1c34c4b27859f33d61a172 Issue-ID: MULTICLOUD-198 Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
Diffstat (limited to 'multivimbroker')
-rw-r--r--multivimbroker/multivimbroker/tests/test_fileutil.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/multivimbroker/multivimbroker/tests/test_fileutil.py b/multivimbroker/multivimbroker/tests/test_fileutil.py
index 9abd23c..e75cc9c 100644
--- a/multivimbroker/multivimbroker/tests/test_fileutil.py
+++ b/multivimbroker/multivimbroker/tests/test_fileutil.py
@@ -49,3 +49,18 @@ class TestFileutil(unittest.TestCase):
new_path = "/tmp/tests"
fileutil.delete_dirs(new_path)
mock_rmtree.assert_called_once_with(new_path)
+
+ @mock.patch.object(fileutil, "make_dirs")
+ @mock.patch("urllib2.urlopen")
+ def test_download_file_from_http_success(self, mock_urlopen, mock_mkdir):
+ url = "http://www.example.org/test.dat"
+ local_dir = "/tmp/"
+ file_name = "test.dat"
+ mock_req = mock.Mock()
+ mock_req.read.return_value = "hello world"
+ mock_urlopen.return_value = mock_req
+ m = mock.mock_open()
+ expect_ret = (True, "/tmp/test.dat")
+ with mock.patch('{}.open'.format(__name__), m, create=True):
+ ret = fileutil.download_file_from_http(url, local_dir, file_name)
+ self.assertEqual(expect_ret, ret)