Example #1
0
def check_reports():
    """
    Task to check send the reports,
    This tasks should execute daily
    """
    reports = Report.objects.all()
    sent_reports_counter = 0

    for report in reports:
        # Daily reports
        if report.duration == "daily":
            sent_val = send_report(report)

        # For weekly we check the day 
        elif report.duration == "weekly":
            if datetime.now().today().weekday() == report.day_to_report:
                sent_val = send_report(report)

        # For months we check the date
        elif report.duration == "monthly":
            if datetime.now().day == day_to_report:
                # Issue: If the day_to_report is 31, some months will be skipped, need a better way to handle this
                sent_val = send_report(report)

        else:
             raise Exception("Incorrect, report duration")

        if sent_val:
            sent_reports_counter += 1

    logger.debug("Sent %s emails for this day %s" %  (sent_reports_counter, datetime.now().today()))
    return sent_reports_counter
Example #2
0
def check_reports():
    """
    Task to check send the reports,
    This tasks should execute daily
    """
    reports = Report_Job.objects.all()
    sent_reports_counter = 0

    for report in reports:
        # Daily reports
        if report.duration == "daily":
            sent_val = send_report(report)

        # For weekly we check the day
        elif report.duration == "weekly":
            if datetime.now().today().weekday() == report.day_to_report:
                sent_val = send_report(report)

        # For months we check the date
        elif report.duration == "monthly":
            if datetime.now().day == day_to_report:
                # Issue: If the day_to_report is 31, some months will be skipped, need a better way to handle this
                sent_val = send_report(report)

        else:
            raise Exception("Incorrect, report duration")

        if sent_val:
            sent_reports_counter += 1

    logger.debug("Sent %s emails for this day %s" %
                 (sent_reports_counter, datetime.now().today()))
    return sent_reports_counter
 def test_send_report(self):
     """
     Testing the sending of the generated reports,
     This tests the sending by mail 
     """
     val = send_report(self.report)
     self.assertTrue(val)
    def test_send_report(self):
        """
        Testing the sending of the generated reports,
        Test logging of report
        """
        val = send_report(self.report)

        report_log = Report_Sent.objects.all()
        self.assertTrue(val)
        self.assertGreater(len(report_log),0)