def test_update_job_change_type(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.put( url_for('api.job', id=task.id), { 'name': task.name, 'description': task.description, 'task': task.task, 'interval': { 'every': 5, 'period': 'minutes', } }) self.assert200(response) self.assertEqual(response.json['id'], str(task.id)) self.assertEqual(response.json['name'], task.name) self.assertEqual(response.json['task'], task.task) self.assertEqual(response.json['description'], task.description) self.assertEqual(response.json['interval']['every'], 5) self.assertEqual(response.json['interval']['period'], 'minutes') self.assertIsNone(response.json['crontab'])
def test_update_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.put( url_for('api.job', id=task.id), { 'name': task.name, 'description': 'New description', 'task': task.task, 'crontab': task.crontab.to_json() }) self.assert200(response) self.assertEqual(response.json['id'], str(task.id)) self.assertEqual(response.json['name'], task.name) self.assertEqual(response.json['task'], task.task) self.assertEqual(response.json['description'], 'New description') self.assertIsNotNone(response.json['crontab']) self.assertIsNone(response.json['interval'])
def test_delete_job_need_admin(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() response = self.delete(url_for('api.job', id=task.id)) self.assert403(response)
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_get_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')) response = self.get(url_for('api.job', id=task.id)) self.assert200(response) self.assertEqual(response.json['id'], str(task.id)) self.assertEqual(response.json['name'], task.name) self.assertEqual(response.json['description'], task.description) self.assertEqual(response.json['task'], task.task)
def test_scheduled_jobs_list(self): @job('a-job') def test_job(): pass for i in range(6): params = { 'name': faker.name(), 'description': faker.sentence(), 'task': 'a-job' } if i % 2: params['crontab'] = PeriodicTask.Crontab(minute=str(i)) else: params['interval'] = PeriodicTask.Interval(every=i, period='minutes') PeriodicTask.objects.create(**params) response = self.get(url_for('api.jobs')) self.assert200(response)
def test_update_job_need_admin(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() response = self.put( url_for('api.job', id=task.id), { 'name': task.name, 'description': 'New description', 'task': task.task, 'crontab': task.crontab.to_json() }) self.assert403(response)