Commit 4c6afb5f authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: test RegularisationRequest_checkToTriggerNextEscalationStep

parent b55f7750
...@@ -11,14 +11,16 @@ event_portal_type = "Mail Message" ...@@ -11,14 +11,16 @@ event_portal_type = "Mail Message"
event = portal.portal_catalog.getResultValue( event = portal.portal_catalog.getResultValue(
portal_type=event_portal_type, portal_type=event_portal_type,
default_resource_uid=current_service.getUid(), resource__uid=current_service.getUid(),
default_follow_up_uid=ticket.getUid(), follow_up__uid=ticket.getUid(),
simulation_state="delivered", simulation_state="delivered",
) )
if (ticket.getSimulationState() == 'suspended') and (event is not None) and (ticket.getResource() == current_service_relative_url): if (ticket.getSimulationState() == 'suspended') and (event is not None) and (ticket.getResource() == current_service_relative_url):
if (DateTime() - event.getStartDate()) > delay_period_in_days: if (DateTime() - event.getStartDate()) > delay_period_in_days:
ticket.RegularisationRequest_checkToSendUniqEvent(next_service_relative_url, title, text_content, comment) ticket.RegularisationRequest_checkToSendUniqEvent(next_service_relative_url, title, text_content, comment,
notification_message=notification_message,
substitution_method_parameter_dict=substitution_method_parameter_dict)
return event.getRelativeUrl() return event.getRelativeUrl()
return None return None
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>delay_period_in_days, current_service_relative_url, next_service_relative_url, title, text_content, comment, REQUEST=None</string> </value> <value> <string>delay_period_in_days, current_service_relative_url, next_service_relative_url, title, text_content, comment, notification_message=None, substitution_method_parameter_dict=None, REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -2,19 +2,10 @@ from zExceptions import Unauthorized ...@@ -2,19 +2,10 @@ from zExceptions import Unauthorized
if REQUEST is not None: if REQUEST is not None:
raise Unauthorized raise Unauthorized
portal = context.getPortalObject()
ndays = 15 ndays = 15
language = "en"
recipient = context.getDestinationSectionValue()
if recipient is not None:
language = recipient.getLanguage("en")
notification_message = portal.portal_notifications.getDocumentValue( subject = 'Reminder: invoice payment requested'
language=language, reference="slapos-crm.acknowledgment.escalation") body = """Dear user,
if notification_message is None:
subject = 'Reminder: invoice payment requested'
body = """Dear user,
We would like to remind you the unpaid invoice you have on %s. We would like to remind you the unpaid invoice you have on %s.
If no payment is done during the coming days, we will stop all your current instances to free some hardware resources. If no payment is done during the coming days, we will stop all your current instances to free some hardware resources.
...@@ -23,21 +14,6 @@ Regards, ...@@ -23,21 +14,6 @@ Regards,
The slapos team The slapos team
""" % context.getPortalObject().portal_preferences.getPreferredSlaposWebSiteUrl() """ % context.getPortalObject().portal_preferences.getPreferredSlaposWebSiteUrl()
else:
notification_mapping_dict = {
'user_name': context.getDestinationSectionTitle(),
'days': ndays}
subject = notification_message.getTitle()
# Preserve HTML else convert to text
if notification_message.getContentType() == "text/html":
body = notification_message.asEntireHTML(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
else:
body = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
return context.RegularisationRequest_checkToTriggerNextEscalationStep( return context.RegularisationRequest_checkToTriggerNextEscalationStep(
delay_period_in_days=ndays, delay_period_in_days=ndays,
current_service_relative_url='service_module/slapos_crm_acknowledgement', current_service_relative_url='service_module/slapos_crm_acknowledgement',
...@@ -45,4 +21,9 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep( ...@@ -45,4 +21,9 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep(
title=subject, title=subject,
text_content=body, text_content=body,
comment='Stopping reminder.', comment='Stopping reminder.',
notification_message="slapos-crm.acknowledgment.escalation",
substitution_method_parameter_dict={
'user_name': context.getDestinationSectionTitle(),
'days': ndays
}
) )
...@@ -482,7 +482,7 @@ class TestSlapOSCrmTriggerEscalationOnAcknowledgmentRegularisationRequest(SlapOS ...@@ -482,7 +482,7 @@ class TestSlapOSCrmTriggerEscalationOnAcknowledgmentRegularisationRequest(SlapOS
"RegularisationRequest_triggerAcknowledgmentEscalation") "RegularisationRequest_triggerAcknowledgmentEscalation")
def test_RegularisationRequest_triggerAcknowledgmentEscalation_alarm__notExpectedResource(self): def test_RegularisationRequest_triggerAcknowledgmentEscalation_alarm_notExpectedResource(self):
ticket = self.createRegularisationRequest() ticket = self.createRegularisationRequest()
ticket.validate() ticket.validate()
ticket.suspend() ticket.suspend()
...@@ -493,6 +493,45 @@ class TestSlapOSCrmTriggerEscalationOnAcknowledgmentRegularisationRequest(SlapOS ...@@ -493,6 +493,45 @@ class TestSlapOSCrmTriggerEscalationOnAcknowledgmentRegularisationRequest(SlapOS
self._test_alarm_not_visited(alarm, ticket, self._test_alarm_not_visited(alarm, ticket,
"RegularisationRequest_triggerAcknowledgmentEscalation") "RegularisationRequest_triggerAcknowledgmentEscalation")
def test_RegularisationRequest_triggerAcknowledgmentEscalation_script_REQUESTdisallowed(self):
ticket = self.createRegularisationRequest()
self.assertRaises(
Unauthorized,
ticket.RegularisationRequest_triggerAcknowledgmentEscalation,
REQUEST={})
@simulate('RegularisationRequest_checkToTriggerNextEscalationStep',
'delay_period_in_days, current_service_relative_url, ' \
'next_service_relative_url, title, text_content, comment, ' \
'notification_message=None, substitution_method_parameter_dict=None, ' \
'REQUEST=None',
'context.portal_workflow.doActionFor(' \
'context, action="edit_action", ' \
'comment="Visited by RegularisationRequest_checkToTriggerNextEscalationStep ' \
'%s %s %s %s %s %s %s %s" % (delay_period_in_days, current_service_relative_url, next_service_relative_url, title, text_content, comment, notification_message, substitution_method_parameter_dict))')
def test_RegularisationRequest_triggerAcknowledgmentEscalation_script_matchingEvent(self):
ticket = self.createRegularisationRequest()
ticket.RegularisationRequest_triggerAcknowledgmentEscalation()
self.assertEqual(
'Visited by RegularisationRequest_checkToTriggerNextEscalationStep ' \
'%s %s %s %s %s %s %s %s' % \
(15,
'service_module/slapos_crm_acknowledgement',
'service_module/slapos_crm_stop_reminder',
'Reminder: invoice payment requested',
"""Dear user,
We would like to remind you the unpaid invoice you have on %s.
If no payment is done during the coming days, we will stop all your current instances to free some hardware resources.
Regards,
The slapos team
""" % self.portal.portal_preferences.getPreferredSlaposWebSiteUrl(),
'Stopping reminder.',
'slapos-crm.acknowledgment.escalation',
"{'user_name': None, 'days': 15}"),
ticket.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSCrmTriggerEscalationOnStopReminderRegularisationRequest(SlapOSTestCaseMixinWithAbort): class TestSlapOSCrmTriggerEscalationOnStopReminderRegularisationRequest(SlapOSTestCaseMixinWithAbort):
......
...@@ -363,81 +363,6 @@ class TestSlapOSRegularisationRequest_checkToTriggerNextEscalationStep( ...@@ -363,81 +363,6 @@ class TestSlapOSRegularisationRequest_checkToTriggerNextEscalationStep(
'', '', '', '', '', '', '', '', '', '', '', '',
REQUEST={}) REQUEST={})
class TestSlapOSRegularisationRequest_triggerAcknowledgmentEscalation(
SlapOSTestCaseMixinWithAbort):
def test_triggerAcknowledgmentEscalation_REQUEST_disallowed(self):
ticket = self.createRegularisationRequest()
self.assertRaises(
Unauthorized,
ticket.RegularisationRequest_triggerAcknowledgmentEscalation,
REQUEST={})
@simulate('NotificationTool_getDocumentValue',
'reference=None, language="en"',
'assert reference == "slapos-crm.acknowledgment.escalation", reference\n' \
'return')
@simulate('RegularisationRequest_checkToTriggerNextEscalationStep',
'delay_period_in_days, current_service_relative_url, next_service_relative_url, title, text_content, comment, REQUEST=None',
'context.portal_workflow.doActionFor(' \
'context, action="edit_action", ' \
'comment="Visited by RegularisationRequest_checkToTriggerNextEscalationStep ' \
'%s %s %s %s %s %s" % (delay_period_in_days, current_service_relative_url, next_service_relative_url, title, text_content, comment))')
def test_checkToTriggerNextEscalationStep_matching_event(self):
ticket = self.createRegularisationRequest()
ticket.RegularisationRequest_triggerAcknowledgmentEscalation()
self.assertEqual(
'Visited by RegularisationRequest_checkToTriggerNextEscalationStep ' \
'%s %s %s %s %s %s' % \
(15,
'service_module/slapos_crm_acknowledgement',
'service_module/slapos_crm_stop_reminder',
'Reminder: invoice payment requested',
"""Dear user,
We would like to remind you the unpaid invoice you have on %s.
If no payment is done during the coming days, we will stop all your current instances to free some hardware resources.
Regards,
The slapos team
""" % self.portal.portal_preferences.getPreferredSlaposWebSiteUrl(),
'Stopping reminder.'),
ticket.workflow_history['edit_workflow'][-1]['comment'])
@simulate('NotificationTool_getDocumentValue',
'reference=None, language="en"',
'assert reference == "slapos-crm.acknowledgment.escalation"\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["test_checkToTriggerNextEscalationStep_notification_message"])')
@simulate('RegularisationRequest_checkToTriggerNextEscalationStep',
'delay_period_in_days, current_service_relative_url, next_service_relative_url, title, text_content, comment, REQUEST=None',
'context.portal_workflow.doActionFor(' \
'context, action="edit_action", ' \
'comment="Visited by RegularisationRequest_checkToTriggerNextEscalationStep ' \
'%s %s %s %s %s %s" % (delay_period_in_days, current_service_relative_url, next_service_relative_url, title, text_content, comment))')
def test_checkToTriggerNextEscalationStep_notification_message(self):
ticket = self.createRegularisationRequest()
new_id = self.generateNewId()
notification_message = self.portal.notification_message_module.newContent(
portal_type="Notification Message",
title='Test NM title %s' % new_id,
text_content='Test NM content\n%s\n' % new_id,
content_type='text/plain',
)
self.portal.REQUEST\
['test_checkToTriggerNextEscalationStep_notification_message'] = \
notification_message.getRelativeUrl()
ticket.RegularisationRequest_triggerAcknowledgmentEscalation()
self.assertEqual(
'Visited by RegularisationRequest_checkToTriggerNextEscalationStep ' \
'%s %s %s %s %s %s' % \
(15,
'service_module/slapos_crm_acknowledgement',
'service_module/slapos_crm_stop_reminder',
'Test NM title %s' % new_id,
'Test NM content\n%s\n' % new_id,
'Stopping reminder.'),
ticket.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSRegularisationRequest_triggerStopReminderEscalation( class TestSlapOSRegularisationRequest_triggerStopReminderEscalation(
SlapOSTestCaseMixinWithAbort): SlapOSTestCaseMixinWithAbort):
......
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