def test_it_should_send_email_with_differents_recipient(self): email_adress = EmailAdress(email=get_random_email(), name=get_random_name()) email = get_random_email() tos = [email_adress.address(), email] EmailSender.send(tos=[email_adress, email], template_path=TEST_EMAIL_PATH) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, tos)
def test_it_should_return_error_with_invalid_template(self): to = get_random_email() try: EmailSender.send(tos=[to], template_path=None) self.assertTrue(False) except EmailException as ex: self.assertTrue(True)
def test_it_should_send_email_with_recipient_full_address(self): to = EmailAdress(email=get_random_email(), name=get_random_name()) EmailSender.send(tos=[to], template_path=TEST_EMAIL_PATH) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [to.address()])
def test_it_should_send_email_with_correct_recipients(self): tos = [] for i in range(10): tos.append(get_random_email()) EmailSender.send(tos=tos, template_path=TEST_EMAIL_PATH) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, tos)
def test_it_should_send_email_with_correct_message(self): to = get_random_email() data = {"username": get_random_name()} EmailSender.send(tos=[to], template_path=TEST_EMAIL_PATH, data=data) self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0].alternatives[0] self.assertTrue(data["username"] in message[0])
def test_it_should_send_email_with_correct_subject(self): to = get_random_email() TEST_SUBJECT = "Subject" EmailSender.send(tos=[to], template_path=TEST_EMAIL_PATH, subject=TEST_SUBJECT) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, TEST_SUBJECT)
def test_it_should_send_email(self): to = get_random_email() EmailSender.send(tos=[to], template_path=TEST_EMAIL_PATH) self.assertEqual(len(mail.outbox), 1)