Exemplo n.º 1
0
 def test_smoke_test(self, send_mail):
     send_html_email("*****@*****.**",
                     "Subject",
                     "Test",
                     "base.html")
     self.assertTrue(send_mail.called)
     self.assertEqual(send_mail.call_args[0][2], settings.DEFAULT_FROM_EMAIL)
Exemplo n.º 2
0
def send_daily_report(emails):
    users_created_yesterday = get_users_created_yesterday()
    send_html_email(
        recipients=emails,
        subject="OpenMalaria Portal report (%s scenarios updated)" %
        get_scenarios_updated_yesterday().count(),
        text="New portal users report",
        template_path="ts_om/emails/new_users_report.html",
        users=users_created_yesterday,
        scenarios=get_scenarios_updated_yesterday(),
        simulation_in_progress=get_simulations_in_progress(),
    )
Exemplo n.º 3
0
    def test_from_email(self, send_mail):
        send_html_email("*****@*****.**",
                        "Subject",
                        "Test",
                        "base.html",
                        from_email="*****@*****.**")
        self.assertTrue(send_mail.called)
        self.assertEqual(send_mail.call_args[0][2], "*****@*****.**")
        self.assertEqual(Email.objects.count(), 1)

        email_object = Email.objects.all()[0]
        self.assertEqual(email_object.email_recipient, "*****@*****.**")
        self.assertEqual(email_object.email_subject, "Subject")
        self.assertEqual(email_object.from_address, "*****@*****.**")
Exemplo n.º 4
0
 def test_recipients_none(self, send_mail):
     result, message = send_html_email(
         None,
         "Subject",
         "Test",
         "base.html")
     self.assertFalse(send_mail.called)
     self.assertTrue(result)
     self.assertIsNone(message)
     self.assertEqual(Email.objects.count(), 0)
Exemplo n.º 5
0
 def test_wrong_mail_backend(self):
     # To trigger "Server Error" branch in send_html_email
     result, message = send_html_email(
         "*****@*****.**",
         "Subject",
         "Test",
         "base.html",
         from_email="*****@*****.**")
     self.assertFalse(result)
     self.assertIn("No module named wrong", message)
Exemplo n.º 6
0
 def test_send_managers(self, mail_managers):
     result, message = send_html_email(
         None,
         "Subject",
         "Test",
         "base.html",
         send_to_managers=True,
         from_email="*****@*****.**")
     self.assertTrue(result)
     self.assertTrue(mail_managers.called)
     self.assertEqual(Email.objects.count(), 0)
Exemplo n.º 7
0
 def test_send_mail_fails(self, mail_managers, send_mail):
     send_mail.side_effect = SMTPConnectError(10, msg="Can't connect")
     result, message = send_html_email(
         "*****@*****.**",
         "Subject",
         "Test",
         "base.html")
     self.assertTrue(send_mail.called)
     self.assertFalse(mail_managers.called)
     self.assertEqual(send_mail.call_args[0][2], settings.DEFAULT_FROM_EMAIL)
     self.assertFalse(result)
     self.assertEqual(message, "(10, \"Can't connect\")")
Exemplo n.º 8
0
 def test_do_not_send_list_2(self, send_mail):
     DoNotSendEmailList.objects.create(email="*****@*****.**")
     result, message = send_html_email(
         "*****@*****.**",
         "Subject",
         "Test",
         "base.html",
         from_email="*****@*****.**")
     self.assertFalse(result)
     self.assertIn("Email opted out from the research", message)
     self.assertFalse(send_mail.called)
     self.assertEqual(Email.objects.count(), 0)
Exemplo n.º 9
0
    def test_send_html_email_option(self, send_mail):
        result, message = send_html_email(
            "*****@*****.**",
            "Subject",
            "Test",
            "base.html",
            from_email="*****@*****.**")
        self.assertTrue(result)
        self.assertEqual(send_mail.call_args[0][3], ["*****@*****.**"])
        self.assertEqual(Email.objects.count(), 1)

        email_object = Email.objects.all()[0]
        self.assertEqual(email_object.email_recipient, "*****@*****.**")
        self.assertEqual(email_object.email_subject, "Subject")
        self.assertEqual(email_object.from_address, "*****@*****.**")
Exemplo n.º 10
0
 def test_wrong_mail_server(self):
     # To trigger "socket error" branch
     result, message = send_html_email(
         "*****@*****.**",
         "Subject",
         "Test",
         "base.html",
         from_email="*****@*****.**")
     self.assertFalse(result)
     # self.assertIn("[Errno 11001] getaddrinfo failed", message)
     self.assertEqual(Email.objects.count(), 1)
     email_object = Email.objects.all()[0]
     self.assertEqual(email_object.email_recipient, "*****@*****.**")
     self.assertEqual(email_object.email_subject, "Subject")
     self.assertEqual(email_object.from_address, "*****@*****.**")
     self.assertNotEqual(email_object.last_error_message, "")
Exemplo n.º 11
0
    def test_success(self, mail_managers, send_mail):
        result, message = send_html_email(
            "*****@*****.**",
            "Subject",
            "Test",
            "base.html")
        self.assertTrue(send_mail.called)
        self.assertFalse(mail_managers.called)
        self.assertEqual(send_mail.call_args[0][2], settings.DEFAULT_FROM_EMAIL)
        self.assertTrue(result)
        self.assertIsNone(message)

        self.assertEqual(Email.objects.count(), 1)
        email_object = Email.objects.all()[0]
        self.assertEqual(email_object.email_recipient, "*****@*****.**")
        self.assertEqual(email_object.email_subject, "Subject")
        self.assertEqual(email_object.from_address, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email_object.last_error_message, None)
Exemplo n.º 12
0
    def test_do_not_send_list_4(self, send_mail):
        DoNotSendEmailList.objects.create(email="*****@*****.**")
        result, message = send_html_email(
            ["*****@*****.**", "*****@*****.**"],
            "Subject",
            "Test",
            "base.html",
            from_email="*****@*****.**")
        self.assertTrue(result)
        self.assertTrue(send_mail.called)

        # One email will be created since we tried two users, and only one was opted out
        self.assertEqual(Email.objects.count(), 1)
        email_object = Email.objects.all()[0]
        self.assertEqual(email_object.email_recipient, "*****@*****.**")
        self.assertEqual(email_object.email_subject, "Subject")
        self.assertEqual(email_object.from_address, "*****@*****.**")
        self.assertEqual(email_object.last_error_message, None)