Exemplo n.º 1
0
def test_scheduler_feature_flag_off(execute_mock, is_feature_enabled):
    """
    Reports scheduler: Test scheduler with feature flag off
    """
    with app.app_context():
        is_feature_enabled.return_value = False
        report_schedule = insert_report_schedule(
            type=ReportScheduleType.ALERT,
            name="report",
            crontab="0 9 * * *",
            timezone="UTC",
        )

        with freeze_time("2020-01-01T09:00:00Z"):
            scheduler()
            execute_mock.assert_not_called()
        db.session.delete(report_schedule)
        db.session.commit()
Exemplo n.º 2
0
def test_scheduler_celery_timeout(execute_mock):
    """
    Reports scheduler: Test scheduler setting celery soft and hard timeout
    """
    with app.app_context():

        report_schedule = insert_report_schedule(
            type=ReportScheduleType.ALERT,
            name=f"report",
            crontab=f"0 9 * * *",
        )

        with freeze_time("2020-01-01T09:00:00Z"):
            scheduler()
            assert execute_mock.call_args[1]["soft_time_limit"] == 3601
            assert execute_mock.call_args[1]["time_limit"] == 3610
        db.session.delete(report_schedule)
        db.session.commit()
Exemplo n.º 3
0
    def create_report_schedules(self):
        with self.create_app().app_context():
            report_schedules = []
            admin_user = self.get_user("admin")
            alpha_user = self.get_user("alpha")
            chart = db.session.query(Slice).first()
            example_db = get_example_database()
            for cx in range(REPORTS_COUNT):
                recipients = []
                logs = []
                for cy in range(cx):
                    config_json = {"target": f"target{cy}@email.com"}
                    recipients.append(
                        ReportRecipients(
                            type=ReportRecipientType.EMAIL,
                            recipient_config_json=json.dumps(config_json),
                        ))
                    logs.append(
                        ReportExecutionLog(
                            scheduled_dttm=datetime(2020, 1, 1),
                            state=ReportState.ERROR,
                            error_message=f"Error {cy}",
                        ))
                report_schedules.append(
                    insert_report_schedule(
                        type=ReportScheduleType.ALERT,
                        name=f"name{cx}",
                        crontab=f"*/{cx} * * * *",
                        sql=f"SELECT value from table{cx}",
                        description=f"Some description {cx}",
                        chart=chart,
                        database=example_db,
                        owners=[admin_user, alpha_user],
                        recipients=recipients,
                        logs=logs,
                    ))
            yield report_schedules

            report_schedules = db.session.query(ReportSchedule).all()
            # rollback changes (assuming cascade delete)
            for report_schedule in report_schedules:
                db.session.delete(report_schedule)
            db.session.commit()
Exemplo n.º 4
0
def test_scheduler_celery_no_timeout_utc(execute_mock):
    """
    Reports scheduler: Test scheduler setting celery soft and hard timeout
    """
    with app.app_context():
        app.config["ALERT_REPORTS_WORKING_TIME_OUT_KILL"] = False
        report_schedule = insert_report_schedule(
            type=ReportScheduleType.ALERT,
            name="report",
            crontab="0 9 * * *",
            timezone="UTC",
        )

        with freeze_time("2020-01-01T09:00:00Z"):
            scheduler()
            assert execute_mock.call_args[1] == {"eta": FakeDatetime(2020, 1, 1, 9, 0)}
        db.session.delete(report_schedule)
        db.session.commit()
        app.config["ALERT_REPORTS_WORKING_TIME_OUT_KILL"] = True
Exemplo n.º 5
0
    def create_working_report_schedule(self):
        with self.create_app().app_context():

            admin_user = self.get_user("admin")
            alpha_user = self.get_user("alpha")
            chart = db.session.query(Slice).first()
            example_db = get_example_database()

            report_schedule = insert_report_schedule(
                type=ReportScheduleType.ALERT,
                name=f"name_working",
                crontab=f"* * * * *",
                sql=f"SELECT value from table",
                description=f"Report working",
                chart=chart,
                database=example_db,
                owners=[admin_user, alpha_user],
                last_state=ReportState.WORKING,
            )

            yield

            db.session.delete(report_schedule)
            db.session.commit()