示例#1
0
class TestRequeueAdminAction(TestCase):
    def setUp(self):
        self.q = Queue()
        self.q.enqueue_call(div_by_zero, args=(1,))
        w = Worker.create(self.q)
        w.work(burst=True)

    def test_requeue_admin_action(self):
        self.assertEqual(0, len(Job.objects.filter(queue_id="default")))
        requeue_failed_jobs(None, None, Job.objects.filter(queue_id="failed"))
        self.assertEqual(0, len(Job.objects.filter(queue_id="failed")))
        self.assertEqual("test_pq.fixtures.div_by_zero", Job.objects.get(queue_id="default").func_name)
示例#2
0
class TestRequeueAdminAction(TestCase):
    def setUp(self):
        self.q = Queue()
        self.q.enqueue_call(div_by_zero, args=(1, ))
        w = Worker.create(self.q)
        w.work(burst=True)

    def test_requeue_admin_action(self):
        self.assertEqual(0, len(Job.objects.filter(queue_id='default')))
        requeue_failed_jobs(None, None, Job.objects.filter(queue_id='failed'))
        self.assertEqual(0, len(Job.objects.filter(queue_id='failed')))
        self.assertEqual('test_pq.fixtures.div_by_zero',
                         Job.objects.get(queue_id='default').func_name)
示例#3
0
class TestEnqueueAsyncFalse(TestCase):
    def setUp(self):
        self.q = Queue()

    def test_enqueue_async_false(self):
        job = self.q.enqueue(some_calculation, args=(2, 3), async=False)
        self.assertEqual(job.result, 6)

    def test_enqueue_call_async_false(self):
        job = self.q.enqueue_call(some_calculation, args=(2, 3), async=False)
        self.assertEqual(job.result, 6)

    def test_schedule_call_async_false(self):
        job = self.q.enqueue_call(some_calculation, args=(2, 3), async=False)
        self.assertEqual(job.result, 6)
示例#4
0
class TestJobAdmin(TransactionTestCase):
    def setUp(self):
        password = '******'
        user = User.objects.create_superuser('test', '*****@*****.**', password)
        self.client.login(username=user.username, password=password)
        self.q = Queue()
        self.q.enqueue_call(say_hello, args=('you',))
        self.q.enqueue_call(div_by_zero, args=(1,))
        self.q.schedule(datetime(2099, 1, 1, tzinfo=utc), say_hello, 'later')
        w = Worker.create(self.q)
        w.work(burst=True)
        self.q.enqueue_call(say_hello, args=('me',))

    def test_changelist(self):
        data = (
            ("failedjob", FailedJob),
            ("queuedjob", QueuedJob),
            ("dequeuedjob", DequeuedJob),
            ("scheduledjob", ScheduledJob),
        )
        for modelname, Model in data:
            url = reverse("admin:pq_%s_changelist" % modelname)
            response = self.client.get(url, follow=True)
            msg = "%s != %s -> %s, url: %s" % (
                response.status_code, 200, repr(Model), url
            )
            self.assertEqual(response.status_code, 200, msg)
示例#5
0
class TestJobAdmin(TestCase):
    def setUp(self):
        password = "******"
        user = User.objects.create_superuser("test", "*****@*****.**", password)
        self.client.login(username=user.username, password=password)
        self.q = Queue()
        self.q.enqueue_call(say_hello, args=("you",))
        self.q.enqueue_call(div_by_zero, args=(1,))
        w = Worker.create(self.q)
        w.work(burst=True)
        self.q.enqueue_call(say_hello, args=("me",))

    @params(("failedjob", FailedJob), ("queuedjob", QueuedJob), ("dequeuedjob", DequeuedJob))
    def test_changelist(self, modelname, Model):
        url = reverse("admin:pq_%s_changelist" % modelname)
        response = self.client.get(url, follow=True)
        self.failUnlessEqual(
            response.status_code, 200, "%s != %s -> %s, url: %s" % (response.status_code, 200, repr(Model), url)
        )
示例#6
0
class TestJobAdmin(TestCase):
    def setUp(self):
        password = '******'
        user = User.objects.create_superuser('test', '*****@*****.**', password)
        self.client.login(username=user.username, password=password)
        self.q = Queue()
        self.q.enqueue_call(say_hello, args=('you', ))
        self.q.enqueue_call(div_by_zero, args=(1, ))
        w = Worker.create(self.q)
        w.work(burst=True)
        self.q.enqueue_call(say_hello, args=('me', ))

    @params(("failedjob", FailedJob), ("queuedjob", QueuedJob),
            ("dequeuedjob", DequeuedJob))
    def test_changelist(self, modelname, Model):
        url = reverse("admin:pq_%s_changelist" % modelname)
        response = self.client.get(url, follow=True)
        self.failUnlessEqual(
            response.status_code, 200, "%s != %s -> %s, url: %s" %
            (response.status_code, 200, repr(Model), url))