예제 #1
0
def test_gate_at_fixed_time_with_specific_timezone(custom_app):
    gate = Gate(
        'fixed_time_gate',
        next_states=NoNextStates(),
        exit_condition=ExitConditionProgram('false'),
        triggers=[TimezoneAwareTrigger(
            datetime.time(12, 1),
            timezone='Europe/London',
        )],
    )
    app = create_app(custom_app, [gate])

    def processor(*, state, **kwargs):
        assert state == gate
        processor.called = True

    processor.called = False

    scheduler = schedule.Scheduler()
    configure_schedule(app, scheduler, processor)

    assert len(scheduler.jobs) == 1, "Should have scheduled a single job"
    job, = scheduler.jobs

    assert job.next_run == datetime.datetime(2018, 1, 1, 12, 1)
    assert processor.called is False

    with freezegun.freeze_time(job.next_run):
        job.run()

    assert processor.called is True
    assert job.next_run == datetime.datetime(2018, 1, 1, 12, 2)
예제 #2
0
def test_gate_metadata_retry(custom_app):
    gate = Gate(
        'fixed_time_gate',
        next_states=NoNextStates(),
        exit_condition=ExitConditionProgram('false'),
        triggers=[MetadataTrigger(metadata_path='foo.bar')],
    )
    app = create_app(custom_app, [gate])

    def processor(*, state, **kwargs):
        assert state == gate
        processor.called = True

    processor.called = False

    scheduler = schedule.Scheduler()
    configure_schedule(app, scheduler, processor)

    assert len(scheduler.jobs) == 1, "Should have scheduled a single job"
    job, = scheduler.jobs

    assert job.next_run == datetime.datetime(2018, 1, 1, 12, 1)
    assert processor.called is False

    with freezegun.freeze_time(job.next_run):
        job.run()

    assert processor.called is True
    assert job.next_run == datetime.datetime(2018, 1, 1, 12, 2)
예제 #3
0
def test_action_once_per_minute(custom_app):
    action = Action('noop_action', next_states=NoNextStates(), webhook='')
    app = create_app(custom_app, [action])

    def processor(*, state, **kwargs):
        assert state == action
        processor.called = True

    processor.called = False

    scheduler = schedule.Scheduler()
    configure_schedule(app, scheduler, processor)

    assert len(scheduler.jobs) == 1, "Should have scheduled a single job"
    job, = scheduler.jobs

    assert job.next_run == datetime.datetime(2018, 1, 1, 12, 1)
    assert processor.called is False

    with freezegun.freeze_time(job.next_run):
        job.run()

    assert processor.called is True
    assert job.next_run == datetime.datetime(2018, 1, 1, 12, 2)