Commit 1c66186e authored by Romain Courteaud's avatar Romain Courteaud

slapos_erp5: wip subscription change request scenario

parent 74628040
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2022 Nexedi SA and Contributors. All Rights Reserved.
#
##############################################################################
from erp5.component.test.testSlapOSERP5VirtualMasterScenario import TestSlapOSVirtualMasterScenarioMixin
from DateTime import DateTime
class TestSlapOSSubscriptionChangeRequestScenarioMixin(TestSlapOSVirtualMasterScenarioMixin):
pass
class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRequestScenarioMixin):
def test_subscription_change_request_change_instance_destination_without_accounting_scenario(self):
currency, _, _, sale_person = self.bootstrapVirtualMasterTest(is_virtual_master_accountable=False)
self.tic()
self.logout()
# lets join as slapos administrator, which will own few compute_nodes
owner_reference = 'owner-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, owner_reference)
self.login()
owner_person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=owner_reference).getParentValue()
#owner_person.setCareerSubordinationValue(seller_organisation)
self.tic()
# hooray, now it is time to create compute_nodes
self.logout()
self.login(sale_person.getUserId())
# create a default project
project_relative_url = self.addProject(person=owner_person, currency=currency)
self.logout()
self.login()
project = self.portal.restrictedTraverse(project_relative_url)
preference = self.portal.portal_preferences.slapos_default_system_preference
preference.edit(
preferred_subscription_assignment_category_list=[
'function/customer',
'role/client',
'destination_project/%s' % project.getRelativeUrl()
]
)
self.tic()
self.logout()
self.login(owner_person.getUserId())
"""
public_server_title = 'Public Server for %s' % owner_reference
public_server_id = self.requestComputeNode(public_server_title, project.getReference())
public_server = self.portal.portal_catalog.getResultValue(
portal_type='Compute Node', reference=public_server_id)
self.setAccessToMemcached(public_server)
self.assertNotEqual(None, public_server)
self.setServerOpenPublic(public_server)
public_server.generateCertificate()
"""
# and install some software on them
public_server_software = self.generateNewSoftwareReleaseUrl()
public_instance_type = 'public type'
"""
self.supplySoftware(public_server, public_server_software)
# format the compute_nodes
self.formatComputeNode(public_server)
software_product, release_variation, type_variation = self.addSoftwareProduct(
"""
self.addSoftwareProduct(
"instance product", project, public_server_software, public_instance_type
)
"""
self.addAllocationSupply("for compute node", public_server, software_product,
release_variation, type_variation)
self.tic()
self.logout()
"""
"""
self.login()
self.checkServiceSubscriptionRequest(public_server)
"""
# join as the another visitor and request software instance on public
# compute_node
self.logout()
public_reference = 'public-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, public_reference)
public_reference2 = 'public2-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, public_reference2)
self.login()
public_person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=public_reference).getParentValue()
public_person2 = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=public_reference2).getParentValue()
person_user_id = public_person.getUserId()
software_release = public_server_software
software_type = public_instance_type
project_reference = project.getReference()
public_instance_title = 'Public title %s' % self.generateNewId()
self.login(person_user_id)
self.personRequestInstanceNotReady(
software_release=software_release,
software_type=software_type,
partition_reference=public_instance_title,
project_reference=project_reference
)
self.tic()
# XXX search only for this user
instance_tree = self.portal.portal_catalog.getResultValue(
portal_type="Instance Tree",
title=public_instance_title,
follow_up__reference=project_reference
)
self.checkServiceSubscriptionRequest(instance_tree)
self.tic()
"""
self.login(person_user_id)
self.personRequestInstance(
software_release=software_release,
software_type=software_type,
partition_reference=public_instance_title,
project_reference=project_reference
)
"""
"""
self.checkInstanceAllocation(public_person.getUserId(),
public_reference, public_instance_title,
public_server_software, public_instance_type,
public_server, project.getReference())
"""
self.login(sale_person.getUserId())
open_sale_order_cell = self.portal.portal_catalog.getResultValue(
portal_type='Open Sale Order Cell',
aggregate__uid=instance_tree.getUid(),
validation_state='validated'
)
open_sale_order_line = open_sale_order_cell.getParentValue()
open_sale_order = open_sale_order_line.getParentValue()
now = DateTime()
subscription_change_request = self.portal.subscription_change_request_module.newContent(
portal_type='Subscription Change Request',
causality_value=open_sale_order,
destination_value=public_person2,
destination_section_value=public_person2,
destination_decision_value=public_person2,
destination_project=open_sale_order.getDestinationProject(),
# XXX XXX should be calculated, and not copied
# to ensure the expected value is fetched
specialise_value=open_sale_order.getSpecialiseValue(),
source=open_sale_order.getSource(),
source_section=open_sale_order.getSourceSection(),
source_project=open_sale_order.getSourceProject(),
price_currency=open_sale_order.getPriceCurrency(),
start_date=now,
effective_date=now,
resource=open_sale_order_line.getResource(),
variation_category_list=open_sale_order_line.getVariationCategoryList(),
quantity_unit=open_sale_order_line.getQuantityUnit(),
aggregate=open_sale_order_cell.getAggregate(portal_type=['Instance Tree', 'Project', 'Compute Node']),
quantity=open_sale_order_cell.getQuantity(),
# ledger="automated",
# XXX check that price is consistent with trade condition payable or not
price=open_sale_order_cell.getPrice() + 1,
# XXX activate_kw=activate_kw
)
subscription_change_request.submit()
self.tic()
self.logout()
self.login()
self.assertEquals(instance_tree.getDestinationSection(),
public_person2.getRelativeUrl())
# Total of quantity should be zero
inventory_list_kw = {
'group_by_section': False,
'group_by_node': False,
'group_by_variation': False,
'group_by_resource': True,
'resource_uid': subscription_change_request.getResourceUid(),
}
inventory_list = self.portal.portal_simulation.getCurrentInventoryList(**inventory_list_kw)
self.assertEquals(1, len(inventory_list))
self.assertEquals(0, inventory_list[0].total_quantity)
# Seller only sold 1 month
inventory_list_kw = {
'node_uid': subscription_change_request.getSourceUid(),
'group_by_section': False,
'group_by_node': False,
'group_by_variation': False,
'group_by_resource': True,
'resource_uid': subscription_change_request.getResourceUid(),
}
inventory_list = self.portal.portal_simulation.getCurrentInventoryList(**inventory_list_kw)
self.assertEquals(1, len(inventory_list))
self.assertEquals(-1, inventory_list[0].total_quantity)
inventory_list_kw = {
'group_by_section': False,
'group_by_node': True,
'group_by_variation': True,
'resource_uid': subscription_change_request.getResourceUid(),
}
inventory_list = self.portal.portal_simulation.getCurrentInventoryList(**inventory_list_kw)
self.assertEquals(3, len(inventory_list))
tracking_list = instance_tree.Item_getTrackingList()
self.assertEquals(2, len(tracking_list))
self.assertEquals(None, self.portal.portal_simulation.getInventoryList())
# Ensure no unexpected object has been created
# 2 credential request
# 1 instance tree
# 7 open sale order
# 4 assignment
# 3 simulation movement
# 4 sale packing list / line
# 2 sale trade condition ( a 3rd trade condition is not linked to the project)
# 1 software instance
# 1 software product
# 1 subscription change request
# 2 subscription request
self.assertRelatedObjectCount(project, 28)
self.checkERP5StateBeforeExit()
<?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>testSlapOSERP5SubscriptionChangeRequestScenario</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.testSlapOSERP5SubscriptionChangeRequestScenario</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>
......@@ -7,6 +7,7 @@ test.erp5.testSlapOSERP5InteractionWorkflow
test.erp5.testSlapOSERP5LocalPermissionSlapOSInteractionWorkflow
test.erp5.testSlapOSERP5SiteDump
test.erp5.testSlapOSERP5SkinSelection
test.erp5.testSlapOSERP5SubscriptionChangeRequestScenario
test.erp5.testSlapOSERP5VirtualMasterScenario
test.erp5.testSlapOSPrecacheManifest
test.erp5.testSlapOSPrecacheManifest
......
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