Commit 291e99cb authored by Rafael Monnerat's avatar Rafael Monnerat

Extending Internal API using *_slap_interface_workflow

This MR aims to introduce and extend the internal API with the support for manage:

   - Project
   - Organisation
   - Site (also Organisation)
   - Tokens
   - Computer Network
   
So via the introductions of workflows we included the following methods:

  - Project.approveRegistration()
  - Project.leaveProject()
  - Project.acceptInvitation()
  - Organisation.approveRegistration()
  - Organisation.leaveOrganisation()
  - Organisation.acceptInvitation()
  - Person.requestProject(project_title)
  - Person.requestOrganisation(organisation_title)
  - Person.requestSite(organisation_title)
  - Person.requestToken(request_url)
  - Person.requestNetwork(network_title)
  - ComputeNote.requestTransfer(...)
  - InstanceTree.requestTransfer(...) 
  - ComputerNetwork.approveRegistration()
  - ComputerNetwork.requestTransfer(...)
 
  
This API with minor exceptions, don't replaces the way the Hateoas/JIO website interacts with ERP5, so the original scripts are kept and just changed to call internal APIs.


See merge request nexedi/slapos.core!348
parents a580f609 82a3b8c6
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
<type>Compute Partition</type> <type>Compute Partition</type>
<workflow>compute_partition_slap_interface_workflow</workflow> <workflow>compute_partition_slap_interface_workflow</workflow>
</chain> </chain>
<chain>
<type>Computer Network</type>
<workflow>network_slap_interface_workflow</workflow>
</chain>
<chain> <chain>
<type>Hosting Subscription</type> <type>Hosting Subscription</type>
<workflow>edit_workflow</workflow> <workflow>edit_workflow</workflow>
...@@ -15,10 +19,18 @@ ...@@ -15,10 +19,18 @@
<type>Instance Tree</type> <type>Instance Tree</type>
<workflow>edit_workflow, instance_slap_interface_workflow, instance_tree_workflow</workflow> <workflow>edit_workflow, instance_slap_interface_workflow, instance_tree_workflow</workflow>
</chain> </chain>
<chain>
<type>Organisation</type>
<workflow>organisation_slap_interface_workflow</workflow>
</chain>
<chain> <chain>
<type>Person</type> <type>Person</type>
<workflow>person_slap_interface_workflow</workflow> <workflow>person_slap_interface_workflow</workflow>
</chain> </chain>
<chain>
<type>Project</type>
<workflow>project_slap_interface_workflow</workflow>
</chain>
<chain> <chain>
<type>Slave Instance</type> <type>Slave Instance</type>
<workflow>edit_workflow, instance_slap_interface_workflow, item_workflow, slapos_cloud_interaction_workflow</workflow> <workflow>edit_workflow, instance_slap_interface_workflow, item_workflow, slapos_cloud_interaction_workflow</workflow>
......
""" """
Create an internal Packing List and attach the compute_node Create an internal Packing List and attach the compute_node
""" """
from DateTime import DateTime context.requestTransfer(
from zExceptions import Unauthorized destination=destination,
destination_project=destination_project,
user = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue() destination_section=destination_section
)
if user is None or user.getRelativeUrl() != context.getSourceAdministration():
raise Unauthorized("Only the compute_node owner can Transfer compute_node from one location to another.")
portal_type = "Internal Packing List"
source = context.Item_getCurrentSiteValue()
source_project = context.Item_getCurrentProjectValue()
source_section = context.Item_getCurrentOwnerValue()
resource_value = context.Item_getResourceValue()
if destination_project is None and source_project is not None:
destination_project = source_project.getRelativeUrl()
if destination_section is None:
destination_section = context.getSourceAdministration()
if destination is None and source is not None:
# We do not change location of the machine
destination = source.getRelativeUrl()
if source is None and destination is None:
raise ValueError("Sorry, destination is required for the initial set.")
if source_section is None:
source_section = context.getSourceAdministration()
resource_value = context.product_module.compute_node
module = context.getDefaultModule(portal_type=portal_type)
line_portal_type = '%s Line' % portal_type
delivery = module.newContent(title="Transfer %s to %s" % (context.getTitle(), destination),
source_value=source,
source_section_value=source_section,
source_project_value=source_project,
destination=destination,
destination_section=destination_section,
source_decision=destination_section,
destination_decision=destination_section,
destination_project_value=destination_project,
start_date=DateTime(),
stop_date=DateTime(),
portal_type=portal_type)
delivery_line = delivery.newContent(
portal_type=line_portal_type,
title=context.getReference(),
quantity_unit=context.getQuantityUnit(),
resource_value=resource_value)
delivery_line.edit(
price=0.0,
quantity=1.0,
aggregate_value=context)
delivery.confirm()
delivery.stop()
delivery.deliver()
...@@ -52,15 +52,6 @@ ...@@ -52,15 +52,6 @@
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>destination=None, destination_project=None, destination_section=None</string> </value> <value> <string>destination=None, destination_project=None, destination_section=None</string> </value>
</item> </item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ComputeNode_createMovement</string> </value> <value> <string>ComputeNode_createMovement</string> </value>
......
""" """
Create an internal Packing List and attach the compute_node Create an internal Packing List and attach the compute_node
""" """
from DateTime import DateTime context.requestTransfer(
from zExceptions import Unauthorized destination_project=destination_project,
destination_section=destination_section
user = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue() )
if user is None or user.getRelativeUrl() != context.getSourceAdministration():
raise Unauthorized("Only the Computer Network owner can transfer it from one location to another.")
portal_type = "Internal Packing List"
source_project = context.Item_getCurrentProjectValue()
source_section = context.Item_getCurrentOwnerValue()
if destination_project is None and source_project is not None:
destination_project = source_project.getRelativeUrl()
if source_section is None:
source_section = context.getSourceAdministrationValue()
if destination_section is None:
destination_section = source_section.getRelativeUrl()
source = context.getSourceAdministration()
destination = context.getSourceAdministration()
resource_value = context.product_module.compute_node
module = context.getDefaultModule(portal_type=portal_type)
line_portal_type = '%s Line' % portal_type
delivery = module.newContent(title="Transfer %s to %s" % (context.getTitle(), destination_project),
source=source,
source_section_value=source_section,
source_project_value=source_project,
destination=destination,
destination_section=destination_section,
source_decision=destination_section,
destination_decision=destination_section,
destination_project=destination_project,
start_date=DateTime(),
stop_date=DateTime(),
portal_type=portal_type)
delivery_line = delivery.newContent(
portal_type=line_portal_type,
title=context.getReference(),
quantity_unit=resource_value.getQuantityUnit(),
resource_value=resource_value)
delivery_line.edit(
price=0.0,
quantity=1.0,
aggregate=context.getRelativeUrl())
delivery.confirm()
delivery.stop()
delivery.deliver()
portal = context.getPortalObject()
reference = "NET-%s" % portal.portal_ids.generateNewId(
id_group='slap_network_reference',
id_generator='uid')
context.edit(reference=reference)
""" """
Create an internal Packing List and attach the compute_node Create an internal Packing List and attach the compute_node
""" """
from DateTime import DateTime context.requestTransfer(
from zExceptions import Unauthorized destination=destination,
destination_project=destination_project
user = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue() )
if user is None or user.getRelativeUrl() != context.getDestinationSection():
raise Unauthorized("Only the Instance Tree owner can transfer it from one location to another.")
portal_type = "Internal Packing List"
source = context.Item_getCurrentSiteValue()
source_project = context.Item_getCurrentProjectValue()
source_section = context.Item_getCurrentOwnerValue()
resource_value = context.Item_getResourceValue()
if destination_project is None and source_project is not None:
destination_project = source_project.getRelativeUrl()
destination_section = context.getDestinationSection()
if source_section is None:
source_section = context.getDestinationSectionValue()
if destination is None and source is not None:
destination = source.getRelativeUrl()
resource_value = context.product_module.compute_node
module = context.getDefaultModule(portal_type=portal_type)
line_portal_type = '%s Line' % portal_type
delivery = module.newContent(title="Transfer %s to %s" % (context.getTitle(), destination_project),
source_value=source,
source_section_value=source_section,
source_project_value=source_project,
destination=destination,
destination_section=destination_section,
source_decision=destination_section,
destination_decision=destination_section,
destination_project_value=destination_project,
start_date=DateTime(),
stop_date=DateTime(),
portal_type=portal_type)
delivery_line = delivery.newContent(
portal_type=line_portal_type,
title=context.getReference(),
quantity_unit=context.getQuantityUnit(),
resource_value=resource_value)
delivery_line.edit(
price=0.0,
quantity=1.0,
aggregate_value=context)
delivery.confirm()
delivery.stop()
delivery.deliver()
<?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>testSlapOSCloudComputeNodeSlapInterfaceWorkflow</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.testSlapOSCloudComputeNodeSlapInterfaceWorkflow</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>
# -*- 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
class TestSlapOSCoreComputePartitionSlapInterfaceWorkflow(SlapOSTestCaseMixin):
def afterSetUp(self):
self.login()
SlapOSTestCaseMixin.afterSetUp(self)
# Clone compute_node document
self.compute_node = self.portal.compute_node_module.template_compute_node\
.Base_createCloneDocument(batch_mode=1)
self.compute_node.edit(
title="compute node %s" % (self.new_id, ),
reference="TESTCOMP-%s" % (self.new_id, ),
allocation_scope='open/personal',
capacity_scope='open',
)
self.compute_node.validate()
login = self.compute_node.newContent(
portal_type="ERP5 Login",
reference=self.compute_node.getReference()
)
login.validate()
# install an software release
self.software_installation = self.portal.software_installation_module\
.newContent(portal_type='Software Installation',
url_string=self.generateNewSoftwareReleaseUrl(),
aggregate=self.compute_node.getRelativeUrl())
self.software_installation.validate()
self.software_installation.requestStart()
self.tic()
self.login(self.compute_node.getUserId())
def test_markFree(self):
partition = self.compute_node.newContent(portal_type='Compute Partition',
reference='PART-%s' % self.generateNewId())
partition.validate()
partition.markFree()
self.tic()
self.assertEqual(1, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
def test_markFree_markBusy(self):
partition = self.compute_node.newContent(portal_type='Compute Partition',
reference='PART-%s' % self.generateNewId())
partition.validate()
partition.markFree()
self.tic()
self.assertEqual(1, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
partition.markBusy()
self.tic()
self.assertEqual(0, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
def test_markFree_markBusy_markFree(self):
partition = self.compute_node.newContent(portal_type='Compute Partition',
reference='PART-%s' % self.generateNewId())
partition.validate()
partition.markFree()
self.tic()
self.assertEqual(1, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
partition.markBusy()
self.tic()
self.assertEqual(0, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
partition.markFree()
self.tic()
self.assertEqual(1, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
def test_markInactive(self):
partition = self.compute_node.newContent(portal_type='Compute Partition',
reference='PART-%s' % self.generateNewId())
partition.validate()
partition.markInactive()
self.tic()
self.assertEqual(0, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
def test_markInactive_markFree(self):
partition = self.compute_node.newContent(portal_type='Compute Partition',
reference='PART-%s' % self.generateNewId())
partition.validate()
partition.markInactive()
self.tic()
self.assertEqual(0, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
partition.markFree()
self.tic()
self.assertEqual(1, self.portal.portal_catalog.countResults(
parent_uid=self.compute_node.getUid(), free_for_request=1)[0][0])
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</item> </item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>testSlapOSCloudWorkflow</string> </value> <value> <string>testSlapOSCloudComputePartitionSlapInterfaceWorkflow</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSCloudWorkflow</string> </value> <value> <string>test.erp5.testSlapOSCloudComputePartitionSlapInterfaceWorkflow</string> </value>
</item> </item>
<item> <item>
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
......
<?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>testSlapOSCloudInstanceSlapInterfaceWorkflow</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.testSlapOSCloudInstanceSlapInterfaceWorkflow</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>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</item> </item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>testSlapOSCloudCreateMovementSkins</string> </value> <value> <string>testSlapOSCloudInteractionWorkflow</string> </value>
</item> </item>
<item> <item>
<key> <string>default_source_reference</string> </key> <key> <string>default_source_reference</string> </key>
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSCloudCreateMovementSkins</string> </value> <value> <string>test.erp5.testSlapOSCloudInteractionWorkflow</string> </value>
</item> </item>
<item> <item>
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
......
# -*- 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 time import sleep
from zExceptions import Unauthorized
import transaction
class TestSlapOSCoreNetworkSlapInterfaceWorkflow(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.network = portal.computer_network_module.newContent(
portal_type="Computer Network"
)
self.tic()
self.assertEqual(
self.network.getReference(), None)
def beforeTearDown(self):
transaction.abort()
def test_network_approveRegistration_with_reference(self):
reference = "TEST-%s" % self.generateNewId()
self.network.setReference(reference)
self.network.approveRegistration()
self.assertEqual(self.network.getReference(), reference)
def test_organisation_approveRegistration_already_validated(self):
# Login as admin since user cannot re-approve a validated organisation
self.login()
self.network.setReference(None)
self.network.validate()
# Don't raise if network is validated
self.assertEqual(self.network.approveRegistration(), None)
def _makeProject(self):
project = self.portal.project_module.newContent()
project.edit(reference="TESTPROJ-%s" % project.getId())
project.validate()
self.tic()
return project
def _makeOrganisation(self):
organisation = self.portal.organisation_module.newContent()
organisation.edit(reference="TESTSITE-%s" % organisation.getId())
organisation.validate()
self.tic()
return organisation
def test_ComputerNetwork_requestTransfer_project(self):
source_administrator = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.network.setSourceAdministrationValue(source_administrator)
self.login()
self.network.approveRegistration()
project = self._makeProject()
other_project = self._makeProject()
self.tic()
self.login(source_administrator.getUserId())
self.assertEqual(self.network.Item_getCurrentProjectValue(), None)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), None)
# Place in a project
self.network.requestTransfer(
destination_section=None,
destination_project=project.getRelativeUrl())
self.tic()
self.assertEqual(self.network.Item_getCurrentProjectValue(), project)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), source_administrator)
self.assertEqual(1,
len(self.network.getAggregateRelatedList(portal_type="Internal Packing List Line"))
)
self.login(source_administrator.getUserId())
# We don't remove from Project if destination project is not provided
self.network.requestTransfer(
destination_project=None,
destination_section=None
)
self.tic()
self.assertEqual(self.network.Item_getCurrentProjectValue(), project)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), source_administrator)
self.assertEqual(2,
len(self.network.getAggregateRelatedList(portal_type="Internal Packing List Line"))
)
# Ensure that we don't have 2 new Internal Packing lists in the same second
sleep(1)
# Place in another project
self.network.requestTransfer(
destination_section=None,
destination_project=other_project.getRelativeUrl())
self.tic()
self.assertEqual(self.network.Item_getCurrentProjectValue(), other_project)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), source_administrator)
self.assertEqual(3,
len(self.network.getAggregateRelatedList(portal_type="Internal Packing List Line"))
)
self.login(source_administrator.getUserId())
# Ensure that we don't have 2 new Internal Packing lists in the same second
sleep(1)
# We don't remove from Project if destination project is not provided
self.network.requestTransfer(
destination_project=None,
destination_section=None
)
self.tic()
self.assertEqual(self.network.Item_getCurrentProjectValue(), other_project)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), source_administrator)
self.assertEqual(4,
len(self.network.getAggregateRelatedList(portal_type="Internal Packing List Line"))
)
def test_ComputerNetwork_requestTransfer_owner(self):
source_administrator = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.network.setSourceAdministrationValue(source_administrator)
self.login()
self.network.approveRegistration()
organisation = self._makeOrganisation()
other_organisation = self._makeOrganisation()
self.tic()
self.login(source_administrator.getUserId())
self.assertEqual(self.network.Item_getCurrentProjectValue(), None)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), None)
self.network.requestTransfer(
destination_project=None,
destination_section=organisation.getRelativeUrl())
self.tic()
self.assertEqual(self.network.Item_getCurrentProjectValue(), None)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), organisation)
self.assertEqual(1,
len(self.network.getAggregateRelatedList(portal_type="Internal Packing List Line"))
)
self.login(source_administrator.getUserId())
# Ensure that we don't have 2 new Internal Packing lists in the same second
sleep(1)
# We don't remove from Project if destination project is not provided
self.network.requestTransfer(
destination_project=None,
destination_section=None)
self.tic()
self.assertEqual(self.network.Item_getCurrentProjectValue(), None)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), organisation)
# Ensure that we don't have 2 new Internal Packing lists in the same second
sleep(1)
# Place in another project
self.network.requestTransfer(
destination_project=None,
destination_section=other_organisation.getRelativeUrl())
self.tic()
self.assertEqual(3,
len(self.network.getAggregateRelatedList(portal_type="Internal Packing List Line"))
)
self.assertEqual(self.network.Item_getCurrentProjectValue(), None)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), other_organisation)
self.assertEqual(3,
len(self.network.getAggregateRelatedList(portal_type="Internal Packing List Line"))
)
self.login(source_administrator.getUserId())
# Ensure that we don't have 2 new Internal Packing lists in the same second
sleep(1)
# We don't remove from Project if destination project is not provided
self.network.requestTransfer(
destination_project=None,
destination_section=None
)
self.tic()
self.assertEqual(self.network.Item_getCurrentProjectValue(), None)
self.assertEqual(self.network.Item_getCurrentOwnerValue(), other_organisation)
self.assertEqual(4,
len(self.network.getAggregateRelatedList(portal_type="Internal Packing List Line"))
)
def test_ComputerNetwork_requestTransfer_Unauthorized(self):
self.network.approveRegistration()
self.login()
self.assertRaises(Unauthorized, self.network.requestTransfer)
source_administrator = self.makePerson(user=1)
self.assertEqual(1 , len(source_administrator.objectValues( portal_type="ERP5 Login")))
self.login(source_administrator.getUserId())
self.assertRaises(Unauthorized, self.network.requestTransfer)
self.login()
other_user = self.makePerson(user=1)
self.assertEqual(1 , len(other_user.objectValues(portal_type="ERP5 Login")))
self.network.setSourceAdministrationValue(source_administrator)
self.tic()
self.assertRaises(Unauthorized, self.network.requestTransfer)
self.login(other_user.getUserId())
self.assertRaises(Unauthorized, self.network.requestTransfer)
self.login(source_administrator.getUserId())
self.network.requestTransfer(
destination_project=None,
destination_section=None
)
<?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>testSlapOSCloudNetworkSlapInterfaceWorkflow</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.testSlapOSCloudNetworkSlapInterfaceWorkflow</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>error_message</string> </key>
<value>
<list>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</list>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="Message" module="Products.ERP5Type.Message"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string>ID is invalid, should be \'${id_prefix}.VERSION.REFERENCE\'</string> </value>
</item>
<item>
<key> <string>domain</string> </key>
<value> <string>erp5_ui</string> </value>
</item>
<item>
<key> <string>mapping</string> </key>
<value>
<dictionary>
<item>
<key> <string>id_prefix</string> </key>
<value> <string>test</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>message</string> </key>
<value> <string>ID is invalid, should be \'${id_prefix}.VERSION.REFERENCE\'</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# -*- 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>
<?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>testSlapOSCloudPersonSlapInterfaceWorkflow</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.testSlapOSCloudPersonSlapInterfaceWorkflow</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>
# -*- 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 TestSlapOSCoreProjectSlapInterfaceWorkflow(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.project = portal.project_module.newContent(
portal_type="Project"
)
# Value set by the init
self.assertTrue(self.project.getReference().startswith("PROJ-"),
"Reference don't start with PROJ- : %s" % self.project.getReference())
self.tic()
def beforeTearDown(self):
transaction.abort()
def test_project_approveRegistration_no_reference(self):
self.project.setReference(None)
self.assertRaises(ValueError, self.project.approveRegistration)
def test_project_approveRegistration_already_validated(self):
# Login as admin since user cannot re-approve a validated project
self.login()
self.project.setReference(None)
self.project.validate()
# Don't raise if project is validated
self.assertEqual(self.project.approveRegistration(), None)
def test_project_approveRegistration(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.project.approveRegistration()
self.tic()
self.logout()
self.login(person.getUserId())
self.assertEqual(self.project.getValidationState(),
'validated')
self.assertNotEqual(self.project.getStartDate(),
None)
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationProjectValue() == self.project]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.assertIn("Assigment for Project ", assignment_list[0].getTitle())
def test_project_leaveProject_no_user(self):
self.login()
self.assertRaises(Unauthorized, self.project.leaveProject)
def test_project_leaveProject_owner(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.project.edit(destination_decision=person.getRelativeUrl())
self.tic()
self.project.leaveProject()
self.assertEqual(self.project.getDestinationDecision(),
None)
def test_project_leaveProject_after_join(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
# Just make things fast, by using the API tested above
self.project.approveRegistration()
self.tic()
self.logout()
self.login(person.getUserId())
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationProjectValue() == self.project]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.project.leaveProject()
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationProjectValue() == self.project]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'closed')
def test_project_acceptInvitation_no_invitation_token(self):
self.assertRaises(TypeError, self.project.acceptInvitation)
def test_project_acceptInvitation_no_token_dont_exist(self):
self.assertRaises(ValueError, self.project.acceptInvitation,
invitation_token="DONOTEXIST")
def test_project_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.project.acceptInvitation,
invitation_token=token_id)
# Not validated yet
self.login(person.getUserId())
self.assertRaises(ValueError, self.project.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.project.acceptInvitation,
invitation_token=token_id)
self.login()
token.setSourceValue(None)
self.login(person.getUserId())
self.project.acceptInvitation(invitation_token=token_id)
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationProjectValue() == self.project]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.assertEqual(token.getValidationState(), "invalidated")
def test_project_acceptInvitation_already_member(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.project.approveRegistration()
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationProjectValue() == self.project]
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.project.acceptInvitation,
invitation_token=token_id)
# Not validated yet
self.login(person.getUserId())
self.assertRaises(ValueError, self.project.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.project.acceptInvitation,
invitation_token=token_id)
self.login()
token.setSourceValue(None)
self.login(person.getUserId())
self.project.acceptInvitation(invitation_token=token_id)
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationProjectValue() == self.project]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.assertEqual(token.getValidationState(), "invalidated")
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<ZopeData> <ZopeData>
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/> <global name="Workflow Script" module="erp5.portal_type"/>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
...@@ -50,41 +50,35 @@ ...@@ -50,41 +50,35 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>**kw</string> </value> <value> <string>state_change</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
<value> <value>
<tuple> <tuple>
<string>Manager</string>
<string>Owner</string> <string>Owner</string>
</tuple> </tuple>
</value> </value>
</item> </item>
<item> <item>
<key> <string>guard</string> </key> <key> <string>description</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <none/>
</value> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ComputerNetwork_init</string> </value> <value> <string>script_ComputeNode_requestTransfer</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Script</string> </value>
</item> </item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Guard" module="Products.DCWorkflow.Guard"/>
</pickle>
<pickle>
<dictionary>
<item> <item>
<key> <string>roles</string> </key> <key> <string>title</string> </key>
<value> <value>
<tuple> <none/>
<string>Owner</string>
</tuple>
</value> </value>
</item> </item>
</dictionary> </dictionary>
......
...@@ -21,10 +21,17 @@ ...@@ -21,10 +21,17 @@
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_report_compute_node_bang</string> <string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_report_compute_node_bang</string>
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_request_compute_node_registration</string> <string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_request_compute_node_registration</string>
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_request_software_release</string> <string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_request_software_release</string>
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_request_transfer</string>
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_revoke_certificate</string> <string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_revoke_certificate</string>
</tuple> </tuple>
</value> </value>
</item> </item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
<value> <value>
......
context.REQUEST.set("role_id", "host")
context.Person_requestOrganisation(state_change)
This diff is collapsed.
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