def test_it_creates_a_job(webapp): job = Job( name="retrieve cash register data", description="connects to the cash register API and fetches latest sale", type=JobType.SCHEDULED, ) test_env = Environment(name="test") context = Context(environment=test_env) context.set_config(url="http://*****:*****@local.local") job.add_context(context) job.add_notification(group, on_retry=True, on_failure=True) db.session.add(job) db.session.commit() assert ( job.notifications[0].groups[0].emails[0].email == "*****@*****.**")
def test_it_compares_correctly_schedule_and_time(): date = datetime(2019, 5, 20, 12, 0) assert should_run(Schedule(name="Every minute"), date) assert should_run( Schedule(name="At 12:00 on day-of-month 20", minute="0", hour="12", day="20"), date, ) assert not should_run( Schedule(name="Every minute past hour 13", hour="13"), date)
def test_it_validate_schedule(webapp): with raises(ValueError) as excinfo: schedule = Schedule(name="Schedule test", hour="/2", minute="/3") db.session.add(schedule) db.session.commit() assert "hour" in str( excinfo.value), f"The Schedule should not accept '/2' for hour" name_schedule_2 = "Schedule test II" schedule_2 = Schedule(name=name_schedule_2, hour="*/2") db.session.add(schedule_2) db.session.commit() schedule_2_commit = (db.session.query(Schedule).filter_by( name=name_schedule_2).one()) assert schedule_2_commit.hour == "*/2" with raises(ValueError): schedule_2.minute = "/3" db.session.commit()
def db_contexts(db_env, db_jobs): [orders_job, cashregister_job, prepare_job, abort_job] = db_jobs orders_context = Context( environment=db_env, job=orders_job, schedules=[Schedule(name="Every minute")], ) cashregister_context = Context(environment=db_env, job=cashregister_job) prepare_context = Context( environment=db_env, job=prepare_job, schedules=[Schedule(name="Every day at 00:00", minute="0", hour="0")], ) abort_context = Context(environment=db_env, job=abort_job) contexts = [ orders_context, cashregister_context, prepare_context, abort_context, ] db.session.add_all(contexts) db.session.commit() return contexts
def test_it_creates_a_script(webapp): test_env = Environment(name="test_env") db.session.add(test_env) job = Job( name="retrieve cash register data", description="connects to the cash register API and fetches latest sale", type=JobType.SCHEDULED, ) db.session.add(job) context = Context(environment=test_env, job=job) schedule = Schedule(name="every two minutes", hour="*", minute="*/2") db.session.add(schedule) context.add_schedule(schedule) db.session.add(context) script = Script( context=context, package_name="test_package", package_version="0.0.1", first_seen=datetime.now(), ) source = Topic(name="source") db.session.add(source) destination = Topic(name="destination") db.session.add(destination) script.add_source(source) script.add_destination(destination) db.session.add(script) db.session.commit() assert script.sources == [source] assert script.destinations == [destination] assert script.context.environment.name == "test_env" assert script.context.job.name == "retrieve cash register data" assert script.context.schedules[0].name == "every two minutes"