diff --git a/mayan/apps/mailer/tests/literals.py b/mayan/apps/mailer/tests/literals.py
index ae3b603355..e3ea1038a0 100644
--- a/mayan/apps/mailer/tests/literals.py
+++ b/mayan/apps/mailer/tests/literals.py
@@ -1,8 +1,10 @@
from __future__ import unicode_literals
-TEST_BODY_HTML = 'test body'
TEST_EMAIL_ADDRESS = 'test@example.com'
+TEST_EMAIL_BODY = 'test body'
+TEST_EMAIL_BODY_HTML = 'test body'
TEST_EMAIL_FROM_ADDRESS = 'from.test@example.com'
+TEST_EMAIL_SUBJECT = 'test subject'
TEST_RECIPIENTS_MULTIPLE_COMMA = 'test@example.com,test2@example.com'
TEST_RECIPIENTS_MULTIPLE_COMMA_RESULT = [
'test@example.com', 'test2@example.com'
diff --git a/mayan/apps/mailer/tests/test_actions.py b/mayan/apps/mailer/tests/test_actions.py
new file mode 100644
index 0000000000..e747d16e20
--- /dev/null
+++ b/mayan/apps/mailer/tests/test_actions.py
@@ -0,0 +1,84 @@
+from __future__ import unicode_literals
+
+from django.core import mail
+
+from mayan.apps.common.tests import GenericViewTestCase
+from mayan.apps.documents.tests.mixins import DocumentTestMixin
+from mayan.apps.document_states.literals import WORKFLOW_ACTION_ON_ENTRY
+from mayan.apps.document_states.tests.mixins import WorkflowTestMixin
+from mayan.apps.document_states.tests.test_actions import ActionTestCase
+
+from ..permissions import permission_user_mailer_use
+from ..workflow_actions import EmailAction
+
+from .literals import (
+ TEST_EMAIL_ADDRESS, TEST_EMAIL_BODY, TEST_EMAIL_FROM_ADDRESS,
+ TEST_EMAIL_SUBJECT
+)
+from .mixins import MailerTestMixin
+
+
+class EmailActionTestCase(MailerTestMixin, ActionTestCase):
+ def test_email_action_literal_text(self):
+ self._create_test_user_mailer()
+
+ action = EmailAction(
+ form_data={
+ 'mailing_profile': self.test_user_mailer.pk,
+ 'recipient': TEST_EMAIL_ADDRESS,
+ 'subject': TEST_EMAIL_SUBJECT,
+ 'body': TEST_EMAIL_BODY,
+ }
+ )
+ action.execute(context={'document': self.test_document})
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertEqual(mail.outbox[0].from_email, TEST_EMAIL_FROM_ADDRESS)
+ self.assertEqual(mail.outbox[0].to, [TEST_EMAIL_ADDRESS])
+
+
+class EmailActionViewTestCase(DocumentTestMixin, MailerTestMixin, WorkflowTestMixin, GenericViewTestCase):
+ auto_upload_document = False
+
+ def test_email_action_create_get_view(self):
+ self._create_test_workflow()
+ self._create_test_workflow_state()
+ self._create_test_user_mailer()
+
+ response = self.get(
+ viewname='document_states:setup_workflow_state_action_create',
+ kwargs={
+ 'pk': self.test_workflow_state.pk,
+ 'class_path': 'mayan.apps.mailer.workflow_actions.EmailAction',
+ }
+ )
+ self.assertEqual(response.status_code, 200)
+
+ self.assertEqual(self.test_workflow_state.actions.count(), 0)
+
+ def test_email_action_create_post_view(self):
+ self._create_test_workflow()
+ self._create_test_workflow_state()
+ self._create_test_user_mailer()
+
+ self.grant_access(
+ obj=self.test_user_mailer, permission=permission_user_mailer_use
+ )
+
+ response = self.post(
+ viewname='document_states:setup_workflow_state_action_create',
+ kwargs={
+ 'pk': self.test_workflow_state.pk,
+ 'class_path': 'mayan.apps.mailer.workflow_actions.EmailAction',
+ }, data={
+ 'when': WORKFLOW_ACTION_ON_ENTRY,
+ 'label': 'test email action',
+ 'mailing_profile': self.test_user_mailer.pk,
+ 'recipient': TEST_EMAIL_ADDRESS,
+ 'subject': TEST_EMAIL_SUBJECT,
+ 'body': TEST_EMAIL_BODY,
+
+ }
+ )
+ self.assertEqual(response.status_code, 302)
+
+ self.assertEqual(self.test_workflow_state.actions.count(), 1)
diff --git a/mayan/apps/mailer/tests/test_models.py b/mayan/apps/mailer/tests/test_models.py
index 376e4ba669..02f3cab3b1 100644
--- a/mayan/apps/mailer/tests/test_models.py
+++ b/mayan/apps/mailer/tests/test_models.py
@@ -5,7 +5,7 @@ from django.core import mail
from mayan.apps.documents.tests.test_models import GenericDocumentTestCase
from .literals import (
- TEST_BODY_HTML, TEST_EMAIL_ADDRESS, TEST_EMAIL_FROM_ADDRESS,
+ TEST_EMAIL_BODY_HTML, TEST_EMAIL_ADDRESS, TEST_EMAIL_FROM_ADDRESS,
TEST_RECIPIENTS_MULTIPLE_COMMA, TEST_RECIPIENTS_MULTIPLE_COMMA_RESULT,
TEST_RECIPIENTS_MULTIPLE_SEMICOLON,
TEST_RECIPIENTS_MULTIPLE_SEMICOLON_RESULT, TEST_RECIPIENTS_MULTIPLE_MIXED,
@@ -25,17 +25,22 @@ class ModelTestCase(MailerTestMixin, GenericDocumentTestCase):
def test_send_simple_with_html(self):
self._create_test_user_mailer()
- self.test_user_mailer.send(to=TEST_EMAIL_ADDRESS, body=TEST_BODY_HTML)
+ self.test_user_mailer.send(
+ to=TEST_EMAIL_ADDRESS, body=TEST_EMAIL_BODY_HTML
+ )
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].from_email, TEST_EMAIL_FROM_ADDRESS)
self.assertEqual(mail.outbox[0].to, [TEST_EMAIL_ADDRESS])
- self.assertEqual(mail.outbox[0].alternatives[0][0], TEST_BODY_HTML)
+ self.assertEqual(
+ mail.outbox[0].alternatives[0][0], TEST_EMAIL_BODY_HTML
+ )
def test_send_attachment(self):
self._create_test_user_mailer()
self.test_user_mailer.send_document(
- to=TEST_EMAIL_ADDRESS, document=self.test_document, as_attachment=True
+ to=TEST_EMAIL_ADDRESS, document=self.test_document,
+ as_attachment=True
)
self.assertEqual(len(mail.outbox), 1)