Commit f5a1573a authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: fixup slapos_crm_create_regularisation_request tests

parent 89d0ba45
...@@ -3,28 +3,23 @@ portal = context.getPortalObject() ...@@ -3,28 +3,23 @@ portal = context.getPortalObject()
person_uid_list = [] person_uid_list = []
for (_, brain) in enumerate(portal.portal_simulation.getInventoryList( for (_, brain) in enumerate(portal.portal_simulation.getInventoryList(
simulation_state=('stopped', 'delivered'), simulation_state=('stopped', 'delivered'),
parent_payment_mode_uid = [
portal.portal_categories.payment_mode.payzen.getUid(),
portal.portal_categories.payment_mode.wechat.getUid()],
group_by_mirror_section=True, group_by_mirror_section=True,
portal_type=portal.getPortalAccountingMovementTypeList(), portal_type=portal.getPortalAccountingMovementTypeList(),
node_uid=[x.uid for x in context.Base_getReceivableAccountList()], node_uid=[x.uid for x in context.Base_getReceivableAccountList()],
grouping_reference=None)): parent__ledger__uid=portal.portal_categories.ledger.automated.getUid(),
grouping_reference=None
)):
payment_request_uid = brain.payment_request_uid section_uid = brain.getDestinationSectionUid(portal_type="Person")
if not payment_request_uid:
payment_request_uid = brain.getObject().getExplanationUid()
payment_request = portal.portal_catalog.getObject(uid=payment_request_uid)
section_uid = payment_request.getDestinationSectionUid(portal_type="Person")
if section_uid is not None: if section_uid is not None:
person_uid_list.append(section_uid) person_uid_list.append(section_uid)
portal.portal_catalog.searchAndActivate( if person_uid_list:
portal_type="Person", portal.portal_catalog.searchAndActivate(
validation_state="validated", portal_type="Person",
uid=person_uid_list, validation_state="validated",
method_id='Person_checkToCreateRegularisationRequest', uid=person_uid_list,
activate_kw={'tag': tag} method_id='Person_checkToCreateRegularisationRequest',
) activate_kw={'tag': tag}
)
context.activate(after_tag=tag).getId() context.activate(after_tag=tag).getId()
...@@ -24,144 +24,144 @@ from erp5.component.test.SlapOSTestCaseMixin import \ ...@@ -24,144 +24,144 @@ from erp5.component.test.SlapOSTestCaseMixin import \
SlapOSTestCaseMixin, SlapOSTestCaseMixinWithAbort SlapOSTestCaseMixin, SlapOSTestCaseMixinWithAbort
from DateTime import DateTime from DateTime import DateTime
class TestSlapOSCRMCreateRegularisationRequest(SlapOSTestCaseMixin): class TestSlapOSCRMCreateRegularisationRequestAlarm(SlapOSTestCaseMixin):
def createFinalInvoice(self, person, grouping_reference=None,
def createFinalInvoice(self, person): ledger="automated",
template = self.portal.restrictedTraverse( source="account_module/receivable",
self.portal.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate()) is_stopped=True):
current_invoice = template.Base_createCloneDocument(batch_mode=1)
current_invoice = self.portal.accounting_module.newContent(
current_invoice.edit( portal_type="Sale Invoice Transaction",
destination_value=person,
destination_section_value=person, destination_section_value=person,
destination_decision_value=person,
start_date=DateTime('2019/10/20'), start_date=DateTime('2019/10/20'),
stop_date=DateTime('2019/10/20'), stop_date=DateTime('2019/10/20'),
title='Fake Invoice for Demo User Functional', title='Fake Invoice for Demo User Functional',
price_currency="currency_module/EUR", resource="currency_module/EUR",
reference='1') reference='1',
ledger=ledger)
cell = current_invoice["1"]["movement_0"] current_invoice.receivable.edit(
cell.edit(quantity=1) source=source,
cell.setPrice(1) quantity=1,
price=1,
grouping_reference=grouping_reference
)
current_invoice.plan() current_invoice.plan()
current_invoice.confirm() current_invoice.confirm()
current_invoice.startBuilding() if is_stopped:
current_invoice.reindexObject() current_invoice.stop()
current_invoice.stop()
self.tic() self.tic()
current_invoice.Delivery_manageBuildingCalculatingDelivery()
self.tic()
applied_rule = current_invoice.getCausalityRelated(portal_type="Applied Rule")
for sm in self.portal.portal_catalog(portal_type='Simulation Movement',
simulation_state=['draft', 'planned', None],
left_join_list=['delivery_uid'],
delivery_uid=None,
path="%%%s%%" % applied_rule):
if sm.getDelivery() is not None:
continue
root_applied_rule = sm.getRootAppliedRule()
root_applied_rule_path = root_applied_rule.getPath()
sm.getCausalityValue(portal_type='Business Link').build(
path='%s/%%' % root_applied_rule_path)
return current_invoice return current_invoice
def test_createRegularisationRequest_expected_person(self): #################################################################
# slapos_crm_create_regularisation_request
#################################################################
def test_Person_checkToCreateRegularisationRequest_alarm_expectedPerson(self):
new_id = self.generateNewId() new_id = self.generateNewId()
person = self.portal.person_module.newContent( person = self.portal.person_module.newContent(
portal_type='Person', portal_type='Person',
title="Test person %s" % new_id title="Test person %s" % new_id
) )
person.validate() person.validate()
self.createFinalInvoice(person) self.createFinalInvoice(person)
self.tic() self.tic()
alarm = self.portal.portal_alarms.\ self._test_alarm(
slapos_crm_create_regularisation_request self.portal.portal_alarms.slapos_crm_create_regularisation_request,
self._test_alarm(alarm, person, "Person_checkToCreateRegularisationRequest") person,
'Person_checkToCreateRegularisationRequest'
)
def test_createRegularisationRequest_not_validated(self): def test_Person_checkToCreateRegularisationRequest_alarm_started(self):
new_id = self.generateNewId() new_id = self.generateNewId()
person = self.portal.person_module.newContent( person = self.portal.person_module.newContent(
portal_type='Person', portal_type='Person',
title="Test person %s" % new_id title="Test person %s" % new_id
) )
person.validate() person.validate()
self.createFinalInvoice(person) self.createFinalInvoice(person, is_stopped=False)
person.invalidate()
self.tic() self.tic()
alarm = self.portal.portal_alarms.\ self._test_alarm_not_visited(
slapos_crm_create_regularisation_request self.portal.portal_alarms.slapos_crm_create_regularisation_request,
self._test_alarm_not_visited(alarm, person, "Person_checkToCreateRegularisationRequest") person,
'Person_checkToCreateRegularisationRequest'
)
def test_createRegularisationRequest_payment_stopped(self): def test_Person_checkToCreateRegularisationRequest_alarm_lettered(self):
new_id = self.generateNewId() new_id = self.generateNewId()
person = self.portal.person_module.newContent( person = self.portal.person_module.newContent(
portal_type='Person', portal_type='Person',
title="Test person %s" % new_id title="Test person %s" % new_id
) )
person.validate() person.validate()
current_invoice = self.createFinalInvoice(person) self.createFinalInvoice(person, grouping_reference="foobar")
payment_template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredDefaultPrePaymentTemplate())
payment = payment_template.Base_createCloneDocument(batch_mode=1)
for line in payment.contentValues():
if line.getSource() == "account_module/payment_to_encash":
line.setQuantity(-1)
elif line.getSource() == "account_module/receivable":
line.setQuantity(1)
payment.confirm()
payment.start()
payment.setCausalityValue(current_invoice)
payment.setDestinationSectionValue(person)
payment.stop()
self.tic() self.tic()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
def test_Person_checkToCreateRegularisationRequest_alarm_noLedger(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
self.createFinalInvoice(person, ledger=None)
self.tic() self.tic()
alarm = self.portal.portal_alarms.\ self._test_alarm_not_visited(
slapos_crm_create_regularisation_request self.portal.portal_alarms.slapos_crm_create_regularisation_request,
self._test_alarm_not_visited(alarm, person, "Person_checkToCreateRegularisationRequest") person,
'Person_checkToCreateRegularisationRequest'
)
def test_createRegularisationRequest_payment_started(self): def test_Person_checkToCreateRegularisationRequest_alarm_noReceivable(self):
new_id = self.generateNewId() new_id = self.generateNewId()
person = self.portal.person_module.newContent( person = self.portal.person_module.newContent(
portal_type='Person', portal_type='Person',
title="Test person %s" % new_id title="Test person %s" % new_id
) )
person.validate() person.validate()
self.createFinalInvoice(person, source="account_module/bank")
self.tic()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
current_invoice = self.createFinalInvoice(person) def test_Person_checkToCreateRegularisationRequest_alarm_notValidatedPerson(self):
payment_template = self.portal.restrictedTraverse( new_id = self.generateNewId()
self.portal.portal_preferences.getPreferredDefaultPrePaymentTemplate()) person = self.portal.person_module.newContent(
payment = payment_template.Base_createCloneDocument(batch_mode=1) portal_type='Person',
title="Test person %s" % new_id
for line in payment.contentValues(): )
if line.getSource() == "account_module/payment_to_encash": person.validate()
line.setQuantity(-1) person.invalidate()
elif line.getSource() == "account_module/receivable": self.createFinalInvoice(person)
line.setQuantity(1) self.tic()
self._test_alarm_not_visited(
payment.confirm() self.portal.portal_alarms.slapos_crm_create_regularisation_request,
payment.start() person,
payment.setCausalityValue(current_invoice) 'Person_checkToCreateRegularisationRequest'
payment.setDestinationSectionValue(person) )
def test_Person_checkToCreateRegularisationRequest_alarm_noInvoice(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
self.tic() self.tic()
alarm = self.portal.portal_alarms.\ self._test_alarm_not_visited(
slapos_crm_create_regularisation_request self.portal.portal_alarms.slapos_crm_create_regularisation_request,
self._test_alarm(alarm, person, "Person_checkToCreateRegularisationRequest") person,
'Person_checkToCreateRegularisationRequest'
)
# XXX couscous
class TestSlapOSCrmInvalidateSuspendedRegularisationRequest(SlapOSTestCaseMixinWithAbort): class TestSlapOSCrmInvalidateSuspendedRegularisationRequest(SlapOSTestCaseMixinWithAbort):
...@@ -488,7 +488,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort) ...@@ -488,7 +488,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
def _test_alarm_check_compute_node_state_selected(self, allocation_scope, def _test_alarm_check_compute_node_state_selected(self, allocation_scope,
monitor_scope=None): monitor_scope=None):
self._makeComputeNode() self._makeComputeNode(self.addProject())
self.compute_node.edit(allocation_scope=allocation_scope) self.compute_node.edit(allocation_scope=allocation_scope)
self.tic() self.tic()
if monitor_scope is not None: if monitor_scope is not None:
...@@ -557,16 +557,13 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase ...@@ -557,16 +557,13 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
self._makeComputeNode(self.addProject()) self._makeComputeNode(self.addProject())
self.compute_node.edit(allocation_scope=allocation_scope) self.compute_node.edit(allocation_scope=allocation_scope)
self.tic() self.tic()
if monitor_scope is not None:
self.compute_node.edit(monitor_scope=monitor_scope)
self.tic()
alarm = self.portal.portal_alarms.\ alarm = self.portal.portal_alarms.\
slapos_crm_check_software_installation_state slapos_crm_check_software_installation_state
self._test_alarm_not_visited(alarm, self.compute_node, "ComputeNode_checkSoftwareInstallationState") self._test_alarm_not_visited(alarm, self.compute_node, "ComputeNode_checkSoftwareInstallationState")
def _test_alarm_run_on_close(self, allocation_scope,): def _test_alarm_run_on_close(self, allocation_scope):
self._makeComputeNode() self._makeComputeNode(self.addProject())
self.compute_node.edit(allocation_scope=allocation_scope) self.compute_node.edit(allocation_scope=allocation_scope)
self.tic() 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