Commit d00185f7 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Added test for organisation_slap_interface_workflow

parent a42e9af7
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
from zExceptions import Unauthorized
import transaction
class TestSlapOSCoreOrganisationSlapInterfaceWorkflow(SlapOSTestCaseMixin):
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
portal = self.getPortalObject()
person_user = self.makePerson()
self.tic()
# Login as new user
self.login(person_user.getUserId())
new_person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.assertEqual(person_user.getRelativeUrl(), new_person.getRelativeUrl())
self.organisation = portal.organisation_module.newContent(
portal_type="Organisation"
)
self.tic()
def beforeTearDown(self):
transaction.abort()
def test_organisation_approveRegistration_with_reference(self):
reference = "TEST-%s" % self.generateNewId()
self.organisation.setReference(reference)
self.organisation.approveRegistration()
self.assertEqual(self.organisation.getReference(), reference)
def test_organisation_approveRegistration_already_validated(self):
# Login as admin since user cannot re-approve a validated organisation
self.login()
self.organisation.setReference(None)
self.organisation.validate()
# Don't raise if organisation is validated
self.assertEqual(self.organisation.approveRegistration(), None)
def test_organisation_approveRegistration_site(self, role="host", expected_prefix="SITE-"):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.organisation.edit(role=role)
self.organisation.approveRegistration()
self.tic()
self.logout()
self.login(person.getUserId())
self.assertEqual(self.organisation.getValidationState(),
'validated')
self.assertTrue(self.organisation.getReference().startswith(expected_prefix),
"Reference don't start with %s : %s " % (
expected_prefix, self.organisation.getReference()))
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationValue() == self.organisation]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.assertIn("Assigment for Organisation ", assignment_list[0].getTitle())
def test_organisation_approveRegistration_organisation(self):
self.test_organisation_approveRegistration_site(role="client", expected_prefix="O-")
def test_organisation_leaveOrganisation_no_user(self):
self.login()
self.assertRaises(Unauthorized, self.organisation.leaveOrganisation)
def test_organisation_leaveOrganisation_after_join(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
# Just make things fast, by using the API tested above
self.organisation.approveRegistration()
self.tic()
self.logout()
self.login(person.getUserId())
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationValue() == self.organisation]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.organisation.leaveOrganisation()
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationValue() == self.organisation]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'closed')
def test_organisation_acceptInvitation_no_invitation_token(self):
self.assertRaises(TypeError, self.organisation.acceptInvitation)
def test_organisation_acceptInvitation_no_token_dont_exist(self):
self.assertRaises(ValueError, self.organisation.acceptInvitation,
invitation_token="DONOTEXIST")
def test_organisation_acceptInvitation(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.login()
token = self.portal.invitation_token_module.newContent(
portal_type="Invitation Token"
)
token_id = token.getId()
# User is None
self.assertRaises(ValueError, self.organisation.acceptInvitation,
invitation_token=token_id)
# Not validated yet
self.login(person.getUserId())
self.assertRaises(ValueError, self.organisation.acceptInvitation,
invitation_token=token_id)
self.login()
token.validate()
token.setSourceValue(person)
self.login(person.getUserId())
# Not used by the owner
self.assertRaises(ValueError, self.organisation.acceptInvitation,
invitation_token=token_id)
self.login()
token.setSourceValue(None)
self.login(person.getUserId())
self.organisation.acceptInvitation(invitation_token=token_id)
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationValue() == self.organisation]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.assertEqual(token.getValidationState(), "invalidated")
def test_organisation_acceptInvitation_already_member(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.organisation.approveRegistration()
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationValue() == self.organisation]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
token = self.portal.invitation_token_module.newContent(
portal_type="Invitation Token"
)
token_id = token.getId()
# User is None
self.assertRaises(ValueError, self.organisation.acceptInvitation,
invitation_token=token_id)
# Not validated yet
self.login(person.getUserId())
self.assertRaises(ValueError, self.organisation.acceptInvitation,
invitation_token=token_id)
self.login()
token.validate()
token.setSourceValue(person)
self.login(person.getUserId())
# Not used by the owner
self.assertRaises(ValueError, self.organisation.acceptInvitation,
invitation_token=token_id)
self.login()
token.setSourceValue(None)
self.login(person.getUserId())
self.organisation.acceptInvitation(invitation_token=token_id)
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationValue() == self.organisation]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.assertEqual(token.getValidationState(), "invalidated")
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSCloudOrganisationSlapInterfaceWorkflow</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSCloudOrganisationSlapInterfaceWorkflow</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
project = state_change['object']
portal = project.getPortalObject()
organisation = state_change['object']
portal = organisation.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
# Get required arguments
......@@ -10,7 +10,7 @@ kwargs = state_change.kwargs
try:
token_id = kwargs['invitation_token']
except KeyError:
raise TypeError("Project_acceptInvitation takes exactly 1 argument")
raise TypeError("Organisation_acceptInvitation takes exactly 1 argument")
try:
invitation_token = portal.invitation_token_module[token_id]
......@@ -33,16 +33,18 @@ if invitation_token.getSourceValue() == person:
message_str = "Invitation Token cannot be used by the same user that generated the token!"
raise ValueError(message_str)
for assignment in person.objectValues(portal_type="Assignment"):
if assignment.getDestinationProject() == project.getRelativeUrl() and \
assignment.getValidationState() == "open":
if assignment.getSubordination() == organisation.getRelativeUrl() and \
assignment.getValidationState() == "open":
invitation_token.invalidate(comment="User already has assignment to the Person")
break
if invitation_token.getValidationState() == "validated":
person.newContent(
title="Assigment for Project %s" % project.getTitle(),
title="Assigment for Organisation (%s) %s" % (organisation.getRole(), organisation.getTitle()),
portal_type="Assignment",
destination_project_value=project).open()
subordination_value=organisation,
destination_value=organisation).open()
invitation_token.invalidate()
......@@ -14,6 +14,9 @@ if organisation.getReference() in [None, ""]:
organisation.setReference(reference)
if organisation.getValidationState() != "draft":
return
organisation.validate()
# Get the user id of the context owner.
......
project = state_change['object']
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
request_method = "POST"
script_name = "Project_acceptInvitation"
web_site = context.getWebSiteValue()
if web_site is None:
web_site = portal
request_url = "%s/%s/%s" % (web_site.absolute_url(), project.getRelativeUrl(), script_name)
# Maybe it would be better to use another portal_type
token = portal.invitation_token_module.newContent(
portal_type="Invitation Token",
source_value=person,
url_string=request_url,
url_method=request_method
)
token.validate()
context.REQUEST.set('request_token_id', token.getId())
context.REQUEST.set('request_token_url_string', request_url)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_Organisation_generateInvitation</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Script</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -6,6 +6,7 @@ test.erp5.testSlapOSCloudPersonSlapInterfaceWorkflow
test.erp5.testSlapOSCloudComputeNodeSlapInterfaceWorkflow
test.erp5.testSlapOSCloudInstanceSlapInterfaceWorkflow
test.erp5.testSlapOSCloudProjectSlapInterfaceWorkflow
test.erp5.testSlapOSCloudOrganisationSlapInterfaceWorkflow
test.erp5.testSlapOSCloudSecurityGroup
test.erp5.testSlapOSCloudConstraint
test.erp5.testSlapOSCloudUpgrader
......
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