Commit ef8287c6 authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: lint test

parent 5121d58b
...@@ -36,7 +36,9 @@ class TestCRMSkinsMixin(SlapOSTestCaseMixinWithAbort): ...@@ -36,7 +36,9 @@ class TestCRMSkinsMixin(SlapOSTestCaseMixinWithAbort):
def afterSetUp(self): def afterSetUp(self):
SlapOSTestCaseMixinWithAbort.afterSetUp(self) SlapOSTestCaseMixinWithAbort.afterSetUp(self)
self.person = self.makePerson(new_id=self.new_id, index=0, user=0) self.project = self.addProject()
self.person = self.makePerson(self.project, new_id=self.new_id,
index=0, user=0)
def _cancelTestSupportRequestList(self, title="%"): def _cancelTestSupportRequestList(self, title="%"):
for support_request in self.portal.portal_catalog( for support_request in self.portal.portal_catalog(
...@@ -87,7 +89,7 @@ class TestCRMSkinsMixin(SlapOSTestCaseMixinWithAbort): ...@@ -87,7 +89,7 @@ class TestCRMSkinsMixin(SlapOSTestCaseMixinWithAbort):
def _makeSoftwareInstallation(self): def _makeSoftwareInstallation(self):
self._makeComputeNode() self._makeComputeNode(self.project)
software_installation = self.portal\ software_installation = self.portal\
.software_installation_module.template_software_installation\ .software_installation_module.template_software_installation\
.Base_createCloneDocument(batch_mode=1) .Base_createCloneDocument(batch_mode=1)
...@@ -156,6 +158,639 @@ class TestSlapOSSupportRequestModule_getMonitoringUrlList(TestCRMSkinsMixin): ...@@ -156,6 +158,639 @@ class TestSlapOSSupportRequestModule_getMonitoringUrlList(TestCRMSkinsMixin):
self.tic() self.tic()
self.assertNotEqual(instance_tree.getSuccessorList(), []) self.assertNotEqual(instance_tree.getSuccessorList(), [])
class TestSlapOSComputeNode_getTicketRelatedList(TestCRMSkinsMixin):
def test_getTicketRelatedList_support_request_related_to_allocated_instance(self):
document = self._makeComputeNode(self.project)[0]
self._makeComplexComputeNode(self.project)
ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id)
ticket.setAggregateValue(self.start_requested_software_instance.getSpecialiseValue())
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.submit()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.validate()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.suspend()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.invalidate()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
def test_getTicketRelatedList_support_request_related_to_compute_node(self):
document = self._makeComputeNode(self.project)[0]
ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id)
ticket.setAggregateValue(document)
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.submit()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.validate()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.suspend()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.invalidate()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
def test_getTicketRelatedList_cancelled_support_request_related_to_allocated_instance(self):
document = self._makeComputeNode(self.project)[0]
self._makeComplexComputeNode(self.project)
ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id)
ticket.setAggregateValue(self.start_requested_software_instance.getSpecialiseValue())
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.submit()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.cancel()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
def test_getTicketRelatedList_cancelled_support_request_related_to_compute_node(self):
document = self._makeComputeNode(self.project)[0]
ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id)
ticket.setAggregateValue(document)
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.submit()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.cancel()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
def test_getTicketRelatedList_upgrade_decision_related_to_allocated_instance(self):
document = self._makeComputeNode(self.project)[0]
self._makeComplexComputeNode(self.project)
def newUpgradeDecision():
ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id)
ticket.immediateReindexObject()
return ticket
ticket = newUpgradeDecision()
ticket.newContent(
portal_type="Upgrade Decision Line"
).setAggregateValue(
self.start_requested_software_instance.getSpecialiseValue())
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.plan()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.confirm()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.start()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.stop()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.deliver()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
def test_getTicketRelatedList_upgrade_decision_related_to_compute_node(self):
document = self._makeComputeNode(self.project)[0]
def newUpgradeDecision():
ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id)
ticket.immediateReindexObject()
return ticket
ticket = newUpgradeDecision()
ticket.newContent(
portal_type="Upgrade Decision Line"
).setAggregateValue(document)
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.plan()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.confirm()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.start()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.stop()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.deliver()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
def test_getTicketRelatedList_cancelled_upgrade_decision_to_allocated_instance(self):
document = self._makeComputeNode(self.project)[0]
self._makeComplexComputeNode(self.project)
def newUpgradeDecision():
ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id)
ticket.immediateReindexObject()
return ticket
ticket = newUpgradeDecision()
ticket.newContent(
portal_type="Upgrade Decision Line"
).setAggregateValue(
self.start_requested_software_instance.getSpecialiseValue())
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.cancel()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
def test_getTicketRelatedList_cancelled_upgrade_decision_to_computer_node(self):
document = self._makeComputeNode(self.project)[0]
def newUpgradeDecision():
ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id)
ticket.immediateReindexObject()
return ticket
ticket = newUpgradeDecision()
ticket.newContent(
portal_type="Upgrade Decision Line"
).setAggregateValue(document)
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.cancel()
ticket.immediateReindexObject()
open_related_ticket_list = document.ComputeNode_getTicketRelatedList()
self.assertEqual(len(open_related_ticket_list), 0)
class TestSlapOSBase_getOpenRelatedTicketList(TestCRMSkinsMixin):
def test_getOpenRelatedTicketList_support_request_related_to_compute_node(self):
self._test_getOpenRelatedTicketList_support_request_related(
self._makeComputeNode(self.project)[0])
def test_getOpenRelatedTicketList_support_request_related_to_instance_tree(self):
self._test_getOpenRelatedTicketList_support_request_related(
self._makeInstanceTree())
def _test_getOpenRelatedTicketList_support_request_related(self, document):
ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id)
ticket.setAggregateValue(document)
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.submit()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.validate()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.suspend()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.invalidate()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
def test_getOpenRelatedTicketList_cancelled_support_request_related_to_compute_node(self):
self._test_getOpenRelatedTicketList_cancelled_support_request_related(
self._makeComputeNode(self.project)[0])
def test_getOpenRelatedTicketList_cancelled_support_request_related_to_instance_tree(self):
self._test_getOpenRelatedTicketList_cancelled_support_request_related(
self._makeInstanceTree())
def _test_getOpenRelatedTicketList_cancelled_support_request_related(self, document):
ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id)
ticket.setAggregateValue(document)
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.submit()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.cancel()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 0)
def test_getOpenRelatedTicketList_upgrade_decision_related_to_compute_node(self):
self._test_getOpenRelatedTicketList_upgrade_decision_related(
self._makeComputeNode(self.project)[0])
def test_getOpenRelatedTicketList_upgrade_decision_related_to_instance_tree(self):
self._test_getOpenRelatedTicketList_upgrade_decision_related(
self._makeInstanceTree())
def _test_getOpenRelatedTicketList_upgrade_decision_related(self, document):
def newUpgradeDecision():
ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id)
ticket.immediateReindexObject()
return ticket
ticket = newUpgradeDecision()
ticket.newContent(
portal_type="Upgrade Decision Line"
).setAggregateValue(document)
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.plan()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.confirm()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.start()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.stop()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
ticket.deliver()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 1)
self.assertEqual(open_related_ticket_list[0].getUid(), ticket.getUid())
def test_getOpenRelatedTicketList_cancelled_upgrade_decision_related_to_compute_node(self):
self._test_getOpenRelatedTicketList_cancelled_upgrade_decision_related(
self._makeComputeNode(self.project)[0])
def test_getOpenRelatedTicketList_cancelled_upgrade_decision_related_to_instance_tree(self):
self._test_getOpenRelatedTicketList_cancelled_upgrade_decision_related(
self._makeInstanceTree())
def _test_getOpenRelatedTicketList_cancelled_upgrade_decision_related(self, document):
def newUpgradeDecision():
ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id)
ticket.immediateReindexObject()
return ticket
ticket = newUpgradeDecision()
ticket.newContent(
portal_type="Upgrade Decision Line"
).setAggregateValue(document)
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
# Not indexed yet
self.assertEqual(len(open_related_ticket_list), 0)
self.tic()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 0)
ticket.cancel()
ticket.immediateReindexObject()
open_related_ticket_list = document.Base_getOpenRelatedTicketList()
self.assertEqual(len(open_related_ticket_list), 0)
class TestSlapOSComputeNode_notifyWrongAllocationScope(TestCRMSkinsMixin):
def afterSetUp(self):
TestCRMSkinsMixin.afterSetUp(self)
self.project = self.addProject()
self._cancelTestSupportRequestList(title="%%TESTCOMPT-%")
def _getGeneratedSupportRequest(self, compute_node):
request_title = '%%We have changed allocation scope for %s' % \
compute_node.getReference()
support_request = self.portal.portal_catalog.getResultValue(
portal_type = 'Support Request',
title = request_title,
simulation_state = 'suspended',
default_aggregate_uid = compute_node.getUid()
)
return support_request
def _makeNotificationMessage(self, reference):
notification_message = self.portal.notification_message_module.newContent(
portal_type="Notification Message",
title='We have changed allocation scope for %s' % reference,
text_content='Test NM content<br/>%s<br/>' % reference,
content_type='text/html',
)
return notification_message.getRelativeUrl()
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0')
@simulate('NotificationTool_getDocumentValue',
'reference=None',
'assert reference == "slapos-crm-compute_node_allocation_scope.notification"\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["test_ComputeNodeNotAllowedAllocationScope_OpenPublic"])')
def test_ComputeNodeNotAllowedAllocationScope_OpenPublic(self):
compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(self.project, user=0))[0]
person = compute_node.getSourceAdministrationValue()
self.portal.REQUEST['test_ComputeNodeNotAllowedAllocationScope_OpenPublic'] = \
self._makeNotificationMessage(compute_node.getReference())
compute_node.edit(allocation_scope='open/public')
ticket = compute_node.ComputeNode_checkAndUpdateAllocationScope()
self.tic()
self.assertEqual(compute_node.getAllocationScope(), 'open/personal')
#ticket = self._getGeneratedSupportRequest(compute_node)
self.assertNotEqual(None, ticket)
self.assertEqual(ticket.getSimulationState(), 'suspended')
event_list = ticket.getFollowUpRelatedValueList()
self.assertEqual(len(event_list), 1)
event = event_list[0]
self.assertEqual(event.getTitle(),
'Allocation scope of %s changed to %s' % (compute_node.getReference(), 'open/personal'))
self.assertIn(compute_node.getReference(), event.getTextContent())
self.assertEqual(event.getSource(), person.getRelativeUrl())
self.assertEqual(event.getDestination(), ticket.getSourceSection())
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0')
@simulate('NotificationTool_getDocumentValue',
'reference=None',
'assert reference == "slapos-crm-compute_node_allocation_scope.notification"\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["test_ComputeNodeNotAllowedAllocationScope_OpenFriend"])')
def test_ComputeNodeNotAllowedAllocationScope_OpenFriend(self):
compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(self.project, user=0))[0]
person = compute_node.getSourceAdministrationValue()
self.portal.REQUEST['test_ComputeNodeNotAllowedAllocationScope_OpenFriend'] = \
self._makeNotificationMessage(compute_node.getReference())
friend_person = self.makePerson(self.project)
compute_node.edit(allocation_scope='open/friend',
destination_section=friend_person.getRelativeUrl())
ticket = compute_node.ComputeNode_checkAndUpdateAllocationScope()
self.tic()
self.assertEqual(compute_node.getAllocationScope(), 'open/personal')
self.assertEqual(ticket.getSimulationState(), 'suspended')
event_list = ticket.getFollowUpRelatedValueList()
self.assertEqual(len(event_list), 1)
event = event_list[0]
self.assertEqual(event.getTitle(),
'Allocation scope of %s changed to %s' % (compute_node.getReference(), 'open/personal'))
self.assertIn(compute_node.getReference(), event.getTextContent())
self.assertEqual(event.getSource(), person.getRelativeUrl())
self.assertEqual(event.getDestination(), ticket.getSourceSection())
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0')
@simulate('ComputeNode_hasContactedRecently', '*args, **kwargs','return False')
@simulate('NotificationTool_getDocumentValue',
'reference=None',
'assert reference == "slapos-crm-compute-node-allocation-scope-closed.notification"\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["test_ComputeNodeToCloseAllocationScope_OpenPersonal"])')
def test_ComputeNodeToCloseAllocationScope_OpenPersonal(self):
compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(self.project, user=0))[0]
person = compute_node.getSourceAdministrationValue()
target_allocation_scope = 'close/outdated'
self.portal.REQUEST['test_ComputeNodeToCloseAllocationScope_OpenPersonal'] = \
self._makeNotificationMessage(compute_node.getReference())
compute_node.edit(allocation_scope='open/personal')
support_request = compute_node.ComputeNode_checkAndUpdatePersonalAllocationScope()
self.tic()
self.assertEqual('suspended', support_request.getSimulationState())
self.assertEqual(compute_node.getAllocationScope(), target_allocation_scope)
event_list = support_request.getFollowUpRelatedValueList()
self.assertEqual(len(event_list), 1)
event = event_list[0]
self.assertEqual(event.getTitle(),
'Allocation scope of %s changed to %s' % \
(compute_node.getReference(), target_allocation_scope))
self.assertIn(compute_node.getReference(), event.getTextContent())
self.assertEqual(event.getSource(), person.getRelativeUrl())
self.assertEqual(event.getDestination(), support_request.getSourceSection())
def test_ComputeNodeNormalAllocationScope_OpenPersonal(self):
compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(self.project, user=0))[0]
person = compute_node.getSourceAdministrationValue()
self._updatePersonAssignment(person, 'role/service_provider')
compute_node.edit(allocation_scope='open/personal')
compute_node.ComputeNode_checkAndUpdateAllocationScope()
self.tic()
self.assertEqual(compute_node.getAllocationScope(), 'open/personal')
def test_ComputeNodeAllowedAllocationScope_OpenPublic(self):
compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(self.project, user=0))[0]
person = compute_node.getSourceAdministrationValue()
self._updatePersonAssignment(person, 'role/service_provider')
compute_node.edit(allocation_scope='open/public')
compute_node.ComputeNode_checkAndUpdateAllocationScope()
self.tic()
self.assertEqual(compute_node.getAllocationScope(), 'open/public')
def test_ComputeNodeAllowedAllocationScope_OpenFriend(self):
compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(self.project, user=0))[0]
friend_person = self.makePerson(self.project)
person = compute_node.getSourceAdministrationValue()
self._updatePersonAssignment(person, 'role/service_provider')
compute_node.edit(allocation_scope='open/friend',
destination_section=friend_person.getRelativeUrl())
compute_node.ComputeNode_checkAndUpdateAllocationScope()
self.tic()
self.assertEqual(compute_node.getAllocationScope(), 'open/friend')
class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
def createSPL(self, compute_node): def createSPL(self, compute_node):
...@@ -181,14 +816,14 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): ...@@ -181,14 +816,14 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
return delivery return delivery
def test_ComputeNode_hasContactedRecently_newly_created(self): def test_ComputeNode_hasContactedRecently_newly_created(self):
compute_node = self._makeComputeNode()[0] compute_node = self._makeComputeNode(self.project)[0]
self.tic() self.tic()
has_contacted = compute_node.ComputeNode_hasContactedRecently() has_contacted = compute_node.ComputeNode_hasContactedRecently()
self.assertTrue(has_contacted) self.assertTrue(has_contacted)
@simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32') @simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32')
def test_ComputeNode_hasContactedRecently_no_data(self): def test_ComputeNode_hasContactedRecently_no_data(self):
compute_node = self._makeComputeNode()[0] compute_node = self._makeComputeNode(self.project)[0]
self.tic() self.tic()
compute_node.getCreationDate = self.portal.ComputeNode_getCreationDate compute_node.getCreationDate = self.portal.ComputeNode_getCreationDate
...@@ -197,7 +832,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): ...@@ -197,7 +832,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
@simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32') @simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32')
def test_ComputeNode_hasContactedRecently_memcached(self): def test_ComputeNode_hasContactedRecently_memcached(self):
compute_node = self._makeComputeNode()[0] compute_node = self._makeComputeNode(self.project)[0]
compute_node.setAccessStatus("") compute_node.setAccessStatus("")
self.tic() self.tic()
...@@ -208,7 +843,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): ...@@ -208,7 +843,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
@simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32') @simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32')
def test_ComputeNode_hasContactedRecently_memcached_oudated_no_spl(self): def test_ComputeNode_hasContactedRecently_memcached_oudated_no_spl(self):
compute_node = self._makeComputeNode()[0] compute_node = self._makeComputeNode(self.project)[0]
try: try:
self.pinDateTime(DateTime()-32) self.pinDateTime(DateTime()-32)
compute_node.setAccessStatus("") compute_node.setAccessStatus("")
...@@ -224,7 +859,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): ...@@ -224,7 +859,7 @@ class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
@simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32') @simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32')
def test_ComputeNode_hasContactedRecently_memcached_oudated_with_spl(self): def test_ComputeNode_hasContactedRecently_memcached_oudated_with_spl(self):
compute_node = self._makeComputeNode()[0] compute_node = self._makeComputeNode(self.project)[0]
try: try:
self.pinDateTime(DateTime()-32) self.pinDateTime(DateTime()-32)
compute_node.setAccessStatus("") compute_node.setAccessStatus("")
...@@ -243,13 +878,14 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin): ...@@ -243,13 +878,14 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin):
def afterSetUp(self): def afterSetUp(self):
TestCRMSkinsMixin.afterSetUp(self) TestCRMSkinsMixin.afterSetUp(self)
self.project = self.addProject()
self._cancelTestSupportRequestList() self._cancelTestSupportRequestList()
self.clearCache() self.clearCache()
def test_ERP5Site_isSupportRequestCreationClosed(self): def test_ERP5Site_isSupportRequestCreationClosed(self):
person = self.makePerson(user=0) person = self.makePerson(self.project, user=0)
other_person = self.makePerson(user=0) other_person = self.makePerson(self.project, user=0)
url = person.getRelativeUrl() url = person.getRelativeUrl()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url)) self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed()) self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed())
...@@ -284,7 +920,7 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin): ...@@ -284,7 +920,7 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin):
other_person.getRelativeUrl())) other_person.getRelativeUrl()))
def test_ERP5Site_isSupportRequestCreationClosed_suspended_state(self): def test_ERP5Site_isSupportRequestCreationClosed_suspended_state(self):
person = self.makePerson(user=0) person = self.makePerson(self.project, user=0)
url = person.getRelativeUrl() url = person.getRelativeUrl()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url)) self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed()) self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed())
...@@ -308,7 +944,7 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin): ...@@ -308,7 +944,7 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin):
def test_ERP5Site_isSupportRequestCreationClosed_nonmonitoring(self): def test_ERP5Site_isSupportRequestCreationClosed_nonmonitoring(self):
person = self.makePerson(user=0) person = self.makePerson(self.project, user=0)
url = person.getRelativeUrl() url = person.getRelativeUrl()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url)) self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed()) self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed())
...@@ -339,6 +975,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -339,6 +975,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
def afterSetUp(self): def afterSetUp(self):
TestCRMSkinsMixin.afterSetUp(self) TestCRMSkinsMixin.afterSetUp(self)
self.project = self.addProject()
self._cancelTestSupportRequestList("% TESTCOMPT-%") self._cancelTestSupportRequestList("% TESTCOMPT-%")
def _makeNotificationMessage(self, reference): def _makeNotificationMessage(self, reference):
...@@ -362,7 +999,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -362,7 +999,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0')
def test_ComputeNode_checkState_call_support_request(self): def test_ComputeNode_checkState_call_support_request(self):
compute_node = self._makeComputeNode(owner=self.makePerson(user=0))[0] compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(user=0))[0]
try: try:
d = DateTime() - 1.1 d = DateTime() - 1.1
self.pinDateTime(d) self.pinDateTime(d)
...@@ -381,7 +1018,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -381,7 +1018,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0')
def test_ComputeNode_checkState_empty_cache(self): def test_ComputeNode_checkState_empty_cache(self):
compute_node = self._makeComputeNode(owner=self.makePerson(user=0))[0] compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(user=0))[0]
compute_node_support_request = compute_node.ComputeNode_checkState() compute_node_support_request = compute_node.ComputeNode_checkState()
compute_node_support_request = compute_node.ComputeNode_checkState() compute_node_support_request = compute_node.ComputeNode_checkState()
...@@ -398,7 +1035,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -398,7 +1035,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
'return context.restrictedTraverse(' \ 'return context.restrictedTraverse(' \
'context.REQUEST["test_ComputeNode_checkState_notify"])') 'context.REQUEST["test_ComputeNode_checkState_notify"])')
def test_ComputeNode_checkState_notify(self): def test_ComputeNode_checkState_notify(self):
compute_node = self._makeComputeNode(owner=self.makePerson(user=0))[0] compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(user=0))[0]
person = compute_node.getSourceAdministrationValue() person = compute_node.getSourceAdministrationValue()
try: try:
...@@ -434,7 +1071,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -434,7 +1071,7 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
'return context.restrictedTraverse(' \ 'return context.restrictedTraverse(' \
'context.REQUEST["test_ComputeNode_checkState_empty_cache_notify"])') 'context.REQUEST["test_ComputeNode_checkState_empty_cache_notify"])')
def test_ComputeNode_checkState_empty_cache_notify(self): def test_ComputeNode_checkState_empty_cache_notify(self):
compute_node = self._makeComputeNode(owner=self.makePerson(user=0))[0] compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(user=0))[0]
person = compute_node.getSourceAdministrationValue() person = compute_node.getSourceAdministrationValue()
self.portal.REQUEST['test_ComputeNode_checkState_empty_cache_notify'] = \ self.portal.REQUEST['test_ComputeNode_checkState_empty_cache_notify'] = \
...@@ -462,8 +1099,8 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -462,8 +1099,8 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
'return context.restrictedTraverse(' \ 'return context.restrictedTraverse(' \
'context.REQUEST["test_ComputeNode_checkState_stalled_instance"])') 'context.REQUEST["test_ComputeNode_checkState_stalled_instance"])')
def test_ComputeNode_checkState_stalled_instance(self): def test_ComputeNode_checkState_stalled_instance(self):
compute_node = self._makeComputeNode(owner=self.makePerson(user=0))[0] compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(user=0))[0]
self._makeComplexComputeNode() self._makeComplexComputeNode(self.project)
person = compute_node.getSourceAdministrationValue() person = compute_node.getSourceAdministrationValue()
...@@ -495,6 +1132,48 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -495,6 +1132,48 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
self.assertEqual(event.getSource(), person.getRelativeUrl()) self.assertEqual(event.getSource(), person.getRelativeUrl())
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0')
@simulate('NotificationTool_getDocumentValue',
'reference=None',
'assert reference == "slapos-crm-compute_node_check_stalled_software_state.notification", reference\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["test_ComputeNode_checkState_stalled_software"])')
def test_ComputeNode_checkState_stalled_software(self):
compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(user=0))[0]
self._makeComplexComputeNode(self.project)
person = compute_node.getSourceAdministrationValue()
self.portal.REQUEST['test_ComputeNode_checkState_stalled_software'] = \
self._makeNotificationMessage(compute_node.getReference())
# Computer is getting access, also internal instance
compute_node.setAccessStatus("")
self.start_requested_software_instance.setAccessStatus("")
try:
self.pinDateTime(DateTime()-1.1)
self.start_requested_software_installation.setAccessStatus("")
finally:
self.unpinDateTime()
compute_node.ComputeNode_checkState()
self.tic()
ticket_title = "[MONITORING] Compute Node %s has a stalled software process" % compute_node.getReference()
ticket = self._getGeneratedSupportRequest(compute_node.getUid(), ticket_title)
self.assertNotEqual(ticket, None)
event_list = ticket.getFollowUpRelatedValueList()
self.assertEqual(len(event_list), 1)
event = event_list[0]
self.assertEqual(event.getTitle(), ticket.getTitle())
self.assertIn(compute_node.getReference(), event.getTextContent())
self.assertEqual(event.getDestination(), ticket.getSourceSection())
self.assertEqual(event.getSource(), person.getRelativeUrl())
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None', 'reference=None',
...@@ -502,8 +1181,8 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin): ...@@ -502,8 +1181,8 @@ class TestSlapOSComputeNode_CheckState(TestCRMSkinsMixin):
'return context.restrictedTraverse(' \ 'return context.restrictedTraverse(' \
'context.REQUEST["test_ComputeNode_checkState_stalled_instance"])') 'context.REQUEST["test_ComputeNode_checkState_stalled_instance"])')
def test_ComputeNode_checkState_stalled_instance_single(self): def test_ComputeNode_checkState_stalled_instance_single(self):
compute_node = self._makeComputeNode(owner=self.makePerson(user=0))[0] compute_node = self._makeComputeNode(self.project)[0]#, owner=self.makePerson(user=0))[0]
self._makeComplexComputeNode() self._makeComplexComputeNode(self.project)
person = compute_node.getSourceAdministrationValue() person = compute_node.getSourceAdministrationValue()
...@@ -548,7 +1227,7 @@ class TestSlapOSInstanceTree_createSupportRequestEvent(SlapOSTestCaseMixin): ...@@ -548,7 +1227,7 @@ class TestSlapOSInstanceTree_createSupportRequestEvent(SlapOSTestCaseMixin):
return notification_message.getRelativeUrl() return notification_message.getRelativeUrl()
def _makeInstanceTree(self): def _makeInstanceTree(self):
person = self.makePerson(user=1) person = self.makePerson(self.project, user=1)
instance_tree = self.portal\ instance_tree = self.portal\
.instance_tree_module.template_instance_tree\ .instance_tree_module.template_instance_tree\
.Base_createCloneDocument(batch_mode=1) .Base_createCloneDocument(batch_mode=1)
...@@ -635,7 +1314,7 @@ class TestSlapOSInstanceTree_createSupportRequestEvent(SlapOSTestCaseMixin): ...@@ -635,7 +1314,7 @@ class TestSlapOSInstanceTree_createSupportRequestEvent(SlapOSTestCaseMixin):
class TestSlapOSHasError(SlapOSTestCaseMixin): class TestSlapOSHasError(SlapOSTestCaseMixin):
def _makeSoftwareRelease(self, software_release_url=None): def makeSoftwareRelease(self, software_release_url=None):
software_release = self.portal.software_release_module\ software_release = self.portal.software_release_module\
.template_software_release.Base_createCloneDocument(batch_mode=1) .template_software_release.Base_createCloneDocument(batch_mode=1)
...@@ -714,7 +1393,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -714,7 +1393,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self.generateNewSoftwareReleaseUrl()) self.generateNewSoftwareReleaseUrl())
instance = instance_tree.getSuccessorValue() instance = instance_tree.getSuccessorValue()
self._makeComputeNode() self._makeComputeNode(self.project)
self._makeComputePartitionList() self._makeComputePartitionList()
instance.setErrorStatus("") instance.setErrorStatus("")
...@@ -729,8 +1408,8 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -729,8 +1408,8 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self.assertEqual(instance.SoftwareInstance_hasReportedError(), None) self.assertEqual(instance.SoftwareInstance_hasReportedError(), None)
def test_SoftwareInstallation_hasReportedError(self): def test_SoftwareInstallation_hasReportedError(self):
software_release = self._makeSoftwareRelease() software_release = self.makeSoftwareRelease()
self._makeComputeNode() self._makeComputeNode(self.project)
installation = self._makeSoftwareInstallation( installation = self._makeSoftwareInstallation(
software_release.getUrlString() software_release.getUrlString()
) )
...@@ -776,7 +1455,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -776,7 +1455,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self.assertEqual(instance.getCreationDate(), date - 2) self.assertEqual(instance.getCreationDate(), date - 2)
self._makeComputeNode() self._makeComputeNode(self.project)
self._makeComputePartitionList() self._makeComputePartitionList()
instance.setAggregateValue(self.compute_node.partition1) instance.setAggregateValue(self.compute_node.partition1)
...@@ -832,7 +1511,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -832,7 +1511,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self.assertEqual(instance.getCreationDate(), date - 2) self.assertEqual(instance.getCreationDate(), date - 2)
self._makeComputeNode() self._makeComputeNode(self.project)
self._makeComputePartitionList() self._makeComputePartitionList()
instance.setAggregateValue(self.compute_node.partition1) instance.setAggregateValue(self.compute_node.partition1)
...@@ -881,7 +1560,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -881,7 +1560,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
self.assertEqual(instance.getCreationDate(), date - 2) self.assertEqual(instance.getCreationDate(), date - 2)
self._makeComputeNode() self._makeComputeNode(self.project)
self._makeComputePartitionList() self._makeComputePartitionList()
instance.setAggregateValue(self.compute_node.partition1) instance.setAggregateValue(self.compute_node.partition1)
...@@ -928,7 +1607,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin): ...@@ -928,7 +1607,7 @@ class TestSlapOSHasError(SlapOSTestCaseMixin):
instance = instance_tree.getSuccessorValue() instance = instance_tree.getSuccessorValue()
self._makeComputeNode() self._makeComputeNode(self.project)
self._makeComputePartitionList() self._makeComputePartitionList()
instance.setAggregateValue(self.compute_node.partition1) instance.setAggregateValue(self.compute_node.partition1)
...@@ -943,10 +1622,11 @@ class TestCRMPropertySheetConstraint(SlapOSTestCaseMixin): ...@@ -943,10 +1622,11 @@ class TestCRMPropertySheetConstraint(SlapOSTestCaseMixin):
def afterSetUp(self): def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self) SlapOSTestCaseMixin.afterSetUp(self)
portal = self.getPortalObject() portal = self.getPortalObject()
self.project = self.addProject()
self.ticket_trade_condition = portal.sale_trade_condition_module.slapos_ticket_trade_condition self.ticket_trade_condition = portal.sale_trade_condition_module.slapos_ticket_trade_condition
person_user = self.makePerson() person_user = self.makePerson(self.project)
self.tic() self.tic()
# Login as new user # Login as new user
...@@ -1012,7 +1692,7 @@ class TestCRMPropertySheetConstraint(SlapOSTestCaseMixin): ...@@ -1012,7 +1692,7 @@ class TestCRMPropertySheetConstraint(SlapOSTestCaseMixin):
self.assertFalse(event.checkConsistency()) self.assertFalse(event.checkConsistency())
self.assertFalse(self.support_request.checkConsistency()) self.assertFalse(self.support_request.checkConsistency())
person_user = self.makePerson() person_user = self.makePerson(self.project)
self.tic() self.tic()
event.setSource(person_user.getRelativeUrl()) event.setSource(person_user.getRelativeUrl())
...@@ -1084,8 +1764,8 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin): ...@@ -1084,8 +1764,8 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin):
support_request.SupportRequest_updateMonitoringDestroyRequestedState()) support_request.SupportRequest_updateMonitoringDestroyRequestedState())
support_request.setAggregateValue( support_request.setAggregateValue(
self._makeComputeNode(owner=self.makePerson(user=0))[0]) self._makeComputeNode(self.project)[0])#, owner=self.makePerson(user=0))[0])
support_request.setDestinationDecisionValue(self.makePerson(user=0)) support_request.setDestinationDecisionValue(self.makePerson(self.project, user=0))
self.assertEqual(None, self.assertEqual(None,
support_request.SupportRequest_updateMonitoringDestroyRequestedState()) support_request.SupportRequest_updateMonitoringDestroyRequestedState())
...@@ -1117,7 +1797,7 @@ class TestSlapOSFolder_getTicketFeedUrl(TestCRMSkinsMixin): ...@@ -1117,7 +1797,7 @@ class TestSlapOSFolder_getTicketFeedUrl(TestCRMSkinsMixin):
def _test(self, module): def _test(self, module):
self.assertRaises(ValueError, module.Folder_getTicketFeedUrl) self.assertRaises(ValueError, module.Folder_getTicketFeedUrl)
person = self.makePerson(user=1) person = self.makePerson(self.project, user=1)
self.tic() self.tic()
self.login(person.getUserId()) self.login(person.getUserId())
...@@ -1145,7 +1825,7 @@ class TestSlapOSFolder_getTicketFeedUrl(TestCRMSkinsMixin): ...@@ -1145,7 +1825,7 @@ class TestSlapOSFolder_getTicketFeedUrl(TestCRMSkinsMixin):
class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin): class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin):
def test_getSlapOSPendingTicket_support_request(self): def test_getSlapOSPendingTicket_support_request(self):
person = self.makePerson() person = self.makePerson(self.project)
ticket = self.portal.support_request_module.newContent(\ ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id, title="Test Support Request %s" % self.new_id,
destination_decision=person.getRelativeUrl()) destination_decision=person.getRelativeUrl())
...@@ -1181,7 +1861,7 @@ class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin): ...@@ -1181,7 +1861,7 @@ class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin):
self.assertEqual(len(pending_ticket_list), 0) self.assertEqual(len(pending_ticket_list), 0)
def test_getSlapOSPendingTicket_support_request_cancelled(self): def test_getSlapOSPendingTicket_support_request_cancelled(self):
person = self.makePerson() person = self.makePerson(self.project)
ticket = self.portal.support_request_module.newContent(\ ticket = self.portal.support_request_module.newContent(\
title="Test Support Request %s" % self.new_id, title="Test Support Request %s" % self.new_id,
destination_decision=person.getRelativeUrl()) destination_decision=person.getRelativeUrl())
...@@ -1215,7 +1895,7 @@ class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin): ...@@ -1215,7 +1895,7 @@ class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin):
ticket.immediateReindexObject() ticket.immediateReindexObject()
return ticket return ticket
person = self.makePerson() person = self.makePerson(self.project)
ticket = newUpgradeDecision() ticket = newUpgradeDecision()
ticket.setDestinationDecisionValue(person) ticket.setDestinationDecisionValue(person)
...@@ -1268,7 +1948,7 @@ class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin): ...@@ -1268,7 +1948,7 @@ class TestSlapOSPerson_getSlapOSPendingTicket(TestCRMSkinsMixin):
ticket.immediateReindexObject() ticket.immediateReindexObject()
return ticket return ticket
person = self.makePerson() person = self.makePerson(self.project)
ticket = newUpgradeDecision() ticket = newUpgradeDecision()
ticket.setDestinationDecisionValue(person) ticket.setDestinationDecisionValue(person)
...@@ -1304,7 +1984,7 @@ class TestSlapOSPerson_getSlapOSPendingTicketMessageTemplate(TestCRMSkinsMixin): ...@@ -1304,7 +1984,7 @@ class TestSlapOSPerson_getSlapOSPendingTicketMessageTemplate(TestCRMSkinsMixin):
'return None') 'return None')
@simulate('Person_getSlapOSPendingTicket', '*args, **kwargs','return range(99)') @simulate('Person_getSlapOSPendingTicket', '*args, **kwargs','return range(99)')
def test_getSlapOSPendingTicketMessageTemplate(self): def test_getSlapOSPendingTicketMessageTemplate(self):
person = self.makePerson() person = self.makePerson(self.project)
# Test without notification message # Test without notification message
title, message = person.Person_getSlapOSPendingTicketMessageTemplate() title, message = person.Person_getSlapOSPendingTicketMessageTemplate()
self.assertEqual(""" You have 99 pending tickets """, title) self.assertEqual(""" You have 99 pending tickets """, title)
...@@ -1328,7 +2008,7 @@ class TestSlapOSPerson_getSlapOSPendingTicketMessageTemplate(TestCRMSkinsMixin): ...@@ -1328,7 +2008,7 @@ class TestSlapOSPerson_getSlapOSPendingTicketMessageTemplate(TestCRMSkinsMixin):
'return context.restrictedTraverse(' \ 'return context.restrictedTraverse(' \
'context.REQUEST["test_getSlapOSPendingTicketMessageTemplate"])') 'context.REQUEST["test_getSlapOSPendingTicketMessageTemplate"])')
def test_getSlapOSPendingTicketMessageTemplate_with_notification_message(self): def test_getSlapOSPendingTicketMessageTemplate_with_notification_message(self):
person = self.makePerson() person = self.makePerson(self.project)
self.portal.REQUEST['test_getSlapOSPendingTicketMessageTemplate'] = \ self.portal.REQUEST['test_getSlapOSPendingTicketMessageTemplate'] = \
self._makeNotificationMessage() self._makeNotificationMessage()
...@@ -1344,7 +2024,7 @@ class TestSlapOSPerson_sendPendingTicketReminder(TestCRMSkinsMixin): ...@@ -1344,7 +2024,7 @@ class TestSlapOSPerson_sendPendingTicketReminder(TestCRMSkinsMixin):
@simulate('Person_getSlapOSPendingTicket', '*args, **kwargs','return []') @simulate('Person_getSlapOSPendingTicket', '*args, **kwargs','return []')
@simulate('Person_sendSlapOSPendingTicketNotification', '*args, **kwargs','assert False') @simulate('Person_sendSlapOSPendingTicketNotification', '*args, **kwargs','assert False')
def test_sendPendingTicketReminder(self): def test_sendPendingTicketReminder(self):
person = self.makePerson() person = self.makePerson(self.project)
# Script Person_sendSlapOSPendingTicketNotification not called # Script Person_sendSlapOSPendingTicketNotification not called
person.Person_sendPendingTicketReminder() person.Person_sendPendingTicketReminder()
...@@ -1352,7 +2032,7 @@ class TestSlapOSPerson_sendPendingTicketReminder(TestCRMSkinsMixin): ...@@ -1352,7 +2032,7 @@ class TestSlapOSPerson_sendPendingTicketReminder(TestCRMSkinsMixin):
@simulate('Person_sendSlapOSPendingTicketNotification', '*args, **kwargs', @simulate('Person_sendSlapOSPendingTicketNotification', '*args, **kwargs',
'context.REQUEST.set("test_getSlapOSPendingTicketMessageTemplate", "called")') 'context.REQUEST.set("test_getSlapOSPendingTicketMessageTemplate", "called")')
def test_sendPendingTicketReminder_positive_amount(self): def test_sendPendingTicketReminder_positive_amount(self):
person = self.makePerson() person = self.makePerson(self.project)
person.Person_sendPendingTicketReminder() person.Person_sendPendingTicketReminder()
self.assertEqual(self.portal.REQUEST["test_getSlapOSPendingTicketMessageTemplate"], self.assertEqual(self.portal.REQUEST["test_getSlapOSPendingTicketMessageTemplate"],
...@@ -1361,7 +2041,7 @@ class TestSlapOSPerson_sendPendingTicketReminder(TestCRMSkinsMixin): ...@@ -1361,7 +2041,7 @@ class TestSlapOSPerson_sendPendingTicketReminder(TestCRMSkinsMixin):
class TestSlapOSPerson_sendSlapOSPendingTicketNotification(TestCRMSkinsMixin): class TestSlapOSPerson_sendSlapOSPendingTicketNotification(TestCRMSkinsMixin):
def test_sendSlapOSPendingTicketNotification(self): def test_sendSlapOSPendingTicketNotification(self):
person = self.makePerson() person = self.makePerson(self.project)
event = person.Person_sendSlapOSPendingTicketNotification( event = person.Person_sendSlapOSPendingTicketNotification(
"TEST TITLE", "TEST TITLE",
"TEST CONTENT", "TEST CONTENT",
......
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