testApparelModel.py 6.56 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 91 92 93 94
##############################################################################
#
# Copyright (c) 2009, 2010 Nexedi SA and Contributors. All Rights Reserved.
#          Fabien Morin <fabien@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.
#
##############################################################################
import unittest
from Products.ERP5Type.tests.utils import reindex
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from zLOG import LOG
import transaction

class TestApparelModel(ERP5TypeTestCase):

  def getTitle(self):
    return "Apparel Model"

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

  def afterSetUp(self):
    """Prepare the test."""
    self.createCategories()

  @reindex
  def createCategories(self):
    """Create the categories for our test. """
    # create categories
    for cat_string in self.getNeededCategoryList() :
      base_cat = cat_string.split("/")[0]
      # if base_cat not exist, create it
      if getattr(self.getPortal().portal_categories, base_cat, None) == None:
        self.getPortal().portal_categories.newContent(\
                                          portal_type='Base Category',
                                          id=base_cat)
      path = self.getPortal().portal_categories[base_cat]
      for cat in cat_string.split("/")[1:] :
        if not cat in path.objectIds() :
          path = path.newContent(
                    portal_type='Category',
                    id=cat,
                    title=cat.replace('_', ' ').title(),)
        else:
          path = path[cat]
    # check categories have been created
    for cat_string in self.getNeededCategoryList() :
      self.assertNotEquals(None,
                self.getCategoryTool().restrictedTraverse(cat_string),
                cat_string)

  def getNeededCategoryList(self):
    """return a list of categories that should be created."""
    return ('composition/acrylique',
            'composition/elasthane',
           )

  def test_checkCopyComposition(self):
    '''
    Check that it's possible to copy composition from a model, and that cells
    are well created.
    '''
    # defin an apparel fabric
    apparel_fabric_module = self.getPortal().getDefaultModule('Apparel Fabric')
    apparel_fabric = apparel_fabric_module.newContent(portal_type=\
        'Apparel Fabric')
    apparel_fabric.setCategoryList(('composition/acrylique', 'composition/elasthane'))
    apparel_fabric.updateCellRange(base_id='composition')

    # create composition cells
95 96 97 98 99 100 101 102
    apparel_fabric.newCell('composition/acrylique',
                           base_id='composition',
                           portal_type='Mapped Value',
                           quantity = 0.88)
    apparel_fabric.newCell('composition/elasthane',
                           base_id='composition',
                           portal_type='Mapped Value',
                           quantity = 0.12)
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

    # add some color variations
    fabric_color1 = apparel_fabric.newContent(portal_type='Apparel Fabric Colour Variation',
        title='Bleu ciel')
    fabric_color2 = apparel_fabric.newContent(portal_type='Apparel Fabric Colour Variation',
        title='Volcano')

    # create an Apparel Colour Range
    apparel_colour_range_module = self.getPortal().getDefaultModule(\
        'Apparel Colour Range')
    apparel_colour_range = apparel_colour_range_module.newContent(portal_type=\
        'Apparel Colour Range')
    color1 = apparel_colour_range.newContent(title='Blue',
        portal_type='Apparel Colour Range Variation')
    color2 = apparel_colour_range.newContent(title='Red',
        portal_type='Apparel Colour Range Variation')

    variation1 = color1.newContent(title='Ocean', int_index=2,
        portal_type='Apparel Colour Range Variation Line')
    variation2 = color1.newContent(title='Volcano', int_index=1,
        portal_type='Apparel Colour Range Variation Line')

    variation1.setSpecialiseValue(fabric_color1)
    variation2.setSpecialiseValue(fabric_color2)

    # create an Apparel Model
    apparel_model_module = self.getPortal().getDefaultModule(\
        'Apparel Model')
    apparel_model = apparel_model_module.newContent(portal_type='Apparel Model')
    apparel_model.setSpecialiseValue(apparel_colour_range)
    apparel_model.ApparelModel_copyComposition()

    # check the cells have been copied
    self.assertEquals(len(apparel_model.contentValues(portal_type=\
        'Mapped Value')), 2)
    self.assertNotEquals(apparel_model.getCell('composition/acrylique',
      base_id='composition'), None)
    cell1 = apparel_model.getCell('composition/acrylique',
                                  base_id='composition')
    self.assertEqual(cell1.getQuantity(), 0.88)
    self.assertNotEquals(apparel_model.getCell('composition/elasthane',
      base_id='composition'), None)
    cell1 = apparel_model.getCell('composition/elasthane',
                                  base_id='composition')
    self.assertEqual(cell1.getQuantity(), 0.12)

    # check indexes are present
    self.assertTrue(apparel_model.index.has_key('composition'))
    self.assertTrue(apparel_model.index['composition'][0].has_key('composition/elasthane'))
    self.assertTrue(apparel_model.index['composition'][0].has_key('composition/acrylique'))

  def test_checkCopyColourRangeVariation(self):
    '''
    Check that it's possible to copy colour range variation from a model, and
    that cells are well created.
    '''
    pass


def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestApparelModel))
  return suite