From 79dcd9221c739f6457887177d3c088319797eb6e Mon Sep 17 00:00:00 2001 From: fujinhua Date: Wed, 15 Aug 2018 15:32:50 +0800 Subject: Add unit test for jobutil Change-Id: I542b1fb508dcc33f4d635d3207192e259f5b8802 Issue-ID: VFC-1009 Signed-off-by: fujinhua --- lcm/pub/utils/tests.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lcm/pub/utils/tests.py b/lcm/pub/utils/tests.py index 76cbfff0..36184720 100644 --- a/lcm/pub/utils/tests.py +++ b/lcm/pub/utils/tests.py @@ -125,3 +125,35 @@ class UtilsTest(unittest.TestCase): ).save() JobUtil.clear_job(job_id) self.assertEqual(0, len(JobModel.objects.filter(jobid=job_id))) + + def test_add_job_status_when_job_is_not_created(self): + JobModel.objects.filter().delete() + self.assertRaises( + Exception, + JobUtil.add_job_status, + job_id="1", + progress=1, + status_decs="2", + error_code="0" + ) + + def test_add_job_status_normal(self): + job_id = "1" + JobModel.objects.filter().delete() + JobStatusModel.objects.filter().delete() + JobModel( + jobid=job_id, + jobtype="1", + jobaction="2", + resid="3", + status=0 + ).save() + JobUtil.add_job_status( + job_id="1", + progress=1, + status_decs="2", + error_code="0" + ) + self.assertEqual(1, len(JobStatusModel.objects.filter(jobid=job_id))) + JobStatusModel.objects.filter().delete() + JobModel.objects.filter().delete() -- cgit 1.2.3-korg