Commit fa981ffb authored by Jérome Perrin's avatar Jérome Perrin

move constraints from erp5_calendar in ERP5 product. Rework them a bit to...

move constraints from erp5_calendar in ERP5 product. Rework them a bit to generate user oriented messages



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21053 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8fb88e46
##############################################################################
#
# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
# Rafael M. Monnerat <rafael@nexedi.com>
# Jerome Perrin <jerome@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.
#
##############################################################################
class CalendarConstraint:
"""Constraints for Calendar
"""
_constraints = (
{ 'id' : 'presence_request_line',
'description' : 'Must contain at least one period',
'type' : 'ContentExistence',
'portal_type' : ('Presence Request Period', ),
'description' : 'No Presence Request Period created yet',
'condition' : 'python: object.getPortalType() == "Presence Request"'
' and object.getSimulationState() not'
' in ("cancelled", "deleted")',
},
{ 'id' : 'leave_request_line',
'description' : 'Must contain at least one period',
'type' : 'ContentExistence',
'portal_type' : ('Leave Request Period', ),
'description' : 'No Leave Request Period created yet',
'condition' : 'python: object.getPortalType() == "Leave Request"'
' and object.getSimulationState() not'
' in ("cancelled", "deleted")',
},
{ 'id' : 'group_request_line',
'description' : 'Must contain at least one period',
'type' : 'ContentExistence',
'portal_type' : ('Group Leave Period', 'Group Presence Period', ),
'description' : 'No Group Presence Period created yet',
'condition' : 'python: object.getPortalType() == "Group Calendar"'
' and object.getSimulationState() not'
' in ("cancelled", "deleted")',
},
)
##############################################################################
#
# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
# Rafael M. Monnerat <rafael@nexedi.com>
# Jerome Perrin <jerome@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.
#
##############################################################################
class CalendarPeriodConstraint:
"""Constraints for Calendar Period
"""
_constraints = (
{ 'id': 'start_date_existence',
'description': 'Date must be defined',
'message_property_not_set': 'Start date must be defined',
'message_no_such_property': 'Start date must be defined',
'condition' : 'python: object.getSimulationState() not'
' in ("cancelled", "deleted")',
'type': 'PropertyExistence',
'start_date' : 1,
},
{ 'id': 'stop_date_existence',
'description': 'Date must be defined',
'message_property_not_set': 'Stop date must be defined',
'message_no_such_property': 'Stop date must be defined',
'condition' : 'python: object.getSimulationState() not'
' in ("cancelled", "deleted")',
'type': 'PropertyExistence',
'stop_date' : 1,
},
{ 'id': 'resource_existence',
'description': 'Type must be defined',
'message_category_not_set':
'Type must be defined',
'portal_type': (),
'condition' : 'python: object.getSimulationState() not'
' in ("cancelled", "deleted")',
'type': 'CategoryExistence',
'resource' : 1,
},
)
##############################################################################
#
# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
# Rafael M. Monnerat <rafael@nexedi.com>
# Jerome Perrin <jerome@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.
#
##############################################################################
class IndividualCalendarConstraint:
"""Constraints for Presence and Leave Request
"""
_constraints = (
{ 'id': 'destination_existance',
'description': 'Person must be defined',
'message_category_not_set':
'Person must be defined',
'portal_type': ('Person',),
'condition' : 'python: object.getSimulationState() not'
' in ("cancelled", "deleted")',
'type': 'CategoryExistence',
'destination' : 1,
},
)
......@@ -27,6 +27,7 @@
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.Base import _aq_reset
from AccessControl.SecurityManagement import newSecurityManager, \
noSecurityManager
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
......@@ -83,6 +84,25 @@ class TestCalendar(ERP5TypeTestCase):
"""
self.category_tool = self.getCategoryTool()
self.createCategories()
# activate constraints
self._addPropertySheet('Group Calendar', 'CalendarConstraint')
self._addPropertySheet('Presence Request', 'CalendarConstraint')
self._addPropertySheet('Leave Request', 'CalendarConstraint')
self._addPropertySheet('Presence Request', 'IndividualCalendarConstraint')
self._addPropertySheet('Leave Request', 'IndividualCalendarConstraint')
self._addPropertySheet('Leave Request Period', 'CalendarPeriodConstraint')
self._addPropertySheet('Presence Request Period', 'CalendarPeriodConstraint')
self._addPropertySheet('Group Presence Period', 'CalendarPeriodConstraint')
def _addPropertySheet(self, type_info_name, property_sheet_name):
ti = self.portal.portal_types.getTypeInfo(type_info_name)
if property_sheet_name not in ti.property_sheet_list:
ti.property_sheet_list = tuple(ti.property_sheet_list)\
+ (property_sheet_name,)
_aq_reset()
def stepCreatePerson(self, sequence=None, sequence_list=None, **kw):
"""
......@@ -716,6 +736,61 @@ class TestCalendar(ERP5TypeTestCase):
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_GroupCalendarConstraint(self):
group_calendar = self.portal.group_calendar_module.newContent(
portal_type='Group Calendar')
# no lines
self.assertEquals(1, len(group_calendar.checkConsistency()))
group_calendar_period = group_calendar.newContent(
portal_type='Group Presence Period')
# invalid line (no dates, no resource)
self.assertEquals(3, len(group_calendar.checkConsistency()))
group_calendar_period.setStartDate(self.start_date)
group_calendar_period.setStopDate(self.stop_date)
self.assertEquals(1, len(group_calendar.checkConsistency()))
group_calendar_period.setResourceValue(
self.portal.portal_categories.calendar_period_type.type1)
self.assertEquals(0, len(group_calendar.checkConsistency()))
def test_LeaveRequestCalendarConstraint(self):
leave_request = self.portal.leave_request_module.newContent(
portal_type='Leave Request')
# no lines, no person
self.assertEquals(2, len(leave_request.checkConsistency()))
leave_request_period = leave_request.newContent(
portal_type='Leave Request Period')
# no person, invalid line (no dates, no resource)
self.assertEquals(4, len(leave_request.checkConsistency()))
leave_request_period.setStartDate(self.start_date)
leave_request_period.setStopDate(self.stop_date)
self.assertEquals(2, len(leave_request.checkConsistency()))
leave_request_period.setResourceValue(
self.portal.portal_categories.calendar_period_type.type1)
self.assertEquals(1, len(leave_request.checkConsistency()))
person = self.portal.person_module.newContent(portal_type='Person')
leave_request.setDestinationValue(person)
self.assertEquals(0, len(leave_request.checkConsistency()))
def test_PresenceRequestCalendarConstraint(self):
presence_request = self.portal.presence_request_module.newContent(
portal_type='Presence Request')
# no lines, no person
self.assertEquals(2, len(presence_request.checkConsistency()))
presence_request_period = presence_request.newContent(
portal_type='Presence Request Period')
# no person, invalid line (no dates, no resource)
self.assertEquals(4, len(presence_request.checkConsistency()))
presence_request_period.setStartDate(self.start_date)
presence_request_period.setStopDate(self.stop_date)
self.assertEquals(2, len(presence_request.checkConsistency()))
presence_request_period.setResourceValue(
self.portal.portal_categories.calendar_period_type.type1)
self.assertEquals(1, len(presence_request.checkConsistency()))
person = self.portal.person_module.newContent(portal_type='Person')
presence_request.setDestinationValue(person)
self.assertEquals(0, len(presence_request.checkConsistency()))
import unittest
def test_suite():
suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment