testApparelModel.py 6.43 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
##############################################################################
#
# 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

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
53
    for cat_string in self.getNeededCategoryList():
54 55
      base_cat = cat_string.split("/")[0]
      # if base_cat not exist, create it
56 57
      if getattr(self.getPortal().portal_categories, base_cat, None) is None:
        self.getPortal().portal_categories.newContent(
58 59 60
                                          portal_type='Base Category',
                                          id=base_cat)
      path = self.getPortal().portal_categories[base_cat]
61 62
      for cat_id in cat_string.split("/")[1:]:
        if not cat_id in path.objectIds():
63 64
          path = path.newContent(
                    portal_type='Category',
65 66
                    id=cat_id,
                    title=cat_id.title())
67
        else:
68
          path = path[cat_id]
69
    # check categories have been created
70
    for cat_string in self.getNeededCategoryList():
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
      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.
    '''
86 87
    portal = self.getPortal()

88
    # defin an apparel fabric
89 90 91 92 93 94 95
    apparel_fabric_module = portal.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')
96 97

    # create composition cells
98 99 100 101 102 103 104 105 106 107
    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)
108 109

    # add some color variations
110 111 112 113 114 115
    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')
116 117

    # create an Apparel Colour Range
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    apparel_colour_range_module = portal.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')
136 137 138 139 140

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

    # create an Apparel Model
141
    apparel_model_module = portal.getDefaultModule('Apparel Model')
142 143 144 145 146
    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
147
    cell_list = apparel_model.contentValues(portal_type = 'Mapped Value')
148
    self.assertEqual(len(cell_list), 2)
149 150 151 152 153

    acrylique = apparel_model.getCell(
        'composition/acrylique',
        base_id = 'composition')
    self.assertNotEquals(acrylique, None)
154
    self.assertEqual(acrylique.getProperty('quantity'), 0.88)
155 156 157 158 159

    elasthane = apparel_model.getCell(
        'composition/elasthane',
        base_id = 'composition')
    self.assertNotEquals(elasthane, None)
160
    self.assertEqual(elasthane.getProperty('quantity'), 0.12)
161 162 163

    # check indexes are present
    self.assertTrue(apparel_model.index.has_key('composition'))
164 165 166
    index = apparel_model.index['composition'][0]
    self.assertTrue(index.has_key('composition/elasthane'))
    self.assertTrue(index.has_key('composition/acrylique'))
167 168 169 170 171 172 173 174 175 176 177 178 179

  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