Commit c9598767 authored by Alain Takoudjou's avatar Alain Takoudjou

slapos_crm: add/fix test for create alarm to close personal computer

parent 11ba14cf
Pipeline #1911 skipped
from DateTime import DateTime
from Products.ERP5Type.DateUtils import addToDate
from Products.ZSQLCatalog.SQLCatalog import Query
portal = context.getPortalObject()
category_personal = portal.restrictedTraverse("portal_categories/allocation_scope/open/personal", None)
......@@ -6,6 +10,7 @@ if category_personal is not None:
portal.portal_catalog.searchAndActivate(
portal_type='Computer',
validation_state='validated',
creation_date=Query(range="max", creation_date=addToDate(DateTime(), {'day': -30})),
default_allocation_scope_uid=category_personal.getUid(),
method_id='Computer_checkAndUpdatePersonalAllocationScope',
activate_kw={'tag': tag})
......
import json
portal = context.getPortalObject()
computer = context
maximum_days = 31
now_date = DateTime()
if (now_date - computer.getCreationDate()) < maximum_days:
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>maximum_days=30</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -969,44 +969,58 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by C
def test_alarm_allowed_allocation_scope_OpenPersonal_old_computer(self):
self._makeComputer()
def getCreationDate(self):
return DateTime() - 31
self.computer.edit(allocation_scope = 'open/personal')
def getModificationDate(self):
return DateTime() - 50
from Products.ERP5Type.Base import Base
self._simulateComputer_checkAndUpdatePersonalAllocationScope()
original_get_modification = Base.getModificationDate
Base.getModificationDate = getModificationDate
original_get_creation = Base.getCreationDate
Base.getCreationDate = getCreationDate
try:
self.portal.portal_alarms.slapos_crm_check_update_personal_allocation_scope.activeSense()
self.tic()
finally:
Base.getModificationDate = original_get_modification
Base.getCreationDate = original_get_creation
self._dropComputer_checkAndUpdatePersonalAllocationScope()
self.assertEqual('Visited by Computer_checkAndUpdatePersonalAllocationScope',
self.computer.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_allowed_allocation_scope_OpenPersonalWithSoftwareInstallation(self):
def test_alarm_allowed_allocation_scope_OpenPersonal_recent_computer(self):
self._makeComputer()
def getCreationDate(self):
return DateTime() - 28
self.computer.edit(allocation_scope = 'open/personal')
self._makeSoftwareInstallation()
def getModificationDate(self):
return DateTime() - 50
from Products.ERP5Type.Base import Base
self._simulateComputer_checkAndUpdatePersonalAllocationScope()
original_get_modification = Base.getModificationDate
Base.getModificationDate = getModificationDate
original_get_creation = Base.getCreationDate
Base.getCreationDate = getCreationDate
try:
self.portal.portal_alarms.slapos_crm_check_update_personal_allocation_scope.activeSense()
self.tic()
finally:
Base.getCreationDate = original_get_creation
self._dropComputer_checkAndUpdatePersonalAllocationScope()
self.assertNotEqual('Visited by Computer_checkAndUpdatePersonalAllocationScope',
self.computer.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_allowed_allocation_scope_OpenPersonal_already_closed(self):
self._makeComputer()
self.computer.edit(allocation_scope = 'open/oudated')
self._simulateComputer_checkAndUpdatePersonalAllocationScope()
try:
self.portal.portal_alarms.slapos_crm_check_update_personal_allocation_scope.activeSense()
self.tic()
finally:
Base.getModificationDate = original_get_modification
self._dropComputer_checkAndUpdatePersonalAllocationScope()
self.assertNotEqual('Visited by Computer_checkAndUpdatePersonalAllocationScope',
......@@ -1095,3 +1109,4 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by H
host_sub.workflow_history['edit_workflow'][-1]['comment'])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment