summaryrefslogtreecommitdiffstats
path: root/multivimbroker
diff options
context:
space:
mode:
authorLiang Ke <lokyse@163.com>2018-03-27 02:25:27 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-27 02:25:27 +0000
commit9308081c2753747c375adfaad698eb9e3309ca34 (patch)
treed8de5712b2d33a5fc9aa15c97948c2944f5232db /multivimbroker
parent2321a26923f2e363d084124cfa2d59f59702ad71 (diff)
parent08bb2134976c67f6f59e46755d74e5bee40d494c (diff)
Merge "Add test_download_file_from_http_fail"
Diffstat (limited to 'multivimbroker')
-rw-r--r--multivimbroker/multivimbroker/tests/test_fileutil.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/multivimbroker/multivimbroker/tests/test_fileutil.py b/multivimbroker/multivimbroker/tests/test_fileutil.py
index e75cc9c..9840bde 100644
--- a/multivimbroker/multivimbroker/tests/test_fileutil.py
+++ b/multivimbroker/multivimbroker/tests/test_fileutil.py
@@ -64,3 +64,16 @@ class TestFileutil(unittest.TestCase):
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)
+
+ @mock.patch.object(fileutil, "make_dirs")
+ @mock.patch("urllib2.urlopen")
+ def test_download_file_from_http_fail(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.side_effect = [Exception("fake exception")]
+ expect_ret = (False, "/tmp/test.dat")
+ ret = fileutil.download_file_from_http(url, local_dir, file_name)
+ self.assertEqual(expect_ret, ret)