Commit a615b731 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud:

* drop person.requestSite
* fix Computer Network creation test
* fix requestComputeNode tests
* ensure Compute Node has no related project security group
* instance has project based security group
parent d1edbab1
......@@ -616,6 +616,8 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
SlapOSTestCaseMixin.afterSetUp(self)
self.project = self.addProject()
person_user = self.makePerson(self.project)
# Only admin can create computer node
self.addProjectProductionManagerAssignment(person_user, self.project)
self.tic()
# Login as new user
......@@ -626,19 +628,24 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
def beforeTearDown(self):
pass
def test_request_requiredParameter(self):
def test_requestComputeNode_requiredParameter(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
# compute_node_title is mandatory
self.assertRaises(TypeError, person.requestComputeNode,
project_reference=self.project.getReference())
# if provided does not raise
compute_node_title = self.generateNewComputeNodeTitle()
# project_reference is mandatory
self.assertRaises(TypeError, person.requestComputeNode,
compute_node_title=compute_node_title)
# if provided does not raise
person.requestComputeNode(project_reference=self.project.getReference(),
compute_node_title=compute_node_title)
def test_request(self):
def test_requestComputeNode_request(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
compute_node_title = self.generateNewComputeNodeTitle()
......@@ -654,7 +661,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertNotEqual(None, compute_node_absolute_url)
self.assertNotEqual(None, compute_node_reference)
def test_request_createdComputeNode(self):
def test_requestComputeNode_createdComputeNode(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
previous_id = self.getPortalObject().portal_ids\
......@@ -683,10 +690,10 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertEqual(compute_node_reference, compute_node.getReference())
self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference())
self.assertEqual('validated', compute_node.getValidationState())
self.assertEqual(None, compute_node.getAllocationScope())
self.assertEqual('open', compute_node.getCapacityScope())
self.assertEqual('open', compute_node.getAllocationScope())
self.assertEqual('close', compute_node.getCapacityScope())
def test_request_notReindexedCompute(self):
def test_requestComputeNode_notReindexedCompute(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
compute_node_title = self.generateNewComputeNodeTitle()
......@@ -697,7 +704,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
project_reference=self.project.getReference(),
compute_node_title=compute_node_title)
def test_multiple_request_createdComputeNode(self):
def test_requestComputeNode_multiple_request_createdComputeNode(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
previous_id = self.getPortalObject().portal_ids\
......@@ -727,7 +734,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertEqual(compute_node_reference, compute_node.getReference())
self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference())
self.assertEqual('validated', compute_node.getValidationState())
self.assertEqual('open/personal', compute_node.getAllocationScope())
self.assertEqual('open', compute_node.getAllocationScope())
self.assertEqual('close', compute_node.getCapacityScope())
self.tic()
......@@ -754,7 +761,7 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertEqual(compute_node_reference, compute_node.getReference())
self.assertEqual('COMP-%s' % (previous_id + 1), compute_node.getReference())
self.assertEqual('validated', compute_node.getValidationState())
self.assertEqual('open/personal', compute_node.getAllocationScope())
self.assertEqual('open', compute_node.getAllocationScope())
self.assertEqual('close', compute_node.getCapacityScope())
# and now another one
......@@ -782,10 +789,10 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
self.assertEqual(compute_node_reference2, compute_node2.getReference())
self.assertEqual('COMP-%s' % (previous_id + 2), compute_node2.getReference())
self.assertEqual('validated', compute_node2.getValidationState())
self.assertEqual('open/personal', compute_node2.getAllocationScope())
self.assertEqual('open', compute_node2.getAllocationScope())
self.assertEqual('close', compute_node2.getCapacityScope())
def test_request_duplicatedComputeNode(self):
def test_requestComputeNode_duplicatedComputeNode(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
compute_node_title = self.generateNewComputeNodeTitle()
......@@ -818,132 +825,6 @@ class TestSlapOSCorePersonRequestComputeNode(SlapOSTestCaseMixin):
compute_node_title=compute_node_title)
class TestSlapOSCorePersonRequestSite(SlapOSTestCaseMixin):
def generateNewOrganisationTitle(self):
return 'My Site %s' % self.generateNewId()
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
self.project = self.addProject()
person_user = self.makePerson(self.project)
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())
def beforeTearDown(self):
pass
def test_Person_requestSite_title_is_mandatoty(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.assertRaises(TypeError, person.requestSite)
def test_Person_requestSite(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
organisation_title = self.generateNewOrganisationTitle()
person.requestSite(organisation_title=organisation_title)
self.tic()
self.login()
# check what is returned via request
organisation_relative_url = person.REQUEST.get('organisation_relative_url')
self.assertNotEqual(None, organisation_relative_url)
organisation = person.restrictedTraverse(organisation_relative_url)
self.assertEqual(organisation.getTitle(), organisation_title)
self.assertEqual(organisation.getValidationState(), "validated")
self.assertEqual(organisation.getRoleId(), "host")
self.assertIn("SITE-", organisation.getReference())
def test_Person_requestSite_duplicated(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
organisation_title = self.generateNewOrganisationTitle()
person.requestSite(organisation_title=organisation_title)
self.tic()
self.login()
# check what is returned via request
organisation_relative_url = person.REQUEST.get('organisation_relative_url')
self.assertNotEqual(None, organisation_relative_url)
organisation = person.restrictedTraverse(organisation_relative_url)
self.assertEqual(organisation.getTitle(), organisation_title)
self.assertEqual(organisation.getValidationState(), "validated")
self.assertEqual(organisation.getRoleId(), "host")
self.assertIn("SITE-", organisation.getReference())
organisation2 = organisation.Base_createCloneDocument(batch_mode=1)
organisation2.validate()
self.tic()
self.login(person.getUserId())
self.assertRaises(NotImplementedError, person.requestSite,
organisation_title=organisation_title)
def test_Person_requestSite_request_again(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
organisation_title = self.generateNewOrganisationTitle()
person.requestSite(organisation_title=organisation_title)
# check what is returned via request
organisation_relative_url = person.REQUEST.get('organisation_relative_url')
self.assertNotEqual(None, organisation_relative_url)
self.tic()
self.login()
# check what is returned via request
person.REQUEST.set('organisation_relative_url', None)
self.login(person.getUserId())
person.requestSite(organisation_title=organisation_title)
# check what is returned via request
same_organisation_relative_url = person.REQUEST.get('organisation_relative_url')
self.assertEqual(same_organisation_relative_url, organisation_relative_url)
def test_Person_requestSite_dont_conflict_with_site(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
organisation_title = self.generateNewOrganisationTitle()
person.requestSite(organisation_title=organisation_title)
self.tic()
self.login()
# check what is returned via request
organisation_relative_url = person.REQUEST.get('organisation_relative_url')
self.assertNotEqual(None, organisation_relative_url)
organisation = person.restrictedTraverse(organisation_relative_url)
self.assertEqual(organisation.getTitle(), organisation_title)
self.assertEqual(organisation.getValidationState(), "validated")
self.assertEqual(organisation.getRoleId(), "host")
self.assertIn("SITE-", organisation.getReference())
organisation2 = organisation.Base_createCloneDocument(batch_mode=1)
organisation2.edit(role="client")
organisation2.validate()
person.REQUEST.set('organisation_relative_url', None)
self.tic()
self.login(person.getUserId())
person.requestSite(organisation_title=organisation_title)
self.tic()
self.login()
# check what is returned via request
same_organisation_relative_url = person.REQUEST.get('organisation_relative_url')
self.assertEqual(same_organisation_relative_url, organisation_relative_url)
class TestSlapOSCorePersonRequestNetwork(SlapOSTestCaseMixin):
def generateNewNetworkTitle(self):
......@@ -953,6 +834,8 @@ class TestSlapOSCorePersonRequestNetwork(SlapOSTestCaseMixin):
SlapOSTestCaseMixin.afterSetUp(self)
self.project = self.addProject()
person_user = self.makePerson(self.project)
# Only admin can create computer network
self.addProjectProductionManagerAssignment(person_user, self.project)
self.tic()
# Login as new user
......@@ -963,14 +846,21 @@ class TestSlapOSCorePersonRequestNetwork(SlapOSTestCaseMixin):
def beforeTearDown(self):
pass
def test_Person_requestNetwork_title_is_mandatoty(self):
def test_Person_requestNetwork_title_is_mandatory(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.assertRaises(TypeError, person.requestNetwork,
project_reference=self.project.getReference())
def test_Person_requestNetwork_project_is_mandatory(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.assertRaises(TypeError, person.requestNetwork)
self.assertRaises(TypeError, person.requestNetwork,
network_title=self.generateNewNetworkTitle())
def test_Person_requestNetwork(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
network_title = self.generateNewNetworkTitle()
person.requestNetwork(network_title=network_title)
person.requestNetwork(network_title=network_title,
project_reference=self.project.getReference())
self.tic()
self.login()
......@@ -978,10 +868,10 @@ class TestSlapOSCorePersonRequestNetwork(SlapOSTestCaseMixin):
network_relative_url = person.REQUEST.get('computer_network_relative_url')
self.assertNotEqual(None, network_relative_url)
network = person.restrictedTraverse(network_relative_url)
self.assertEqual(network.getSourceAdministration(),
person.getRelativeUrl())
self.assertEqual(network.getFollowUp(),
self.project.getRelativeUrl())
self.assertEqual(network.getTitle(), network_title)
self.assertEqual(network.getValidationState(), "validated")
self.assertIn("NET-", network.getReference())
......@@ -990,7 +880,8 @@ class TestSlapOSCorePersonRequestNetwork(SlapOSTestCaseMixin):
def test_Person_requestNetwork_duplicated(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
network_title = self.generateNewNetworkTitle()
person.requestNetwork(network_title=network_title)
person.requestNetwork(network_title=network_title,
project_reference=self.project.getReference())
self.tic()
self.login()
......@@ -1000,8 +891,8 @@ class TestSlapOSCorePersonRequestNetwork(SlapOSTestCaseMixin):
self.assertNotEqual(None, network_relative_url)
network = person.restrictedTraverse(network_relative_url)
self.assertEqual(network.getSourceAdministration(),
person.getRelativeUrl())
self.assertEqual(network.getFollowUp(),
self.project.getRelativeUrl())
self.assertEqual(network.getTitle(), network_title)
self.assertEqual(network.getValidationState(), "validated")
self.assertIn("NET-", network.getReference())
......@@ -1012,12 +903,14 @@ class TestSlapOSCorePersonRequestNetwork(SlapOSTestCaseMixin):
self.login(person.getUserId())
self.assertRaises(NotImplementedError, person.requestNetwork,
network_title=network_title)
network_title=network_title,
project_reference=self.project.getReference())
def test_Person_requestNetwork_request_again(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
network_title = self.generateNewNetworkTitle()
person.requestNetwork(network_title=network_title)
person.requestNetwork(network_title=network_title,
project_reference=self.project.getReference())
# check what is returned via request
network_relative_url = person.REQUEST.get('computer_network_relative_url')
......@@ -1030,7 +923,8 @@ class TestSlapOSCorePersonRequestNetwork(SlapOSTestCaseMixin):
person.REQUEST.set('computer_network_relative_url', None)
self.login(person.getUserId())
person.requestNetwork(network_title=network_title)
person.requestNetwork(network_title=network_title,
project_reference=self.project.getReference())
# check what is returned via request
same_network_relative_url = person.REQUEST.get('computer_network_relative_url')
......
......@@ -42,6 +42,7 @@ class TestSlapOSSecurityMixin(SlapOSTestCaseMixin):
portal_type.replace(" ", "_").lower(), random.random())
result_list = self.portal.portal_catalog(
portal_type=portal_type,
limit=[0, 1],
**{search_key: random_user_id}
)
if not len(result_list):
......@@ -83,12 +84,15 @@ class TestSlapOSSecurityMixin(SlapOSTestCaseMixin):
(plugin_name, login, password))
class TestSlapOSComputeNodeSecurity(TestSlapOSSecurityMixin):
def test_active(self, login_portal_type="Certificate Login"):
user_id = self._generateRandomUniqueUserId('Compute Node')
reference = self._generateRandomUniqueReference('Compute Node')
project = self.addProject()
compute_node = self.portal.compute_node_module.newContent(
portal_type='Compute Node', reference=reference)
portal_type='Compute Node', reference=reference, follow_up_value=project)
compute_node.setUserId(user_id)
compute_node.validate()
compute_node.newContent(portal_type=login_portal_type,
......@@ -158,6 +162,22 @@ class TestSlapOSSoftwareInstanceSecurity(TestSlapOSSecurityMixin):
self.assertSameSet(['R-INSTANCE', subscription_reference],
user.getGroups())
# check project security group
self.login()
project = self.addProject()
instance.setFollowUpValue(project)
self.tic()
# clear cache in order to reset calculation
self.portal.portal_caches.clearAllCache()
self.login(user_id)
user = getSecurityManager().getUser()
self.assertTrue('Authenticated' in user.getRoles())
self.assertSameSet(['R-INSTANCE', subscription_reference,
project.getReference(),
'%s_R-INSTANCE' % project.getReference()],
user.getGroups())
def test_inactive(self, login_portal_type="Certificate Login"):
user_id = self._generateRandomUniqueUserId(self.portal_type)
reference = self._generateRandomUniqueReference(self.portal_type)
......
context.REQUEST.set("role_id", "host")
person = state_change['object']
portal = person.getPortalObject()
# Get required arguments
kwargs = state_change.kwargs
# Required args
# Raise TypeError if all parameters are not provided
try:
organisation_title = kwargs['organisation_title']
except KeyError:
raise TypeError, "Person_requestOrganisation takes exactly 1 argument"
role_id = context.REQUEST.get("role_id", "client")
tag = "%s_%s_%s_OrganisationInProgress" % (person.getUid(),
role_id,
organisation_title)
if (portal.portal_activities.countMessageWithTag(tag) > 0):
# The software instance is already under creation but can not be fetched from catalog
# As it is not possible to fetch informations, it is better to raise an error
raise NotImplementedError(tag)
organisation_portal_type = "Organisation"
if role_id not in ["client", "host"]:
raise NotImplementedError
organisation_list = [ i for i in portal.portal_catalog.portal_catalog(
portal_type=organisation_portal_type,
title=organisation_title,
limit=2) if i.getRole() == role_id]
if len(organisation_list) == 2:
raise NotImplementedError
elif len(organisation_list) == 1:
context.REQUEST.set("organisation_relative_url", organisation_list[0].getRelativeUrl())
else:
module = portal.getDefaultModule(portal_type=organisation_portal_type)
organisation = module.newContent(
portal_type=organisation_portal_type,
title=organisation_title,
role=role_id,
activate_kw={'tag': tag}
)
context.REQUEST.set("organisation_relative_url", organisation.getRelativeUrl())
organisation.approveRegistration()
<?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>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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_Person_requestSite</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Script</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Person_requestSite</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -19,7 +19,6 @@
<string>destination/portal_workflow/person_slap_interface_workflow/transition_notify</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_compute_node</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_network</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_site</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_software_instance</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_support</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_token</string>
......
......@@ -20,7 +20,6 @@
<string>destination/portal_workflow/person_slap_interface_workflow/transition_notify</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_compute_node</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_network</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_site</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_software_instance</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_support</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_token</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Transition" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>action_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/workflow</string>
<string>before_script/portal_workflow/person_slap_interface_workflow/script_Person_checkConsistency</string>
<string>after_script/portal_workflow/person_slap_interface_workflow/script_Person_requestSite</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>guard_permission</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>transition_request_site</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Transition</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Request Site</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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