def test_unschedule_job(self, cli): PeriodicTask.objects.create( task=JOB_NAME, name='job', description='I\'m a scheduled job', enabled=True, crontab=PeriodicTask.Crontab.parse('0 0 0 0 0'), ) cli('job unschedule {0}'.format(JOB_NAME)) assert len(PeriodicTask.objects(task=JOB_NAME)) == 0
def test_unschedule_job_different_parameters(self, cli): PeriodicTask.objects.create( task=JOB_NAME, name='job', description='I\'m a scheduled job', enabled=True, crontab=PeriodicTask.Crontab.parse('0 0 0 0 0'), ) result = cli('job unschedule {0} arg'.format(JOB_NAME), check=False) assert result.exit_code != 0 assert len(PeriodicTask.objects(task=JOB_NAME)) == 1
def test_unschedule_job_with_parameters(self, cli): PeriodicTask.objects.create( task=JOB_NAME, name='job', description='I\'m a scheduled job', enabled=True, args=['arg'], kwargs={'key': 'value'}, crontab=PeriodicTask.Crontab.parse('0 0 0 0 0'), ) cli('job unschedule {0} arg key=value'.format(JOB_NAME)) assert len(PeriodicTask.objects(task=JOB_NAME)) == 0
def test_delete_job(self): @job('a-job') def test_job(): pass task = PeriodicTask.objects.create( name=faker.name(), description=faker.sentence(), task='a-job', crontab=PeriodicTask.Crontab(minute='5')) self.login(AdminFactory()) response = self.delete(url_for('api.job', id=task.id)) self.assert204(response) self.assertIsNone(PeriodicTask.objects(id=task.id).first())
def test_schedule_job(self, cli): cli('job schedule "0 1 2 3 sunday" fake-job') tasks = PeriodicTask.objects(task=JOB_NAME) assert len(tasks) == 1 task = tasks[0] assert task.args == [] assert task.kwargs == {} assert task.crontab.minute == '0' assert task.crontab.hour == '1' assert task.crontab.day_of_month == '2' assert task.crontab.month_of_year == '3' assert task.crontab.day_of_week == 'sunday' assert task.enabled assert task.name == 'Job {0}'.format(JOB_NAME)
def test_delete_job(self): @job('a-job') def test_job(): pass task = PeriodicTask.objects.create( name=faker.name(), description=faker.sentence(), task='a-job', crontab=PeriodicTask.Crontab(minute='5') ) self.login(AdminFactory()) response = self.delete(url_for('api.job', id=task.id)) self.assert204(response) self.assertIsNone(PeriodicTask.objects(id=task.id).first())
def test_schedule_job_with_parameters(self, cli): cli('job schedule "0 1 2 3 sunday" fake-job ' 'arg0 arg1 key1=value1 key0=value0') tasks = PeriodicTask.objects(task=JOB_NAME) assert len(tasks) == 1 task = tasks[0] assert task.args == ['arg0', 'arg1'] # Arguments order is preserved assert task.kwargs == {'key0': 'value0', 'key1': 'value1'} assert task.crontab.minute == '0' assert task.crontab.hour == '1' assert task.crontab.day_of_month == '2' assert task.crontab.month_of_year == '3' assert task.crontab.day_of_week == 'sunday' assert task.enabled # kwargs are sorted expected = 'Job {0}(arg0, arg1, key0=value0, key1=value1)' assert task.name == expected.format(JOB_NAME)