Commit 9cdac07c authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting/testSlapOSAccountingAlarm: Clean up tests for rely on API to test alarm

parent 275b9026
...@@ -1225,24 +1225,6 @@ class TestSlapOSUpdateOpenSaleOrderPeriod(SlapOSTestCaseMixin): ...@@ -1225,24 +1225,6 @@ class TestSlapOSUpdateOpenSaleOrderPeriod(SlapOSTestCaseMixin):
self.portal.OpenSaleOrder_updatePeriod, self.portal.OpenSaleOrder_updatePeriod,
REQUEST={}) REQUEST={})
def _simulatePerson_storeOpenSaleOrderJournal(self):
script_name = 'Person_storeOpenSaleOrderJournal'
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 Person_storeOpenSaleOrderJournal') """ )
transaction.commit()
def _dropPerson_storeOpenSaleOrderJournal(self):
script_name = 'Person_storeOpenSaleOrderJournal'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_updatePeriod_no_person(self): def test_updatePeriod_no_person(self):
open_order = self.createOpenOrder() open_order = self.createOpenOrder()
open_order.OpenSaleOrder_updatePeriod() open_order.OpenSaleOrder_updatePeriod()
...@@ -1255,14 +1237,13 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -1255,14 +1237,13 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
destination_decision_value=person, destination_decision_value=person,
) )
self._simulatePerson_storeOpenSaleOrderJournal() script_name = "Person_storeOpenSaleOrderJournal"
self._simulateScript(script_name)
try: try:
open_order.OpenSaleOrder_updatePeriod() open_order.OpenSaleOrder_updatePeriod()
finally: finally:
self._dropPerson_storeOpenSaleOrderJournal() self._dropScript(script_name)
self.assertEqual( self.assertScriptVisited(person, script_name)
'Visited by Person_storeOpenSaleOrderJournal',
person.workflow_history['edit_workflow'][-1]['comment'])
def test_updatePeriod_invalidated(self): def test_updatePeriod_invalidated(self):
open_order = self.createOpenOrder() open_order = self.createOpenOrder()
...@@ -1273,74 +1254,43 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -1273,74 +1254,43 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
) )
open_order.invalidate() open_order.invalidate()
self._simulatePerson_storeOpenSaleOrderJournal() script_name = "Person_storeOpenSaleOrderJournal"
self._simulateScript(script_name)
try: try:
open_order.OpenSaleOrder_updatePeriod() open_order.OpenSaleOrder_updatePeriod()
finally: finally:
self._dropPerson_storeOpenSaleOrderJournal() self._dropScript(script_name)
self.assertNotEqual( self.assertScriptNotVisited(person, script_name)
'Visited by Person_storeOpenSaleOrderJournal',
person.workflow_history['edit_workflow'][-1]['comment'])
def _simulateOpenSaleOrder_updatePeriod(self):
script_name = 'OpenSaleOrder_updatePeriod'
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 OpenSaleOrder_updatePeriod') """ )
transaction.commit()
def _dropOpenSaleOrder_updatePeriod(self):
script_name = 'OpenSaleOrder_updatePeriod'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm(self): def test_alarm(self):
open_order = self.createOpenOrder() open_order = self.createOpenOrder()
open_order.newContent(portal_type="Open Sale Order Line") open_order.newContent(portal_type="Open Sale Order Line")
self.tic() self.tic()
self._simulateOpenSaleOrder_updatePeriod() script_name = "OpenSaleOrder_updatePeriod"
try: alarm = self.portal.portal_alarms.slapos_update_open_sale_order_period
self.portal.portal_alarms.slapos_update_open_sale_order_period.activeSense()
self.tic() self._test_alarm(
finally: alarm, open_order, script_name)
self._dropOpenSaleOrder_updatePeriod()
self.assertEqual(
'Visited by OpenSaleOrder_updatePeriod',
open_order.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_invalidated(self): def test_alarm_invalidated(self):
open_order = self.createOpenOrder() open_order = self.createOpenOrder()
open_order.newContent(portal_type="Open Sale Order Line") open_order.newContent(portal_type="Open Sale Order Line")
open_order.invalidate() open_order.invalidate()
self.tic() self.tic()
self._simulateOpenSaleOrder_updatePeriod() script_name = "OpenSaleOrder_updatePeriod"
try: alarm = self.portal.portal_alarms.slapos_update_open_sale_order_period
self.portal.portal_alarms.slapos_update_open_sale_order_period.activeSense()
self.tic() self._test_alarm_not_visited(
finally: alarm, open_order, script_name)
self._dropOpenSaleOrder_updatePeriod()
self.assertNotEqual(
'Visited by OpenSaleOrder_updatePeriod',
open_order.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_no_line(self): def test_alarm_no_line(self):
open_order = self.createOpenOrder() open_order = self.createOpenOrder()
self.tic() self.tic()
self._simulateOpenSaleOrder_updatePeriod() script_name = "OpenSaleOrder_updatePeriod"
try: alarm = self.portal.portal_alarms.slapos_update_open_sale_order_period
self.portal.portal_alarms.slapos_update_open_sale_order_period.activeSense()
self.tic() self._test_alarm_not_visited(
finally: alarm, open_order, script_name)
self._dropOpenSaleOrder_updatePeriod()
self.assertNotEqual(
'Visited by OpenSaleOrder_updatePeriod',
open_order.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSReindexOpenSaleOrder(SlapOSTestCaseMixin): class TestSlapOSReindexOpenSaleOrder(SlapOSTestCaseMixin):
...@@ -1354,8 +1304,7 @@ class TestSlapOSReindexOpenSaleOrder(SlapOSTestCaseMixin): ...@@ -1354,8 +1304,7 @@ class TestSlapOSReindexOpenSaleOrder(SlapOSTestCaseMixin):
) )
return open_order return open_order
def _simulateOpenSaleOrder_reindexIfIndexedBeforeLine(self): def _simulateScript(self, script_name):
script_name = 'OpenSaleOrder_reindexIfIndexedBeforeLine'
if script_name in self.portal.portal_skins.custom.objectIds(): if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name) raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom, createZODBPythonScript(self.portal.portal_skins.custom,
...@@ -1363,14 +1312,8 @@ class TestSlapOSReindexOpenSaleOrder(SlapOSTestCaseMixin): ...@@ -1363,14 +1312,8 @@ class TestSlapOSReindexOpenSaleOrder(SlapOSTestCaseMixin):
'uid=None,*args, **kwargs', 'uid=None,*args, **kwargs',
'# Script body\n' '# Script body\n'
"""portal_workflow = context.portal_workflow """portal_workflow = context.portal_workflow
open_order = context.portal_catalog.getResultValue(uid=uid) document = context.portal_catalog.getResultValue(uid=uid)
portal_workflow.doActionFor(open_order, action='edit_action', comment='Visited by OpenSaleOrder_reindexIfIndexedBeforeLine') """ ) portal_workflow.doActionFor(document, action='edit_action', comment='Visited by %s') """ % script_name )
transaction.commit()
def _dropOpenSaleOrder_reindexIfIndexedBeforeLine(self):
script_name = 'OpenSaleOrder_reindexIfIndexedBeforeLine'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit() transaction.commit()
def test_alarm(self): def test_alarm(self):
...@@ -1380,28 +1323,20 @@ portal_workflow.doActionFor(open_order, action='edit_action', comment='Visited b ...@@ -1380,28 +1323,20 @@ portal_workflow.doActionFor(open_order, action='edit_action', comment='Visited b
time.sleep(1) time.sleep(1)
open_order.newContent(portal_type="Open Sale Order Line") open_order.newContent(portal_type="Open Sale Order Line")
self.tic() self.tic()
self._simulateOpenSaleOrder_reindexIfIndexedBeforeLine() script_name = "OpenSaleOrder_reindexIfIndexedBeforeLine"
try: alarm = self.portal.portal_alarms.slapos_reindex_open_sale_order
self.portal.portal_alarms.slapos_reindex_open_sale_order.activeSense()
self.tic() self._test_alarm(
finally: alarm, open_order, script_name)
self._dropOpenSaleOrder_reindexIfIndexedBeforeLine()
self.assertEqual(
'Visited by OpenSaleOrder_reindexIfIndexedBeforeLine',
open_order.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_no_line(self): def test_alarm_no_line(self):
open_order = self.createOpenOrder() open_order = self.createOpenOrder()
self.tic() self.tic()
self._simulateOpenSaleOrder_reindexIfIndexedBeforeLine() script_name = "OpenSaleOrder_reindexIfIndexedBeforeLine"
try: alarm = self.portal.portal_alarms.slapos_reindex_open_sale_order
self.portal.portal_alarms.slapos_reindex_open_sale_order.activeSense()
self.tic() self._test_alarm_not_visited(
finally: alarm, open_order, script_name)
self._dropOpenSaleOrder_reindexIfIndexedBeforeLine()
self.assertNotEqual(
'Visited by OpenSaleOrder_reindexIfIndexedBeforeLine',
open_order.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin): class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin):
...@@ -1412,49 +1347,23 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin): ...@@ -1412,49 +1347,23 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin):
) )
return document return document
def _simulateComputerConsumptionTioXMLFile_solveInvoicingGeneration(self):
script_name = 'ComputerConsumptionTioXMLFile_solveInvoicingGeneration'
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 ComputerConsumptionTioXMLFile_solveInvoicingGeneration') """ )
transaction.commit()
def _dropComputerConsumptionTioXMLFile_solveInvoicingGeneration(self):
script_name = 'ComputerConsumptionTioXMLFile_solveInvoicingGeneration'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm(self): def test_alarm(self):
document = self.createTioXMLFile() document = self.createTioXMLFile()
document.submit() document.submit()
self.tic() self.tic()
self._simulateComputerConsumptionTioXMLFile_solveInvoicingGeneration()
try: script_name = "ComputerConsumptionTioXMLFile_solveInvoicingGeneration"
self.portal.portal_alarms.\ alarm = self.portal.portal_alarms.slapos_accounting_generate_packing_list_from_tioxml
slapos_accounting_generate_packing_list_from_tioxml.activeSense()
self.tic() self._test_alarm(
finally: alarm, document, script_name)
self._dropComputerConsumptionTioXMLFile_solveInvoicingGeneration()
self.assertEqual(
'Visited by ComputerConsumptionTioXMLFile_solveInvoicingGeneration',
document.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_submitted(self): def test_alarm_not_submitted(self):
document = self.createTioXMLFile() document = self.createTioXMLFile()
self.tic() self.tic()
self._simulateComputerConsumptionTioXMLFile_solveInvoicingGeneration()
try: script_name = "ComputerConsumptionTioXMLFile_solveInvoicingGeneration"
self.portal.portal_alarms.\ alarm = self.portal.portal_alarms.slapos_accounting_generate_packing_list_from_tioxml
slapos_accounting_generate_packing_list_from_tioxml.activeSense()
self.tic() self._test_alarm_not_visited(
finally: alarm, document, script_name)
self._dropComputerConsumptionTioXMLFile_solveInvoicingGeneration()
self.assertNotEqual(
'Visited by ComputerConsumptionTioXMLFile_solveInvoicingGeneration',
document.workflow_history['edit_workflow'][-1]['comment'])
...@@ -112,11 +112,13 @@ ...@@ -112,11 +112,13 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -129,8 +131,9 @@ ...@@ -129,8 +131,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
<none/> </value>
</tuple> </item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
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