Commit d46cef4e authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud:

* configure Allocation Supply Cell predicate
* test Allocation Supply predicate
parent ce3298e6
line = context.getParentValue()
supply = line.getParentValue()
if (supply.getPortalType() != 'Allocation Supply') or (supply.getValidationState() != 'validated'):
return None
if not context.isAllocable():
return None
base_category_tuple = ('resource', 'software_type', 'software_release', 'destination_project')
if supply.getDestination():
base_category_tuple += ('destination',)
return context.generatePredicate(membership_criterion_base_category_list = base_category_tuple,
criterion_property_list = ('start_date',))
<?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>*args,**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AllocationSupplyCell_asPredicate</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -46,15 +46,15 @@ tmp_context = portal.portal_trash.newContent(
resource_value=software_product,
software_type_value=type_variation,
software_release_value=release_variation,
destination_value=context,
destination_project_value=software_product.getFollowUpValue(),
start_date=DateTime()
)
allocation_cell_list = [x.getObject() for x in \
domain_tool.searchPredicateList(
tmp_context, portal_type=['Allocation Supply Cell'],
validation_state='validated',
destination_project__uid=project_uid,
tested_base_category_list=['resource', 'software_type', 'software_release']) if x.isAllocable()]
tmp_context, portal_type=['Allocation Supply Cell'])
if x.isAllocable()]
#context.log('allocation_cell_list %s' % str(allocation_cell_list))
if not allocation_cell_list:
......
# Copyright (c) 2022 Nexedi SA and Contributors. All Rights Reserved.
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixin
from DateTime import DateTime
from Products.CMFCore.utils import getToolByName
class TestSlapOSAllocationSupply(SlapOSTestCaseMixin):
def test_check(self):
# Create 2 projects
project_1 = self.portal.project_module.newContent(
portal_type="Project",
title="project_1"
)
project_2 = self.portal.project_module.newContent(
portal_type="Project",
title="project_2"
)
# Create 2 software product
# - one with 1 release and 1 type
# - one with 2 releases and 2 types
simple_product = self.portal.software_product_module.newContent(
portal_type="Software Product",
title="Simple Product"
)
simple_product.newContent(
portal_type="Software Product Type Variation",
title="software_type_a"
)
simple_product.newContent(
portal_type="Software Product Release Variation",
url_string="http://example.org/release_1"
)
complex_product = self.portal.software_product_module.newContent(
portal_type="Software Product",
title="Complex Product"
)
complex_product.newContent(
portal_type="Software Product Type Variation",
title="software_type_b"
)
complex_product.newContent(
portal_type="Software Product Type Variation",
title="software_type_c"
)
complex_product.newContent(
portal_type="Software Product Release Variation",
url_string="http://example.org/release_2"
)
complex_product.newContent(
portal_type="Software Product Release Variation",
url_string="http://example.org/release_3"
)
# create 2 users
person_1 = self.portal.person_module.newContent()
person_2 = self.portal.person_module.newContent()
# Create 2 allocation supplies
# - one for everybody (no destination)
# - one for one specific user
now = DateTime()
everybody_supply = self.portal.allocation_supply_module.newContent(
title="Everybody Supply",
start_date_range_min=now,
destination_project_value=project_1
)
person_1_supply = self.portal.allocation_supply_module.newContent(
title="Person 1 Supply",
start_date_range_min=now,
destination_project_value=project_1,
destination_value=person_1
)
# Create Allocation Line/Cell for all product combination
allocation_supply_cell_list = []
base_id = 'path'
for allocation_supply in [everybody_supply, person_1_supply]:
for software_product in [simple_product, complex_product]:
allocation_supply_line = allocation_supply.newContent(
portal_type="Allocation Supply Line",
resource_value=software_product
)
allocation_supply_line.edit(
p_variation_base_category_list=allocation_supply_line.getVariationRangeBaseCategoryList()
)
allocation_supply_line.setCellRange(
base_id=base_id,
*allocation_supply_line.SupplyLine_asCellRange(base_id=base_id)
)
for cell_key in list(allocation_supply_line.getCellKeyList(base_id=base_id)):
allocation_supply_cell = allocation_supply_line.newCell(
base_id=base_id,
portal_type='Allocation Supply Cell',
*cell_key
)
allocation_supply_cell.edit(
mapped_value_property_list=['allocable'],
allocable=True,
predicate_category_list=cell_key,
variation_category_list=cell_key
)
allocation_supply_cell_list.append(allocation_supply_cell)
allocation_supply.validate()
self.tic()
# Create 2 movements
# one for everybody
# one for one specific user
# check if predicates match
i = 0
domain_tool = getToolByName(self.portal, 'portal_domains')
for software_product in [simple_product, complex_product]:
for software_type in software_product.contentValues(portal_type="Software Product Type Variation"):
for software_release in software_product.contentValues(portal_type="Software Product Release Variation"):
for project in [project_1, project_2, None]:
for destination in [person_1, person_2, None]:
for start_date in [now, now-1, None]:
tmp_context = self.portal.portal_trash.newContent(
portal_type='Movement',
temp_object=1,
resource_value=software_product,
software_type_value=software_type,
software_release_value=software_release,
start_date=start_date,
destination_project_value=project,
destination_value=destination
)
for allocation_supply_cell in allocation_supply_cell_list:
expected_test_result = (
(software_product.getRelativeUrl() == allocation_supply_cell.getResource()) and
(software_type.getRelativeUrl() == allocation_supply_cell.getSoftwareType()) and
(software_release.getRelativeUrl() == allocation_supply_cell.getSoftwareRelease()) and
(project == allocation_supply_cell.getParentValue().getParentValue().getDestinationProjectValue()) and
((allocation_supply_cell.getParentValue().getParentValue().getDestinationValue() is None) or
(destination == allocation_supply_cell.getParentValue().getParentValue().getDestinationValue())) and
(start_date == allocation_supply_cell.getParentValue().getParentValue().getStartDateRangeMin())
)
assert allocation_supply_cell.test(tmp_context) == expected_test_result, """Expected: %s %i
Product: %s %s
Type: %s %s
Release: %s %s
Project: %s %s
Destination: %s %s
Date: %s %s
""" % (
expected_test_result, i,
software_product.getRelativeUrl(), allocation_supply_cell.getResource(),
software_type.getRelativeUrl(), allocation_supply_cell.getSoftwareType(),
software_release.getRelativeUrl(), allocation_supply_cell.getSoftwareRelease(),
project.getRelativeUrl(),allocation_supply_cell.getParentValue().getParentValue().getDestinationProject(),
destination, allocation_supply_cell.getParentValue().getParentValue().getDestination(),
start_date, allocation_supply_cell.getParentValue().getParentValue().getStartDateRangeMin()
)
assert (allocation_supply_cell in domain_tool.searchPredicateList(
tmp_context, portal_type=['Allocation Supply Cell'])) == expected_test_result
i += 1
<?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>default_reference</string> </key>
<value> <string>testSlapOSAllocationSupply</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.testSlapOSAllocationSupply</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">AAAAAAAAAAI=</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>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<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>
test.erp5.testSlapOSCloudAlarm
test.erp5.testSlapOSAllocationSupply
test.erp5.testSlapOSCloudAllocationAlarm
test.erp5.testSlapOSCloudComputePartitionSlapInterfaceWorkflow
test.erp5.testSlapOSCloudInteractionWorkflow
......
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