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.
import transaction
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
from Products.ERP5Type.tests.utils import createZODBPythonScript
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):
self._makeTree()
preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(True)
self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try:
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense()
self.tic()
finally:
self._dropSoftwareInstance_requestValidationPayment()
self.assertEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
script_name = "SoftwareInstance_requestValidationPayment"
alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self._test_alarm(
alarm, self.software_instance, script_name)
def test_alarm_slave_instance_unallocated(self):
self._makeSlaveTree()
preference = self.portal.portal_preferences.getActiveSystemPreference()
preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(True)
self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try:
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense()
self.tic()
finally:
self._dropSoftwareInstance_requestValidationPayment()
self.assertEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
script_name = "SoftwareInstance_requestValidationPayment"
alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self._test_alarm(
alarm, self.software_instance, script_name)
def test_alarm_software_instance_unallocated_disable_cloud_contract(self):
self._makeTree()
......@@ -63,32 +33,24 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by S
preference.setPreferredCloudContractEnabled(False)
self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try:
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense()
self.tic()
finally:
self._dropSoftwareInstance_requestValidationPayment()
self.assertNotEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
script_name = "SoftwareInstance_requestValidationPayment"
alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self._test_alarm_not_visited(
alarm, self.software_instance, script_name)
def test_alarm_slave_instance_unallocated_disable_cloud_contract(self):
self._makeSlaveTree()
preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(False)
self.tic()
self.clearCache()
self._simulateSoftwareInstance_requestValidationPayment()
try:
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense()
self.tic()
finally:
self._dropSoftwareInstance_requestValidationPayment()
self.assertNotEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
script_name = "SoftwareInstance_requestValidationPayment"
alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self._test_alarm_not_visited(
alarm, self.software_instance, script_name)
def test_alarm_software_instance_allocated(self):
self._makeTree()
......@@ -98,30 +60,39 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by S
self._makeComputer()
self.software_instance.setAggregate(self.partition.getRelativeUrl())
self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try:
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense()
self.tic()
finally:
self._dropSoftwareInstance_requestValidationPayment()
self.assertNotEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
script_name = "SoftwareInstance_requestValidationPayment"
alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self._test_alarm_not_visited(
alarm, self.software_instance, script_name)
def test_alarm_slave_instance_allocated(self):
self._makeSlaveTree()
preference = self.portal.portal_preferences.getActiveSystemPreference()
preference.setPreferredCloudContractEnabled(True)
self.tic()
self._makeComputer()
self.software_instance.setAggregate(self.partition.getRelativeUrl())
self.tic()
self._simulateSoftwareInstance_requestValidationPayment()
try:
self.portal.portal_alarms.slapos_contract_request_validation_payment.activeSense()
self.tic()
finally:
self._dropSoftwareInstance_requestValidationPayment()
self.assertNotEqual(
'Visited by SoftwareInstance_requestValidationPayment',
self.software_instance.workflow_history['edit_workflow'][-1]['comment'])
script_name = "SoftwareInstance_requestValidationPayment"
alarm = self.portal.portal_alarms.slapos_contract_request_validation_payment
self._test_alarm_not_visited(
alarm, self.software_instance, script_name)
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