testTransformation.py 4.81 KB
Newer Older
1 2 3 4 5 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
##############################################################################
#
# Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved.
#          Sebastien Robin <seb@nexedi.com>
#
# 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.
#
##############################################################################

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase

class TestTransformationMixin:
  """
  Mixin class for checking transformations
  """
  transformation_portal_type = 'Transformation'
  transformed_resource_portal_type = \
     'Transformation Transformed Resource'
  component_portal_type = 'Component'

  def createTransformation(self):
    module = self.getPortalObject().getDefaultModule(
        self.transformation_portal_type)
    transformation = module.newContent(portal_type=self.transformation_portal_type)
    return transformation

  def createTransformedResource(self, transformation=None):
    transformed_resource = transformation.newContent(
        portal_type=self.transformed_resource_portal_type)
    return transformed_resource

  def createComponent(self, variation_property_list=None):
    module = self.getPortalObject().getDefaultModule(self.component_portal_type)
    component = module.newContent(portal_type=self.component_portal_type)
    if variation_property_list is not None:
      component.setVariationPropertyList(variation_property_list)
    return component

class TestTransformation(TestTransformationMixin, ERP5TypeTestCase):

  def getBusinessTemplateList(self):
    """
    """
    return ('erp5_base','erp5_pdm', 'erp5_trade', 'erp5_mrp',)

  def test_01_getAggregatedAmountListWithVariatedProperty(self):
    """
    Make sure that getAggregatedAmountList is still working properly if we
    have additionnals propertysheets on transformations lines and that used
    variation properties
    """
    # Only for testing purpose, use a property sheet that has nothing to
    # do with component. It would have been possible to create a new
    # property sheet for this test
    self._addPropertySheet(self.transformed_resource_portal_type, 'Bug')
    variation_property_list = ['tested']

    transformation = self.createTransformation()
    transformed_resource = self.createTransformedResource(transformation)
    component = self.createComponent(
        variation_property_list=variation_property_list)
    transformed_resource.edit(
        resource_value=component,
        quantity=1)
    transformed_resource.setTested(True)
    aggregated_amount_list = transformation.getAggregatedAmountList()
    self.assertEquals(len(aggregated_amount_list), 1)
    aggregated_amount = aggregated_amount_list[0]
    # Make sure that the isTested method is working properly on the
    # temp object
    self.assertTrue(aggregated_amount.isTested())
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

  def test_resourceIsNotAcquiredOnTransformationLines(self):
    '''
    We don't want resource define on transformation to be acquired on
    transformation lines
    '''
    transformation = self.createTransformation()

    # create a product
    portal = self.getPortalObject()
    product_module = portal.getDefaultModule('Product')
    product = product_module.newContent(portal_type='Product')

    # set the product as resource of the transformations
    transformation.setResourceValue(product)

    # add transformations lines and check the don't acquire the resource
    operation = transformation.newContent(portal_type='Transformation Operation')
    self.assertEquals(operation.getResource(), None)

    optional_resource = transformation.newContent(portal_type=\
        'Transformation Optional Resource')
    self.assertEquals(optional_resource.getResource(), None)

    transformed_resource = transformation.newContent(portal_type=\
        'Transformation Transformed Resource')
    self.assertEquals(transformed_resource.getResource(), None)