diff options
author | Ethan Lynn <ethanlynnl@vmware.com> | 2018-03-25 22:29:38 -0700 |
---|---|---|
committer | Ethan Lynn <ethanlynnl@vmware.com> | 2018-03-25 22:30:00 -0700 |
commit | 08bb2134976c67f6f59e46755d74e5bee40d494c (patch) | |
tree | c2fdd828366735b1661a6d5e5d521475852104ea /multivimbroker | |
parent | cd363b6f336f181b01bbf4fbb9c0a8c1da3ab00a (diff) |
Add test_download_file_from_http_fail
Add test_download_file_from_http_fail to fileutil.py
Change-Id: I4cbeeb9f8d988ed6443005989b80faf1e522360d
Issue-ID: MULTICLOUD-198
Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
Diffstat (limited to 'multivimbroker')
-rw-r--r-- | multivimbroker/multivimbroker/tests/test_fileutil.py | 13 |
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) |