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()
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:
message = 'Recipients must be defined'
else:
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)
message = 'Events are being created in background'
return context.Base_redirect(keep_items={'portal_status_message': context.Base_translateString(message)})
return redirect('Recipients must be defined')
if event_path.getEventPortalType() is None:
return redirect('Event Type must be defined')
if event_path.getSourceValue() is None:
return redirect('Sender must be defined')
if event_path.getResourceValue() is None:
return redirect('Notification Message must be defined')
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 @@
##############################################################################
import unittest
import urlparse
import os
import textwrap
from unittest import expectedFailure
......@@ -509,14 +510,12 @@ class TestCRM(BaseTestCRM):
portal = self.portal
notification_message_reference = 'campaign-Event.Path'
service = portal.service_module.newContent(portal_type='Service')
resource = portal.notification_message_module.newContent(
reference=notification_message_reference,
notification_message = portal.notification_message_module.newContent(
content_type="text/html",
portal_type="Notification Message",
specialise_value=service,
text_content_substitution_mapping_method_id=mapping_method_id,
text_content="Hello ${destination_title}")
resource.validate()
sender = portal.person_module.newContent(portal_type="Person",
reference='sender', first_name='Sender')
first_user = portal.person_module.newContent(portal_type="Person",
......@@ -537,13 +536,54 @@ class TestCRM(BaseTestCRM):
organisation_domain.setCriterionPropertyList(['portal_type'])
organisation_domain.setCriterion('portal_type', identity=['Organisation'])
campaign = self.portal.campaign_module.newContent(portal_type="Campaign",
default_event_path_event_portal_type="Mail Message",
default_event_path_destination="portal_domains/%s" % person_domain.getRelativeUrl(),
default_event_path_source=sender.getRelativeUrl(),
default_event_path_resource=resource.getRelativeUrl())
campaign = self.portal.campaign_module.newContent(
portal_type="Campaign",
default_event_path_event_portal_type="Mail Message",)
# 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()
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()
event_list = [event for event in campaign.getFollowUpRelatedValueList()
if event.getPortalType() != 'Mail Message']
......@@ -562,7 +602,7 @@ class TestCRM(BaseTestCRM):
default_event_path_event_portal_type="Visit",
default_event_path_destination='portal_domains/%s' % organisation_domain.getRelativeUrl(),
default_event_path_source=sender.getRelativeUrl(),
default_event_path_resource=resource.getRelativeUrl())
default_event_path_resource=notification_message.getRelativeUrl())
self.tic()
campaign.Ticket_createEventFromDefaultEventPath()
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