Commit 8b63c868 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: drop usage of createZODBPythonScript

parent 68e452dd
# Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, simulate
import transaction
from Products.ERP5Type.tests.utils import createZODBPythonScript
from DateTime import DateTime
class TestSlapOSAccountingInteractionWorkflow(SlapOSTestCaseMixin):
def beforeTearDown(self):
transaction.abort()
def _simulateHostingSubscription_calculateSubscriptionStartDate(self, date):
script_name = 'HostingSubscription_calculateSubscriptionStartDate'
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'
"""from DateTime import DateTime
return DateTime('%s') """ % date.ISO())
transaction.commit()
def _dropHostingSubscription_calculateSubscriptionStartDate(self):
script_name = 'HostingSubscription_calculateSubscriptionStartDate'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_HostingSubscription_fixConsistency(self,
date=DateTime('2012/01/15'), day=15):
def _test_HostingSubscription_fixConsistency(self, day):
new_id = self.generateNewId()
item = self.portal.hosting_subscription_module.newContent(
portal_type='Hosting Subscription',
......@@ -43,18 +23,29 @@ return DateTime('%s') """ % date.ISO())
self.assertEqual(item.getPeriodicityMinute(), None)
self.assertEqual(item.getPeriodicityMonthDay(), None)
self._simulateHostingSubscription_calculateSubscriptionStartDate(date)
try:
item.fixConsistency()
finally:
self._dropHostingSubscription_calculateSubscriptionStartDate()
self.assertEqual(item.getPeriodicityHourList(), [0])
self.assertEqual(item.getPeriodicityMinuteList(), [0])
self.assertEqual(item.getPeriodicityMonthDay(), day)
@simulate('HostingSubscription_calculateSubscriptionStartDate',
'*args, **kwargs',
"""# Script body
from DateTime import DateTime
return DateTime('%s')
""" % DateTime('2012/01/15').ISO())
def test_HostingSubscription_fixConsistency(self):
self._test_HostingSubscription_fixConsistency(15)
@simulate('HostingSubscription_calculateSubscriptionStartDate',
'*args, **kwargs',
"""# Script body
from DateTime import DateTime
return DateTime('%s')
""" % DateTime('2012/01/29').ISO())
def test_HostingSubscription_fixConsistency_today_after_28(self):
self.test_HostingSubscription_fixConsistency(DateTime('2012/01/29'), 28)
self._test_HostingSubscription_fixConsistency(28)
def test_HostingSubscription_manageAfter(self):
class DummyTestException(Exception):
......@@ -90,24 +81,12 @@ return DateTime('%s') """ % date.ISO())
self.portal.portal_types.resetDynamicDocumentsOnceAtTransactionBoundary()
transaction.commit()
def _simulateDelivery_calculate(self):
script_name = 'Delivery_calculate'
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,
@simulate('Delivery_calculate',
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by Delivery_calculate') """)
transaction.commit()
def _dropDelivery_calculate(self):
script_name = 'Delivery_calculate'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
"""# Script body
portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by Delivery_calculate')
""")
def _test_calculate(self, new_id, newContent, **new_kw):
cancel_spl = newContent(**new_kw)
close_spl = newContent(**new_kw)
......@@ -125,8 +104,6 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by D
stop_spl.confirm()
submit_spl = newContent(**new_kw)
self._simulateDelivery_calculate()
try:
cancel_spl.cancel()
close_spl.close()
confirm_spl.confirm()
......@@ -137,8 +114,7 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by D
start_spl.start()
stop_spl.stop()
submit_spl.submit()
finally:
self._dropDelivery_calculate()
self.assertEqual(
cancel_spl.workflow_history['edit_workflow'][-1]['comment'],
'Visited by Delivery_calculate')
......
......@@ -6,12 +6,6 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSAccountingInteractionWorkflow</string> </value>
......@@ -55,28 +49,13 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -89,7 +68,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -98,7 +77,7 @@
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
......
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