def test_is_interval_expired__hourly(self):
        self.config.set_interval('hourly')

        self.assertEqual(utils.get_last_notification_date(), None)
        self.assertEqual(utils.is_interval_expired(), True)

        self.now = datetime.datetime(2010, 12, 27, 10, 00)
        utils.set_last_notification_date_to_now()
        self.assertEqual(utils.is_interval_expired(), False)

        self.now = datetime.datetime(2010, 12, 27, 10, 31)
        self.assertEqual(utils.is_interval_expired(), False)

        self.now = datetime.datetime(2010, 12, 27, 11, 01)
        self.assertEqual(utils.is_interval_expired(), True)
    def get_options(self):
        """Returns a `dict` of data needed for rendering the mail template.
        """
        config = self.get_configuration()
        last_date = get_last_notification_date()
        queue = IQueue(self.context)
        data = {'success': 0,
                'warning': 0,
                'error': 0,
                'total': 0,
                'jobs_in_queue': 0,
                'erroneous_jobs': [],
                'show_details': config.detailed_report,
                'subject': self.get_subject(),
                'portal': self.context}

        # count the jobs by group and total
        for _key, job in queue.get_executed_jobs():
            # get the runs
            runs = getattr(job, 'executed_list', None)
            if not runs or len(runs) == 0:
                continue

            # was it published since last notification?
            if last_date and runs[-1]['date'] < last_date:
                continue

            # count it
            state = job.get_latest_executed_entry()
            if isinstance(state, states.ErrorState):
                data['error'] += 1
                data['erroneous_jobs'].append(job)
            elif isinstance(state, states.WarningState):
                data['warning'] += 1
            if isinstance(state, states.SuccessState):
                data['success'] += 1
            data['total'] += 1

        # get the amount of jobs in the queue
        data['jobs_in_queue'] = queue.countJobs()

        return data
 def test_set_set_last_notification_date_to_now(self):
     self.assertEqual(utils.get_last_notification_date(), None)
     utils.set_last_notification_date_to_now()
     self.assertEqual(utils.get_last_notification_date(), self.now)
 def test_default_values(self):
     import datetime
     self.assertEqual(utils.get_last_notification_date(), None)
     self.assertEqual(utils.is_interval_expired(), True)
     self.assertEqual(utils.get_interval_delta(), datetime.timedelta(1))