Ejemplo n.º 1
0
 def test_save_raises_for_multiple_schedules(self):
     schedules = [('crontab', CrontabSchedule()),
                  ('interval', IntervalSchedule()),
                  ('solar', SolarSchedule()),
                  ('clocked', ClockedSchedule())]
     for i, options in enumerate(combinations(schedules, 2)):
         with self.assertRaises(ValidationError):
             PeriodicTask(name='task{}'.format(i), **dict(options)).save()
Ejemplo n.º 2
0
 def test_validate_unique_raises_for_multiple_schedules(self):
     schedules = [('crontab', CrontabSchedule()),
                  ('interval', IntervalSchedule()),
                  ('solar', SolarSchedule()),
                  ('clocked', ClockedSchedule())]
     for options in combinations(schedules, 2):
         with self.assertRaises(ValidationError):
             PeriodicTask(**dict(options)).validate_unique()
Ejemplo n.º 3
0
    def test_SolarSchedule_schedule(self):
        s = SolarSchedule(event='solar_noon', latitude=48.06, longitude=12.86)
        dt = datetime(day=26, month=7, year=2050, hour=1, minute=0)
        dt_lastrun = make_aware(dt)

        assert s.schedule is not None
        isdue, nextcheck = s.schedule.is_due(dt_lastrun)
        assert isdue is False  # False means task isn't due, but keep checking.
        assert (nextcheck > 0) and (isdue is False) or \
            (nextcheck == s.max_interval) and (isdue is True)

        s2 = SolarSchedule(event='solar_noon', latitude=48.06, longitude=12.86)
        dt2 = datetime(day=26, month=7, year=2000, hour=1, minute=0)
        dt2_lastrun = make_aware(dt2)

        assert s2.schedule is not None
        isdue2, nextcheck2 = s2.schedule.is_due(dt2_lastrun)
        assert isdue2 is True  # True means task is due and should run.
        assert (nextcheck2 > 0) and (isdue2 is True) or \
            (nextcheck2 == s2.max_interval) and (isdue2 is False)
Ejemplo n.º 4
0
    def test_SolarSchedule_schedule(self):
        s = SolarSchedule(event='solar_noon', latitude=48.06, longitude=12.86)
        dt = datetime(day=25, month=7, year=2017, hour=12, minute=0)
        dt_lastrun = make_aware(dt)

        assert s.schedule is not None

        isdue, nextcheck = s.schedule.is_due(dt_lastrun)
        assert isdue is False  # False means scheduler needs to keep checking.
        assert (nextcheck > 0) and (isdue is False) or \
            (nextcheck == s.max_interval) and (isdue is True)
Ejemplo n.º 5
0
 def test_validate_unique_raises_for_multiple_schedules(self):
     schedules = [('crontab', CrontabSchedule()),
                  ('interval', IntervalSchedule()),
                  ('solar', SolarSchedule()),
                  ('clocked', ClockedSchedule())]
     expected_error_msg = (
         'Only one of clocked, interval, crontab, or solar '
         'must be set')
     for i, options in enumerate(combinations(schedules, 2)):
         name = 'task{}'.format(i)
         options_dict = dict(options)
         with self.assertRaises(ValidationError) as cm:
             PeriodicTask(name=name, **options_dict).validate_unique()
         errors = cm.exception.args[0]
         self.assertEqual(errors.keys(), options_dict.keys())
         for error_msg in errors.values():
             self.assertEqual(error_msg, [expected_error_msg])
Ejemplo n.º 6
0
 def test_validate_unique_not_raises(self):
     PeriodicTask(crontab=CrontabSchedule()).validate_unique()
     PeriodicTask(interval=IntervalSchedule()).validate_unique()
     PeriodicTask(solar=SolarSchedule()).validate_unique()
Ejemplo n.º 7
0
 def create_model_solar(self, schedule, **kwargs):
     solar = SolarSchedule.from_schedule(schedule)
     solar.save()
     return self.create_model(solar=solar, **kwargs)
Ejemplo n.º 8
0
 def test_validate_unique_not_raises(self):
     PeriodicTask(crontab=CrontabSchedule()).validate_unique()
     PeriodicTask(interval=IntervalSchedule()).validate_unique()
     PeriodicTask(solar=SolarSchedule()).validate_unique()
     PeriodicTask(clocked=ClockedSchedule(), one_off=True).validate_unique()
Ejemplo n.º 9
0
 def create_model_solar(self, schedule, **kwargs):
     solar = SolarSchedule.from_schedule(schedule)
     solar.save()
     return self.create_model(solar=solar, **kwargs)