Commit 97ec74c4 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Fixup and write tests

parent 26551a5a
from Products.ZSQLCatalog.SQLCatalog import ComplexQuery, SimpleQuery from Products.ZSQLCatalog.SQLCatalog import ComplexQuery, SimpleQuery
portal = context.getPortalObject() portal = context.getPortalObject()
person_uid = context.getUid()
query = ComplexQuery( query = ComplexQuery(
ComplexQuery( ComplexQuery(
SimpleQuery(portal_type=["Support Request", "Regularisation Request"]), SimpleQuery(portal_type=["Support Request", "Regularisation Request"]),
SimpleQuery(simulation_state="suspended"), SimpleQuery(simulation_state="suspended"),
SimpleQuery(destination_decision_uid=person_uid),
logical_operator='and'), logical_operator='and'),
ComplexQuery( ComplexQuery(
SimpleQuery(portal_type="Upgrade Decision Line"), SimpleQuery(portal_type="Upgrade Decision"),
SimpleQuery(simulation_state="confirmed"), SimpleQuery(simulation_state="confirmed"),
SimpleQuery(destination_decision_uid=person_uid),
logical_operator='and'), logical_operator='and'),
logical_operator='or') logical_operator='or')
......
...@@ -12,6 +12,6 @@ if notification_message is not None: ...@@ -12,6 +12,6 @@ if notification_message is not None:
return notification_message.getTitle(), notification_message.asText( return notification_message.getTitle(), notification_message.asText(
substitution_method_parameter_dict={'mapping_dict': mapping_dict}) substitution_method_parameter_dict={'mapping_dict': mapping_dict})
message = """ You have %s pending tickets """ % pending_ticket_list_amount, message = """ You have %s pending tickets """ % pending_ticket_list_amount
return message, message return message, message
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>response_event_title, response_event_text_content, batch_mode=False, **kw</string> </value> <value> <string></string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -18,7 +18,7 @@ event_kw = { ...@@ -18,7 +18,7 @@ event_kw = {
# Create event # Create event
event = portal.event_module.newContent(**event_kw) event = portal.event_module.newContent(**event_kw)
event.plan() event.plan()
event.sent(comment="Sent via Person_sendSlapOSPendingTicketNotification") event.start(send_mail=True, comment="Sent via Person_sendSlapOSPendingTicketNotification")
if batch_mode: if batch_mode:
return event return event
......
...@@ -1400,7 +1400,6 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin): ...@@ -1400,7 +1400,6 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin):
support_request.getSimulationState()) support_request.getSimulationState())
class TestSlapOSFolder_getTicketFeedUrl(TestCRMSkinsMixin): class TestSlapOSFolder_getTicketFeedUrl(TestCRMSkinsMixin):
def _test(self, module): def _test(self, module):
...@@ -1425,3 +1424,229 @@ class TestSlapOSFolder_getTicketFeedUrl(TestCRMSkinsMixin): ...@@ -1425,3 +1424,229 @@ class TestSlapOSFolder_getTicketFeedUrl(TestCRMSkinsMixin):
def test_Folder_getTicketFeedUrl_incident_response_module(self): def test_Folder_getTicketFeedUrl_incident_response_module(self):
self._test(self.portal.incident_response_module) self._test(self.portal.incident_response_module)
class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin):
def test_getSlapOSPendingTicket_support_request(self):
person = self.makePerson()
ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id,
destination_decision=person.getRelativeUrl())
pending_ticket_list = person.Person_getSlapOSPendingTicket()
# Not indexed yet
self.assertEqual(len(pending_ticket_list), 0)
self.tic()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.submit()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.validate()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.suspend()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 1)
self.assertEqual(pending_ticket_list[0].getUid(), ticket.getUid())
ticket.invalidate()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
def test_getSlapOSPendingTicket_support_request_cancelled(self):
person = self.makePerson()
ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id,
destination_decision=person.getRelativeUrl())
pending_ticket_list = person.Person_getSlapOSPendingTicket()
# Not indexed yet
self.assertEqual(len(pending_ticket_list), 0)
self.tic()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.submit()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.cancel()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
def test_getSlapOSPendingTicket_upgrade_decision(self):
def newUpgradeDecision():
ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id)
ticket.immediateReindexObject()
return ticket
person = self.makePerson()
ticket = newUpgradeDecision()
ticket.setDestinationDecisionValue(person)
ticket.newContent(
portal_type="Upgrade Decision Line"
)
pending_ticket_list = person.Person_getSlapOSPendingTicket()
# Not indexed yet
self.assertEqual(len(pending_ticket_list), 0)
self.tic()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.plan()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.confirm()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 1)
self.assertEqual(pending_ticket_list[0].getUid(), ticket.getUid())
ticket.start()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.stop()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.deliver()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
def test_getSlapOSPendingTicket_upgrade_decision_cancel(self):
def newUpgradeDecision():
ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id)
ticket.immediateReindexObject()
return ticket
person = self.makePerson()
ticket = newUpgradeDecision()
ticket.setDestinationDecisionValue(person)
ticket.newContent(
portal_type="Upgrade Decision Line"
)
pending_ticket_list = person.Person_getSlapOSPendingTicket()
# Not indexed yet
self.assertEqual(len(pending_ticket_list), 0)
self.tic()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.plan()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
ticket.cancel()
ticket.immediateReindexObject()
pending_ticket_list = person.Person_getSlapOSPendingTicket()
self.assertEqual(len(pending_ticket_list), 0)
class TestSlapOSPerson_getSlapOSPendingTicketMessageTemplate(TestCRMSkinsMixin):
@simulate('Person_getSlapOSPendingTicket', '*args, **kwargs','return range(99)')
def test_getSlapOSPendingTicketMessageTemplate(self):
person = self.makePerson()
title, message = person.Person_getSlapOSPendingTicketMessageTemplate()
self.assertEqual(""" You have 99 pending tickets """, title)
self.assertEqual(""" You have 99 pending tickets """, message)
def _makeNotificationMessage(self):
notification_message = self.portal.notification_message_module.newContent(
portal_type="Notification Message",
title='Pending ticket',
text_content_substitution_mapping_method_id='NotificationMessage_getSubstitutionMappingDictFromArgument',
text_content='Test NM content ${username} AMOUNT (${amount}) WEBSITE(${website})',
content_type='text/plain',
)
return notification_message.getRelativeUrl()
@simulate('Person_getSlapOSPendingTicket', '*args, **kwargs','return range(99)')
@simulate('NotificationTool_getDocumentValue',
'reference=None',
'assert reference == "slapos-crm-person-pending-ticket-notification"\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["test_getSlapOSPendingTicketMessageTemplate"])')
def test_getSlapOSPendingTicketMessageTemplate_with_notification_message(self):
person = self.makePerson()
self.portal.REQUEST['test_getSlapOSPendingTicketMessageTemplate'] = \
self._makeNotificationMessage()
title, message = person.Person_getSlapOSPendingTicketMessageTemplate()
self.assertEqual('Pending ticket', title)
self.assertEqual('Test NM content Member Template AMOUNT (99) WEBSITE()', message)
class TestSlapOSPerson_sendPendingTicketReminder(TestCRMSkinsMixin):
@simulate('Person_getSlapOSPendingTicket', '*args, **kwargs','return []')
@simulate('Person_sendSlapOSPendingTicketNotification', '*args, **kwargs','assert False')
def test_sendPendingTicketReminder(self):
person = self.makePerson()
# Script Person_sendSlapOSPendingTicketNotification not called
person.Person_sendPendingTicketReminder()
@simulate('Person_getSlapOSPendingTicket', '*args, **kwargs','return [1]')
@simulate('Person_sendSlapOSPendingTicketNotification', '*args, **kwargs',
'context.REQUEST.set("test_getSlapOSPendingTicketMessageTemplate", "called")')
def test_sendPendingTicketReminder_positive_amount(self):
person = self.makePerson()
person.Person_sendPendingTicketReminder()
self.assertEqual(self.portal.REQUEST["test_getSlapOSPendingTicketMessageTemplate"],
"called")
class TestSlapOSPerson_sendSlapOSPendingTicketNotification(TestCRMSkinsMixin):
def test_sendSlapOSPendingTicketNotification(self):
person = self.makePerson()
event = person.Person_sendSlapOSPendingTicketNotification(
"TEST TITLE",
"TEST CONTENT",
batch_mode=1
)
self.tic()
self.assertEqual(event.getTitle(), "TEST TITLE")
self.assertEqual(event.getTextContent(), "TEST CONTENT")
self.assertEqual(event.getSimulationState(), "started")
self.assertEqual(event.getPortalType(), "Mail Message")
self.assertEqual(event.getDestination(), person.getRelativeUrl())
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