-
Notifications
You must be signed in to change notification settings - Fork 7
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
2 changed files
with
60 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from unittest.mock import patch | ||
|
||
from cms.api import add_plugin | ||
from cms.test_utils.testcases import CMSTestCase | ||
|
||
from djangocms_form_builder.actions import get_registered_actions | ||
from tests.fixtures import TestFixture | ||
|
||
|
||
class ActionTestCase(TestFixture, CMSTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.actions = get_registered_actions() | ||
self.save_action = [key for key, value in self.actions if value == "Save form submission"][0] | ||
self.send_mail_action = [key for key, value in self.actions if value == "Send email"][0] | ||
|
||
def test_send_mail_action(self): | ||
plugin_instance = add_plugin( | ||
placeholder=self.placeholder, | ||
plugin_type="FormPlugin", | ||
language=self.language, | ||
form_name="test_form", | ||
) | ||
plugin_instance.action_parameters = {"sendemail_recipients": "[email protected] [email protected]", "sendemail_template": "default"} | ||
plugin_instance.form_actions = f"[\"{self.send_mail_action}\"]" | ||
plugin_instance.save() | ||
|
||
child_plugin = add_plugin( | ||
placeholder=self.placeholder, | ||
plugin_type="CharFieldPlugin", | ||
language=self.language, | ||
target=plugin_instance, | ||
config={"field_name": "field1"} | ||
) | ||
child_plugin.save() | ||
plugin_instance.child_plugin_instances = [child_plugin] | ||
child_plugin.child_plugin_instances = [] | ||
|
||
plugin = plugin_instance.get_plugin_class_instance() | ||
plugin.instance = plugin_instance | ||
|
||
# Simulate form submission | ||
with patch("django.core.mail.send_mail") as mock_send_mail: | ||
form = plugin.get_form_class()({}, request=self.get_request("/")) | ||
form.cleaned_data = {"field1": "value1", "field2": "value2"} | ||
form.save() | ||
|
||
# Validate send_mail call | ||
mock_send_mail.assert_called_once() | ||
args, kwargs = mock_send_mail.call_args | ||
self.assertEqual(args[0], 'Test form form submission') | ||
self.assertIn('Form submission', args[1]) | ||
self.assertEqual(args[3], ['[email protected]', '[email protected]']) |