Commit b55f7750 authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: test RegularisationRequest_invalidateIfPersonBalanceIsOk

parent f83baeac
......@@ -8,14 +8,5 @@ if (state not in ('suspended', 'validated')) or \
(person is None):
return
outstanding_amount = person.Entity_statSlapOSOutstandingAmount()
# It can't be smaller, we are considernig all open invoices are from unpaid_payment_amount
if round(float(outstanding_amount), 2) == round(float(0), 2):
context.invalidate(comment="Automatically disabled as balance is %s" % outstanding_amount)
return
if (int(outstanding_amount) > 0):
return
context.invalidate(comment="Automatically disabled as balance is %s" % outstanding_amount)
if not person.Entity_hasOutstandingAmount():
context.invalidate(comment="Automatically disabled as balance is ok")
......@@ -360,8 +360,6 @@ The slapos team
REQUEST={})
class TestSlapOSCrmInvalidateSuspendedRegularisationRequest(SlapOSTestCaseMixinWithAbort):
def createRegularisationRequest(self):
new_id = self.generateNewId()
return self.portal.regularisation_request_module.newContent(
......@@ -399,6 +397,53 @@ class TestSlapOSCrmInvalidateSuspendedRegularisationRequest(SlapOSTestCaseMixinW
slapos_crm_invalidate_suspended_regularisation_request
self._test_alarm_not_visited(alarm, ticket, "RegularisationRequest_invalidateIfPersonBalanceIsOk")
def test_RegularisationRequest_invalidateIfPersonBalanceIsOk_script_REQUESTdisallowed(self):
ticket = self.createRegularisationRequest()
self.assertRaises(
Unauthorized,
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk,
REQUEST={})
@simulate('Entity_hasOutstandingAmount', '*args, **kwargs', 'return False')
def test_RegularisationRequest_invalidateIfPersonBalanceIsOk_script_matchingCase(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket = self.createRegularisationRequest()
ticket.edit(destination_decision_value=person)
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'invalidated')
@simulate('Entity_hasOutstandingAmount', '*args, **kwargs', 'return False')
def test_RegularisationRequest_invalidateIfPersonBalanceIsOk_script_validated(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket = self.createRegularisationRequest()
ticket.edit(destination_decision_value=person)
ticket.validate()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'invalidated')
@simulate('Entity_hasOutstandingAmount', '*args, **kwargs', 'return False')
def test_RegularisationRequest_invalidateIfPersonBalanceIsOk_script_noPerson(self):
ticket = self.createRegularisationRequest()
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'suspended')
@simulate('Entity_hasOutstandingAmount', '*args, **kwargs', 'return True')
def test_RegularisationRequest_invalidateIfPersonBalanceIsOk_script_wrongBalance(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket = self.createRegularisationRequest()
ticket.edit(destination_decision_value=person)
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'suspended')
class TestSlapOSCrmTriggerEscalationOnAcknowledgmentRegularisationRequest(SlapOSTestCaseMixinWithAbort):
......
......@@ -28,63 +28,7 @@ from zExceptions import Unauthorized
from DateTime import DateTime
class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk(
SlapOSTestCaseMixinWithAbort):
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_statOutstandingAmount', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_matching_case(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket = self.createRegularisationRequest()
ticket.edit(source_project_value=person)
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'invalidated')
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_validated(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket = self.createRegularisationRequest()
ticket.edit(source_project_value=person)
ticket.validate()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'invalidated')
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_no_person(self):
ticket = self.createRegularisationRequest()
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'suspended')
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_invalidateIfPersonBalanceIsOk_wrong_balance(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket = self.createRegularisationRequest()
ticket.edit(source_project_value=person)
ticket.validate()
ticket.suspend()
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'suspended')
class TestSlapOSRegularisationRequest_checkToSendUniqEvent(SlapOSTestCaseMixin):
......
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