Commit 275b9026 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting/testSlapOSContractAlarm: Clean up test for Contract alarm

    It was rewritten to use a simplified shared API from the Test Mixin
parent 0dda8b83
# 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 TestSlapOSRequestValidationPayment(SlapOSTestCaseMixin): class TestSlapOSRequestValidationPayment(SlapOSTestCaseMixin):
def _makeSlaveTree(self, requested_template_id='template_slave_instance'):
SlapOSTestCaseMixin.\
_makeTree(self, requested_template_id=requested_template_id)
def _simulateSoftwareInstance_requestValidationPayment(self):
script_name = 'SoftwareInstance_requestValidationPayment'
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 SoftwareInstance_requestValidationPayment') """ )
transaction.commit()
def _dropSoftwareInstance_requestValidationPayment(self):
script_name = 'SoftwareInstance_requestValidationPayment'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm_software_instance_unallocated(self): def test_alarm_software_instance_unallocated(self):
self._makeTree() self._makeTree()
preference = self.portal.portal_preferences.getActiveSystemPreference() preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(True) preference.setPreferredCloudContractEnabled(True)
self.tic() self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try: script_name = "SoftwareInstance_requestValidationPayment"
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense() alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self.tic()
finally: self._test_alarm(
self._dropSoftwareInstance_requestValidationPayment() alarm, self.software_instance, script_name)
self.assertEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_slave_instance_unallocated(self): def test_alarm_slave_instance_unallocated(self):
self._makeSlaveTree() self._makeSlaveTree()
preference = self.portal.portal_preferences.getActiveSystemPreference() preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(True) preference.setPreferredCloudContractEnabled(True)
self.tic() self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try: script_name = "SoftwareInstance_requestValidationPayment"
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense() alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self.tic()
finally: self._test_alarm(
self._dropSoftwareInstance_requestValidationPayment() alarm, self.software_instance, script_name)
self.assertEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_software_instance_unallocated_disable_cloud_contract(self): def test_alarm_software_instance_unallocated_disable_cloud_contract(self):
self._makeTree() self._makeTree()
...@@ -63,32 +33,24 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by S ...@@ -63,32 +33,24 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by S
preference.setPreferredCloudContractEnabled(False) preference.setPreferredCloudContractEnabled(False)
self.tic() self.tic()
self._simulateSoftwareInstance_requestValidationPayment() script_name = "SoftwareInstance_requestValidationPayment"
try: alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense()
self.tic() self._test_alarm_not_visited(
finally: alarm, self.software_instance, script_name)
self._dropSoftwareInstance_requestValidationPayment()
self.assertNotEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_slave_instance_unallocated_disable_cloud_contract(self): def test_alarm_slave_instance_unallocated_disable_cloud_contract(self):
self._makeSlaveTree() self._makeSlaveTree()
preference = self.portal.portal_preferences.getActiveSystemPreference() preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(False) preference.setPreferredCloudContractEnabled(False)
self.tic() self.tic()
self.clearCache()
script_name = "SoftwareInstance_requestValidationPayment"
self._simulateSoftwareInstance_requestValidationPayment() alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
try:
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense() self._test_alarm_not_visited(
self.tic() alarm, self.software_instance, script_name)
finally:
self._dropSoftwareInstance_requestValidationPayment()
self.assertNotEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_software_instance_allocated(self): def test_alarm_software_instance_allocated(self):
self._makeTree() self._makeTree()
...@@ -98,30 +60,39 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by S ...@@ -98,30 +60,39 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by S
self._makeComputer() self._makeComputer()
self.software_instance.setAggregate(self.partition.getRelativeUrl()) self.software_instance.setAggregate(self.partition.getRelativeUrl())
self.tic() self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try: script_name = "SoftwareInstance_requestValidationPayment"
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense() alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self.tic()
finally: self._test_alarm_not_visited(
self._dropSoftwareInstance_requestValidationPayment() alarm, self.software_instance, script_name)
self.assertNotEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_slave_instance_allocated(self): def test_alarm_slave_instance_allocated(self):
self._makeSlaveTree() self._makeSlaveTree()
preference = self.portal.portal_preferences.getActiveSystemPreference() preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(True) preference.setPreferredCloudContractEnabled(True)
self.tic() self.tic()
self._makeComputer() self._makeComputer()
self.software_instance.setAggregate(self.partition.getRelativeUrl()) self.software_instance.setAggregate(self.partition.getRelativeUrl())
self.tic() self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try: script_name = "SoftwareInstance_requestValidationPayment"
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense() alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self.tic()
finally: self._test_alarm_not_visited(
self._dropSoftwareInstance_requestValidationPayment() alarm, self.software_instance, script_name)
self.assertNotEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
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