1 # Copyright 2018 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
21 from lcm.pub.database.models import JobStatusModel, JobModel
22 from lcm.pub.utils.jobutil import JobUtil
33 class UtilsTest(unittest.TestCase):
41 MY_TYPE = enumutil.enum(SAMLL=0, LARGE=1)
42 self.assertEqual(0, MY_TYPE.SAMLL)
43 self.assertEqual(1, MY_TYPE.LARGE)
45 def test_create_and_delete_dir(self):
47 fileutil.make_dirs(dirs)
48 fileutil.make_dirs(dirs)
49 fileutil.delete_dirs(dirs)
51 @mock.patch.object(urllib2, 'urlopen')
52 def test_download_file_from_http(self, mock_urlopen):
53 mock_urlopen.return_value = MockReq()
54 fileutil.delete_dirs("abc")
55 is_ok, f_name = fileutil.download_file_from_http("1", "abc", "1.txt")
56 self.assertTrue(is_ok)
57 self.assertTrue(f_name.endswith("abc/1.txt"))
58 fileutil.delete_dirs("abc")
60 def test_query_job_status(self):
62 JobStatusModel.objects.filter().delete()
81 jobs = JobUtil.query_job_status(job_id)
82 self.assertEqual(1, len(jobs))
83 self.assertEqual(3, jobs[0].indexid)
84 jobs = JobUtil.query_job_status(job_id, 1)
85 self.assertEqual(2, len(jobs))
86 self.assertEqual(3, jobs[0].indexid)
87 self.assertEqual(2, jobs[1].indexid)
88 JobStatusModel.objects.filter().delete()
90 def test_is_job_exists(self):
92 JobModel.objects.filter().delete()
100 self.assertTrue(JobUtil.is_job_exists(job_id))
101 JobModel.objects.filter().delete()