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