Commit 2687799b authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: testSlapOSAccountingBuilder

Recreate the expected organisation.
Drop the aggregated builder test
parent 2bd65de0
......@@ -14,6 +14,13 @@ def convertCategoryList(base, l):
return ['%s/%s' % (base, q) for q in l]
class TestSlapOSSalePackingListBuilder(SlapOSTestCaseMixin):
def afterSetUp(self):
super(TestSlapOSSalePackingListBuilder, self).afterSetUp()
self.expected_slapos_organisation = self.portal.organisation_module.newContent(
portal_type="Organisation",
title="testSlapOSAccountingBuilder"
).getRelativeUrl()
def checkSimulationMovement(self, simulation_movement):
self.assertEqual(1.0, simulation_movement.getDeliveryRatio())
self.assertEqual(0.0, simulation_movement.getDeliveryError())
......@@ -152,6 +159,7 @@ class TestSlapOSSalePackingListBuilder(SlapOSTestCaseMixin):
self.checkDelivery(simulation_movement_2, delivery_2, **delivery_kw)
class TestSlapOSSaleInvoiceBuilder(TestSlapOSSalePackingListBuilder):
def test(self, causality1=None, causality2=None): # pylint: disable=arguments-differ
person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1)
......@@ -1826,184 +1834,3 @@ class TestSlapOSSaleInvoiceTransactionTradeModelBuilder(TestSlapOSSalePackingLis
self.assertEqual(invoice_2.getRelativeUrl(),
model_line_2_tax_bis.getParentValue().getRelativeUrl())
class TestSlapOSAggregatedDeliveryBuilder(SlapOSTestCaseMixin):
def emptyBuild(self, **kw):
delivery_list = self._build(**kw)
self.assertSameSet([], delivery_list)
return delivery_list
def fullBuild(self, **kw):
delivery_list = self._build(**kw)
self.assertNotEqual([], delivery_list)
return delivery_list
def _build(self, **kw):
return self.portal.portal_orders.slapos_aggregated_delivery_builder.build(
**kw)
def _createDelivery(self, **kwargs):
delivery = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredInstanceDeliveryTemplate()
).Base_createCloneDocument(batch_mode=1)
delivery.edit(**kwargs)
self.portal.portal_workflow._jumpToStateFor(delivery, 'delivered')
return delivery
def _addDeliveryLine(self, delivery, **kwargs):
kwargs.setdefault('portal_type', 'Sale Packing List Line')
kwargs.setdefault('quantity', 1.0)
kwargs.setdefault('resource', 'service_module/slapos_instance_setup')
kwargs.setdefault('price', 0.0)
delivery_line = delivery.newContent(**kwargs)
return delivery_line
def test(self):
person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1)
delivery = self._createDelivery(destination_value=person,
destination_decision_value=person)
delivery_line = self._addDeliveryLine(delivery)
self.tic()
delivery_list = self.fullBuild(uid=delivery_line.getUid())
self.assertEqual(1, len(delivery_list))
built_delivery = delivery_list[0]
self.assertEqual(delivery_line.getGroupingReference(),
built_delivery.getReference())
self.assertEqual('confirmed', built_delivery.getSimulationState())
self.assertEqual('building', built_delivery.getCausalityState())
self.assertSameSet([
'destination/%s' % person.getRelativeUrl(),
'destination_decision/%s' % person.getRelativeUrl(),
'destination_section/%s' % person.getRelativeUrl(),
'price_currency/currency_module/EUR',
'source/%s' % self.expected_slapos_organisation,
'source_section/%s' % self.expected_slapos_organisation,
'specialise/%s' % AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL],
built_delivery.getCategoryList())
self.assertEqual(DateTime().earliestTime(), built_delivery.getStartDate())
delivery_line_list = built_delivery.contentValues(
portal_type='Sale Packing List Line')
self.assertEqual(1, len(delivery_line_list))
built_delivery_line = delivery_line_list[0]
self.assertEqual(1.0, built_delivery_line.getQuantity())
self.assertEqual(0.0, built_delivery_line.getPrice())
self.assertEqual(delivery_line.getResource(),
built_delivery_line.getResource())
def test_many_lines(self):
person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1)
delivery = self._createDelivery(destination_value=person,
destination_decision_value=person)
setup_line_1 = self._addDeliveryLine(delivery)
setup_line_2 = self._addDeliveryLine(delivery)
cleanup_line = self._addDeliveryLine(delivery,
resource='service_module/slapos_instance_cleanup')
update_line = self._addDeliveryLine(delivery,
resource='service_module/slapos_instance_update')
subscription_line = self._addDeliveryLine(delivery,
resource='service_module/slapos_instance_subscription')
self.tic()
delivery_list = self.fullBuild(uid=[setup_line_1.getUid(),
setup_line_2.getUid(), cleanup_line.getUid(), update_line.getUid(),
subscription_line.getUid()])
self.assertEqual(1, len(delivery_list))
built_delivery = delivery_list[0]
self.assertEqual(setup_line_1.getGroupingReference(),
built_delivery.getReference())
self.assertEqual(setup_line_2.getGroupingReference(),
built_delivery.getReference())
self.assertEqual(cleanup_line.getGroupingReference(),
built_delivery.getReference())
self.assertEqual(update_line.getGroupingReference(),
built_delivery.getReference())
self.assertEqual('confirmed', built_delivery.getSimulationState())
self.assertEqual('building', built_delivery.getCausalityState())
delivery_line_list = built_delivery.contentValues(
portal_type='Sale Packing List Line')
self.assertEqual(4, len(delivery_line_list))
built_setup_line = [q for q in delivery_line_list if q.getResource() == 'service_module/slapos_instance_setup'][0]
built_cleanup_line = [q for q in delivery_line_list if q.getResource() == 'service_module/slapos_instance_cleanup'][0]
built_update_line = [q for q in delivery_line_list if q.getResource() == 'service_module/slapos_instance_update'][0]
built_subscription_line = [q for q in delivery_line_list if q.getResource() == 'service_module/slapos_instance_subscription'][0]
self.assertEqual(2.0, built_setup_line.getQuantity())
self.assertEqual(0.0, built_setup_line.getPrice())
self.assertEqual(setup_line_1.getResource(),
built_setup_line.getResource())
self.assertEqual(1.0, built_cleanup_line.getQuantity())
self.assertEqual(0.0, built_cleanup_line.getPrice())
self.assertEqual(cleanup_line.getResource(),
built_cleanup_line.getResource())
self.assertEqual(1.0, built_update_line.getQuantity())
self.assertEqual(0.0, built_update_line.getPrice())
self.assertEqual(update_line.getResource(),
built_update_line.getResource())
self.assertEqual(1.0, built_subscription_line.getQuantity())
self.assertAlmostEqual(0.0, built_subscription_line.getPrice(), 3)
self.assertEqual(subscription_line.getResource(),
built_subscription_line.getResource())
def test_added_after(self):
person = self.portal.person_module.template_member\
.Base_createCloneDocument(batch_mode=1)
delivery = self._createDelivery(destination_value=person,
destination_decision_value=person)
delivery_line = self._addDeliveryLine(delivery)
self.tic()
delivery_list = self.fullBuild(uid=delivery_line.getUid())
self.assertEqual(1, len(delivery_list))
built_delivery = delivery_list[0]
self.assertEqual(delivery_line.getGroupingReference(),
built_delivery.getReference())
self.assertEqual('confirmed', built_delivery.getSimulationState())
self.assertEqual('building', built_delivery.getCausalityState())
delivery_line_list = built_delivery.contentValues(
portal_type='Sale Packing List Line')
self.assertEqual(1, len(delivery_line_list))
built_delivery_line = delivery_line_list[0]
self.assertEqual(1.0, built_delivery_line.getQuantity())
self.assertEqual(0.0, built_delivery_line.getPrice())
self.assertEqual(delivery_line.getResource(),
built_delivery_line.getResource())
delivery_line_2 = self._addDeliveryLine(delivery)
self.tic()
delivery_list = self.fullBuild(uid=delivery_line_2.getUid())
self.assertEqual(1, len(delivery_list))
new_built_delivery = delivery_list[0]
self.assertEqual(built_delivery, new_built_delivery)
self.assertEqual(delivery_line_2.getGroupingReference(),
built_delivery.getReference())
self.assertEqual('confirmed', built_delivery.getSimulationState())
self.assertEqual('building', built_delivery.getCausalityState())
delivery_line_list = built_delivery.contentValues(
portal_type='Sale Packing List Line')
self.assertEqual(1, len(delivery_line_list))
built_delivery_line = delivery_line_list[0]
self.assertEqual(2.0, built_delivery_line.getQuantity())
self.assertEqual(0.0, built_delivery_line.getPrice())
self.assertEqual(delivery_line_2.getResource(),
built_delivery_line.getResource())
......@@ -6,12 +6,6 @@
</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>testSlapOSAccountingBuilder</string> </value>
......@@ -55,28 +49,13 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<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/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -89,7 +68,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -98,7 +77,7 @@
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
......
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