Exemplo n.º 1
0
    def test_skip_if_no_patients(self):
        """Skip sending the email if there are not patients for this date."""

        appt_date = datetime.date.today() + datetime.timedelta(days=5)
        confirmed = self.create_confirmed_notification(self.test_patient, appt_date)

        self.startRouter()
        self.router.logger.setLevel(logging.DEBUG)
        # run email job
        from afrims.apps.reminders.app import daily_email_callback
        daily_email_callback(self.router)

        self.assertEqual(len(mail.outbox), 0)
        self.stopRouter()
Exemplo n.º 2
0
    def test_sending_mail(self):
        """Test email goes out the contacts in the daily report group."""

        appt_date = datetime.date.today() + datetime.timedelta(days=7) # Default for email
        confirmed = self.create_confirmed_notification(self.test_patient, appt_date)

        self.startRouter()
        self.router.logger.setLevel(logging.DEBUG)

        # run email job
        from afrims.apps.reminders.app import daily_email_callback
        daily_email_callback(self.router)

        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]
        self.assertTrue(self.test_contact.email in message.to)
        self.stopRouter()
Exemplo n.º 3
0
    def test_skip_blank_emails(self):
        """Test handling contacts with blank/null email addresses."""
        appt_date = datetime.date.today() + datetime.timedelta(days=7) # Default for email
        confirmed = self.create_confirmed_notification(self.test_patient, appt_date)
        blank_contact = self.create_contact(data={'email': ''})
        null_contact = self.create_contact(data={'email': None})
        self.group.contacts.add(blank_contact)
        self.group.contacts.add(null_contact)

        self.startRouter()
        self.router.logger.setLevel(logging.DEBUG)
        # run email job
        from afrims.apps.reminders.app import daily_email_callback
        daily_email_callback(self.router)

        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]
        self.assertEqual(len(message.to), 1)
        self.stopRouter()
Exemplo n.º 4
0
    def test_appointment_date(self):
        """Test email contains info for the appointment date."""
        appt_date = datetime.date.today() + datetime.timedelta(days=7) # Default for email
        confirmed = self.create_confirmed_notification(self.test_patient, appt_date)
        unconfirmed = self.create_unconfirmed_notification(self.other_patient, appt_date)

        self.startRouter()
        self.router.logger.setLevel(logging.DEBUG)

        # run email job
        from afrims.apps.reminders.app import daily_email_callback
        daily_email_callback(self.router)

        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]
        self.assertPatientInMessage(message, self.test_patient)
        self.assertPatientInMessage(message, self.other_patient)
        self.assertPatientNotInMessage(message, self.unrelated_patient)
        self.stopRouter()
Exemplo n.º 5
0
    def test_changing_date(self):
        """Test changing appointment date via callback kwarg."""
        days = 2
        appt_date = datetime.date.today() + datetime.timedelta(days=days)
        reminders.Patient.objects.filter(
            pk__in=[self.test_patient.pk, self.other_patient.pk]
        ).update(next_visit=appt_date)
        confirmed = self.create_confirmed_notification(self.test_patient, appt_date)
        unconfirmed = self.create_unconfirmed_notification(self.other_patient, appt_date)

        self.startRouter()
        self.router.logger.setLevel(logging.DEBUG)

        # run email job
        from afrims.apps.reminders.app import daily_email_callback
        daily_email_callback(self.router, days=days)

        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]
        self.assertPatientInMessage(message, self.test_patient)
        self.assertPatientInMessage(message, self.other_patient)
        self.assertPatientNotInMessage(message, self.unrelated_patient)
        self.stopRouter()