def test_handle_worker(self): worker = Worker(hostname='fuzzie') worker.event('online', time(), time(), {}) self.cam._last_worker_write.clear() m = self.cam.handle_worker((worker.hostname, worker)) self.assertTrue(m) self.assertTrue(m.hostname) self.assertTrue(m.last_heartbeat) self.assertTrue(m.is_alive()) self.assertEqual(unicode(m), unicode(m.hostname)) self.assertTrue(repr(m))
def test_CrontabSchedule_unicode(self): self.assertEqual(unicode(CrontabSchedule(minute=3, hour=3, day_of_week=None)), '3 3 * * * (m/h/d/dM/MY)') self.assertEqual(unicode(CrontabSchedule(minute=3, hour=3, day_of_week='tue', day_of_month='*/2', month_of_year='4,6')), '3 3 tue */2 4,6 (m/h/d/dM/MY)')
def test_handle_task_received(self): worker = Worker(hostname='fuzzie') worker.event('online', time(), time(), {}) self.cam.handle_worker((worker.hostname, worker)) task = create_task(worker) task.event('received', time(), time(), {}) self.assertEqual(task.state, 'RECEIVED') mt = self.cam.handle_task((task.uuid, task)) self.assertEqual(mt.name, task.name) self.assertTrue(unicode(mt)) self.assertTrue(repr(mt)) mt.eta = celery.now() self.assertIn('eta', unicode(mt)) self.assertIn(mt, models.TaskState.objects.active())
def test_tasksetmeta(self): m1 = self.createTaskSetMeta() m2 = self.createTaskSetMeta() m3 = self.createTaskSetMeta() self.assertTrue(unicode(m1).startswith('<TaskSet:')) self.assertTrue(m1.taskset_id) self.assertIsInstance(m1.date_done, datetime) self.assertEqual( TaskSetMeta.objects.restore_taskset(m1.taskset_id).taskset_id, m1.taskset_id, ) # Have to avoid save() because it applies the auto_now=True. TaskSetMeta.objects.filter(taskset_id=m1.taskset_id, ).update( date_done=now() - timedelta(days=10)) expired = TaskSetMeta.objects.get_all_expired( celery.conf.CELERY_TASK_RESULT_EXPIRES, ) self.assertIn(m1, expired) self.assertNotIn(m2, expired) self.assertNotIn(m3, expired) TaskSetMeta.objects.delete_expired( celery.conf.CELERY_TASK_RESULT_EXPIRES, ) self.assertNotIn(m1, TaskSetMeta.objects.all()) m4 = self.createTaskSetMeta() self.assertEqual( TaskSetMeta.objects.restore_taskset(m4.taskset_id).taskset_id, m4.taskset_id, ) TaskSetMeta.objects.delete_taskset(m4.taskset_id) self.assertIsNone(TaskSetMeta.objects.restore_taskset(m4.taskset_id))
def request(self, **request): """Similar to parent class, but returns the request object as soon as it has created it.""" environ = { 'HTTP_COOKIE': unicode(self.cookies), 'HTTP_USER_AGENT': 'Django UnitTest Client 1.0', 'REMOTE_ADDR': '127.0.0.1', 'PATH_INFO': '/', 'QUERY_STRING': '', 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': '', 'SERVER_NAME': 'testserver', 'SERVER_PORT': 80, 'SERVER_PROTOCOL': 'HTTP/1.1', 'wsgi.input': WhateverIO(), } environ.update(self.defaults) environ.update(request) return WSGIRequest(environ)
def test_tasksetmeta(self): m1 = self.createTaskSetMeta() m2 = self.createTaskSetMeta() m3 = self.createTaskSetMeta() self.assertTrue(unicode(m1).startswith('<TaskSet:')) self.assertTrue(m1.taskset_id) self.assertIsInstance(m1.date_done, datetime) self.assertEqual( TaskSetMeta.objects.restore_taskset(m1.taskset_id).taskset_id, m1.taskset_id, ) # Have to avoid save() because it applies the auto_now=True. TaskSetMeta.objects.filter( taskset_id=m1.taskset_id, ).update(date_done=now() - timedelta(days=10)) expired = TaskSetMeta.objects.get_all_expired( celery.conf.CELERY_TASK_RESULT_EXPIRES, ) self.assertIn(m1, expired) self.assertNotIn(m2, expired) self.assertNotIn(m3, expired) TaskSetMeta.objects.delete_expired( celery.conf.CELERY_TASK_RESULT_EXPIRES, ) self.assertNotIn(m1, TaskSetMeta.objects.all()) m4 = self.createTaskSetMeta() self.assertEqual( TaskSetMeta.objects.restore_taskset(m4.taskset_id).taskset_id, m4.taskset_id, ) TaskSetMeta.objects.delete_taskset(m4.taskset_id) self.assertIsNone(TaskSetMeta.objects.restore_taskset(m4.taskset_id))
def test_PeriodicTask_unicode_no_schedule(self): p = create_model() self.assertEqual(unicode(p), '{0}: {{no schedule}}'.format(p.name))
def test_PeriodicTask_unicode_crontab(self): p = create_model_crontab(crontab(hour='4, 5', day_of_week='4, 5')) self.assertEqual(unicode(p), '{0}: * 4,5 4,5 * * (m/h/d/dM/MY)'.format(p.name))
def test_PeriodicTask_unicode_interval(self): p = create_model_interval(schedule(timedelta(seconds=10))) self.assertEqual(unicode(p), '{0}: every 10 seconds'.format(p.name))
def test_IntervalSchedule_unicode(self): self.assertEqual(unicode(IntervalSchedule(every=1, period='seconds')), 'every second') self.assertEqual(unicode(IntervalSchedule(every=10, period='seconds')), 'every 10 seconds')
def test_CrontabSchedule_unicode(self): self.assertEqual(unicode(CrontabSchedule(minute=3, hour=3, day_of_week=None)), "3 3 * * * (m/h/d/dM/MY)") self.assertEqual( unicode(CrontabSchedule(minute=3, hour=3, day_of_week="tue", day_of_month="*/2", month_of_year="4,6")), "3 3 tue */2 4,6 (m/h/d/dM/MY)", )
def test_IntervalSchedule_unicode(self): self.assertEqual(unicode(IntervalSchedule(every=1, period="seconds")), "every second") self.assertEqual(unicode(IntervalSchedule(every=10, period="seconds")), "every 10 seconds")