mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 08:38:16 -06:00
Add test cases for BackgroundJob handling
This commit is contained in:
parent
b17b2050df
commit
60e4e81020
@ -6,6 +6,7 @@ from django_rq import get_queue
|
|||||||
|
|
||||||
from ..jobs import *
|
from ..jobs import *
|
||||||
from core.models import Job
|
from core.models import Job
|
||||||
|
from core.choices import JobStatusChoices
|
||||||
|
|
||||||
|
|
||||||
class TestBackgroundJob(BackgroundJob):
|
class TestBackgroundJob(BackgroundJob):
|
||||||
@ -44,6 +45,24 @@ class BackgroundJobTest(BackgroundJobTestCase):
|
|||||||
|
|
||||||
self.assertEqual(NamedBackgroundJob.name, 'TestName')
|
self.assertEqual(NamedBackgroundJob.name, 'TestName')
|
||||||
|
|
||||||
|
def test_handle(self):
|
||||||
|
job = TestBackgroundJob.enqueue(immediate=True)
|
||||||
|
|
||||||
|
self.assertEqual(job.status, JobStatusChoices.STATUS_COMPLETED)
|
||||||
|
|
||||||
|
def test_handle_errored(self):
|
||||||
|
class ErroredBackgroundJob(TestBackgroundJob):
|
||||||
|
EXP = Exception('Test error')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run(cls, *args, **kwargs):
|
||||||
|
raise cls.EXP
|
||||||
|
|
||||||
|
job = ErroredBackgroundJob.enqueue(immediate=True)
|
||||||
|
|
||||||
|
self.assertEqual(job.status, JobStatusChoices.STATUS_ERRORED)
|
||||||
|
self.assertEqual(job.error, repr(ErroredBackgroundJob.EXP))
|
||||||
|
|
||||||
|
|
||||||
class EnqueueTest(BackgroundJobTestCase):
|
class EnqueueTest(BackgroundJobTestCase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user