[Erp5-report] r21053 - in /erp5/trunk/products/ERP5: PropertySheet/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed May 21 11:56:50 CEST 2008
Author: jerome
Date: Wed May 21 11:56:50 2008
New Revision: 21053
URL: http://svn.erp5.org?rev=21053&view=rev
Log:
move constraints from erp5_calendar in ERP5 product. Rework them a bit to generate user oriented messages
Added:
erp5/trunk/products/ERP5/PropertySheet/CalendarConstraint.py
erp5/trunk/products/ERP5/PropertySheet/CalendarPeriodConstraint.py
erp5/trunk/products/ERP5/PropertySheet/IndividualCalendarConstraint.py
Modified:
erp5/trunk/products/ERP5/tests/testCalendar.py
Added: erp5/trunk/products/ERP5/PropertySheet/CalendarConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/CalendarConstraint.py?rev=21053&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/CalendarConstraint.py (added)
+++ erp5/trunk/products/ERP5/PropertySheet/CalendarConstraint.py Wed May 21 11:56:50 2008
@@ -1,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+# Rafael M. Monnerat <rafael at nexedi.com>
+# Jerome Perrin <jerome at 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")',
+ },
+
+ )
Added: erp5/trunk/products/ERP5/PropertySheet/CalendarPeriodConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/CalendarPeriodConstraint.py?rev=21053&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/CalendarPeriodConstraint.py (added)
+++ erp5/trunk/products/ERP5/PropertySheet/CalendarPeriodConstraint.py Wed May 21 11:56:50 2008
@@ -1,0 +1,67 @@
+##############################################################################
+#
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+# Rafael M. Monnerat <rafael at nexedi.com>
+# Jerome Perrin <jerome at 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,
+ },
+
+ )
Added: erp5/trunk/products/ERP5/PropertySheet/IndividualCalendarConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/IndividualCalendarConstraint.py?rev=21053&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/IndividualCalendarConstraint.py (added)
+++ erp5/trunk/products/ERP5/PropertySheet/IndividualCalendarConstraint.py Wed May 21 11:56:50 2008
@@ -1,0 +1,47 @@
+##############################################################################
+#
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+# Rafael M. Monnerat <rafael at nexedi.com>
+# Jerome Perrin <jerome at 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,
+ },
+
+ )
Modified: erp5/trunk/products/ERP5/tests/testCalendar.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testCalendar.py?rev=21053&r1=21052&r2=21053&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testCalendar.py (original)
+++ erp5/trunk/products/ERP5/tests/testCalendar.py Wed May 21 11:56:50 2008
@@ -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 @@
"""
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 @@
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()
More information about the Erp5-report
mailing list