Commit 573390ee authored by Romain Courteaud's avatar Romain Courteaud

Migrate ticket invalidation alarm.

Regularisation Request are now used instead of Support Request.
parent 70d62bc0
......@@ -8,7 +8,7 @@
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_updatePayzenSuspendedSupportRequest</string> </value>
<value> <string>Alarm_invalidateSuspendedRegularisationRequest</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -22,7 +22,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_payzen_update_suspended_support_request</string> </value>
<value> <string>slapos_crm_invalidate_suspended_regularisation_request</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
......@@ -95,7 +95,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Handles suspended Support Request</string> </value>
<value> <string>Invalidate suspended regularisation request</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -52,10 +52,9 @@
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
portal.portal_catalog.searchAndActivate(\n
portal_type="Support Request", \n
portal_type="Regularisation Request", \n
simulation_state=["suspended"],\n
method_id=\'SupportRequest_updateStatus\',\n
default_source_project_portal_type="Payment Transaction",\n
method_id=\'RegularisationRequest_invalidateIfPersonBalanceIsOk\',\n
activate_kw={\'tag\': tag}\n
)\n
context.activate(after_tag=tag).getId()\n
......@@ -67,7 +66,7 @@ context.activate(after_tag=tag).getId()\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_updatePayzenSuspendedSupportRequest</string> </value>
<value> <string>Alarm_invalidateSuspendedRegularisationRequest</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -50,27 +50,31 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string># from DateTime import DateTime\n
portal = context.getPortalObject()\n
<value> <string encoding="cdata"><![CDATA[
from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
state = context.getSimulationState()\n
payment = context.getSourceProjectValue(portal_type="Payment Transaction")\n
person = context.getSourceProjectValue(portal_type="Person")\n
if (state != \'suspended\') or \\\n
(payment is None) or \\\n
(payment.getPaymentMode() != \'payzen\') or \\\n
(payment.getSimulationState() not in ("cancelled", "stopped", "delivered")):\n
(person is None) or \\\n
(int(person.Entity_statBalance()) > 0):\n
return\n
else:\n
context.invalidate(comment="Payzen payment state is %s" % payment.getSimulationState())\n
</string> </value>
context.invalidate(comment="Automatically disabled as balance is %s" % person.Entity_statBalance())\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SupportRequest_updateStatus</string> </value>
<value> <string>RegularisationRequest_invalidateIfPersonBalanceIsOk</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -111,3 +111,66 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
'Visited by Person_checkToCreateRegularisationRequest',
person.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSCrmInvalidateSuspendedRegularisationRequest(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createRegularisationRequest(self):
new_id = self.generateNewId()
return self.portal.regularisation_request_module.newContent(
portal_type='Regularisation Request',
title="Test Reg. Req.%s" % new_id,
reference="TESTREGREQ-%s" % new_id,
)
def _simulateRegularisationRequest_invalidateIfPersonBalanceIsOk(self):
script_name = 'RegularisationRequest_invalidateIfPersonBalanceIsOk'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by RegularisationRequest_invalidateIfPersonBalanceIsOk') """ )
transaction.commit()
def _dropRegularisationRequest_invalidateIfPersonBalanceIsOk(self):
script_name = 'RegularisationRequest_invalidateIfPersonBalanceIsOk'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm_not_suspended_regularisation_request(self):
ticket = self.createRegularisationRequest()
ticket.validate()
self.tic()
self._simulateRegularisationRequest_invalidateIfPersonBalanceIsOk()
try:
self.portal.portal_alarms.\
slapos_crm_invalidate_suspended_regularisation_request.activeSense()
self.tic()
finally:
self._dropRegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertNotEqual(
'Visited by RegularisationRequest_invalidateIfPersonBalanceIsOk',
ticket.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_suspended_regularisation_request(self):
ticket = self.createRegularisationRequest()
ticket.validate()
ticket.suspend()
self.tic()
self._simulateRegularisationRequest_invalidateIfPersonBalanceIsOk()
try:
self.portal.portal_alarms.\
slapos_crm_invalidate_suspended_regularisation_request.activeSense()
self.tic()
finally:
self._dropRegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(
'Visited by RegularisationRequest_invalidateIfPersonBalanceIsOk',
ticket.workflow_history['edit_workflow'][-1]['comment'])
......@@ -151,3 +151,69 @@ The slapos team
person.Person_checkToCreateRegularisationRequest,
REQUEST={})
class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk(
testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPerson(self):
new_id = self.generateNewId()
return self.portal.person_module.newContent(
portal_type='Person',
title="Person %s" % new_id,
reference="TESTPERS-%s" % new_id,
)
def createRegularisationRequest(self):
new_id = self.generateNewId()
return self.portal.regularisation_request_module.newContent(
portal_type='Regularisation Request',
title="Test Reg. Req.%s" % new_id,
reference="TESTREGREQ-%s" % new_id,
)
def test_invalidateIfPersonBalanceIsOk_REQUEST_disallowed(self):
ticket = self.createRegularisationRequest()
self.assertRaises(
Unauthorized,
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk,
REQUEST={})
@simulate('Entity_statBalance', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_matching_case(self):
person = self.createPerson()
ticket = self.createRegularisationRequest()
ticket.edit(source_project_value=person)
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEquals(ticket.getSimulationState(), 'invalidated')
@simulate('Entity_statBalance', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_not_suspended(self):
person = self.createPerson()
ticket = self.createRegularisationRequest()
ticket.edit(source_project_value=person)
ticket.validate()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEquals(ticket.getSimulationState(), 'validated')
@simulate('Entity_statBalance', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_no_person(self):
ticket = self.createRegularisationRequest()
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEquals(ticket.getSimulationState(), 'suspended')
@simulate('Entity_statBalance', '*args, **kwargs', 'return "1"')
def test_invalidateIfPersonBalanceIsOk_wrong_balance(self):
person = self.createPerson()
ticket = self.createRegularisationRequest()
ticket.edit(source_project_value=person)
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEquals(ticket.getSimulationState(), 'suspended')
11
\ No newline at end of file
12
\ No newline at end of file
event_module/slapos_crm_web_message_template
portal_alarms/slapos_crm_create_regularisation_request
portal_alarms/slapos_crm_invalidate_suspended_regularisation_request
regularisation_request_module/slapos_crm_regularisation_request_template
service_module/slapos_crm_acknowledgement
service_module/slapos_crm_complaint
......
......@@ -463,232 +463,3 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
'Visited by PaymentTransaction_updateStatus',
transaction.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSPayzenUpdateSuspendedSupportRequest(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def test_not_suspended_support_request(self):
new_id = self.generateNewId()
payment = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Payment %s" % new_id,
reference="TESTPAY-%s" % new_id,
payment_mode="payzen",
)
payment.cancel()
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
source_project_value=payment,
)
simulation_state = ticket.getSimulationState()
modification_date = ticket.getModificationDate()
ticket.SupportRequest_updateStatus()
self.assertEquals(ticket.getSimulationState(), simulation_state)
self.assertEquals(ticket.getModificationDate(), modification_date)
def test_not_payzen_payment_support_request(self):
new_id = self.generateNewId()
payment = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Payment %s" % new_id,
reference="TESTPAY-%s" % new_id,
)
payment.cancel()
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
source_project_value=payment,
)
ticket.validate()
ticket.suspend()
simulation_state = ticket.getSimulationState()
modification_date = ticket.getModificationDate()
ticket.SupportRequest_updateStatus()
self.assertEquals(ticket.getSimulationState(), simulation_state)
self.assertEquals(ticket.getModificationDate(), modification_date)
def test_not_finalyzed_payment_support_request(self):
new_id = self.generateNewId()
payment = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Payment %s" % new_id,
reference="TESTPAY-%s" % new_id,
payment_mode="payzen",
)
payment.start()
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
source_project_value=payment,
)
ticket.validate()
ticket.suspend()
simulation_state = ticket.getSimulationState()
modification_date = ticket.getModificationDate()
ticket.SupportRequest_updateStatus()
self.assertEquals(ticket.getSimulationState(), simulation_state)
self.assertEquals(ticket.getModificationDate(), modification_date)
def test_no_payment_support_request(self):
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
)
ticket.validate()
ticket.suspend()
simulation_state = ticket.getSimulationState()
modification_date = ticket.getModificationDate()
ticket.SupportRequest_updateStatus()
self.assertEquals(ticket.getSimulationState(), simulation_state)
self.assertEquals(ticket.getModificationDate(), modification_date)
def test_cancel_payment_support_request(self):
new_id = self.generateNewId()
payment = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Payment %s" % new_id,
reference="TESTPAY-%s" % new_id,
payment_mode="payzen",
)
payment.cancel()
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
source_project_value=payment,
)
ticket.validate()
ticket.suspend()
ticket.SupportRequest_updateStatus()
self.assertEquals(ticket.getSimulationState(), "invalidated")
def test_closed_payment_support_request(self):
new_id = self.generateNewId()
payment = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Payment %s" % new_id,
reference="TESTPAY-%s" % new_id,
payment_mode="payzen",
)
_jumpToStateFor = self.portal.portal_workflow._jumpToStateFor
_jumpToStateFor(payment, "stopped")
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
source_project_value=payment,
)
ticket.validate()
ticket.suspend()
ticket.SupportRequest_updateStatus()
self.assertEquals(ticket.getSimulationState(), "invalidated")
def _simulateSupportRequest_updateStatus(self):
script_name = 'SupportRequest_updateStatus'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by SupportRequest_updateStatus') """ )
transaction.commit()
def _dropSupportRequest_updateStatus(self):
script_name = 'SupportRequest_updateStatus'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm_no_payment_support_request(self):
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
)
ticket.validate()
ticket.suspend()
self.tic()
self._simulateSupportRequest_updateStatus()
try:
self.portal.portal_alarms.\
slapos_payzen_update_suspended_support_request.activeSense()
self.tic()
finally:
self._dropSupportRequest_updateStatus()
self.assertNotEqual(
'Visited by SupportRequest_updateStatus',
ticket.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_suspended_support_request(self):
new_id = self.generateNewId()
payment = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Payment %s" % new_id,
reference="TESTPAY-%s" % new_id,
)
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
source_project_value=payment,
)
ticket.validate()
self.tic()
self._simulateSupportRequest_updateStatus()
try:
self.portal.portal_alarms.\
slapos_payzen_update_suspended_support_request.activeSense()
self.tic()
finally:
self._dropSupportRequest_updateStatus()
self.assertNotEqual(
'Visited by SupportRequest_updateStatus',
ticket.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_suspended_support_request(self):
new_id = self.generateNewId()
payment = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Payment %s" % new_id,
reference="TESTPAY-%s" % new_id,
)
new_id = self.generateNewId()
ticket = self.portal.support_request_module.newContent(
portal_type='Support Request',
title="Ticket %s" % new_id,
reference="TESTSUPREQ-%s" % new_id,
source_project_value=payment,
)
ticket.validate()
ticket.suspend()
self.tic()
self._simulateSupportRequest_updateStatus()
try:
self.portal.portal_alarms.\
slapos_payzen_update_suspended_support_request.activeSense()
self.tic()
finally:
self._dropSupportRequest_updateStatus()
self.assertEqual(
'Visited by SupportRequest_updateStatus',
ticket.workflow_history['edit_workflow'][-1]['comment'])
114
\ No newline at end of file
115
\ No newline at end of file
......@@ -2,7 +2,6 @@ accounting_module/template_sale_invoice_transaction
accounting_module/template_sale_invoice_transaction/**
portal_alarms/slapos_payzen_update_confirmed_payment
portal_alarms/slapos_payzen_update_started_payment
portal_alarms/slapos_payzen_update_suspended_support_request
portal_alarms/slapos_trigger_payment_transaction_order_builder
portal_integrations/slapos_payzen_test_integration
portal_integrations/slapos_payzen_test_integration/Causality
......
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