Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
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())
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
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())
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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)