config: compute holidays + test

This commit is contained in:
Frederik Jaeckel 2024-06-01 23:37:06 +02:00
parent 3c65390284
commit b54a8d678f
4 changed files with 188 additions and 8 deletions

View file

@ -116,6 +116,52 @@ class PlannerTestCase(object):
'Depot | 0.00 usd | Open | 0.0000 u')
return book
@with_transaction()
def test_func_holiday_parseconfig(self):
""" check function holiday_parseconfig()
"""
Config = Pool().get('cashbook.configuration')
company = self.prep_company()
with Transaction().set_context({'company': company.id}):
# check valid data
result = Config.holiday_parseconfig(
'2022-05-01;12-25;12-25:+1;easter;easter:-2;easterjul;' +
'ascension;whitsun;whitsun:+1;',
[2022, 2023, 2024])
self.assertEqual(result, {
'definition': '2022-05-01;12-25;12-25:+1;easter;easter:-2;' +
'easterjul;ascension;whitsun;whitsun:+1',
'dates': [
date(2022, 5, 1), date(2022, 12, 25), date(2023, 12, 25),
date(2024, 12, 25), date(2022, 12, 26), date(2023, 12, 26),
date(2024, 12, 26), date(2022, 4, 17), date(2023, 4, 9),
date(2024, 3, 31), date(2022, 4, 15), date(2023, 4, 7),
date(2024, 3, 29), date(2022, 4, 11), date(2023, 4, 3),
date(2024, 4, 22), date(2022, 5, 26), date(2023, 5, 18),
date(2024, 5, 9), date(2022, 6, 5), date(2023, 5, 28),
date(2024, 5, 19), date(2022, 6, 6), date(2023, 5, 29),
date(2024, 5, 20)]})
# check invalid data
self.assertEqual(
Config.holiday_parseconfig('not-a-value;'),
{'definition': '', 'dates': []})
# check no data
self.assertEqual(
Config.holiday_parseconfig(''),
{'definition': '', 'dates': []})
self.assertEqual(
Config.holiday_parseconfig(None),
{'definition': '', 'dates': []})
cfg1 = Config(holidays='2022-05-01;easter;whitsun')
cfg1.save()
self.assertEqual(
cfg1.holiday_dates([2022]),
[date(2022, 5, 1), date(2022, 4, 17), date(2022, 6, 5)])
@with_transaction()
def test_planner_create_job(self):
""" create job, check rule + constraints