-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,15 @@ def test_process_regular(self, mocked_start): | |
|
||
self.assertIsNone(service.process()) | ||
mocked_start.assert_called_once() | ||
|
||
@mock.patch.object(Thread, "start") | ||
@mock.patch.object(ThreadEmailService, "is_valid", return_value=False) | ||
def test_process_invalid(self, mocked_service, mocked_start): | ||
email = "[email protected]" | ||
subject = "Test email" | ||
service = ThreadEmailService(recipient_email_list=[email]) | ||
service.subject = subject | ||
service.template_name = "testapp/test_email.html" | ||
|
||
self.assertIsNone(service.process()) | ||
mocked_start.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
from django.conf import settings | ||
from django.core.mail import EmailMultiAlternatives | ||
from django.test import TestCase, override_settings | ||
from django.utils import translation | ||
from freezegun import freeze_time | ||
|
||
from django_pony_express.errors import EmailServiceAttachmentError, EmailServiceConfigError | ||
|
@@ -228,6 +229,21 @@ def test_build_mail_object_with_attachments(self): | |
self.assertEqual(len(msg_obj.attachments), 1) | ||
self.assertEqual(msg_obj.attachments[0][0], basename(file_path)) | ||
|
||
@mock.patch.object(BaseEmailService, "get_translation", return_value=None) | ||
def test_build_mail_object_missing_language(self, *args): | ||
email = "[email protected]" | ||
my_var = "Lorem ipsum dolor!" | ||
file_path = settings.BASE_PATH / "tests/files/testfile.txt" | ||
service = BaseEmailService( | ||
recipient_email_list=[email], context_data={"my_var": my_var}, attachment_list=[file_path] | ||
) | ||
|
||
service.template_name = "testapp/test_email.html" | ||
|
||
with mock.patch.object(translation, "activate") as mocked_activate: | ||
service._build_mail_object() | ||
mocked_activate.assert_not_called() | ||
|
||
def test_setting_txt_templates_works(self): | ||
my_var = "Lorem ipsum dolor!" | ||
service = BaseEmailService( | ||
|
@@ -372,3 +388,8 @@ def test_process_with_error(self): | |
service.template_name = "testapp/test_email.html" | ||
with self.assertRaises(EmailServiceConfigError): | ||
service.process() | ||
|
||
@mock.patch.object(BaseEmailService, "is_valid", return_value=False) | ||
def test_process_is_valid_invalid(self, *args): | ||
factory = BaseEmailService() | ||
self.assertEqual(factory.process(), 0) |