test.erp5.testPDM.py 6.45 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
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Nexedi KK, Nexedi SA and Contributors. All Rights Reserved.
#
# 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.ERP5TypeTestCase import ERP5TypeTestCase
from Products.CMFCore.exceptions import AccessControl_Unauthorized


class TestPDMWithSecurity(ERP5TypeTestCase):
  """
  Test PDM with Security
  """

  def getTitle(self):
    return 'Test PDM with Security'

  def getBusinessTemplateList(self):

    return ('erp5_base',
            'erp5_pdm',
            )

  def afterSetUp(self):
    if getattr(self.portal, '_run_after_setup', None) is not None:
      return


    self.portal._run_after_setup = True

    user_folder = self.getPortal().acl_users
    user_folder._doAddUser('author', '', ['Auditor', 'Author'], [])
    user_folder._doAddUser('assignor', '', ['Auditor', 'Author', 'Assignor'], [])
    user_folder._doAddUser('assignee', '', ['Auditor', 'Author', 'Assignee'], [])

59 60
    self.tic()

61 62 63 64
  def testValidatedProductCanContainMeasure(self):
    """
    Make sure that validated product can contain measure.
    """
65
    self.loginByUserName('author')
66 67 68 69 70 71 72 73 74 75 76 77
    product = self.portal.product_module.newContent(portal_type='Product',
                                                    title='Chair')

    self.tic()

    # Author try to add a measure to validated product and succeed.
    product.newContent(portal_type='Measure')

    self.tic()

    self.assertEqual(len(product.contentValues(portal_type='Measure')), 1)

78
    self.loginByUserName('assignor')
79 80 81 82 83 84 85
    self.portal.portal_workflow.doActionFor(product, 'validate_action')

    self.tic()

    self.assertEqual(product.getValidationState(), 'validated')

    # Change to author and try to add a measure to validated product and fail.
86
    self.loginByUserName('author')
87 88 89 90
    self.assertRaises(AccessControl_Unauthorized,
                      product.newContent, portal_type='Measure')

    # Change to assignee and try to add a measure to validated product and succeed.
91
    self.loginByUserName('assignee')
92 93 94 95 96 97 98
    product.newContent(portal_type='Measure')

    self.tic()

    self.assertEqual(len(product.contentValues(portal_type='Measure')),
                     2)

99 100 101 102 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
class DefaultSupplyLineTestCase(ERP5TypeTestCase):
  def _makeOne(self):
    raise NotImplementedError()

  def afterSetUp(self):
    super(DefaultSupplyLineTestCase, self).afterSetUp()
    if self.portal.portal_categories.quantity_unit.get('time') is None:
      self.portal.portal_categories.quantity_unit.newContent(id='time')
    if self.portal.portal_categories.quantity_unit.time.get('hour') is None:
      self.portal.portal_categories.quantity_unit.time.newContent(id='hour')
    self.resource = self._makeOne()

  def test_purchase_supply_line(self):
    self.resource.edit(purchase_supply_line_base_price=123)
    self.assertEqual(self.resource.getPurchaseSupplyLineBasePrice(), 123)
    self.resource.edit(purchase_supply_line_priced_quantity=2)
    self.assertEqual(self.resource.getPurchaseSupplyLinePricedQuantity(), 2)
    self.resource.edit(purchase_supply_line_quantity_unit='time/hour')
    self.assertEqual(
        self.resource.getPurchaseSupplyLineQuantityUnitValue(),
        self.portal.portal_categories.quantity_unit.time.hour)
    self.assertEqual(
        self.resource.default_psl.getPortalType(), 'Purchase Supply Line')

  def test_internal_supply_line(self):
    self.resource.edit(internal_supply_line_base_price=123)
    self.assertEqual(self.resource.getInternalSupplyLineBasePrice(), 123)
    self.resource.edit(internal_supply_line_priced_quantity=2)
    self.assertEqual(self.resource.getInternalSupplyLinePricedQuantity(), 2)
    self.resource.edit(internal_supply_line_quantity_unit='time/hour')
    self.assertEqual(
        self.resource.getInternalSupplyLineQuantityUnitValue(),
        self.portal.portal_categories.quantity_unit.time.hour)
    self.assertEqual(
        self.resource.default_isl.getPortalType(), 'Internal Supply Line')

  def test_sale_supply_line(self):
    self.resource.edit(sale_supply_line_base_price=123)
    self.assertEqual(self.resource.getSaleSupplyLineBasePrice(), 123)
    self.resource.edit(sale_supply_line_priced_quantity=2)
    self.assertEqual(self.resource.getSaleSupplyLinePricedQuantity(), 2)
    self.resource.edit(sale_supply_line_quantity_unit='time/hour')
    self.assertEqual(
        self.resource.getSaleSupplyLineQuantityUnitValue(),
        self.portal.portal_categories.quantity_unit.time.hour)
    self.assertEqual(
        self.resource.default_ssl.getPortalType(), 'Sale Supply Line')


class TestProductDefaultSupplyLine(DefaultSupplyLineTestCase):
  def _makeOne(self):
    return self.portal.product_module.newContent(portal_type='Product')


class TestServiceDefaultSupplyLine(DefaultSupplyLineTestCase):
  def _makeOne(self):
    return self.portal.service_module.newContent(portal_type='Service')


class TestComponentDefaultSupplyLine(DefaultSupplyLineTestCase):
  def _makeOne(self):
    return self.portal.component_module.newContent(portal_type='Component')

162 163 164 165

def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestPDMWithSecurity))
166 167 168
  suite.addTest(unittest.makeSuite(TestProductDefaultSupplyLine))
  suite.addTest(unittest.makeSuite(TestServiceDefaultSupplyLine))
  suite.addTest(unittest.makeSuite(TestComponentDefaultSupplyLine))
169
  return suite