Commit e4f4e55e authored by Julien Muchembled's avatar Julien Muchembled

TestOrderBuilder: code style

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41628 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ff8b912c
......@@ -59,30 +59,21 @@ class TestOrderBuilderMixin(TestOrderMixin):
max_delay = 0.0
min_flow = 0.0
def stepSetMaxDelayOnResource(self, sequence=None, sequence_list=None,
**kw):
def stepSetMaxDelayOnResource(self, sequence):
"""
Sets max_delay on resource
"""
resource = sequence.get('resource')
resource.edit(max_delay=self.max_delay)
resource.edit(
max_delay = self.max_delay,
)
def stepSetMinFlowOnResource(self, sequence=None, sequence_list=None,
**kw):
def stepSetMinFlowOnResource(self, sequence):
"""
Sets min_flow on resource
"""
resource = sequence.get('resource')
resource.edit(min_flow=self.min_flow)
resource.edit(
min_flow = self.min_flow,
)
def stepFillOrderBuilder(self, sequence=None, sequence_list=None,
**kw):
def stepFillOrderBuilder(self, sequence):
"""
Fills Order Builder with proper quantites
"""
......@@ -94,9 +85,7 @@ class TestOrderBuilderMixin(TestOrderMixin):
delivery_portal_type = self.order_portal_type,
delivery_line_portal_type = self.order_line_portal_type,
delivery_cell_portal_type = self.order_cell_portal_type,
destination_value = organisation,
resource_portal_type = self.resource_portal_type,
)
......@@ -132,148 +121,67 @@ class TestOrderBuilderMixin(TestOrderMixin):
int_index=1
)
def stepCheckGeneratedDocumentListVariated(self, sequence=None, sequence_list=None,
**kw):
def stepCheckGeneratedDocumentListVariated(self, sequence):
"""
Checks documents generated by Order Builders with its properties for variated resource
"""
# XXX: Some values still hardcoded
organisation = sequence.get('organisation')
resource = sequence.get('resource')
generated_document_list = sequence.get('generated_document_list')
self.assertEquals(
1, # XXX
len(generated_document_list)
)
order = generated_document_list[0]
self.assertEquals(
order.getDestinationValue(),
organisation
)
self.assertEquals(
order.getStartDate(),
self.wanted_start_date
)
self.assertEquals(
order.getStopDate(),
self.wanted_stop_date
)
order_line_list = order.contentValues(filter={'portal_type':self.order_line_portal_type})
self.assertEquals(
1, # XXX
len(order_line_list)
)
order_line = order_line_list[0] # XXX: add support for more lines and cells too
self.assertEquals(
order_line.getResourceValue(),
resource
)
self.assertEquals(
order_line.getTotalQuantity(),
sum(self.wanted_quantity_matrix.itervalues())
)
order_cell_list = order_line.contentValues(filter={'portal_type':self.order_cell_portal_type})
self.assertEquals(
len(order_cell_list),
len(self.wanted_quantity_matrix.values())
)
for order_cell in order_cell_list:
self.assertEquals(
order_cell.getQuantity(),
self.wanted_quantity_matrix[
order_cell.getProperty('membership_criterion_category')
]
)
def stepCheckGeneratedDocumentList(self, sequence=None, sequence_list=None,
**kw):
# XXX: add support for more generated documents
order, = sequence.get('generated_document_list')
self.assertEqual(order.getDestinationValue(), organisation)
self.assertEqual(order.getStartDate(), self.wanted_start_date)
self.assertEqual(order.getStopDate(), self.wanted_stop_date)
# XXX: ... and for more lines/cells too
order_line, = order.contentValues(portal_type=self.order_line_portal_type)
self.assertEqual(order_line.getResourceValue(), resource)
self.assertEqual(order_line.getTotalQuantity(),
sum(self.wanted_quantity_matrix.itervalues()))
quantity_matrix = {}
for cell in order_line.contentValues(portal_type=self.order_cell_portal_type):
key = cell.getProperty('membership_criterion_category')
self.assertFalse(key in quantity_matrix)
quantity_matrix[key] = cell.getQuantity()
self.assertEqual(quantity_matrix, self.wanted_quantity_matrix)
def stepCheckGeneratedDocumentList(self, sequence):
"""
Checks documents generated by Order Builders with its properties
"""
# XXX: Some values still hardcoded
organisation = sequence.get('organisation')
resource = sequence.get('resource')
generated_document_list = sequence.get('generated_document_list')
self.assertEquals(
1, # XXX
len(generated_document_list)
)
order = generated_document_list[0]
self.assertEquals(
order.getDestinationValue(),
organisation
)
self.assertEquals(
order.getStartDate(),
self.wanted_start_date
)
self.assertEquals(
order.getStopDate(),
self.wanted_stop_date
)
order_line_list = order.contentValues(filter={'portal_type':self.order_line_portal_type})
self.assertEquals(
1, # XXX
len(order_line_list)
)
order_line = order_line_list[0] # XXX: add support for more lines and cells too
# XXX: add support for more generated documents
order, = sequence.get('generated_document_list')
self.assertEqual(order.getDestinationValue(), organisation)
self.assertEqual(order.getStartDate(), self.wanted_start_date)
self.assertEqual(order.getStopDate(), self.wanted_stop_date)
self.assertEquals(
order_line.getResourceValue(),
resource
)
self.assertEquals(
order_line.getTotalQuantity(),
self.wanted_quantity
)
# XXX: ... and for more lines/cells too
order_line, = order.contentValues(portal_type=self.order_line_portal_type)
self.assertEqual(order_line.getResourceValue(), resource)
self.assertEqual(order_line.getTotalQuantity(), self.wanted_quantity)
def stepBuildOrderBuilder(self, sequence=None, sequence_list=None,
**kw):
def stepBuildOrderBuilder(self, sequence):
"""
Invokes build method for Order Builder
"""
order_builder = sequence.get('order_builder')
generated_document_list = order_builder.build()
sequence.edit(generated_document_list = generated_document_list)
sequence.set('generated_document_list', generated_document_list)
def stepCreateOrderBuilder(self, sequence=None, sequence_list=None,
**kw):
def stepCreateOrderBuilder(self, sequence):
"""
Creates empty Order Builder
"""
portal_orders = self.portal.portal_orders
order_builder = self.portal.portal_orders.newContent(
portal_type=self.order_builder_portal_type)
sequence.set('order_builder', order_builder)
order_builder = portal_orders.newContent(
portal_type = self.order_builder_portal_type
)
sequence.edit(
order_builder = order_builder
)
def stepDecreaseOrganisationResourceQuantityVariated(self, sequence=None, sequence_list=None,
**kw):
def stepDecreaseOrganisationResourceQuantityVariated(self, sequence):
"""
Creates movement with variation from organisation to None.
Using Internal Packing List, confirms it.
......@@ -300,7 +208,7 @@ class TestOrderBuilderMixin(TestOrderMixin):
)
packing_list_line.setVariationCategoryList(
list(self.decrease_quantity_matrix.iterkeys())
self.decrease_quantity_matrix.keys(),
)
transaction.commit()
......@@ -311,7 +219,7 @@ class TestOrderBuilderMixin(TestOrderMixin):
cell_key_list.sort()
for cell_key in cell_key_list:
cell = packing_list_line.newCell(base_id=base_id, \
cell = packing_list_line.newCell(base_id=base_id,
portal_type=self.packing_list_cell_portal_type, *cell_key)
cell.edit(mapped_value_property_list=['price','quantity'],
quantity=self.decrease_quantity_matrix[cell_key[0]],
......@@ -320,8 +228,7 @@ class TestOrderBuilderMixin(TestOrderMixin):
packing_list.confirm()
def stepDecreaseOrganisationResourceQuantity(self, sequence=None, sequence_list=None,
**kw):
def stepDecreaseOrganisationResourceQuantity(self, sequence):
"""
Creates movement from organisation to None.
Using Internal Packing List, confirms it.
......@@ -355,21 +262,21 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
"""
run_all_test = 1
common_sequence_string = '\
CreateOrganisation \
CreateNotVariatedResource \
SetMaxDelayOnResource \
SetMinFlowOnResource \
Tic \
DecreaseOrganisationResourceQuantity \
Tic \
CreateOrderBuilder \
FillOrderBuilder \
Tic \
BuildOrderBuilder \
Tic \
CheckGeneratedDocumentList \
'
common_sequence_string = """
CreateOrganisation
CreateNotVariatedResource
SetMaxDelayOnResource
SetMinFlowOnResource
Tic
DecreaseOrganisationResourceQuantity
Tic
CreateOrderBuilder
FillOrderBuilder
Tic
BuildOrderBuilder
Tic
CheckGeneratedDocumentList
"""
def getTitle(self):
return "Order Builder"
......@@ -383,7 +290,7 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
self.wanted_quantity = 1.0
self.wanted_start_date = DateTime(
str(self.datetime.earliestTime() \
str(self.datetime.earliestTime()
+ self.order_builder_hardcoded_time_diff))
self.wanted_stop_date = self.wanted_start_date
......@@ -399,25 +306,25 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
"""
if not run: return
sequence_string = '\
CreateOrganisation \
CreateVariatedResource \
SetMaxDelayOnResource \
SetMinFlowOnResource \
Tic \
DecreaseOrganisationResourceQuantityVariated \
Tic \
CreateOrderBuilder \
FillOrderBuilder \
Tic \
BuildOrderBuilder \
Tic \
CheckGeneratedDocumentListVariated \
'
sequence_string = """
CreateOrganisation
CreateVariatedResource
SetMaxDelayOnResource
SetMinFlowOnResource
Tic
DecreaseOrganisationResourceQuantityVariated
Tic
CreateOrderBuilder
FillOrderBuilder
Tic
BuildOrderBuilder
Tic
CheckGeneratedDocumentListVariated
"""
self.wanted_quantity = 1.0
self.wanted_start_date = DateTime(
str(self.datetime.earliestTime() + \
str(self.datetime.earliestTime() +
self.order_builder_hardcoded_time_diff))
self.wanted_stop_date = self.wanted_start_date
......@@ -444,12 +351,12 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
self.wanted_quantity = 1.0
self.wanted_start_date = DateTime(
str(self.datetime.earliestTime() \
- self.max_delay \
str(self.datetime.earliestTime()
- self.max_delay
+ self.order_builder_hardcoded_time_diff))
self.wanted_stop_date = DateTime(
str(self.datetime.earliestTime() \
str(self.datetime.earliestTime()
+ self.order_builder_hardcoded_time_diff))
sequence_list = SequenceList()
......@@ -465,7 +372,7 @@ class TestOrderBuilder(TestOrderBuilderMixin, ERP5TypeTestCase):
self.wanted_quantity = 1.0
self.wanted_start_date = DateTime(
str(self.datetime.earliestTime() \
str(self.datetime.earliestTime()
+ self.order_builder_hardcoded_time_diff))
self.wanted_stop_date = self.wanted_start_date
......
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