Commit 015f2b24 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Update Constraint for check Duplicate Reference

   Unify constraints to check if reference is Unique under SlapOSReferenceConstraint

   Before the introduction of ERP5 Login, it would require to check if reference was unique, by checking also Person documents. This isnt required anymore, since ERP5 Login/Certificate Login and user_id has its own code to check if user is Unique.
parent cc426ec7
......@@ -37,7 +37,6 @@
<portal_type id="Instance Tree">
<item>HostingSubscriptionUpgradeConstraint</item>
<item>InstanceTree</item>
<item>SlapOSReferenceConstraint</item>
<item>SlaposInstanceTreeConstraint</item>
<item>SoftwareInstance</item>
<item>SoftwareInstanceUpgradeConstraint</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Script Constraint" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>constraint_type/default</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>check_duplicate_constraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Script Constraint</string> </value>
</item>
<item>
<key> <string>script_id</string> </key>
<value> <string>Base_checkDuplicatedReference</string> </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/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -34,7 +34,7 @@
</item>
<item>
<key> <string>filter_parameter</string> </key>
<value> <string>python: {\'portal_type\': (object.getPortalType(), \'Person\'), \'reference\': object.getReference()}</string> </value>
<value> <string>python: {\'portal_type\': (object.getPortalType(), ), \'reference\': object.getReference()}</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
portal = context.getPortalObject()
error_list = []
reference = context.getReference()
result = portal.portal_catalog(reference=reference,
portal_type=context.getPortalType(), limit=2)
if len(result) > 1 or \
(len(result) == 1 and result[0].getUid() != context.getUid()):
error_list.append("%s (%s) has duplicated reference." % (
context.getRelativeUrl(), context.getReference()))
return error_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</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>fixit=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_checkDuplicatedReference</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -550,37 +550,69 @@ class TestSlapOSComputeNodeConstraint(TestSlapOSConstraintMixin):
consistency_message = 'Title must be defined'
self.assertTrue(consistency_message in self.getMessageList(compute_node))
compute_node.setTitle(self.generateNewId())
self.assertFalse(consistency_message in self.getMessageList(compute_node))
def test_reference_not_empty(self):
compute_node = self.portal.compute_node_module.newContent(portal_type='Compute Node')
consistency_message = 'Reference must be defined'
self.assertTrue(consistency_message in self.getMessageList(compute_node))
class TestSlapOSReferenceConstraint(TestSlapOSConstraintMixin):
compute_node.setReference(self.generateNewId())
def test_reference_not_empty_compute_node(self):
self._test_reference_not_empty(
self.portal.compute_node_module.newContent(portal_type='Compute Node'))
self.assertFalse(consistency_message in self.getMessageList(compute_node))
def test_reference_not_empty_software_instance(self):
self._test_reference_not_empty(
self.portal.software_instance_module.newContent(portal_type='Software Instance'))
def test_reference_unique(self):
reference = self.generateNewId()
reference_2 = self.generateNewId()
compute_node = self.portal.compute_node_module.newContent(portal_type='Compute Node',
reference=reference)
compute_node_2 = self.portal.compute_node_module.newContent(portal_type='Compute Node',
reference=reference)
consistency_message = 'Reference must be unique'
def test_reference_not_empty_slave_instance(self):
self._test_reference_not_empty(
self.portal.software_instance_module.newContent(portal_type='Slave Instance'))
def test_reference_not_empty_software_installation(self):
self._test_reference_not_empty(
self.portal.software_installation_module.newContent(portal_type='Software Installation'))
def _test_reference_not_empty(self, document):
consistency_message = 'Reference must be defined'
self.assertIn(consistency_message, self.getMessageList(document))
document.setReference(self.generateNewId())
self.assertNotIn(consistency_message, self.getMessageList(document))
def test_reference_unique_compute_node(self):
module = self.portal.compute_node_module
self._test_reference_unique(
module.newContent(portal_type='Compute Node', reference=self.generateNewId()),
module.newContent(portal_type='Compute Node', reference=self.generateNewId()))
def test_reference_unique_software_instance(self):
module = self.portal.software_instance_module
self._test_reference_unique(
module.newContent(portal_type='Software Instance', reference=self.generateNewId()),
module.newContent(portal_type='Software Instance', reference=self.generateNewId()))
def test_reference_unique_slave_instance(self):
module = self.portal.software_instance_module
self._test_reference_unique(
module.newContent(portal_type='Slave Instance', reference=self.generateNewId()),
module.newContent(portal_type='Slave Instance', reference=self.generateNewId()))
def test_reference_unique_software_installation(self):
module = self.portal.software_installation_module
self._test_reference_unique(
module.newContent(portal_type='Software Installation', reference=self.generateNewId()),
module.newContent(portal_type='Software Installation', reference=self.generateNewId()))
def _test_reference_unique(self, documentA, documentB):
consistency_message = 'Reference must be unique'
self.tic()
self.assertTrue(consistency_message in self.getMessageList(compute_node))
self.assertTrue(consistency_message in self.getMessageList(compute_node_2))
self.assertNotIn(consistency_message, self.getMessageList(documentA))
self.assertNotIn(consistency_message, self.getMessageList(documentB))
compute_node_2.setReference(reference_2)
documentB.setReference(documentA.getReference())
self.tic()
self.assertFalse(consistency_message in self.getMessageList(compute_node))
self.assertFalse(consistency_message in self.getMessageList(compute_node_2))
self.assertEqual(documentB.getReference(), documentA.getReference())
self.assertIn(consistency_message, self.getMessageList(documentA))
self.assertIn(consistency_message, self.getMessageList(documentB))
......@@ -17,7 +17,6 @@ Email | SlaposEmailConstraint
Hosting Subscription | HostingSubscriptionUpgradeConstraint
Instance Tree | HostingSubscriptionUpgradeConstraint
Instance Tree | InstanceTree
Instance Tree | SlapOSReferenceConstraint
Instance Tree | SlaposInstanceTreeConstraint
Instance Tree | SoftwareInstance
Instance Tree | SoftwareInstanceUpgradeConstraint
......
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