Commit 748aa612 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: fix InstanceTree_assertSuccessor tests

parent d3d3971d
......@@ -248,6 +248,36 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
return person_user
def addInstanceTree(self, project=None, person=None, shared=False):
# XXX supposed to replace _makeTree
if project is None:
project = self.addProject()
self.tic()
new_id = self.generateNewId()
if person is None:
person = self.makePerson(project, new_id=new_id, index=False)
person_user = person
request_kw = dict(
software_release=self.generateNewSoftwareReleaseUrl(),
software_title=self.generateNewSoftwareTitle(),
software_type=self.generateNewSoftwareType(),
instance_xml=self.generateSafeXml(),
sla_xml=self.generateEmptyXml(),
shared=shared,
state="started",
project_reference=project.getReference()
)
# As the software url does not match any service, and any trade condition
# no instance is automatically created.
# except if we fake Item_getSubscriptionStatus
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
person_user.requestSoftwareInstance(**request_kw)
return person_user.REQUEST.get('request_instance_tree')
def _makeTree(self, project, requested_template_id='template_software_instance'):
new_id = self.generateNewId()
......
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
import transaction
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin, TemporaryAlarmScript
import time
from zExceptions import Unauthorized
from DateTime import DateTime
from erp5.component.module.DateUtils import addToDate
class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(
SlapOSTestCaseMixin):
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
self.project = self.addProject()
self._makeTree(self.project)
def test_InstanceTree_assertSuccessor(self):
self.software_instance.rename(new_name=self.generateNewSoftwareTitle())
self.tic()
# check that no interaction has recreated the instance
self.assertFalse(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
self.instance_tree.InstanceTree_assertSuccessor()
self.assertTrue(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
def test_InstanceTree_assertSuccessor_stop_requested(self):
self.software_instance.rename(new_name=self.generateNewSoftwareTitle())
self.portal.portal_workflow._jumpToStateFor(self.instance_tree,
'stop_requested')
self.tic()
# check that no interaction has recreated the instance
self.assertFalse(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
self.instance_tree.InstanceTree_assertSuccessor()
self.assertTrue(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
def test_InstanceTree_assertSuccessor_destroy_requested(self):
self.software_instance.rename(new_name=self.generateNewSoftwareTitle())
self.portal.portal_workflow._jumpToStateFor(self.instance_tree,
'destroy_requested')
self.tic()
# check that no interaction has recreated the instance
self.assertFalse(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
self.instance_tree.InstanceTree_assertSuccessor()
self.assertFalse(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
def test_InstanceTree_assertSuccessor_archived(self):
self.software_instance.rename(new_name=self.generateNewSoftwareTitle())
self.instance_tree.archive()
self.tic()
# check that no interaction has recreated the instance
self.assertFalse(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
self.instance_tree.InstanceTree_assertSuccessor()
self.assertFalse(self.instance_tree.getTitle() in
self.instance_tree.getSuccessorTitleList())
class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(SlapOSTestCaseMixin):
#################################################################
# InstanceTree_assertSuccessor
#################################################################
def test_InstanceTree_assertSuccessor_alarm_orphaned(self):
instance_tree = self.portal.instance_tree_module.newContent(
portal_type='Instance Tree'
......@@ -80,21 +24,105 @@ class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(
)
def test_InstanceTree_assertSuccessor_alarm_renamed(self):
self.software_instance.edit(title=self.generateNewSoftwareTitle())
instance_tree = self.addInstanceTree()
instance_tree.getSuccessorValue().edit(title=self.generateNewSoftwareTitle())
self._test_alarm(
self.portal.portal_alarms.slapos_assert_instance_tree_successor,
self.instance_tree,
instance_tree,
'InstanceTree_assertSuccessor'
)
def test_InstanceTree_assertSuccessor_alarm_not_renamed(self):
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_assert_instance_tree_successor,
self.instance_tree,
self.addInstanceTree(),
'InstanceTree_assertSuccessor'
)
#################################################################
# InstanceTree_assertSuccessor
#################################################################
def test_InstanceTree_assertSuccessor_script_renamed(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.edit(title=self.generateNewSoftwareTitle())
self.tic()
# check that no interaction has recreated the instance
self.assertNotEqual(instance_tree.getTitle(), software_instance.getTitle())
self.assertFalse(instance_tree.getTitle() in
instance_tree.getSuccessorTitleList())
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
instance_tree.InstanceTree_assertSuccessor()
self.assertNotEqual(instance_tree.getTitle(), software_instance.getTitle())
self.assertTrue(instance_tree.getTitle() in
instance_tree.getSuccessorTitleList())
def test_InstanceTree_assertSuccessor_script_renamedAndStopped(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.edit(title=self.generateNewSoftwareTitle())
self.portal.portal_workflow._jumpToStateFor(instance_tree,
'stop_requested')
self.tic()
# check that no interaction has recreated the instance
self.assertNotEqual(instance_tree.getTitle(), software_instance.getTitle())
self.assertFalse(instance_tree.getTitle() in
instance_tree.getSuccessorTitleList())
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
instance_tree.InstanceTree_assertSuccessor()
self.assertNotEqual(instance_tree.getTitle(), software_instance.getTitle())
self.assertTrue(instance_tree.getTitle() in
instance_tree.getSuccessorTitleList())
def test_InstanceTree_assertSuccessor_script_renamedAndDestroyed(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.edit(title=self.generateNewSoftwareTitle())
self.portal.portal_workflow._jumpToStateFor(instance_tree,
'destroy_requested')
self.tic()
# check that no interaction has recreated the instance
self.assertNotEqual(instance_tree.getTitle(), software_instance.getTitle())
self.assertFalse(instance_tree.getTitle() in
instance_tree.getSuccessorTitleList())
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
instance_tree.InstanceTree_assertSuccessor()
self.assertNotEqual(instance_tree.getTitle(), software_instance.getTitle())
self.assertFalse(instance_tree.getTitle() in
instance_tree.getSuccessorTitleList())
def test_InstanceTree_assertSuccessor_script_archived(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.edit(title=self.generateNewSoftwareTitle())
instance_tree.archive()
self.tic()
# check that no interaction has recreated the instance
self.assertNotEqual(instance_tree.getTitle(), software_instance.getTitle())
self.assertFalse(instance_tree.getTitle() in
instance_tree.getSuccessorTitleList())
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
instance_tree.InstanceTree_assertSuccessor()
self.assertNotEqual(instance_tree.getTitle(), software_instance.getTitle())
self.assertFalse(instance_tree.getTitle() in
instance_tree.getSuccessorTitleList())
#################################################################
# slapos_free_compute_partition
#################################################################
class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
def afterSetUp(self):
......
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