Commit 7d663881 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Fix Tests to follow up recent changes

parent 72a3ddb3
from DateTime import DateTime from DateTime import DateTime
import json
from Products.ERP5Type.DateUtils import addToDate
portal = context.getPortalObject() portal = context.getPortalObject()
document = context.getAggregateValue() document = context.getAggregateValue()
...@@ -10,6 +7,7 @@ if document is None: ...@@ -10,6 +7,7 @@ if document is None:
return return
has_error = False has_error = False
software_instance = None
# Check if at least one software Instance is Allocated # Check if at least one software Instance is Allocated
for instance in document.getSpecialiseRelatedValueList( for instance in document.getSpecialiseRelatedValueList(
...@@ -20,6 +18,7 @@ for instance in document.getSpecialiseRelatedValueList( ...@@ -20,6 +18,7 @@ for instance in document.getSpecialiseRelatedValueList(
if instance.getAggregateValue() is not None: if instance.getAggregateValue() is not None:
if instance.getPortalType() == "Software Instance" and \ if instance.getPortalType() == "Software Instance" and \
instance.SoftwareInstance_hasReportedError(): instance.SoftwareInstance_hasReportedError():
software_instance = instance
has_error = True has_error = True
break break
else: else:
...@@ -31,10 +30,11 @@ if not has_error: ...@@ -31,10 +30,11 @@ if not has_error:
if not person: if not person:
return return
message = instance.SoftwareInstance_hasReportedError(include_message=True) if software_instance is not None:
message = software_instance.SoftwareInstance_hasReportedError(include_message=True)
if message in ["Not possible to find the last message", "#access instance available"]: if message in ["Not possible to find the last message", "#access instance available"]:
# Do not change state in case of transitory states. # Do not change state in case of transitory states.
return message return
if context.getSimulationState() == "validated": if context.getSimulationState() == "validated":
context.suspend() context.suspend()
......
...@@ -58,7 +58,6 @@ class TestSlapOSFolder_getOpenTicketList(testSlapOSMixin): ...@@ -58,7 +58,6 @@ class TestSlapOSFolder_getOpenTicketList(testSlapOSMixin):
self.assertEquals(len(open_ticket_list), expected_amount) self.assertEquals(len(open_ticket_list), expected_amount)
self.assertEquals(open_ticket_list[0].getUid(), ticket.getUid()) self.assertEquals(open_ticket_list[0].getUid(), ticket.getUid())
ticket.validate() ticket.validate()
ticket.immediateReindexObject() ticket.immediateReindexObject()
open_ticket_list = module.Folder_getOpenTicketList(title=ticket.getTitle()) open_ticket_list = module.Folder_getOpenTicketList(title=ticket.getTitle())
...@@ -77,7 +76,6 @@ class TestSlapOSFolder_getOpenTicketList(testSlapOSMixin): ...@@ -77,7 +76,6 @@ class TestSlapOSFolder_getOpenTicketList(testSlapOSMixin):
self.assertEquals(len(open_ticket_list), expected_amount) self.assertEquals(len(open_ticket_list), expected_amount)
self.assertEquals(open_ticket_list[0].getUid(), ticket.getUid()) self.assertEquals(open_ticket_list[0].getUid(), ticket.getUid())
def _test_upgrade_decision(self, ticket, expected_amount): def _test_upgrade_decision(self, ticket, expected_amount):
module = ticket.getParentValue() module = ticket.getParentValue()
open_ticket_list = module.Folder_getOpenTicketList(title=ticket.getTitle()) open_ticket_list = module.Folder_getOpenTicketList(title=ticket.getTitle())
...@@ -112,7 +110,6 @@ class TestSlapOSFolder_getOpenTicketList(testSlapOSMixin): ...@@ -112,7 +110,6 @@ class TestSlapOSFolder_getOpenTicketList(testSlapOSMixin):
self.assertEquals(len(open_ticket_list), expected_amount) self.assertEquals(len(open_ticket_list), expected_amount)
self.assertEquals(open_ticket_list[0].getUid(), ticket.getUid()) self.assertEquals(open_ticket_list[0].getUid(), ticket.getUid())
def test_support_request(self): def test_support_request(self):
def newSupportRequest(): def newSupportRequest():
sr = self.portal.support_request_module.newContent(\ sr = self.portal.support_request_module.newContent(\
...@@ -149,12 +146,10 @@ class TestSlapOSFolder_getOpenTicketList(testSlapOSMixin): ...@@ -149,12 +146,10 @@ class TestSlapOSFolder_getOpenTicketList(testSlapOSMixin):
ticket = self.portal.upgrade_decision_module.newContent( ticket = self.portal.upgrade_decision_module.newContent(
portal_type='Upgrade Decision', portal_type='Upgrade Decision',
title="Upgrade Decision Test %s" % self.new_id, title="Upgrade Decision Test %s" % self.new_id,
reference="TESTUD-%s" % self.new_id reference="TESTUD-%s" % self.new_id)
)
ticket.immediateReindexObject() ticket.immediateReindexObject()
return ticket return ticket
ticket = newUpgradeDecision() ticket = newUpgradeDecision()
self._test_upgrade_decision(ticket, 1) self._test_upgrade_decision(ticket, 1)
...@@ -213,7 +208,6 @@ class TestSlapOSTicketEvent(testSlapOSMixin): ...@@ -213,7 +208,6 @@ class TestSlapOSTicketEvent(testSlapOSMixin):
last_event = ticket.Ticket_getLatestEvent() last_event = ticket.Ticket_getLatestEvent()
self.assertEquals(last_event, event) self.assertEquals(last_event, event)
# Now we test unwanted cases (deleted and cancelled) # Now we test unwanted cases (deleted and cancelled)
another_event = newEvent(ticket) another_event = newEvent(ticket)
last_event = ticket.Ticket_getLatestEvent() last_event = ticket.Ticket_getLatestEvent()
...@@ -2119,8 +2113,6 @@ class TestSlapOSRegularisationRequest_deleteHostingSubscriptionList( ...@@ -2119,8 +2113,6 @@ class TestSlapOSRegularisationRequest_deleteHostingSubscriptionList(
self.tic() self.tic()
class TestSlapOSComputer_notifyWrongAllocationScope(testSlapOSMixin): class TestSlapOSComputer_notifyWrongAllocationScope(testSlapOSMixin):
def beforeTearDown(self): def beforeTearDown(self):
...@@ -2304,7 +2296,6 @@ class TestSlapOSComputer_notifyWrongAllocationScope(testSlapOSMixin): ...@@ -2304,7 +2296,6 @@ class TestSlapOSComputer_notifyWrongAllocationScope(testSlapOSMixin):
self.tic() self.tic()
self.assertEquals(computer.getAllocationScope(), 'open/personal') self.assertEquals(computer.getAllocationScope(), 'open/personal')
def test_computerAllowedAllocationScope_OpenPublic(self): def test_computerAllowedAllocationScope_OpenPublic(self):
computer = self._makeComputer() computer = self._makeComputer()
person = computer.getSourceAdministrationValue() person = computer.getSourceAdministrationValue()
...@@ -2315,7 +2306,6 @@ class TestSlapOSComputer_notifyWrongAllocationScope(testSlapOSMixin): ...@@ -2315,7 +2306,6 @@ class TestSlapOSComputer_notifyWrongAllocationScope(testSlapOSMixin):
self.tic() self.tic()
self.assertEquals(computer.getAllocationScope(), 'open/public') self.assertEquals(computer.getAllocationScope(), 'open/public')
def test_computerAllowedAllocationScope_OpenFriend(self): def test_computerAllowedAllocationScope_OpenFriend(self):
computer = self._makeComputer() computer = self._makeComputer()
person = computer.getSourceAdministrationValue() person = computer.getSourceAdministrationValue()
...@@ -2438,7 +2428,6 @@ class TestSlapOSPerson_isServiceProvider(testSlapOSMixin): ...@@ -2438,7 +2428,6 @@ class TestSlapOSPerson_isServiceProvider(testSlapOSMixin):
def afterSetUp(self): def afterSetUp(self):
super(TestSlapOSPerson_isServiceProvider, self).afterSetUp() super(TestSlapOSPerson_isServiceProvider, self).afterSetUp()
def test_Person_isServiceProvider(self): def test_Person_isServiceProvider(self):
person = self.portal.person_module.template_member\ person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1) .Base_createCloneDocument(batch_mode=1)
...@@ -2568,7 +2557,6 @@ class TestSlapOSisSupportRequestCreationClosed(testSlapOSMixin): ...@@ -2568,7 +2557,6 @@ class TestSlapOSisSupportRequestCreationClosed(testSlapOSMixin):
class TestSlapOSGenerateSupportRequestForSlapOS(testSlapOSMixin): class TestSlapOSGenerateSupportRequestForSlapOS(testSlapOSMixin):
def afterSetUp(self): def afterSetUp(self):
super(TestSlapOSGenerateSupportRequestForSlapOS, self).afterSetUp() super(TestSlapOSGenerateSupportRequestForSlapOS, self).afterSetUp()
self.tic() self.tic()
...@@ -2820,7 +2808,6 @@ class TestSlapOSGenerateSupportRequestForSlapOS(testSlapOSMixin): ...@@ -2820,7 +2808,6 @@ class TestSlapOSGenerateSupportRequestForSlapOS(testSlapOSMixin):
self.assertEqual(support_request.getRelativeUrl(), in_progress) self.assertEqual(support_request.getRelativeUrl(), in_progress)
class TestSlapOSComputer_CheckState(testSlapOSMixin): class TestSlapOSComputer_CheckState(testSlapOSMixin):
def beforeTearDown(self): def beforeTearDown(self):
...@@ -3097,17 +3084,10 @@ class TestSlapOSHostingSubscription_createSupportRequestEvent(testSlapOSMixin): ...@@ -3097,17 +3084,10 @@ class TestSlapOSHostingSubscription_createSupportRequestEvent(testSlapOSMixin):
hosting_subscription, "test-slapos-crm-check.notification") hosting_subscription, "test-slapos-crm-check.notification")
self.tic() self.tic()
previous_ticket = ticket
ticket = self._getGeneratedSupportRequest( ticket = self._getGeneratedSupportRequest(
hosting_subscription.getUid()) hosting_subscription.getUid())
self.assertEqual(ticket, previous_ticket) # Do not reopen the ticket if it is suspended
self.assertEqual(ticket.getSimulationState(), "validated") self.assertEqual(None, ticket)
self.assertEqual('Visited by SupportRequest_trySendNotificationMessage ' \
'%s %s %s' % ( \
ticket_title.replace('', ''),
'Test NM content\n%s\n' % hosting_subscription.getReference(),
person.getRelativeUrl()),
ticket.workflow_history['edit_workflow'][-1]['comment'])
@simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 1') @simulate('ERP5Site_isSupportRequestCreationClosed', '*args, **kwargs','return 1')
def testHostingSubscription_createSupportRequestEvent_closed(self): def testHostingSubscription_createSupportRequestEvent_closed(self):
...@@ -3221,7 +3201,7 @@ class TestSlapOSHasError(testSlapOSMixin): ...@@ -3221,7 +3201,7 @@ class TestSlapOSHasError(testSlapOSMixin):
instance.setAggregateValue(self.computer.partition1) instance.setAggregateValue(self.computer.partition1)
self.assertEquals(instance.SoftwareInstance_hasReportedError(), error_date) self.assertEquals(str(instance.SoftwareInstance_hasReportedError()), '#error ')
memcached_dict[instance.getReference()] = json.dumps( memcached_dict[instance.getReference()] = json.dumps(
{"created_at":"%s" % error_date, "text": "#access "} {"created_at":"%s" % error_date, "text": "#access "}
......
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