Commit cc05ee0c authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_pdm: Clean up testSlapOSPDMAlarm

   * Use single API
   * Unify usage of _simulateScript with the mixin
parent ce3be333
# Copyright (c) 2013 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2013 Nexedi SA and Contributors. All Rights Reserved.
import transaction
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
from Products.ERP5Type.tests.utils import createZODBPythonScript
class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin): class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin):
def afterSetUp(self): def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self) SlapOSTestCaseMixin.afterSetUp(self)
...@@ -18,21 +15,6 @@ class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin): ...@@ -18,21 +15,6 @@ class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin):
upgrade_decision.confirm() upgrade_decision.confirm()
return upgrade_decision return upgrade_decision
def _makeComputer(self,new_id):
# Clone computer document
person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1)
computer = self.portal.computer_module\
.template_computer.Base_createCloneDocument(batch_mode=1)
computer.edit(
title="computer ticket %s" % (new_id, ),
reference="TESTCOMPT-%s" % (new_id, ),
source_administration_value=person
)
computer.validate()
return computer
def _makeHostingSubscription(self, slap_state="start_requested"): def _makeHostingSubscription(self, slap_state="start_requested"):
hosting_subscription = self.portal\ hosting_subscription = self.portal\
.hosting_subscription_module.template_hosting_subscription\ .hosting_subscription_module.template_hosting_subscription\
...@@ -46,24 +28,6 @@ class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin): ...@@ -46,24 +28,6 @@ class TestSlapOSUpgradeDecisionProcess(SlapOSTestCaseMixin):
return hosting_subscription return hosting_subscription
def _simulateScript(self, script_name, fake_return='True'):
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 %s')
return %s
""" % (script_name, fake_return ))
transaction.commit()
def _dropScript(self, script_name):
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm_upgrade_decision_process_hosting_subscription(self): def test_alarm_upgrade_decision_process_hosting_subscription(self):
upgrade_decision = self._makeUpgradeDecision() upgrade_decision = self._makeUpgradeDecision()
upgrade_decision.start() upgrade_decision.start()
...@@ -84,7 +48,7 @@ return %s ...@@ -84,7 +48,7 @@ return %s
upgrade_decision.plan() upgrade_decision.plan()
self.tic() self.tic()
self._simulateScript('UpgradeDecision_notify') self._simulateScript('UpgradeDecision_notify', 'True')
try: try:
self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_planned.\ self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_planned.\
activeSense() activeSense()
...@@ -102,7 +66,7 @@ return %s ...@@ -102,7 +66,7 @@ return %s
upgrade_decision.stop() upgrade_decision.stop()
self.tic() self.tic()
self._simulateScript('UpgradeDecision_notifyDelivered') self._simulateScript('UpgradeDecision_notifyDelivered', 'True')
try: try:
self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_stopped.\ self.portal.portal_alarms.slapos_pdm_upgrade_decision_process_stopped.\
activeSense() activeSense()
...@@ -114,15 +78,12 @@ return %s ...@@ -114,15 +78,12 @@ return %s
upgrade_decision.workflow_history['edit_workflow'][-1]['comment']) upgrade_decision.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_computer_create_upgrade_decision(self): def test_alarm_computer_create_upgrade_decision(self):
computer = self._makeComputer(self.new_id) computer = self._makeComputer(allocation_scope = 'open/public')[0]
computer.edit(allocation_scope = 'open/public') computer2 = self._makeComputer(allocation_scope = 'open/personal')[0]
computer2 = self._makeComputer(self.generateNewId()) computer3 = self._makeComputer(allocation_scope = 'open/friend')[0]
computer2.edit(allocation_scope = 'open/personal')
computer3 = self._makeComputer(self.generateNewId())
computer3.edit(allocation_scope = 'open/friend')
self.tic() self.tic()
self._simulateScript('Computer_checkAndCreateUpgradeDecision') self._simulateScript('Computer_checkAndCreateUpgradeDecision', 'True')
try: try:
self.portal.portal_alarms.slapos_pdm_computer_create_upgrade_decision.\ self.portal.portal_alarms.slapos_pdm_computer_create_upgrade_decision.\
activeSense() activeSense()
...@@ -146,7 +107,7 @@ return %s ...@@ -146,7 +107,7 @@ return %s
self.tic() self.tic()
self._simulateScript('HostingSubscription_createUpgradeDecision') self._simulateScript('HostingSubscription_createUpgradeDecision', 'True')
try: try:
self.portal.portal_alarms.slapos_pdm_hosting_subscription_create_upgrade_decision.\ self.portal.portal_alarms.slapos_pdm_hosting_subscription_create_upgrade_decision.\
activeSense() activeSense()
...@@ -168,7 +129,7 @@ return %s ...@@ -168,7 +129,7 @@ return %s
hosting_subscription2 = self._makeHostingSubscription(slap_state="destroy_requested") hosting_subscription2 = self._makeHostingSubscription(slap_state="destroy_requested")
self.tic() self.tic()
self._simulateScript('HostingSubscription_createUpgradeDecision') self._simulateScript('HostingSubscription_createUpgradeDecision', 'True')
try: try:
self.portal.portal_alarms.slapos_pdm_hosting_subscription_create_upgrade_decision.\ self.portal.portal_alarms.slapos_pdm_hosting_subscription_create_upgrade_decision.\
activeSense() activeSense()
...@@ -183,13 +144,11 @@ return %s ...@@ -183,13 +144,11 @@ return %s
hosting_subscription2.workflow_history['edit_workflow'][-1]['comment']) hosting_subscription2.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_create_upgrade_decision_closed_computer(self): def test_alarm_create_upgrade_decision_closed_computer(self):
computer = self._makeComputer(self.new_id) computer = self._makeComputer(allocation_scope='close/oudtated')[0]
computer.edit(allocation_scope = 'close/oudtated') computer2 = self._makeComputer(allocation_scope='close/maintenance')[0]
computer2 = self._makeComputer(self.generateNewId())
computer2.edit(allocation_scope = 'close/maintenance')
self.tic() self.tic()
self._simulateScript('Computer_checkAndCreateUpgradeDecision') self._simulateScript('Computer_checkAndCreateUpgradeDecision', 'True')
try: try:
self.portal.portal_alarms.slapos_pdm_computer_create_upgrade_decision.\ self.portal.portal_alarms.slapos_pdm_computer_create_upgrade_decision.\
activeSense() activeSense()
......
...@@ -100,24 +100,28 @@ ...@@ -100,24 +100,28 @@
</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>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>validate</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>validate</string> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>validated</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>validated</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</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