Commit 5e957f7f authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: test ComputeNode_hasContactedRecently

Do not check if there is a packing list. It is unrelated to the contact.
parent 9feab327
portal = context.getPortalObject()
compute_node = context compute_node = context
now_date = DateTime() now_date = DateTime()
...@@ -15,13 +14,4 @@ if message_dict.has_key('created_at'): ...@@ -15,13 +14,4 @@ if message_dict.has_key('created_at'):
contact_date = DateTime(message_dict.get('created_at').encode('utf-8')) contact_date = DateTime(message_dict.get('created_at').encode('utf-8'))
return (now_date - contact_date) < maximum_days return (now_date - contact_date) < maximum_days
# If no access status information, check in consumption report
for sale_packing_list in portal.portal_catalog(
portal_type="Sale Packing List Line",
simulation_state="delivered",
default_aggregate_uid=compute_node.getUid(),
sort_on=[('movement.start_date', 'DESC')],
limit=1):
return (now_date - sale_packing_list.getStartDate()) < maximum_days
return False return False
...@@ -792,87 +792,50 @@ class TestSlapOSComputeNode_notifyWrongAllocationScope(TestCRMSkinsMixin): ...@@ -792,87 +792,50 @@ class TestSlapOSComputeNode_notifyWrongAllocationScope(TestCRMSkinsMixin):
class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort): class TestComputeNode_hasContactedRecently(SlapOSTestCaseMixinWithAbort):
def createSPL(self, compute_node):
delivery_template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredInstanceDeliveryTemplate())
delivery = delivery_template.Base_createCloneDocument(batch_mode=1)
delivery.edit(
title="TEST SPL COMP %s" % compute_node.getReference(),
start_date=compute_node.getCreationDate(),
)
delivery.newContent(
portal_type="Sale Packing List Line",
title="SPL Line for %s" % compute_node.getReference(),
quantity=1,
aggregate_value_list=compute_node,
)
delivery.confirm(comment="Created from %s" % compute_node.getRelativeUrl())
delivery.start()
delivery.stop()
delivery.deliver()
return delivery
def test_ComputeNode_hasContactedRecently_newly_created(self): def test_ComputeNode_hasContactedRecently_newly_created(self):
compute_node = self._makeComputeNode(self.project)[0] compute_node, _ = self._makeComputeNode(self.addProject())
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')
def test_ComputeNode_hasContactedRecently_no_data(self): def test_ComputeNode_hasContactedRecently_no_data(self):
compute_node = self._makeComputeNode(self.project)[0] try:
self.pinDateTime(DateTime()-32)
compute_node, _ = self._makeComputeNode(self.addProject())
finally:
self.unpinDateTime()
self.tic() self.tic()
compute_node.getCreationDate = self.portal.ComputeNode_getCreationDate
has_contacted = compute_node.ComputeNode_hasContactedRecently() has_contacted = compute_node.ComputeNode_hasContactedRecently()
self.assertFalse(has_contacted) self.assertFalse(has_contacted)
@simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32')
def test_ComputeNode_hasContactedRecently_memcached(self): def test_ComputeNode_hasContactedRecently_memcached(self):
compute_node = self._makeComputeNode(self.project)[0]
compute_node.setAccessStatus("")
self.tic()
compute_node.getCreationDate = self.portal.ComputeNode_getCreationDate
has_contacted = compute_node.ComputeNode_hasContactedRecently()
self.assertTrue(has_contacted)
@simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32')
def test_ComputeNode_hasContactedRecently_memcached_oudated_no_spl(self):
compute_node = self._makeComputeNode(self.project)[0]
try: try:
self.pinDateTime(DateTime()-32) self.pinDateTime(DateTime()-32)
compute_node.setAccessStatus("") compute_node, _ = self._makeComputeNode(self.addProject())
finally: finally:
self.unpinDateTime() self.unpinDateTime()
compute_node.setAccessStatus("")
self.tic() self.tic()
compute_node.getCreationDate = self.portal.ComputeNode_getCreationDate
has_contacted = compute_node.ComputeNode_hasContactedRecently() has_contacted = compute_node.ComputeNode_hasContactedRecently()
self.assertFalse(has_contacted) self.assertTrue(has_contacted)
@simulate('ComputeNode_getCreationDate', '*args, **kwargs','return DateTime() - 32') def test_ComputeNode_hasContactedRecently_memcached_oudated_no_spl(self):
def test_ComputeNode_hasContactedRecently_memcached_oudated_with_spl(self):
compute_node = self._makeComputeNode(self.project)[0]
try: try:
self.pinDateTime(DateTime()-32) self.pinDateTime(DateTime()-32)
compute_node, _ = self._makeComputeNode(self.addProject())
compute_node.setAccessStatus("") compute_node.setAccessStatus("")
finally: finally:
self.unpinDateTime() self.unpinDateTime()
self.createSPL(compute_node)
self.tic() self.tic()
compute_node.getCreationDate = self.portal.ComputeNode_getCreationDate
has_contacted = compute_node.ComputeNode_hasContactedRecently() has_contacted = compute_node.ComputeNode_hasContactedRecently()
self.assertFalse(has_contacted) self.assertFalse(has_contacted)
class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin): class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin):
def afterSetUp(self): 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