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

erp5: an attempt to test getNextPeriodicalDate

This API is crazy, I give up
parent 0186ac99
##############################################################################
#
# Copyright (c) 2016 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 DateTime import DateTime
class TestPeriodicityMixin:
def test_minute_frequency(self):
periodicity = self._makeOne()
periodicity.setPeriodicityMinuteFrequency(3)
periodicity.setPeriodicityStartDate(DateTime('2015/01/01 00:00:00'))
self.assertEqual(
DateTime('2016/01/01 00:03:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
self.assertEqual(
DateTime('2016/01/01 00:06:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:03:00 UTC')))
# XXX getNextPeriodicalDate does not support calculate the next date from a
# date that would not be in the sequence of dates defined by this
# periodicity. So we just cannot do that:
# self.assertEqual(
# DateTime('2016/01/01 00:13:01 UTC'),
# periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:10:01 UTC')))
# not sure if bug or feature.
def test_minute_list(self):
periodicity = self._makeOne()
periodicity.setPeriodicityMinuteList([10, 20])
self.assertEqual(
DateTime('2016/01/01 00:10:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
self.assertEqual(
DateTime('2016/01/01 00:20:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:10:00 UTC')))
def test_hour_frequency(self):
periodicity = self._makeOne()
periodicity.setPeriodicityHourFrequency(3)
self.assertEqual(
DateTime('2016/01/01 03:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
self.assertEqual(
DateTime('2016/01/01 06:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 03:00:00 UTC')))
def test_hour_list(self):
periodicity = self._makeOne()
periodicity.setPeriodicityHourList([10, 20])
self.assertEqual(
DateTime('2016/01/01 10:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 10:00:00 UTC')))
self.assertEqual(
DateTime('2016/01/01 20:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 10:00:00 UTC')))
def test_day_frequency(self):
periodicity = self._makeOne()
periodicity.setPeriodicityDayFrequency(3)
self.assertEqual(
DateTime('2016/01/04 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
self.assertEqual(
DateTime('2016/01/07 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/04 00:00:00 UTC')))
def test_day_list(self):
periodicity = self._makeOne()
periodicity.setPeriodicityDayList([10, 20])
self.assertEqual(
DateTime('2016/01/10 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
self.assertEqual(
DateTime('2016/01/20 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/10 00:00:00 UTC')))
def test_day_list_invalid_day(self):
periodicity = self._makeOne()
periodicity.setPeriodicityDayList([31, ])
self.assertEqual(
DateTime('2016/01/31 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
# no 31th february
self.assertEqual(
DateTime('2016/03/31 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/02/01 00:00:00 UTC')))
def test_week_frequency(self):
periodicity = self._makeOne()
periodicity.setPeriodicityWeekFrequency(1)
self.assertEqual(
DateTime('2016/01/08 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
self.assertEqual(
DateTime('2016/01/09 01:02:03 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/02 01:02:03 UTC')))
def test_week_list(self):
periodicity = self._makeOne()
periodicity.setPeriodicityWeekList([2, 3])
self.assertEqual(
DateTime('2016/01/08 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
self.assertEqual(
DateTime('2016/01/09 01:02:03 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/02 01:02:03 UTC')))
def test_month_frequency(self):
periodicity = self._makeOne()
periodicity.setPeriodicityMonthFrequency(1)
self.assertEqual(
DateTime('2016/02/01 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 00:00:00 UTC')))
self.assertEqual(
DateTime('2016/03/01 00:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/02/01 00:00:00 UTC')))
def test_month_list(self):
periodicity = self._makeOne()
periodicity.setPeriodicityMonthList([1, 2])
self.assertEqual(
DateTime('2016/02/01 01:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/01/01 01:00:00 UTC')))
self.assertEqual(
DateTime('2017/01/01 01:00:00 UTC'),
periodicity.getNextPeriodicalDate(DateTime('2016/02/01 01:00:00 UTC')))
class TestPeriodicityLine(TestPeriodicityMixin, ERP5TypeTestCase):
def _makeOne(self):
from Products.ERP5Type.Document import newTempPeriodicityLine
return newTempPeriodicityLine(self.portal, self.id())
class TestPresencePeriod(TestPeriodicityMixin, ERP5TypeTestCase):
def getBusinessTemplateList(self):
return ('erp5_calendar', )
def _makeOne(self):
from Products.ERP5Type.Document import newTempPresencePeriod
return newTempPresencePeriod(self.portal, self.id())
def test_suite():
suite = unittest.TestSuite()
#suite.addTest(unittest.makeSuite(TestPeriodicityLine))
suite.addTest(unittest.makeSuite(TestPresencePeriod))
return suite
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