diff options
author | 2018-08-14 14:38:16 +0800 | |
---|---|---|
committer | 2018-08-14 14:56:01 +0800 | |
commit | 68d6f7f81784780aff58f096870bf8ab53f9963e (patch) | |
tree | 166d96e47f617354baa4df88deb707c29c254edd | |
parent | 5b6370f13ea84abea960daf77b99f93dc88ad85c (diff) |
Add unit test for fileutil
Change-Id: Ida68d6281350a6e5226493eef7f81a7e8c9664b4
Issue-ID: VFC-1009
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/pub/utils/tests.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lcm/pub/utils/tests.py b/lcm/pub/utils/tests.py index 00fafdee..706b28bd 100644 --- a/lcm/pub/utils/tests.py +++ b/lcm/pub/utils/tests.py @@ -13,7 +13,18 @@ # limitations under the License. import unittest +import mock import enumutil +import fileutil +import urllib2 + + +class MockReq(): + def read(self): + return "1" + + def close(self): + pass class UtilsTest(unittest.TestCase): @@ -27,3 +38,18 @@ class UtilsTest(unittest.TestCase): MY_TYPE = enumutil.enum(SAMLL=0, LARGE=1) self.assertEqual(0, MY_TYPE.SAMLL) self.assertEqual(1, MY_TYPE.LARGE) + + def test_create_and_delete_dir(self): + dirs = "abc/def/hij" + fileutil.make_dirs(dirs) + fileutil.make_dirs(dirs) + fileutil.delete_dirs(dirs) + + @mock.patch.object(urllib2, 'urlopen') + def test_download_file_from_http(self, mock_urlopen): + mock_urlopen.return_value = MockReq() + fileutil.delete_dirs("abc") + is_ok, f_name = fileutil.download_file_from_http("1", "abc", "1.txt") + self.assertTrue(is_ok) + self.assertTrue(f_name.endswith("abc/1.txt")) + fileutil.delete_dirs("abc") |