Commit 6749766d authored by Jérome Perrin's avatar Jérome Perrin

crm: Add some checks for "Create Events of Communication Plan" action

parent 4accffef
Pipeline #14843 failed with stage
portal = context.getPortalObject() portal = context.getPortalObject()
domain = context.getDefaultEventPathDestinationValue() domain = context.getDefaultEventPathDestinationValue()
def redirect(message):
return context.Base_redirect(keep_items={'portal_status_message': context.Base_translateString(message)})
event_path = context.getDefaultEventPathValue()
if domain is None: if domain is None:
message = 'Recipients must be defined' return redirect('Recipients must be defined')
else:
event_path = context.getDefaultEventPathValue(portal_type="Event Path") if event_path.getEventPortalType() is None:
method_kw = {'event_path': event_path.getRelativeUrl(), return redirect('Event Type must be defined')
'keep_draft': keep_draft}
portal.portal_catalog.activate(activity='SQLQueue').searchAndActivate( if event_path.getSourceValue() is None:
"Entity_createEventFromDefaultEventPath", return redirect('Sender must be defined')
selection_domain={domain.getParentId(): ('portal_domains', domain.getRelativeUrl())},
method_kw=method_kw) if event_path.getResourceValue() is None:
message = 'Events are being created in background' return redirect('Notification Message must be defined')
return context.Base_redirect(keep_items={'portal_status_message': context.Base_translateString(message)}) if (not event_path.getResourceReference()) \
or portal.notification_message_module.NotificationTool_getDocumentValue(
event_path.getResourceReference()) is None:
return redirect('Notification Message must be validated')
event_path = context.getDefaultEventPathValue(portal_type="Event Path")
method_kw = {
'event_path': event_path.getRelativeUrl(),
'keep_draft': keep_draft,
}
portal.portal_catalog.activate(activity='SQLQueue').searchAndActivate(
"Entity_createEventFromDefaultEventPath",
selection_domain={domain.getParentId(): ('portal_domains', domain.getRelativeUrl())},
method_kw=method_kw)
return redirect('Events are being created in background')
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
############################################################################## ##############################################################################
import unittest import unittest
import urlparse
import os import os
import textwrap import textwrap
from unittest import expectedFailure from unittest import expectedFailure
...@@ -509,14 +510,12 @@ class TestCRM(BaseTestCRM): ...@@ -509,14 +510,12 @@ class TestCRM(BaseTestCRM):
portal = self.portal portal = self.portal
notification_message_reference = 'campaign-Event.Path' notification_message_reference = 'campaign-Event.Path'
service = portal.service_module.newContent(portal_type='Service') service = portal.service_module.newContent(portal_type='Service')
resource = portal.notification_message_module.newContent( notification_message = portal.notification_message_module.newContent(
reference=notification_message_reference,
content_type="text/html", content_type="text/html",
portal_type="Notification Message", portal_type="Notification Message",
specialise_value=service, specialise_value=service,
text_content_substitution_mapping_method_id=mapping_method_id, text_content_substitution_mapping_method_id=mapping_method_id,
text_content="Hello ${destination_title}") text_content="Hello ${destination_title}")
resource.validate()
sender = portal.person_module.newContent(portal_type="Person", sender = portal.person_module.newContent(portal_type="Person",
reference='sender', first_name='Sender') reference='sender', first_name='Sender')
first_user = portal.person_module.newContent(portal_type="Person", first_user = portal.person_module.newContent(portal_type="Person",
...@@ -537,13 +536,54 @@ class TestCRM(BaseTestCRM): ...@@ -537,13 +536,54 @@ class TestCRM(BaseTestCRM):
organisation_domain.setCriterionPropertyList(['portal_type']) organisation_domain.setCriterionPropertyList(['portal_type'])
organisation_domain.setCriterion('portal_type', identity=['Organisation']) organisation_domain.setCriterion('portal_type', identity=['Organisation'])
campaign = self.portal.campaign_module.newContent(portal_type="Campaign", campaign = self.portal.campaign_module.newContent(
default_event_path_event_portal_type="Mail Message", portal_type="Campaign",
default_event_path_destination="portal_domains/%s" % person_domain.getRelativeUrl(), default_event_path_event_portal_type="Mail Message",)
default_event_path_source=sender.getRelativeUrl(),
default_event_path_resource=resource.getRelativeUrl()) # This action checks everything is properly defined
ret = campaign.Ticket_createEventFromDefaultEventPath()
self.assertEqual(
urlparse.parse_qs(urlparse.urlparse(ret).query)['portal_status_message'],
["Recipients must be defined"])
campaign.setDefaultEventPathDestination(
"portal_domains/%s" % person_domain.getRelativeUrl())
campaign.setDefaultEventPathEventPortalType(None)
ret = campaign.Ticket_createEventFromDefaultEventPath()
self.assertEqual(
urlparse.parse_qs(urlparse.urlparse(ret).query)['portal_status_message'],
["Event Type must be defined"])
campaign.setDefaultEventPathEventPortalType('Mail Message')
ret = campaign.Ticket_createEventFromDefaultEventPath()
self.assertEqual(
urlparse.parse_qs(urlparse.urlparse(ret).query)['portal_status_message'],
["Sender must be defined"])
campaign.setDefaultEventPathSource(sender.getRelativeUrl())
ret = campaign.Ticket_createEventFromDefaultEventPath()
self.assertEqual(
urlparse.parse_qs(urlparse.urlparse(ret).query)['portal_status_message'],
["Notification Message must be defined"])
campaign.setDefaultEventPathResource(notification_message.getRelativeUrl())
ret = campaign.Ticket_createEventFromDefaultEventPath()
self.assertEqual(
urlparse.parse_qs(urlparse.urlparse(ret).query)['portal_status_message'],
["Notification Message must be validated"])
notification_message.setReference(notification_message_reference)
ret = campaign.Ticket_createEventFromDefaultEventPath()
self.assertEqual(
urlparse.parse_qs(urlparse.urlparse(ret).query)['portal_status_message'],
["Notification Message must be validated"])
notification_message.validate()
self.tic() self.tic()
campaign.Ticket_createEventFromDefaultEventPath()
ret = campaign.Ticket_createEventFromDefaultEventPath()
self.assertEqual(
urlparse.parse_qs(urlparse.urlparse(ret).query)['portal_status_message'],
["Events are being created in background"])
self.tic() self.tic()
event_list = [event for event in campaign.getFollowUpRelatedValueList() event_list = [event for event in campaign.getFollowUpRelatedValueList()
if event.getPortalType() != 'Mail Message'] if event.getPortalType() != 'Mail Message']
...@@ -562,7 +602,7 @@ class TestCRM(BaseTestCRM): ...@@ -562,7 +602,7 @@ class TestCRM(BaseTestCRM):
default_event_path_event_portal_type="Visit", default_event_path_event_portal_type="Visit",
default_event_path_destination='portal_domains/%s' % organisation_domain.getRelativeUrl(), default_event_path_destination='portal_domains/%s' % organisation_domain.getRelativeUrl(),
default_event_path_source=sender.getRelativeUrl(), default_event_path_source=sender.getRelativeUrl(),
default_event_path_resource=resource.getRelativeUrl()) default_event_path_resource=notification_message.getRelativeUrl())
self.tic() self.tic()
campaign.Ticket_createEventFromDefaultEventPath() campaign.Ticket_createEventFromDefaultEventPath()
self.tic() self.tic()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment