Commit 25ff6c76 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Limit ticket creations per project

    Dont use cache to check ticket creation is closed.
    Use countResults to not require len() over the list.
parent fae625b7
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed():
# Stop process alarm if there are too many tickets
return
monitor_enabled_category = portal.restrictedTraverse( monitor_enabled_category = portal.restrictedTraverse(
"portal_categories/monitor_scope/enabled", None) "portal_categories/monitor_scope/enabled", None)
......
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed():
# Stop verification if there are too much tickets
return
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
portal_type='Instance Tree', portal_type='Instance Tree',
validation_state='validated', validation_state='validated',
......
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed():
# Stop process alarm if there are too many tickets
return
monitor_enabled_category = portal.restrictedTraverse( monitor_enabled_category = portal.restrictedTraverse(
"portal_categories/monitor_scope/enabled", None) "portal_categories/monitor_scope/enabled", None)
......
from DateTime import DateTime from DateTime import DateTime
portal = context.getPortalObject() portal = context.getPortalObject()
if (context.getMonitorScope() == "disabled") or \ if (context.getMonitorScope() == "disabled"):
portal.ERP5Site_isSupportRequestCreationClosed(): return
project = context.getFollowUpValue()
if project.Project_isSupportRequestCreationClosed():
return return
software_installation_list = portal.portal_catalog( software_installation_list = portal.portal_catalog(
......
from DateTime import DateTime from DateTime import DateTime
portal = context.getPortalObject() portal = context.getPortalObject()
if (context.getMonitorScope() == "disabled") or \ if (context.getMonitorScope() == "disabled"):
portal.ERP5Site_isSupportRequestCreationClosed(): return
project = context.getFollowUpValue()
if project.Project_isSupportRequestCreationClosed():
return return
reference = context.getReference() reference = context.getReference()
...@@ -76,8 +79,6 @@ if not should_notify: ...@@ -76,8 +79,6 @@ if not should_notify:
context.getTitle(), context.getReference(), last_contact) context.getTitle(), context.getReference(), last_contact)
if should_notify: if should_notify:
project = context.getFollowUpValue()
support_request = project.Project_createSupportRequestWithCausality( support_request = project.Project_createSupportRequestWithCausality(
ticket_title, ticket_title,
description, description,
......
from Products.ERP5Type.Cache import CachingMethod
portal = context.getPortalObject()
def isSupportRequestCreationClosed(destination_decision=None):
limit = int(portal.portal_preferences.getPreferredSupportRequestCreationLimit(5))
kw = {
'limit': limit,
'portal_type': 'Support Request',
'simulation_state': ["validated", "submitted"],
'resource__uid': portal.service_module.slapos_crm_monitoring.getUid()
}
if destination_decision:
kw['destination_decision__uid'] = context.restrictedTraverse(
destination_decision).getUid()
support_request_amount_list = context.portal_catalog(**kw)
return limit <= len(support_request_amount_list)
return CachingMethod(isSupportRequestCreationClosed,
"isSupportRequestCreationClosed",
cache_factory="erp5_content_short")(destination_decision=destination_decision)
...@@ -4,8 +4,8 @@ from erp5.component.module.DateUtils import addToDate ...@@ -4,8 +4,8 @@ from erp5.component.module.DateUtils import addToDate
instance_tree = context instance_tree = context
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed(): project = context.getFollowUpValue()
# Stop ticket creation if project.Project_isSupportRequestCreationClosed():
return return
date_check_limit = addToDate(DateTime(), to_add={'hour': -1}) date_check_limit = addToDate(DateTime(), to_add={'hour': -1})
...@@ -49,7 +49,6 @@ for instance in software_instance_list: ...@@ -49,7 +49,6 @@ for instance in software_instance_list:
else: else:
error_message = "No message!" error_message = "No message!"
project = context.getFollowUpValue()
support_request = project.Project_createSupportRequestWithCausality( support_request = project.Project_createSupportRequestWithCausality(
ticket_title, ticket_title,
description, description,
......
portal = context.getPortalObject()
assert context.getPortalType() == 'Project', "context is not a project"
limit = int(portal.portal_preferences.getPreferredSupportRequestCreationLimit(5))
kw = {
'limit': limit,
'portal_type': 'Support Request',
'simulation_state': ["validated", "submitted", "suspended"],
'source_project__uid': context.getUid(),
'resource__uid': portal.service_module.slapos_crm_monitoring.getUid()
}
return limit <= int(portal.portal_catalog.countResults(**kw)[0][0])
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>destination_decision=None, **kw</string> </value> <value> <string>**kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ERP5Site_isSupportRequestCreationClosed</string> </value> <value> <string>Project_isSupportRequestCreationClosed</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -1312,7 +1312,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort) ...@@ -1312,7 +1312,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
self._test_alarm_check_compute_node_state_selected( self._test_alarm_check_compute_node_state_selected(
allocation_scope='close/noallocation') allocation_scope='close/noallocation')
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs','return 0')
def test_ComputeNode_checkState_script_oldAccessStatus(self): def test_ComputeNode_checkState_script_oldAccessStatus(self):
compute_node, _ = self._makeComputeNode(self.addProject()) compute_node, _ = self._makeComputeNode(self.addProject())
d = DateTime() - 1.1 d = DateTime() - 1.1
...@@ -1328,7 +1328,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort) ...@@ -1328,7 +1328,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
self.assertIn(d.strftime("%Y/%m/%d %H:%M:%S"), self.assertIn(d.strftime("%Y/%m/%d %H:%M:%S"),
compute_node_support_request.getDescription()) compute_node_support_request.getDescription())
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
def test_ComputeNode_checkState_script_noAccessStatus(self): def test_ComputeNode_checkState_script_noAccessStatus(self):
compute_node, _ = self._makeComputeNode(self.addProject()) compute_node, _ = self._makeComputeNode(self.addProject())
compute_node_support_request = compute_node.ComputeNode_checkState() compute_node_support_request = compute_node.ComputeNode_checkState()
...@@ -1357,7 +1357,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort) ...@@ -1357,7 +1357,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
) )
return support_request return support_request
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_check_state.notification", reference\n' \ 'assert reference == "slapos-crm-compute_node_check_state.notification", reference\n' \
...@@ -1398,7 +1398,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort) ...@@ -1398,7 +1398,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
self.assertEqual(event.getSimulationState(), "delivered") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_check_state.notification"\n' \ 'assert reference == "slapos-crm-compute_node_check_state.notification"\n' \
...@@ -1435,7 +1435,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort) ...@@ -1435,7 +1435,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
self.assertEqual(event.getSimulationState(), "delivered") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_check_stalled_instance_state.notification", reference\n' \ 'assert reference == "slapos-crm-compute_node_check_stalled_instance_state.notification", reference\n' \
...@@ -1480,7 +1480,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort) ...@@ -1480,7 +1480,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
self.assertEqual(event.getSimulationState(), "delivered") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_check_stalled_instance_state.notification", reference\n' \ 'assert reference == "slapos-crm-compute_node_check_stalled_instance_state.notification", reference\n' \
...@@ -1574,7 +1574,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase ...@@ -1574,7 +1574,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
causality__uid=compute_node_uid causality__uid=compute_node_uid
) )
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \ 'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \
...@@ -1621,7 +1621,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase ...@@ -1621,7 +1621,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
""" """
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \ 'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \
...@@ -1667,7 +1667,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase ...@@ -1667,7 +1667,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
self.assertEqual(event.getSimulationState(), "delivered") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \ 'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \
...@@ -1695,7 +1695,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase ...@@ -1695,7 +1695,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
self.assertEqual(ticket, None) self.assertEqual(ticket, None)
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \ 'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \
...@@ -1741,7 +1741,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase ...@@ -1741,7 +1741,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
self.assertEqual(event.getSimulationState(), "delivered") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 0') @simulate('Project_isSupportRequestCreationClosed', '*args, **kwargs', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \ 'assert reference == "slapos-crm-compute_node_software_installation_state.notification", reference\n' \
...@@ -1789,7 +1789,6 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort): ...@@ -1789,7 +1789,6 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort):
return instance_tree return instance_tree
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0')
def test_InstanceTree_checkSoftwareInstanceState_alarm_validated(self): def test_InstanceTree_checkSoftwareInstanceState_alarm_validated(self):
host_sub = self._makeInstanceTree() host_sub = self._makeInstanceTree()
self.tic() self.tic()
...@@ -1797,7 +1796,6 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort): ...@@ -1797,7 +1796,6 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort):
slapos_crm_check_instance_in_error slapos_crm_check_instance_in_error
self._test_alarm(alarm, host_sub, "InstanceTree_checkSoftwareInstanceState") self._test_alarm(alarm, host_sub, "InstanceTree_checkSoftwareInstanceState")
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0')
def test_InstanceTree_checkSoftwareInstanceState_alarm_archived(self): def test_InstanceTree_checkSoftwareInstanceState_alarm_archived(self):
host_sub = self._makeInstanceTree() host_sub = self._makeInstanceTree()
host_sub.archive() host_sub.archive()
...@@ -1823,7 +1821,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort): ...@@ -1823,7 +1821,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort):
causality__uid=compute_node_uid causality__uid=compute_node_uid
) )
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0') @simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-instance-tree-instance-state.notification", reference\n' \ 'assert reference == "slapos-crm-instance-tree-instance-state.notification", reference\n' \
...@@ -1870,7 +1868,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort): ...@@ -1870,7 +1868,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort):
self.assertEqual(event.getSimulationState(), "delivered") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0') @simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
def test_InstanceTree_checkSoftwareInstanceState_script_notifyErrorTolerance(self): def test_InstanceTree_checkSoftwareInstanceState_script_notifyErrorTolerance(self):
with PinnedDateTime(self, DateTime()-1.1): with PinnedDateTime(self, DateTime()-1.1):
self._makeComputeNode(self.addProject()) self._makeComputeNode(self.addProject())
...@@ -1895,7 +1893,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort): ...@@ -1895,7 +1893,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort):
self.assertEqual(ticket, None) self.assertEqual(ticket, None)
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0') @simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-instance-tree-instance-allocation.notification", reference\n' \ 'assert reference == "slapos-crm-instance-tree-instance-allocation.notification", reference\n' \
...@@ -1942,7 +1940,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort): ...@@ -1942,7 +1940,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort):
self.assertEqual(event.getSimulationState(), "delivered") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0') @simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
def test_InstanceTree_checkSoftwareInstanceState_script_tooEarly(self): def test_InstanceTree_checkSoftwareInstanceState_script_tooEarly(self):
with PinnedDateTime(self, DateTime()): with PinnedDateTime(self, DateTime()):
self._makeComputeNode(self.addProject()) self._makeComputeNode(self.addProject())
...@@ -1966,7 +1964,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort): ...@@ -1966,7 +1964,7 @@ class TestSlapOSCrmMonitoringCheckInstanceInError(SlapOSTestCaseMixinWithAbort):
self.assertEqual(ticket, None) self.assertEqual(ticket, None)
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 1') @simulate('Project_isSupportRequestCreationClosed', '', 'return 1')
def test_InstanceTree_checkSoftwareInstanceState_script_closed(self): def test_InstanceTree_checkSoftwareInstanceState_script_closed(self):
with PinnedDateTime(self, DateTime()-1): with PinnedDateTime(self, DateTime()-1):
self._makeComputeNode(self.addProject()) self._makeComputeNode(self.addProject())
...@@ -2078,7 +2076,7 @@ class TestSlaposCrmUpdateSupportRequestState(SlapOSTestCaseMixinWithAbort): ...@@ -2078,7 +2076,7 @@ class TestSlaposCrmUpdateSupportRequestState(SlapOSTestCaseMixinWithAbort):
) )
return notification_message.getRelativeUrl() return notification_message.getRelativeUrl()
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0') @simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
@simulate('NotificationTool_getDocumentValue', @simulate('NotificationTool_getDocumentValue',
'reference=None, **kw', 'reference=None, **kw',
'assert reference == "slapos-crm-support-request-close-destroyed-notification", reference\n' \ 'assert reference == "slapos-crm-support-request-close-destroyed-notification", reference\n' \
...@@ -2120,7 +2118,7 @@ class TestSlaposCrmUpdateSupportRequestState(SlapOSTestCaseMixinWithAbort): ...@@ -2120,7 +2118,7 @@ class TestSlaposCrmUpdateSupportRequestState(SlapOSTestCaseMixinWithAbort):
self.assertEqual(event.getSimulationState(), "delivered") self.assertEqual(event.getSimulationState(), "delivered")
self.assertEqual(event.getPortalType(), "Web Message") self.assertEqual(event.getPortalType(), "Web Message")
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0') @simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
def test_SupportRequest_updateMonitoringState_script_notDestroyed(self): def test_SupportRequest_updateMonitoringState_script_notDestroyed(self):
support_request = self._makeSupportRequest() support_request = self._makeSupportRequest()
support_request.setResource("service_module/slapos_crm_monitoring") support_request.setResource("service_module/slapos_crm_monitoring")
...@@ -2142,7 +2140,7 @@ class TestSlaposCrmUpdateSupportRequestState(SlapOSTestCaseMixinWithAbort): ...@@ -2142,7 +2140,7 @@ class TestSlaposCrmUpdateSupportRequestState(SlapOSTestCaseMixinWithAbort):
self.assertEqual(len(event_list), 0) self.assertEqual(len(event_list), 0)
self.assertEqual(ticket.getSimulationState(), "submitted") self.assertEqual(ticket.getSimulationState(), "submitted")
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0') @simulate('Project_isSupportRequestCreationClosed', '', 'return 0')
def test_SupportRequest_updateMonitoringState_script_invalidated(self): def test_SupportRequest_updateMonitoringState_script_invalidated(self):
support_request = self._makeSupportRequest() support_request = self._makeSupportRequest()
support_request.setResource("service_module/slapos_crm_monitoring") support_request.setResource("service_module/slapos_crm_monitoring")
......
...@@ -205,93 +205,69 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin): ...@@ -205,93 +205,69 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin):
def afterSetUp(self): def afterSetUp(self):
TestCRMSkinsMixin.afterSetUp(self) TestCRMSkinsMixin.afterSetUp(self)
self.project = self.addProject() self.project = self.addProject()
self._cancelTestSupportRequestList() self.other_project = self.addProject()
self.clearCache() # ensure it is set to 5
def test_ERP5Site_isSupportRequestCreationClosed(self):
person = self.makePerson(self.project, user=0)
other_person = self.makePerson(self.project, user=0)
url = person.getRelativeUrl()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed())
self.portal.portal_preferences.slapos_default_system_preference\ self.portal.portal_preferences.slapos_default_system_preference\
.setPreferredSupportRequestCreationLimit(5) .setPreferredSupportRequestCreationLimit(5)
def newSupportRequest():
sr = self.portal.support_request_module.newContent(\
title="Test Support Request POIUY",
resource="service_module/slapos_crm_monitoring",
destination_decision=url)
sr.validate()
sr.immediateReindexObject()
newSupportRequest()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
newSupportRequest()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
newSupportRequest()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
newSupportRequest()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
newSupportRequest()
# It hit cache
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.clearCache() self.clearCache()
self.assertTrue(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertTrue(self.portal.ERP5Site_isSupportRequestCreationClosed())
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed( def newDummySupportRequest(self,
other_person.getRelativeUrl()))
def test_ERP5Site_isSupportRequestCreationClosed_suspended_state(self):
person = self.makePerson(self.project, user=0)
url = person.getRelativeUrl()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed())
def newSupportRequest():
sr = self.portal.support_request_module.newContent(\
title="Test Support Request POIUY",
resource="service_module/slapos_crm_monitoring", resource="service_module/slapos_crm_monitoring",
destination_decision=url) state='validated'):
sr.validate()
sr.suspend()
sr.immediateReindexObject()
# Create five tickets, the limit of ticket creation
newSupportRequest()
newSupportRequest()
newSupportRequest()
newSupportRequest()
newSupportRequest()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed())
def test_ERP5Site_isSupportRequestCreationClosed_nonmonitoring(self):
person = self.makePerson(self.project, user=0)
url = person.getRelativeUrl()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed())
def newSupportRequest():
sr = self.portal.support_request_module.newContent(\ sr = self.portal.support_request_module.newContent(\
title="Test Support Request POIUY", title="Test isSupportRequestCreationClosed %s" % self.generateNewId(),
destination_decision=url) resource=resource,
source_project_value=self.project)
if state == 'validated':
sr.validate()
elif state == 'suspended':
sr.validate() sr.validate()
sr.suspend()
elif state == 'submited':
sr.submit()
sr.immediateReindexObject() sr.immediateReindexObject()
# Create five tickets, the limit of ticket creation def test_Project_isSupportRequestCreationClosed(self, state='validated'):
newSupportRequest() self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
newSupportRequest() self.newDummySupportRequest(state=state)
newSupportRequest() self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
newSupportRequest() self.newDummySupportRequest(state=state)
newSupportRequest() self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(state=state)
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url)) self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed()) self.newDummySupportRequest(state=state)
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(state=state)
self.assertTrue(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(state=state)
self.assertTrue(self.project.Project_isSupportRequestCreationClosed())
# it dont close another project
self.assertFalse(self.other_project.Project_isSupportRequestCreationClosed())
def test_Project_isSupportRequestCreationClosed_submited_state(self):
self.test_Project_isSupportRequestCreationClosed(state='submited')
def test_Project_isSupportRequestCreationClosed_suspended_state(self):
self.test_Project_isSupportRequestCreationClosed(state='suspended')
def test_Project_isSupportRequestCreationClosed_nonmonitoring(self):
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(resource='')
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(resource='')
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(resource='')
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(resource='')
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(resource='')
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(resource='')
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
self.newDummySupportRequest(resource='')
self.assertFalse(self.project.Project_isSupportRequestCreationClosed())
# it dont close another project
self.assertFalse(self.other_project.Project_isSupportRequestCreationClosed())
class TestSlapOSHasError(SlapOSTestCaseMixin): class TestSlapOSHasError(SlapOSTestCaseMixin):
......
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