Example #1
0
    def test_crontab_minute(self):
        # validates the following minutes
        valids = [0, 1, 4, 6, 8, 9, 12, 18, 24, 30, 36, 42, 48, 54]
        validate_m = crontab(minute="4,8-9,*/6,1")

        for x in xrange(60):
            res = validate_m(datetime.datetime(2011, 1, 1, 1, x))
            self.assertEqual(res, x in valids)
Example #2
0
    def test_crontab_hour(self):
        # validates the following hours
        valids = [0, 1, 4, 6, 8, 9, 12, 18]
        validate_h = crontab(hour="8-9,*/6,1,4")

        for x in xrange(24):
            res = validate_h(datetime.datetime(2011, 1, 1, x))
            self.assertEqual(res, x in valids)
Example #3
0
    def test_crontab_day(self):
        # validates the following days
        valids = [1, 4, 7, 8, 9, 13, 19, 25, 31]
        validate_d = crontab(day="*/6,1,4,8-9")

        for x in xrange(1, 32):
            res = validate_d(datetime.datetime(2011, 1, x))
            self.assertEqual(res, x in valids)
Example #4
0
    def test_crontab_month(self):
        # validates the following months, 1, 4, 7, 8, 9
        valids = [1, 4, 7, 8, 9]
        validate_m = crontab(month="1,4,*/6,8-9")

        for x in xrange(1, 13):
            res = validate_m(datetime.datetime(2011, x, 1))
            self.assertEqual(res, x in valids)
Example #5
0
    def test_crontab_day_of_week(self):
        # validates the following days of week
        # jan, 1, 2011 is a saturday
        valids = [2, 4, 9, 11, 16, 18, 23, 25, 30]
        validate_dow = crontab(day_of_week="0,2")

        for x in xrange(1, 32):
            res = validate_dow(datetime.datetime(2011, 1, x))
            self.assertEqual(res, x in valids)
Example #6
0
    def test_crontab_all_together(self):
        # jan 1, 2011 is a saturday
        # may 1, 2011 is a sunday
        validate = crontab(month="1,5", day="1,4,7", day_of_week="0,6", hour="*/4", minute="1-5,10-15,50")

        self.assertTrue(validate(datetime.datetime(2011, 5, 1, 4, 11)))
        self.assertTrue(validate(datetime.datetime(2011, 5, 7, 20, 50)))
        self.assertTrue(validate(datetime.datetime(2011, 1, 1, 0, 1)))

        # fails validation on month
        self.assertFalse(validate(datetime.datetime(2011, 6, 4, 4, 11)))

        # fails validation on day
        self.assertFalse(validate(datetime.datetime(2011, 1, 6, 4, 11)))

        # fails validation on day_of_week
        self.assertFalse(validate(datetime.datetime(2011, 1, 4, 4, 11)))

        # fails validation on hour
        self.assertFalse(validate(datetime.datetime(2011, 1, 1, 1, 11)))

        # fails validation on minute
        self.assertFalse(validate(datetime.datetime(2011, 1, 1, 4, 6)))
Example #7
0
 def validate_datetime(self, dt):
     return crontab(minute="*/30")(dt)
Example #8
0

@queue_command
def throw_error():
    raise BampfException("bampf")


class TestPeriodicCommand(PeriodicQueueCommand):
    def execute(self):
        User.objects.create_user("thirty", "thirty", "thirty")

    def validate_datetime(self, dt):
        return crontab(minute="*/30")(dt)


@periodic_command(crontab(minute="*/15"))
def every_fifteen():
    User.objects.create_user("fifteen", "fifteen", "fifteen")


class QueueTest(TestCase):
    def setUp(self):
        self.orig_always_eager = getattr(settings, "QUEUE_ALWAYS_EAGER", False)
        settings.QUEUE_ALWAYS_EAGER = False

        self.dummy = User.objects.create_user("username", "*****@*****.**", "password")
        self.consumer_options = Options(
            pidfile="", logfile="", delay=0.1, backoff=2, max_delay=0.4, no_periodic=False, threads=2
        )
        invoker.flush()