Commit ee99acde authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: test: update titles

parent 83a2f63c
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
import transaction import transaction
from functools import wraps from functools import wraps
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, withAbort from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, withAbort, TemporaryAlarmScript
import os import os
import tempfile import tempfile
...@@ -106,25 +107,26 @@ if context.getTitle() == 'Not visited by %s': ...@@ -106,25 +107,26 @@ if context.getTitle() == 'Not visited by %s':
class TestSlapOSTriggerBuildAlarm(SlapOSTestCaseMixin): class TestSlapOSTriggerBuildAlarm(SlapOSTestCaseMixin):
@simulateByTitlewMark('SimulationMovement_buildSlapOS') #################################################################
def test_SimulationMovement_withoutDelivery(self): # slapos_trigger_build
#################################################################
def test_SimulationMovement_buildSlapOS_alarm_withoutDelivery(self):
applied_rule = self.portal.portal_simulation.newContent( applied_rule = self.portal.portal_simulation.newContent(
portal_type='Applied Rule') portal_type='Applied Rule')
simulation_movement = applied_rule.newContent( simulation_movement = applied_rule.newContent(
portal_type='Simulation Movement', portal_type='Simulation Movement',
ledger='automated', ledger='automated',
title='Not visited by SimulationMovement_buildSlapOS') title='Not visited by SimulationMovement_buildSlapOS')
self.tic() with TemporaryAlarmScript(self.portal, 'SimulationMovement_buildSlapOS', "''", attribute='title'):
self.tic()
self.portal.portal_alarms.slapos_trigger_build.activeSense() self._test_alarm(
self.tic() self.portal.portal_alarms.slapos_trigger_build,
simulation_movement,
self.assertEqual( 'SimulationMovement_buildSlapOS',
'Visited by SimulationMovement_buildSlapOS', attribute='title'
simulation_movement.getTitle()) )
@simulateByTitlewMark('SimulationMovement_buildSlapOS') def test_SimulationMovement_buildSlapOS_alarm_withDelivery(self):
def test_SimulationMovement_withDelivery(self):
delivery = self.portal.sale_packing_list_module.newContent( delivery = self.portal.sale_packing_list_module.newContent(
portal_type='Sale Packing List') portal_type='Sale Packing List')
delivery_line = delivery.newContent(portal_type='Sale Packing List Line') delivery_line = delivery.newContent(portal_type='Sale Packing List Line')
...@@ -134,18 +136,21 @@ class TestSlapOSTriggerBuildAlarm(SlapOSTestCaseMixin): ...@@ -134,18 +136,21 @@ class TestSlapOSTriggerBuildAlarm(SlapOSTestCaseMixin):
portal_type='Simulation Movement', portal_type='Simulation Movement',
ledger='automated', ledger='automated',
delivery=delivery_line.getRelativeUrl(), delivery=delivery_line.getRelativeUrl(),
title='Shall be visited by SimulationMovement_buildSlapOS') title='Not visited by SimulationMovement_buildSlapOS')
self.tic() with TemporaryAlarmScript(self.portal, 'SimulationMovement_buildSlapOS', "''", attribute='title'):
self.tic()
self.portal.portal_alarms.slapos_trigger_build.activeSense() self._test_alarm_not_visited(
self.tic() self.portal.portal_alarms.slapos_trigger_build,
simulation_movement,
self.assertNotEqual( 'SimulationMovement_buildSlapOS',
'Not visited by SimulationMovement_buildSlapOS', attribute='title'
simulation_movement.getTitle()) )
#################################################################
# SimulationMovement_buildSlapOS
#################################################################
@withAbort @withAbort
def test_SimulationMovement_buildSlapOS(self): def test_SimulationMovement_buildSlapOS_script_withoutDelivery(self):
build_simulator = tempfile.mkstemp()[1] build_simulator = tempfile.mkstemp()[1]
activate_simulator = tempfile.mkstemp()[1] activate_simulator = tempfile.mkstemp()[1]
...@@ -238,7 +243,7 @@ class TestSlapOSTriggerBuildAlarm(SlapOSTestCaseMixin): ...@@ -238,7 +243,7 @@ class TestSlapOSTriggerBuildAlarm(SlapOSTestCaseMixin):
os.unlink(activate_simulator) os.unlink(activate_simulator)
@withAbort @withAbort
def test_SimulationMovement_buildSlapOS_withDelivery(self): def test_SimulationMovement_buildSlapOS_script_withDelivery(self):
build_simulator = tempfile.mkstemp()[1] build_simulator = tempfile.mkstemp()[1]
activate_simulator = tempfile.mkstemp()[1] activate_simulator = tempfile.mkstemp()[1]
...@@ -304,33 +309,39 @@ class TestSlapOSTriggerBuildAlarm(SlapOSTestCaseMixin): ...@@ -304,33 +309,39 @@ class TestSlapOSTriggerBuildAlarm(SlapOSTestCaseMixin):
os.unlink(activate_simulator) os.unlink(activate_simulator)
class TestSlapOSManageBuildingCalculatingDeliveryAlarm(SlapOSTestCaseMixin): class TestSlapOSManageBuildingCalculatingDeliveryAlarm(SlapOSTestCaseMixin):
@simulateByTitlewMark('Delivery_manageBuildingCalculatingDelivery') #################################################################
def _test(self, state, message): # slapos_manage_building_calculating_delivery
#################################################################
def _test(self, state, test_function):
delivery = self.portal.sale_packing_list_module.newContent( delivery = self.portal.sale_packing_list_module.newContent(
title='Not visited by Delivery_manageBuildingCalculatingDelivery', title='Not visited by Delivery_manageBuildingCalculatingDelivery',
ledger='automated', ledger='automated',
portal_type='Sale Packing List') portal_type='Sale Packing List')
self.portal.portal_workflow._jumpToStateFor(delivery, state) self.portal.portal_workflow._jumpToStateFor(delivery, state)
self.tic() with TemporaryAlarmScript(self.portal, 'Delivery_manageBuildingCalculatingDelivery', "''", attribute='title'):
self.tic()
self.portal.portal_alarms.slapos_manage_building_calculating_delivery\ test_function(
.activeSense() self.portal.portal_alarms.slapos_manage_building_calculating_delivery,
self.tic() delivery,
'Delivery_manageBuildingCalculatingDelivery',
self.assertEqual(message, delivery.getTitle()) attribute='title'
)
def test_building(self): def test_Delivery_manageBuildingCalculatingDelivery_alarm_building(self):
self._test('building', 'Visited by Delivery_manageBuildingCalculatingDelivery') self._test('building', self._test_alarm)
def test_calculating(self): def test_Delivery_manageBuildingCalculatingDelivery_alarm_calculating(self):
self._test('calculating', 'Visited by Delivery_manageBuildingCalculatingDelivery') self._test('calculating', self._test_alarm)
def test_diverged(self): def test_Delivery_manageBuildingCalculatingDelivery_alarm_diverged(self):
self._test('diverged', 'Not visited by Delivery_manageBuildingCalculatingDelivery') self._test('diverged', self._test_alarm_not_visited)
def test_solved(self): def test_Delivery_manageBuildingCalculatingDelivery_alarm_solved(self):
self._test('solved', 'Not visited by Delivery_manageBuildingCalculatingDelivery') self._test('solved', self._test_alarm_not_visited)
#################################################################
# Delivery_manageBuildingCalculatingDelivery
#################################################################
@withAbort @withAbort
def _test_Delivery_manageBuildingCalculatingDelivery(self, state, empty=False): def _test_Delivery_manageBuildingCalculatingDelivery(self, state, empty=False):
updateCausalityState_simulator = tempfile.mkstemp()[1] updateCausalityState_simulator = tempfile.mkstemp()[1]
...@@ -381,19 +392,28 @@ class TestSlapOSManageBuildingCalculatingDeliveryAlarm(SlapOSTestCaseMixin): ...@@ -381,19 +392,28 @@ class TestSlapOSManageBuildingCalculatingDeliveryAlarm(SlapOSTestCaseMixin):
if os.path.exists(updateSimulation_simulator): if os.path.exists(updateSimulation_simulator):
os.unlink(updateSimulation_simulator) os.unlink(updateSimulation_simulator)
def test_Delivery_manageBuildingCalculatingDelivery_calculating(self): def test_Delivery_manageBuildingCalculatingDelivery_script_calculating(self):
self._test_Delivery_manageBuildingCalculatingDelivery('calculating') self._test_Delivery_manageBuildingCalculatingDelivery('calculating')
def test_Delivery_manageBuildingCalculatingDelivery_building(self): def test_Delivery_manageBuildingCalculatingDelivery_script_building(self):
self._test_Delivery_manageBuildingCalculatingDelivery('building') self._test_Delivery_manageBuildingCalculatingDelivery('building')
def test_Delivery_manageBuildingCalculatingDelivery_solved(self): def test_Delivery_manageBuildingCalculatingDelivery_script_solved(self):
self._test_Delivery_manageBuildingCalculatingDelivery('solved', True) self._test_Delivery_manageBuildingCalculatingDelivery('solved', True)
def test_Delivery_manageBuildingCalculatingDelivery_diverged(self): def test_Delivery_manageBuildingCalculatingDelivery_script_diverged(self):
self._test_Delivery_manageBuildingCalculatingDelivery('diverged', True) self._test_Delivery_manageBuildingCalculatingDelivery('diverged', True)
class TestSlapOSConfirmedDeliveryMixin:
class TestSlapOSStopConfirmedAggregatedSaleInvoiceTransactionAlarm(SlapOSTestCaseMixin):
destination_state = 'stopped'
script = 'Delivery_stopConfirmedAggregatedSaleInvoiceTransaction'
portal_type = 'Sale Invoice Transaction'
alarm = 'slapos_stop_confirmed_aggregated_sale_invoice_transaction'
#################################################################
# slapos_stop_confirmed_aggregated_sale_invoice_transaction
#################################################################
def _test(self, simulation_state, causality_state, ledger, positive, def _test(self, simulation_state, causality_state, ledger, positive,
delivery_date=DateTime('2012/04/22'), delivery_date=DateTime('2012/04/22'),
accounting_date=DateTime('2012/04/28')): accounting_date=DateTime('2012/04/28')):
...@@ -423,21 +443,24 @@ class TestSlapOSConfirmedDeliveryMixin: ...@@ -423,21 +443,24 @@ class TestSlapOSConfirmedDeliveryMixin:
_real(self, simulation_state, causality_state, ledger, positive, _real(self, simulation_state, causality_state, ledger, positive,
delivery_date, accounting_date) delivery_date, accounting_date)
def test_typical(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_alarm_typical(self):
self._test('confirmed', 'solved', self._test('confirmed', 'solved',
'automated', True) 'automated', True)
def test_bad_ledger(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_alarm_bad_ledger(self):
self._test('confirmed', 'solved', None, False) self._test('confirmed', 'solved', None, False)
def test_bad_simulation_state(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_alarm_bad_simulation_state(self):
self._test('started', 'solved', self._test('started', 'solved',
'automated', False) 'automated', False)
def test_bad_causality_state(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_alarm_bad_causality_state(self):
self._test('confirmed', 'calculating', self._test('confirmed', 'calculating',
'automated', False) 'automated', False)
#################################################################
# Delivery_stopConfirmedAggregatedSaleInvoiceTransaction
#################################################################
@withAbort @withAbort
def _test_script(self, simulation_state, causality_state, ledger, def _test_script(self, simulation_state, causality_state, ledger,
destination_state, consistency_failure=False): destination_state, consistency_failure=False):
...@@ -463,40 +486,34 @@ class TestSlapOSConfirmedDeliveryMixin: ...@@ -463,40 +486,34 @@ class TestSlapOSConfirmedDeliveryMixin:
delattr(Folder, 'original_checkConsistency') delattr(Folder, 'original_checkConsistency')
self.assertEqual(destination_state, delivery.getSimulationState()) self.assertEqual(destination_state, delivery.getSimulationState())
def test_script_typical(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_script_typical(self):
self._test_script('confirmed', 'solved', self._test_script('confirmed', 'solved',
'automated', 'automated',
self.destination_state) self.destination_state)
def test_script_bad_ledger(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_script_bad_ledger(self):
self._test_script('confirmed', 'solved', None, 'confirmed') self._test_script('confirmed', 'solved', None, 'confirmed')
def test_script_bad_simulation_state(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_script_bad_simulation_state(self):
self._test_script('started', 'solved', self._test_script('started', 'solved',
'automated', 'automated',
'started') 'started')
def test_script_bad_causality_state(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_script_bad_causality_state(self):
self._test_script('confirmed', 'building', self._test_script('confirmed', 'building',
'automated', 'automated',
'confirmed') 'confirmed')
def test_script_bad_consistency(self): def test_Delivery_stopConfirmedAggregatedSaleInvoiceTransaction_script_bad_consistency(self):
self._test_script('confirmed', 'solved', self._test_script('confirmed', 'solved',
'automated', 'automated',
'confirmed', True) 'confirmed', True)
class TestSlapOSStopConfirmedAggregatedSaleInvoiceTransactionAlarm(
SlapOSTestCaseMixin, TestSlapOSConfirmedDeliveryMixin):
destination_state = 'stopped'
script = 'Delivery_stopConfirmedAggregatedSaleInvoiceTransaction'
portal_type = 'Sale Invoice Transaction'
alarm = 'slapos_stop_confirmed_aggregated_sale_invoice_transaction'
class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin): class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin):
#################################################################
# slapos_accounting_generate_packing_list_from_tioxml
#################################################################
def createTioXMLFile(self): def createTioXMLFile(self):
document = self.portal.consumption_document_module.newContent( document = self.portal.consumption_document_module.newContent(
title=self.generateNewId(), title=self.generateNewId(),
...@@ -504,7 +521,7 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin): ...@@ -504,7 +521,7 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin):
) )
return document return document
def test_alarm(self): def test_ComputerConsumptionTioXMLFile_solveInvoicingGeneration_alarm(self):
document = self.createTioXMLFile() document = self.createTioXMLFile()
document.submit() document.submit()
self.tic() self.tic()
...@@ -515,7 +532,7 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin): ...@@ -515,7 +532,7 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin):
self._test_alarm( self._test_alarm(
alarm, document, script_name) alarm, document, script_name)
def test_alarm_not_submitted(self): def test_ComputerConsumptionTioXMLFile_solveInvoicingGeneration_alarm_not_submitted(self):
document = self.createTioXMLFile() document = self.createTioXMLFile()
self.tic() self.tic()
...@@ -527,7 +544,9 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin): ...@@ -527,7 +544,9 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin):
class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCaseMixin): class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCaseMixin):
#################################################################
# slapos_cancel_sale_invoice_transaction_paied_payment_list
#################################################################
def _test_payment_is_draft(self, payment_mode): def _test_payment_is_draft(self, payment_mode):
new_id = self.generateNewId() new_id = self.generateNewId()
payment_transaction = self.portal.accounting_module.newContent( payment_transaction = self.portal.accounting_module.newContent(
...@@ -538,19 +557,16 @@ class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCase ...@@ -538,19 +557,16 @@ class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCase
) )
self.tic() self.tic()
self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list.activeSense() self._test_alarm_not_visited(
self.tic() self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list,
payment_transaction,
self.assertNotEqual( "PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered"
'Not visited by PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered', )
payment_transaction.getTitle())
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered') def test_PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered_alarm_isDraftPayzen(self):
def test_payment_is_draft_payzen(self):
self._test_payment_is_draft(payment_mode="payzen") self._test_payment_is_draft(payment_mode="payzen")
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered') def test_PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered_alarm_isDraftWeChat(self):
def test_payment_is_draft_wechat(self):
self._test_payment_is_draft(payment_mode="wechat") self._test_payment_is_draft(payment_mode="wechat")
def _test_payment_is_stopped(self, payment_mode): def _test_payment_is_stopped(self, payment_mode):
...@@ -567,22 +583,18 @@ class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCase ...@@ -567,22 +583,18 @@ class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCase
payment_transaction.stop() payment_transaction.stop()
self.tic() self.tic()
self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list.activeSense() self._test_alarm_not_visited(
self.tic() self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list,
payment_transaction,
self.assertNotEqual( "PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered"
'Not visited by PaymentTransaction_cancelIfSaleInvoiceTransactionisLettered', )
payment_transaction.getTitle())
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionisLettered') def test_PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered_alarm_isStoppedPayzen(self):
def test_payment_is_stopped_payzen(self):
self._test_payment_is_stopped(payment_mode="payzen") self._test_payment_is_stopped(payment_mode="payzen")
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionisLettered') def test_PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered_alarm_isStoppedWechat(self):
def test_payment_is_stopped_wechat(self):
self._test_payment_is_stopped(payment_mode="wechat") self._test_payment_is_stopped(payment_mode="wechat")
def _test_payment_is_started(self, payment_mode): def _test_payment_is_started(self, payment_mode):
new_id = self.generateNewId() new_id = self.generateNewId()
payment_transaction = self.portal.accounting_module.newContent( payment_transaction = self.portal.accounting_module.newContent(
...@@ -596,17 +608,14 @@ class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCase ...@@ -596,17 +608,14 @@ class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCase
payment_transaction.start() payment_transaction.start()
self.tic() self.tic()
self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list.activeSense() self._test_alarm(
self.tic() self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list,
payment_transaction,
self.assertNotEqual( "PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered"
'Visited by PaymentTransaction_cancelIfSaleInvoiceTransactionisLettered', )
payment_transaction.getTitle())
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionisLettered') def test_PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered_alarm_isStartedPayzen(self):
def test_payment_is_started_payzen(self):
self._test_payment_is_started(payment_mode="payzen") self._test_payment_is_started(payment_mode="payzen")
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionisLettered') def test_PaymentTransaction_cancelIfSaleInvoiceTransactionIsLettered_alarm_isStartedWechat(self):
def test_payment_is_started_wechat(self): self._test_payment_is_started(payment_mode="wechat")
self._test_payment_is_started(payment_mode="wechat")
\ No newline at end of file
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