def setup_scheduler(self, app): self.app = app self.app.conf.beat_schedule = {} self.m1 = self.create_model_interval( schedule(timedelta(seconds=10))) self.m1.save() self.m1.refresh_from_db() self.m2 = self.create_model_interval( schedule(timedelta(minutes=20))) self.m2.save() self.m2.refresh_from_db() self.m3 = self.create_model_crontab( crontab(minute='2,4,5')) self.m3.save() self.m3.refresh_from_db() self.m4 = self.create_model_solar( solar('solar_noon', 48.06, 12.86)) self.m4.save() self.m4.refresh_from_db() # disabled, should not be in schedule m5 = self.create_model_interval( schedule(timedelta(seconds=1))) m5.enabled = False m5.save() self.s = self.Scheduler(app=self.app)
def test_PeriodicTask_unicode_solar(self): p = self.create_model_solar( solar('solar_noon', 48.06, 12.86), name='solar_event' ) assert text_t(p) == 'solar_event: {0} ({1}, {2})'.format( 'solar_noon', '48.06', '12.86' )
def test_coordinates(self): with pytest.raises(ValueError): solar('sunrise', -120, 60, app=self.app) with pytest.raises(ValueError): solar('sunrise', 120, 60, app=self.app) with pytest.raises(ValueError): solar('sunrise', 60, -200, app=self.app) with pytest.raises(ValueError): solar('sunrise', 60, 200, app=self.app)
def test_coordinates(self): with self.assertRaises(ValueError): solar('sunrise', -120, 60) with self.assertRaises(ValueError): solar('sunrise', 120, 60) with self.assertRaises(ValueError): solar('sunrise', 60, -200) with self.assertRaises(ValueError): solar('sunrise', 60, 200)
def test_event_uses_center(self): s = solar('solar_noon', 60, 60, app=self.app) for ev, is_center in s._use_center_l.items(): s.method = s._methods[ev] s.is_center = s._use_center_l[ev] try: s.remaining_estimate(datetime.utcnow()) except TypeError: pytest.fail("{0} was called with 'use_center' which is not a \ valid keyword for the function.".format(s.method))
def test_eq(self): assert self.s == solar('sunrise', 60, 30, app=self.app) assert self.s != solar('sunset', 60, 30, app=self.app) assert self.s != schedule(10)
def setup(self): self.s = solar('sunrise', 60, 30, app=self.app)
def test_invalid_event(self): with self.assertRaises(ValueError): solar('asdqwewqew', 60, 60)
def test_eq(self): self.assertEqual(self.s, solar('sunrise', 60, 30, app=self.app)) self.assertNotEqual(self.s, solar('sunset', 60, 30, app=self.app)) self.assertNotEqual(self.s, schedule(10))
def setup(self): try: import ephem # noqa except ImportError: raise SkipTest('ephem module not installed') self.s = solar('sunrise', 60, 30, app=self.app)
def schedule(self): return schedules.solar(self.event, self.latitude, self.longitude, nowfun=lambda: make_aware(now()))
def test_invalid_event(self): with pytest.raises(ValueError): solar('asdqwewqew', 60, 60, app=self.app)
def test_PeriodicTask_unicode_solar(self): p = self.create_model_solar(solar('solar_noon', 48.06, 12.86), name='solar_event') assert text_t(p) == 'solar_event: {0} ({1}, {2})'.format( 'solar_noon', '48.06', '12.86')
import json from datetime import datetime import pytest from celery.beat import ScheduleEntry from celery.schedules import crontab, solar, schedule # noinspection PyProtectedMember from beatx.serializer import encode_schedule, decode_schedule, \ serialize_entry, deserialize_entry @pytest.mark.parametrize('dt', [ crontab('10', '*/2'), solar('sunset', -37.81753, 144.96715), schedule(17, relative=True) ]) def test_serialize_entry_json_serializable(dt): entry = ScheduleEntry( name='entry-1', task='entry-1-task', schedule=dt, args=('arg1', 'arg2'), kwargs={ 'key1': 'val1', 'key2': 'val2' }, last_run_at=datetime.now(), total_run_count=1, options={}, )