Commit 904fa415 authored by Sebastien Robin's avatar Sebastien Robin

added test for ranges and predicates


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3067 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 71edb726
......@@ -112,9 +112,9 @@ class Test(ERP5TypeTestCase):
portal = self.getPortal()
type_tool = self.getTypeTool()
module_type = type_tool['Organisation Module']
module_type.allowed_content_types += ('Predicate Group',)
module_type.allowed_content_types += ('Mapped Value',)
organisation_module = self.getOrganisationModule()
predicate = organisation_module.newContent(id='1',portal_type='Predicate Group')
predicate = organisation_module.newContent(id='1',portal_type='Mapped Value')
predicate.setCriterion('quantity',identity=None,min=None,max=None)
predicate.immediateReindexObject()
......@@ -124,7 +124,6 @@ class Test(ERP5TypeTestCase):
resource.newContent(id='red',portal_type=self.resource_variation_type,immediate_reindex=1)
resource.setVariationBaseCategoryList(['variation'])
self.supply_line = supply_line = resource.newContent(id='default_supply_line',portal_type='Supply Line')
supply_line.setVariationBaseCategoryList(['colour'])
# Then create an order with a particular line
order_module = self.getSaleOrderModule()
......@@ -146,6 +145,7 @@ class Test(ERP5TypeTestCase):
big_region = portal_categories[bc].newContent(id='africa',portal_type='Category')
if not 'asia' in portal_categories[bc].objectIds():
big_region = portal_categories[bc].newContent(id='asia',portal_type='Category')
portal_categories[bc].recursiveImmediateReindexObject()
def checkPredicate(self, test=None):
......@@ -159,7 +159,6 @@ class Test(ERP5TypeTestCase):
order_line = self.getOrderLine()
domain_tool = self.getDomainTool()
test = 0
# Test with order line and predicate to none
predicate_list = domain_tool.searchPredicateList(order_line,test=test)
self.assertEquals(len(predicate_list),1) # Actually, a predicate where
......@@ -222,8 +221,8 @@ class Test(ERP5TypeTestCase):
predicate.setMembershipCriterionBaseCategoryList(['region'])
predicate.setMembershipCriterionCategoryList(['region/europe'])
predicate.immediateReindexObject()
predicate_list = domain_tool.searchPredicateList(order_line,test=test)
#get_transaction().commit()
predicate_list = domain_tool.searchPredicateList(order_line,test=test)
self.assertEquals(len(predicate_list),0)
order_line.setCategoryList(['region/africa'])
predicate_list = domain_tool.searchPredicateList(order_line,test=test)
......@@ -254,29 +253,61 @@ class Test(ERP5TypeTestCase):
if not quiet:
self.logMessage('Generate Mapped Value')
self.createData()
self.supply_line.setVariationBaseCategoryList(['colour'])
self.supply_line.setBasePrice(23)
self.supply_line.setPricedQuantity(1)
self.supply_line.setDefaultResourceValue(self.resource)
self.supply_line.setMultimembershipCriterionBaseCategoryList(['resource'])
#self.supply_line.setMultimembershipCriterionBaseCategoryList(['resource'])
self.supply_line.setMappedValuePropertyList(['base_price','priced_quantity'])
self.supply_line.setMembershipCriterionCategoryList(['resource/%s' % self.resource.getRelativeUrl()])
#self.supply_line.setMembershipCriterionCategoryList(['resource/%s' % self.resource.getRelativeUrl()])
self.supply_line.recursiveImmediateReindexObject()
domain_tool = self.getDomainTool()
context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl()])
mapped_value = domain_tool.generateMappedValue(context)
#get_transaction().commit()
self.assertEquals(mapped_value.getBasePrice(),23)
def test_04_GenerateMappedValueWithRanges(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
self.logMessage('Generate Mapped Value With Ranges')
self.createData()
self.supply_line.setBasePrice(23)
self.supply_line.setPricedQuantity(1)
self.supply_line.setDefaultResourceValue(self.resource)
date1 = DateTime('2005/04/08')
date2 = DateTime('2005/04/10')
self.supply_line.setStartDateRangeMin(date1)
self.supply_line.setStartDateRangeMax(date2)
LOG('Test04, supply_line.getStartDateRangeMin',0,self.supply_line.getStartDateRangeMin())
LOG('Test04, supply_line.getStartDateRangeMax',0,self.supply_line.getStartDateRangeMax())
self.supply_line.setMappedValuePropertyList(['base_price','priced_quantity'])
self.supply_line.recursiveImmediateReindexObject()
domain_tool = self.getDomainTool()
order_line = self.getOrderLine()
order_line.setDefaultResourceValue(self.resource)
current_date = DateTime('2005/04/01')
order_line.setStartDate(current_date)
kw = {'portal_type':('Supply Line','Supply Cell')}
mapped_value = domain_tool.generateMappedValue(order_line,**kw)
self.assertEquals(mapped_value,None)
current_date = DateTime('2005/04/09')
order_line.setStartDate(current_date)
mapped_value = domain_tool.generateMappedValue(order_line,**kw)
self.assertEquals(mapped_value.getBasePrice(),23)
def test_04_GenerateMappedValueWithVariation(self, quiet=0, run=run_all_test):
def test_05_GenerateMappedValueWithVariation(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
self.logMessage('Generate Mapped Value With Variation')
self.createData()
self.supply_line.setVariationBaseCategoryList(['colour'])
self.supply_line.setBasePrice(23)
self.supply_line.setPricedQuantity(1)
self.supply_line.setDefaultResourceValue(self.resource)
self.supply_line.setMultimembershipCriterionBaseCategoryList(['resource']) # Do we need to add 'variation' ???
#self.supply_line.setMultimembershipCriterionBaseCategoryList(['resource']) # Do we need to add 'variation' ???
self.supply_line.setMappedValuePropertyList(['base_price','priced_quantity'])
self.supply_line.setMembershipCriterionCategoryList(['resource/%s' % self.resource.getRelativeUrl()])
#self.supply_line.setMembershipCriterionCategoryList(['resource/%s' % self.resource.getRelativeUrl()])
self.supply_line.setPVariationBaseCategoryList(['variation'])
self.supply_line.updateCellRange(base_id='path')
cell_range = self.supply_line.SupplyLine_asCellRange()
......@@ -309,7 +340,7 @@ class Test(ERP5TypeTestCase):
domain_tool = self.getDomainTool()
context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl(),'variation/%s/blue' % self.resource.getRelativeUrl()])
mapped_value = domain_tool.generateMappedValue(context,sort_method=sort_method)
get_transaction().commit()
#get_transaction().commit()
self.assertEquals(mapped_value.getProperty('base_price'),45)
context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl(),'variation/%s/red' % self.resource.getRelativeUrl()])
mapped_value = domain_tool.generateMappedValue(context,sort_method=sort_method)
......
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