From 68d6f7f81784780aff58f096870bf8ab53f9963e Mon Sep 17 00:00:00 2001 From: fujinhua Date: Tue, 14 Aug 2018 14:38:16 +0800 Subject: Add unit test for fileutil Change-Id: Ida68d6281350a6e5226493eef7f81a7e8c9664b4 Issue-ID: VFC-1009 Signed-off-by: fujinhua --- lcm/pub/utils/tests.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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") -- cgit 1.2.3-korg