mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
TI-68: Add tests for modifying synthetic intervals
This commit is contained in:
parent
a5dc0cd385
commit
33e0cd185d
4 changed files with 231 additions and 6 deletions
76
test/move.t
76
test/move.t
|
@ -29,7 +29,7 @@
|
|||
import sys
|
||||
import os
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -129,6 +129,80 @@ class TestMove(TestCase):
|
|||
ends = [str(x['end']) for x in self.t.export()]
|
||||
self.assertNotIn('20170301T140000Z', ends)
|
||||
|
||||
def test_move_synthetic_interval_into_exclusion(self):
|
||||
"""Move a synthetic interval into exclusion"""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
five_hours_before = now - timedelta(hours=5)
|
||||
|
||||
exclusion = "{:%H}:00-{:%H}:00".format(four_hours_before, three_hours_before)
|
||||
|
||||
self.t.config("exclusions.friday", exclusion)
|
||||
self.t.config("exclusions.thursday", exclusion)
|
||||
self.t.config("exclusions.wednesday", exclusion)
|
||||
self.t.config("exclusions.tuesday", exclusion)
|
||||
self.t.config("exclusions.monday", exclusion)
|
||||
self.t.config("exclusions.sunday", exclusion)
|
||||
self.t.config("exclusions.saturday", exclusion)
|
||||
|
||||
self.t("start {}T{:%H}:45:00".format(now.date(), five_hours_before))
|
||||
|
||||
self.t("move @2 {}T{:%H}:50:00".format(now.date(), five_hours_before))
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertTrue('start' in j[0])
|
||||
self.assertEqual(j[0]['start'], '{:%Y%m%dT%H}5000Z'.format(now_utc-timedelta(hours=5)), 'start time of lengthened interval does not match')
|
||||
self.assertTrue('end' in j[0])
|
||||
self.assertEqual(j[0]['end'], '{:%Y%m%dT%H}0500Z'.format(now_utc - timedelta(hours=4)), 'end time of lengthened interval does not match')
|
||||
self.assertFalse('tags' in j[0])
|
||||
self.assertTrue('start' in j[1])
|
||||
self.assertEqual(j[1]['start'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=3)), 'start time of unmodified interval does not match')
|
||||
self.assertFalse('end' in j[1])
|
||||
self.assertFalse('tags' in j[1])
|
||||
|
||||
def test_move_synthetic_interval_away_from_exclusion(self):
|
||||
"""Move a synthetic interval away from exclusion"""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
five_hours_before = now - timedelta(hours=5)
|
||||
|
||||
exclusion = "{:%H}:00-{:%H}:00".format(four_hours_before, three_hours_before)
|
||||
|
||||
self.t.config("exclusions.friday", exclusion)
|
||||
self.t.config("exclusions.thursday", exclusion)
|
||||
self.t.config("exclusions.wednesday", exclusion)
|
||||
self.t.config("exclusions.tuesday", exclusion)
|
||||
self.t.config("exclusions.monday", exclusion)
|
||||
self.t.config("exclusions.sunday", exclusion)
|
||||
self.t.config("exclusions.saturday", exclusion)
|
||||
|
||||
self.t("start {}T{:%H}:45:00".format(now.date(), five_hours_before))
|
||||
|
||||
self.t("move @2 {}T{:%H}:40:00".format(now.date(), five_hours_before))
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertTrue('start' in j[0])
|
||||
self.assertEqual(j[0]['start'], '{:%Y%m%dT%H}4000Z'.format(now_utc-timedelta(hours=5)), 'start time of lengthened interval does not match')
|
||||
self.assertTrue('end' in j[0])
|
||||
self.assertEqual(j[0]['end'], '{:%Y%m%dT%H}5500Z'.format(now_utc - timedelta(hours=5)), 'end time of lengthened interval does not match')
|
||||
self.assertFalse('tags' in j[0])
|
||||
self.assertTrue('start' in j[1])
|
||||
self.assertEqual(j[1]['start'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=3)), 'start time of unmodified interval does not match')
|
||||
self.assertFalse('end' in j[1])
|
||||
self.assertFalse('tags' in j[1])
|
||||
|
||||
|
||||
|
||||
# TODO Add :adjust tests.
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue