testApparelTransformation.py 42.1 KB
Newer Older
Sebastien Robin's avatar
Sebastien Robin committed
1 2 3 4
##############################################################################
#
# Copyright (c) 2004, 2005 Nexedi SARL and Contributors. All Rights Reserved.
#          Sebastien Robin <seb@nexedi.com>
Guillaume Michon's avatar
Guillaume Michon committed
5
#          Guillaume Michon <guillaume.michon@e-asc.com>
Sebastien Robin's avatar
Sebastien Robin committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

#
# Skeleton ZopeTestCase
#

from random import randint

36
import transaction
Sebastien Robin's avatar
Sebastien Robin committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
import os, sys
if __name__ == '__main__':
    execfile(os.path.join(sys.path[0], 'framework.py'))

# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'

from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager, \
                                             noSecurityManager
from DateTime import DateTime
from Acquisition import aq_base, aq_inner
from zLOG import LOG
from Products.ERP5Type.DateUtils import addToDate
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
import time
import os
from Products.ERP5Type import product_path
from Products.CMFCore.utils import getToolByName
from testOrder import TestOrderMixin

60
class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase):
Sebastien Robin's avatar
Sebastien Robin committed
61
  """
62 63 64 65 66 67 68
    Test Transformations with erp5_apparel configuration

    This test :
      - is checking so many values
      - is specific to erp5_apparel, so does not allows to reuse it's code

    Therefore, it's better to use testTransformation for future tests
Sebastien Robin's avatar
Sebastien Robin committed
69 70 71 72 73
  """
  run_all_test = 1
  transformation_portal_type = 'Apparel Transformation'
  component_portal_type = 'Apparel Component'
  component_variation_portal_type = 'Apparel Component Variation'
Guillaume Michon's avatar
Guillaume Michon committed
74 75
  transformed_resource_portal_type = 'Apparel Transformation Transformed Resource'
  operation_portal_type = 'Apparel Transformation Operation'
Sebastien Robin's avatar
Sebastien Robin committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

  def getTitle(self):
    return "Transformation"

  def enableLightInstall(self):
    """
    You can override this. 
    Return if we should do a light install (1) or not (0)
    """
    return 1

  def enableActivityTool(self):
    """
    You can override this.
    Return if we should create (1) or not (0) an activity tool.
    """
    return 1
Guillaume Michon's avatar
Guillaume Michon committed
93 94
  
  def stepCreateComponentDict(self, sequence=None, sequence_list=None, \
Sebastien Robin's avatar
Sebastien Robin committed
95 96
                                 **kw):
    """
Guillaume Michon's avatar
Guillaume Michon committed
97
      Create a number of variated component
Sebastien Robin's avatar
Sebastien Robin committed
98 99 100 101
    """
    portal = self.getPortal()
    component_module = portal.getDefaultModule(self.component_portal_type)

Guillaume Michon's avatar
Guillaume Michon committed
102 103 104 105 106 107 108 109
    components = [
      { 'name':'zip', 'quantity': 100., 'prices':[10.] },
      { 'name':'tissu', 'quantity': 50., 'prices':[4.5, 7.] },
      { 'name':'bouton', 'quantity': 1000., 'prices':[150.] }, ]
    
    component_dict = {} 
    for component_info in components:
      component_name = component_info['name']
110
      component = component_module.newContent(title=component_name)
Guillaume Michon's avatar
Guillaume Michon committed
111
      component_dict[component_name] = component
112 113 114 115 116 117
      variation1 = component.newContent(
                          portal_type=self.component_variation_portal_type,
                          id='1')
      variation2 = component.newContent(
                          portal_type=self.component_variation_portal_type,
                          id='2')
Guillaume Michon's avatar
Guillaume Michon committed
118
      variations = [variation1, variation2]
119 120

      # Commit and catalog
121
      transaction.commit()
122
      self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
123 124 125
      
      component.setVariationBaseCategoryList(['variation'])
      component.setPVariationBaseCategoryList(['variation'])
126 127 128
      # Variation are automatically acquired if they are individual variation.
#       component.setCategoryList( 
#                     ['variation/' + x.getRelativeUrl() for x in variations] )
Guillaume Michon's avatar
Guillaume Michon committed
129 130
      # Set the price
      supply_line = component.newContent(portal_type='Supply Line')
131 132
      supply_line.edit(mapped_value_property_list=['base_price'],
          priced_quantity=component_info['quantity'])
Guillaume Michon's avatar
Guillaume Michon committed
133 134 135 136 137 138 139
      component_prices = component_info['prices']
      if len(component_prices) == 1:
        supply_line.edit(
            membership_criterion_base_category = ['variation'],
            membership_criterion_category = ['variation/' + x.getRelativeUrl() for x in variations],
            base_price = component_prices[0])
      else:
140
#         supply_line.setVariationBaseCategoryList(['variation'])
Guillaume Michon's avatar
Guillaume Michon committed
141 142
        supply_line.updateCellRange(base_id = 'path')
        for i in range(2):
143 144 145
          supply_cell = supply_line.newCell(
                   'variation/apparel_component_module/%s/%d' % \
                                      (component.getId(),(i+1)), 
146
                   portal_type='Supply Cell',
147
                   base_id='path')
Guillaume Michon's avatar
Guillaume Michon committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
          supply_cell.edit(
            membership_criterion_base_category = ['variation'],
            membership_criterion_category = ['variation/' + variations[i].getRelativeUrl()],
            base_price = component_prices[i],
            mapped_value_property_list = ['base_price'],
            resource = supply_line.getResource() )
    sequence.edit(component_dict=component_dict)
  
      
  def stepCreateOperationDict(self, sequence=None, sequence_list=None, **kw):
    """
      Create a number of operations
    """
    portal = self.getPortal()
    operation_dict = {}
    for operation_name in ('piquage', 'taillage'):
      operation = portal.portal_categories.operation.newContent(id=operation_name)
      operation_dict[operation_name] = operation
    sequence.edit(operation_dict=operation_dict)
    
    
Sebastien Robin's avatar
Sebastien Robin committed
169 170 171
  def stepCreateTransformation(self, sequence=None, sequence_list=None, \
                                 **kw):
    """
Guillaume Michon's avatar
Guillaume Michon committed
172
      Create a transformation
Sebastien Robin's avatar
Sebastien Robin committed
173 174
    """
    portal = self.getPortal()
Guillaume Michon's avatar
Guillaume Michon committed
175 176
    resource = sequence.get('resource')
    
Sebastien Robin's avatar
Sebastien Robin committed
177 178 179
    transformation_module = portal.getDefaultModule(self.transformation_portal_type)
    transformation = transformation_module.newContent(portal_type=self.transformation_portal_type)
    sequence.edit(transformation=transformation)
Guillaume Michon's avatar
Guillaume Michon committed
180 181 182 183 184 185 186 187 188
    transformation.setResourceValue(resource)
    transformation.setVariationBaseCategoryList(('size','colour', 'morphology'))

    
  def stepCreateIncludedTransformation(self, sequence=None, sequence_list=None, **kw):
    """
      Create a transformation to be included into the other
    """
    portal = self.getPortal()
Sebastien Robin's avatar
Sebastien Robin committed
189
    resource = sequence.get('resource')
Guillaume Michon's avatar
Guillaume Michon committed
190 191 192
    transformation_module = portal.getDefaultModule(self.transformation_portal_type)
    transformation = transformation_module.newContent(portal_type = self.transformation_portal_type)
    sequence.edit(included_transformation = transformation)
Sebastien Robin's avatar
Sebastien Robin committed
193
    transformation.setResourceValue(resource)
Guillaume Michon's avatar
Guillaume Michon committed
194 195 196 197 198 199 200 201 202
    transformation.setVariationBaseCategoryList(('size',))

    
  def stepCreateTransformationLine(self, sequence=None, sequence_list=None, **kw):
    """
      Create transformed resources and operations for transformation
    """
    transformation = sequence.get('transformation')
    component_dict = sequence.get('component_dict')
Sebastien Robin's avatar
Sebastien Robin committed
203

Guillaume Michon's avatar
Guillaume Michon committed
204 205 206 207 208 209 210 211 212 213
    # Transformed Resource 1 : permanent consumption
    tr_resource_name = 'bouton'
    transformed_resource = transformation.newContent(portal_type=self.transformed_resource_portal_type)
    transformed_resource.edit(
        title = tr_resource_name,
        quantity = 2.,
        resource_value = component_dict[tr_resource_name],
        )
    transformed_resource.edit(
       categories = transformed_resource.getCategoryList() + ['variation/' + component_dict[tr_resource_name]['1'].getRelativeUrl()])
Sebastien Robin's avatar
Sebastien Robin committed
214

Guillaume Michon's avatar
Guillaume Michon committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
    # Transformed Resource 2 : 1 variation axis
    line_list =  [ ('size/Baby',     '1'),
                   ('size/Child/32', '2'),
                   ('size/Child/34', '1'),
                   ('size/Man',      '2'),
                   ('size/Woman',    '1') ]
    tr_resource_name = 'zip'
    transformed_resource = transformation.newContent(portal_type=self.transformed_resource_portal_type)
    transformed_resource.edit(
        title = tr_resource_name,
        quantity = 1.,
        resource_value = component_dict[tr_resource_name]
        )
    base_category_list = ['size']
    transformed_resource.setVariationBaseCategoryList(base_category_list)
    range_list = [x[0] for x in line_list]
    transformed_resource.setCellRange(range_list, base_id='variation')
    for line in line_list:
      size, variation = line
      variation = component_dict[tr_resource_name][variation]
      cell = transformed_resource.newCell(size, base_id='variation')
      cell.edit(
        membership_criterion_base_category = base_category_list,
        membership_criterion_category = [size],
        categories = ('variation/' + variation.getRelativeUrl() ) )
    self.stepTic()

    # Transformed Resource 3 : 3 variation axis
    line_list = [ ('size/Baby', 'ColourVariation1', 'MorphologyVariation1', '2', 3.),
                  ('size/Baby', 'ColourVariation1', 'MorphologyVariation2', '1', 3.5),
                  ('size/Baby', 'ColourVariation2', 'MorphologyVariation1', '1', 3.),                 
                  ('size/Baby', 'ColourVariation2', 'MorphologyVariation2', '2', 3.5),
                  ('size/Baby', 'ColourVariation3', 'MorphologyVariation1', '1', 3.5),
                  ('size/Baby', 'ColourVariation3', 'MorphologyVariation2', '1', 3.5),
                  
                  ('size/Child/32', 'ColourVariation1', 'MorphologyVariation1', '1', 6.),
                  ('size/Child/32', 'ColourVariation1', 'MorphologyVariation2', '1', 6.5),
                  ('size/Child/32', 'ColourVariation2', 'MorphologyVariation1', '1', 6.),
                  ('size/Child/32', 'ColourVariation2', 'MorphologyVariation2', '2', 6.5),
                  ('size/Child/32', 'ColourVariation3', 'MorphologyVariation1', '2', 6.),
                  ('size/Child/32', 'ColourVariation3', 'MorphologyVariation2', '1', 6.5),
                  
                  ('size/Child/34', 'ColourVariation1', 'MorphologyVariation1', '1', 9.),
                  ('size/Child/34', 'ColourVariation1', 'MorphologyVariation2', '2', 9.5),
                  ('size/Child/34', 'ColourVariation2', 'MorphologyVariation1', '2', 9.),
                  ('size/Child/34', 'ColourVariation2', 'MorphologyVariation2', '1', 9.5),
                  ('size/Child/34', 'ColourVariation3', 'MorphologyVariation1', '2', 9.),
                  ('size/Child/34', 'ColourVariation3', 'MorphologyVariation2', '2', 9.5),
                  
                  ('size/Man', 'ColourVariation1', 'MorphologyVariation1', '2', 12.),
                  ('size/Man', 'ColourVariation1', 'MorphologyVariation2', '2', 12.5),
                  ('size/Man', 'ColourVariation2', 'MorphologyVariation1', '2', 12.),
                  ('size/Man', 'ColourVariation2', 'MorphologyVariation2', '1', 12.5),
                  ('size/Man', 'ColourVariation3', 'MorphologyVariation1', '1', 12.),
                  ('size/Man', 'ColourVariation3', 'MorphologyVariation2', '2', 12.5),
                  
                  ('size/Woman', 'ColourVariation1', 'MorphologyVariation1', '2', 15.),
                  ('size/Woman', 'ColourVariation1', 'MorphologyVariation2', '1', 15.5),
                  ('size/Woman', 'ColourVariation2', 'MorphologyVariation1', '1', 15.),
                  ('size/Woman', 'ColourVariation2', 'MorphologyVariation2', '2', 15.5),
                  ('size/Woman', 'ColourVariation3', 'MorphologyVariation1', '2', 15.),
                  ('size/Woman', 'ColourVariation3', 'MorphologyVariation2', '2', 15.5),
               ]
    mapping_dict = {'ColourVariation1': 'colour/apparel_model_module/1/1',
                    'ColourVariation2': 'colour/apparel_model_module/1/2',
                    'ColourVariation3': 'colour/apparel_model_module/1/3',
                    'MorphologyVariation1': 'morphology/apparel_model_module/1/4',
                    'MorphologyVariation2': 'morphology/apparel_model_module/1/5',
                    '1': 'apparel_component_module/2/1',
                    '2': 'apparel_component_module/2/2' }
                    
               
    tr_resource_name = 'tissu'
    transformed_resource = transformation.newContent(portal_type=self.transformed_resource_portal_type)
    transformed_resource.edit(
        title = tr_resource_name,
        resource_value = component_dict[tr_resource_name]
        )
    base_category_list = ['size', 'colour', 'morphology']
    transformed_resource.setVariationBaseCategoryList(base_category_list)
    variation_range_list_list = []
    for base_category in base_category_list:
      variation_range_category_list = transformation.getVariationRangeCategoryList(base_category_list=[base_category]) 
      variation_range_list_list.append(variation_range_category_list)

    transformed_resource.setCellRange(base_id='variation', *variation_range_list_list)
    transformed_resource.setCellRange(base_id='quantity', *variation_range_list_list)
    
    # Define the cells
    for line in line_list:
      size, colour, morphology, variation, quantity = line
      colour = mapping_dict[colour]
      morphology = mapping_dict[morphology]
      variation = component_dict[tr_resource_name][variation]
      cell_variation = transformed_resource.newCell(size, colour, morphology, base_id='variation')
      cell_quantity = transformed_resource.newCell(size, colour, morphology, base_id='quantity')
      cell_variation.edit(
        membership_criterion_base_category = base_category_list,
        membership_criterion_category = [size, colour, morphology],
        categories = ('variation/' + variation.getRelativeUrl()) )
      cell_quantity.edit(
        membership_criterion_base_category = base_category_list,
        membership_criterion_category = [size, colour, morphology],
        quantity = quantity,
        mapped_value_property_list = ['quantity'] ) 
    self.stepTic()

    
  def stepCreateIncludedTransformationLine(self, sequence=None, sequence_list=None, **kw):
    """
      Create transformed resources and operations for transformation
    """
    transformation = sequence.get('included_transformation')
    operation_dict = sequence.get('operation_dict')
    component_dict = sequence.get('component_dict')

    # Operation 1 : permanent consumption
    op_name = 'taillage'
    operation = transformation.newContent(portal_type=self.operation_portal_type)
    operation.edit(
        title = op_name,
        quantity = 10.,
        categories = operation.getCategoryList() + [ 'resource/' + operation_dict[op_name].getRelativeUrl(),
                                                     'quantity_unit/time/min' ]
        )

    # Operation 2 : 1 variation axis
    line_list =  [ ('size/Baby',     2.),
                   ('size/Child/32', 2.5),
                   ('size/Child/34', 3.),
                   ('size/Man',      3.5),
                   ('size/Woman',    4.) ]
    op_name = 'piquage'
    operation = transformation.newContent(portal_type=self.operation_portal_type)
    operation.edit(
        title = op_name,
        categories = operation.getCategoryList() + [ 'resource/' + operation_dict[op_name].getRelativeUrl(),
                                                     'quantity_unit/time/min' ]
        )
    base_category_list = ['size']
    operation.setVariationBaseCategoryList(base_category_list)
    range_list = [x[0] for x in line_list]
    operation.setCellRange(range_list, base_id='quantity')
    for line in line_list:
      size, quantity = line
      cell = operation.newCell(size, base_id='quantity')
      cell.edit(
        membership_criterion_base_category = base_category_list,
        membership_criterion_category = [size],
        quantity = quantity,
        mapped_value_property_list = ['quantity'])
    self.stepTic()
    
  # Transformed Resource : 1 variation axis
    line_list =  [ ('size/Baby',     1.),
                   ('size/Child/32', 1.5),
                   ('size/Child/34', 2.),
                   ('size/Man',      3.),
                   ('size/Woman',    2.5) ]
    tr_resource_name = 'tissu'
    transformed_resource = transformation.newContent(portal_type=self.transformed_resource_portal_type)
    transformed_resource.edit(
        title = tr_resource_name,
        resource_value = component_dict[tr_resource_name],
        )
    transformed_resource.edit(
       categories = transformed_resource.getCategoryList() + ['variation/' + component_dict[tr_resource_name]['1'].getRelativeUrl()])
    base_category_list = ['size']
    transformed_resource.setVariationBaseCategoryList(base_category_list)
    range_list = [x[0] for x in line_list]
    transformed_resource.setCellRange(range_list, base_id='quantity')
    for line in line_list:
      size, quantity = line
      cell = transformed_resource.newCell(size, base_id='quantity')
      cell.edit(
        membership_criterion_base_category = base_category_list,
        membership_criterion_category = [size],
        quantity = quantity,
        mapped_value_property_list = ['quantity'])
    self.stepTic()
    
    
  def stepIncludeTransformation(self, sequence=None, sequence_list=None, **kw):
    transformation = sequence.get('transformation')
    included_transformation = sequence.get('included_transformation')
    transformation.edit(specialise_value = included_transformation)
    
    
  def stepVerifyTransformationAggregatedAmountList(self, sequence=None, sequence_list=None, **kw):
    """
      Verify the return of getAggregatedAmountList
    """
    expected_list = [
      {'id':('size/Baby', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.42], 'total':.82, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Baby', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.315], 'total':.715, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Baby', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.27], 'total':.67, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Baby', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.49], 'total':.89, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Baby', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.315], 'total':.715, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Baby', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.315], 'total':.715, 'duration':[None,None,None], 'total_duration':None},
      
      {'id':('size/Child/32', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.54], 'total':.94, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.585], 'total':.985, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.54], 'total':.94, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.91], 'total':1.31, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.84], 'total':1.24, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.585], 'total':.985, 'duration':[None,None,None], 'total_duration':None},
      
      {'id':('size/Child/34', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.81], 'total':1.21, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.33], 'total':1.73, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.26], 'total':1.66, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.855], 'total':1.255, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.26], 'total':1.66, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.33], 'total':1.73, 'duration':[None,None,None], 'total_duration':None},
         
      {'id':('size/Man', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.68], 'total':2.08, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Man', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.75], 'total':2.15, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Man', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.68], 'total':2.08, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Man', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.125], 'total':1.525, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Man', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.08], 'total':1.48, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Man', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.75], 'total':2.15, 'duration':[None,None,None], 'total_duration':None},
         
      {'id':('size/Woman', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,2.1], 'total':2.5, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Woman', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.395], 'total':1.795, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Woman', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.35], 'total':1.75, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Woman', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,2.17], 'total':2.57, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Woman', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,2.1], 'total':2.5, 'duration':[None,None,None], 'total_duration':None},
      {'id':('size/Woman', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,2.17], 'total':2.57, 'duration':[None,None,None], 'total_duration':None},
       ]
    transformation = sequence.get('transformation')
    self.verifyAggregatedAmountList(transformation, expected_list)
        
          
  def stepVerifyIncludedTransformationAggregatedAmountList(self, sequence=None, sequence_list=None, **kw):
    """
      Verify the return of getAggregatedAmountList
    """
    expected_list = [
      {'id':('size/Baby', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.09], 'total':.09, 'duration':[10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.09], 'total':.09, 'duration':[10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.09], 'total':.09, 'duration':[10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.09], 'total':.09, 'duration':[10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.09], 'total':.09, 'duration':[10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.09], 'total':.09, 'duration':[10.,2.,None], 'total_duration':12.},
      
      {'id':('size/Child/32', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.135], 'total':.135, 'duration':[10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.135], 'total':.135, 'duration':[10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.135], 'total':.135, 'duration':[10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.135], 'total':.135, 'duration':[10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.135], 'total':.135, 'duration':[10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.135], 'total':.135, 'duration':[10.,2.5,None], 'total_duration':12.5},
      
      {'id':('size/Child/34', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.18], 'total':.18, 'duration':[10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.18], 'total':.18, 'duration':[10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.18], 'total':.18, 'duration':[10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.18], 'total':.18, 'duration':[10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.18], 'total':.18, 'duration':[10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.18], 'total':.18, 'duration':[10.,3.,None], 'total_duration':13.},
         
      {'id':('size/Man', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.27], 'total':.27, 'duration':[10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.27], 'total':.27, 'duration':[10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.27], 'total':.27, 'duration':[10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.27], 'total':.27, 'duration':[10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.27], 'total':.27, 'duration':[10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.27], 'total':.27, 'duration':[10.,3.5,None], 'total_duration':13.5},
         
      {'id':('size/Woman', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.225], 'total':.225, 'duration':[10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.225], 'total':.225, 'duration':[10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.225], 'total':.225, 'duration':[10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.225], 'total':.225, 'duration':[10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[None,None,.225], 'total':.225, 'duration':[10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[None,None,.225], 'total':.225, 'duration':[10.,4.,None], 'total_duration':14.},
       ]     
    transformation = sequence.get('included_transformation')
    self.verifyAggregatedAmountList(transformation, expected_list)
    
  
  def stepVerifySpecialisedTransformationAggregatedAmountList(self, sequence=None, sequence_list=None, **kw):
    """
      Verify the return of AggregatedAmountList for a transformation which includes another one
    """
    expected_list = [
      {'id':('size/Baby', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.42,None,None,.09], 'total':.91, 'duration':[None,None,None,10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.315,None,None,.09], 'total':.805, 'duration':[None,None,None,10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.27,None,None,.09], 'total':.76, 'duration':[None,None,None,10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.49,None,None,.09], 'total':.98, 'duration':[None,None,None,10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.315,None,None,.09], 'total':.805, 'duration':[None,None,None,10.,2.,None], 'total_duration':12.},
      {'id':('size/Baby', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.315,None,None,.09], 'total':.805, 'duration':[None,None,None,10.,2.,None], 'total_duration':12.},
         
      {'id':('size/Child/32', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.54,None,None,.135], 'total':1.075, 'duration':[None,None,None,10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.585,None,None,.135], 'total':1.12, 'duration':[None,None,None,10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.54,None,None,.135], 'total':1.075, 'duration':[None,None,None,10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.91,None,None,.135], 'total':1.445, 'duration':[None,None,None,10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.84,None,None,.135], 'total':1.375, 'duration':[None,None,None,10.,2.5,None], 'total_duration':12.5},
      {'id':('size/Child/32', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.585,None,None,.135], 'total':1.12, 'duration':[None,None,None,10.,2.5,None], 'total_duration':12.5},
          
      {'id':('size/Child/34', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,.81,None,None,.18], 'total':1.39, 'duration':[None,None,None,10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.33,None,None,.18], 'total':1.91, 'duration':[None,None,None,10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.26,None,None,.18], 'total':1.84, 'duration':[None,None,None,10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,.855,None,None,.18], 'total':1.435, 'duration':[None,None,None,10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.26,None,None,.18], 'total':1.84, 'duration':[None,None,None,10.,3.,None], 'total_duration':13.},
      {'id':('size/Child/34', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.33,None,None,.18], 'total':1.91, 'duration':[None,None,None,10.,3.,None], 'total_duration':13.},
         
      {'id':('size/Man', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.68,None,None,.27], 'total':2.35, 'duration':[None,None,None,10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.75,None,None,.27], 'total':2.42, 'duration':[None,None,None,10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.68,None,None,.27], 'total':2.35, 'duration':[None,None,None,10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.125,None,None,.27], 'total':1.795, 'duration':[None,None,None,10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.08,None,None,.27], 'total':1.75, 'duration':[None,None,None,10.,3.5,None], 'total_duration':13.5},
      {'id':('size/Man', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.75,None,None,.27], 'total':2.42, 'duration':[None,None,None,10.,3.5,None], 'total_duration':13.5},
         
      {'id':('size/Woman', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,2.1,None,None,.225], 'total':2.725, 'duration':[None,None,None,10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/1', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,1.395,None,None,.225], 'total':2.02, 'duration':[None,None,None,10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,1.35,None,None,.225], 'total':1.975, 'duration':[None,None,None,10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/2', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,2.17,None,None,.225], 'total':2.795, 'duration':[None,None,None,10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/4'),
         'amount':[.3,.1,2.1,None,None,.225], 'total':2.725, 'duration':[None,None,None,10.,4.,None], 'total_duration':14.},
      {'id':('size/Woman', 'colour/apparel_model_module/1/3', 'morphology/apparel_model_module/1/5'),
         'amount':[.3,.1,2.17,None,None,.225], 'total':2.795, 'duration':[None,None,None,10.,4.,None], 'total_duration':14.},
       ]
    transformation = sequence.get('transformation')
    self.verifyAggregatedAmountList(transformation, expected_list)
    
    
  def verifyAggregatedAmountList(self, transformation, expected_list):
    """
      Verify aggregated data according to an expected structure
    """
    for expected in expected_list:
      aggregated_amount_list = transformation.getAggregatedAmountList(
        context=transformation.asContext(categories = expected['id']) )
      expected_amount_list = expected['amount']
      
      # Check the number of aggregated components
      if len(aggregated_amount_list) != len(expected_amount_list):
        LOG('TEST ERROR :', 0, 'number of Amount differs between expected (%d) and aggregated (%d) for categories %s' %
             (len(expected_amount_list), len(aggregated_amount_list), expected['id']))
        self.failUnless(0)
        
      # Check quantity for each component
      for i in range(len(aggregated_amount_list)):
        a_amount = aggregated_amount_list[i]
        a_price = a_amount.getTotalPrice()
        e_price = expected_amount_list[i]
        error = 0
        if e_price is None and a_price is not None:
          error = 1
        if a_price is None and e_price is not None:
          error = 1
        if e_price is not None and a_price is not None:
          if round(a_price,10) != round(e_price,10):
            error = 1
        if error == 1:
          LOG('TEST ERROR :', 0, 'Total price differs between expected (%s) and aggregated (%s) Amounts (resource : %s, id_categories : %s, amount.categories : %s)' %
            (repr(e_price), repr(a_price), repr(a_amount.getResource()), expected['id'], a_amount.getCategoryList()))
          self.failUnless(0)
          
      # Check duration for each component
        a_duration = a_amount.getDuration()
        e_duration = expected['duration'][i]
        error = 0
        if e_duration is None and a_duration is not None:
          error = 1
        if a_duration is None and e_duration is not None:
          error = 1
        if e_duration is not None and a_duration is not None:
          if round(a_duration,10) != round(e_duration,10):
            error = 1
        if error == 1:
          LOG('TEST ERROR :', 0, 'Duration differs between expected (%s) and aggregated (%s) Amounts (resource : %s, id_categories : %s, amount.categories : %s)' %
            (repr(e_duration), repr(a_duration), repr(a_amount.getResource()), expected['id'], a_amount.getCategoryList()))
          self.failUnless(0)
            
      # Check global quantity
      total_price = aggregated_amount_list.getTotalPrice()
      if round(total_price, 10) != round(expected['total'], 10):
        LOG('TEST ERROR :', 0, 'Total price for AggregatedAmountList differs between expected (%s) and aggregated (%s) (%s)' %
          (repr(total_price), repr(expected['total']), expected['id']))
        self.failUnless(0)
        
      # Check global duration
      total_duration = aggregated_amount_list.getTotalDuration()
      expected_duration = expected['total_duration']
      error = 0
      if total_duration is None and expected_duration is not None:
        error = 1
      if expected_duration is None and total_duration is not None:
        error = 1
      if total_duration is not None and expected_duration is not None:
        if round(total_duration, 10) != round(expected_duration, 10):
          error = 1
      if error == 1:
        LOG('TEST ERROR :', 0, 'Total duration differs between expected (%s) and aggregated (%s) (%s)' %
          (repr(expected_duration), repr(total_duration), expected['id']))
       
               
Sebastien Robin's avatar
Sebastien Robin committed
697 698 699 700 701 702 703 704 705
  def test_01_getAggregatedAmountList(self, quiet=0, run=run_all_test):
    """
      Test the method getAggregatedAmountList
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = '\
Guillaume Michon's avatar
Guillaume Michon committed
706 707 708
                      CreateComponentDict \
                      CreateOperationDict \
                      Tic \
Sebastien Robin's avatar
Sebastien Robin committed
709
                      CreateVariatedResource \
Guillaume Michon's avatar
Guillaume Michon committed
710
                      Tic \
Sebastien Robin's avatar
Sebastien Robin committed
711
                      CreateTransformation \
Guillaume Michon's avatar
Guillaume Michon committed
712 713 714 715 716 717 718 719 720 721 722 723
                      Tic \
                      CreateTransformationLine \
                      Tic \
                      CreateIncludedTransformation \
                      Tic \
                      CreateIncludedTransformationLine \
                      Tic \
                      VerifyTransformationAggregatedAmountList \
                      VerifyIncludedTransformationAggregatedAmountList \
                      IncludeTransformation \
                      Tic \
                      VerifySpecialisedTransformationAggregatedAmountList \
Sebastien Robin's avatar
Sebastien Robin committed
724 725 726 727
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)