def test_not_greater(self): class DateForm(Form): start_date = BetterDateTimeField(validators=[NotGreater('end_date')]) end_date = BetterDateTimeField() class NumberForm(Form): start = IntegerField(validators=[NotGreater('end')]) end = IntegerField() class MixedForm(Form): start = IntegerField(validators=[NotGreater('end')]) end = StringField() form = DateForm(start_date=thirty_days_ago(), end_date=today()) assert_equals(form.validate(), True) form = DateForm(start_date=today(), end_date=thirty_days_ago()) assert_equals(form.validate(), False) form = NumberForm(start=1, end=2) assert_equals(form.validate(), True) form = NumberForm(start=3, end=2) assert_equals(form.validate(), False) form = NumberForm(start=3, end=3) assert_equals(form.validate(), True) form = MixedForm(start=3, end='abc') assert_equals(form.validate(), False)
def test_not_greater(self): class DateForm(Form): start_date = BetterDateTimeField( validators=[NotGreater('end_date')]) end_date = BetterDateTimeField() class NumberForm(Form): start = IntegerField(validators=[NotGreater('end')]) end = IntegerField() class MixedForm(Form): start = IntegerField(validators=[NotGreater('end')]) end = StringField() form = DateForm(start_date=thirty_days_ago(), end_date=today()) assert_equals(form.validate(), True) form = DateForm(start_date=today(), end_date=thirty_days_ago()) assert_equals(form.validate(), False) form = NumberForm(start=1, end=2) assert_equals(form.validate(), True) form = NumberForm(start=3, end=2) assert_equals(form.validate(), False) form = NumberForm(start=3, end=3) assert_equals(form.validate(), True) form = MixedForm(start=3, end='abc') assert_equals(form.validate(), False)
def days_missed(cls, report, session): """ Examine the past runs of a recurring report, for up to 30 days. Find any missed runs, including today's run. Raise an exception if there are more runs than expected. Parameters: report : the recurring report to examine session : session to the database Returns: An array of datetimes representing the days when the report did not run """ search_from = strip_time(report.created) look_at_most_this_far = to_datetime(thirty_days_ago()) if search_from < look_at_most_this_far: search_from = look_at_most_this_far completed_days = [pr[0] for pr in session.query(PersistentReport.created) .filter(PersistentReport.recurrent_parent_id == report.id) .filter(PersistentReport.created >= search_from) .filter(PersistentReport.status != celery.states.FAILURE) .all()] expected_days = timestamps_to_now(search_from, timedelta(days=1)) missed_days, unexpected_days = diff_datewise(expected_days, completed_days) if len(unexpected_days) > 0: task_logger.warn('Problem with recurrent report id {}'.format(report.id)) task_logger.warn('Completed runs: {}'.format(sorted(completed_days))) task_logger.warn('Unexpected runs: {}'.format(sorted(unexpected_days))) raise Exception('More reports ran than were supposed to') return missed_days
def reports_list(): db_session = db.get_session() try: reports = db_session.query(ReportStore)\ .filter(ReportStore.user_id == current_user.id)\ .filter(ReportStore.created > thirty_days_ago())\ .filter(ReportStore.show_in_ui)\ .all() # TODO: update status for all reports at all times (not just show_in_ui ones) # update status for each report for report in reports: report.update_status() # TODO fix json_response to deal with ReportStore objects reports_json = json_response(reports=[report._asdict() for report in reports]) finally: db_session.close() return reports_json
def reports_list(): db_session = db.get_session() # Joins with TaskError to get the error message for failed reports. report_tuples = db_session.query(ReportStore, TaskErrorStore.message)\ .outerjoin(TaskErrorStore)\ .filter(ReportStore.user_id == current_user.id)\ .filter(or_(ReportStore.created > thirty_days_ago(), ReportStore.recurrent))\ .filter(ReportStore.show_in_ui)\ .filter(or_( TaskErrorStore.task_type == 'report', TaskErrorStore.task_type == None))\ .all() # TODO: update status for all reports at all times (not just show_in_ui ones) # update status for each report and build response reports = [] for report_tuple in report_tuples: report = report_tuple.ReportStore report.update_status() report_dict = report._asdict() report_dict['error_message'] = report_tuple.message reports.append(report_dict) # TODO fix json_response to deal with ReportStore objects return json_response(reports=reports)