Пример #1
0
    def test_due_date_caldav_restriction(self):
        task = Task('uid', Mock())
        later = datetime(2021, 11, 24, 21, 52, 45)
        before = later - timedelta(days=1)
        task.set_start_date(later)
        task.set_due_date(before)
        field = DueDateField('due', 'get_due_date_constraint', 'set_due_date')
        self.assertEqual(later, field.get_gtg(task, '').dt_value)

        task.set_start_date(before)
        task.set_due_date(later)
        self.assertEqual(later, field.get_gtg(task, '').dt_value)
Пример #2
0
 def test_translate_from_task(self):
     now, today = datetime.now(), date.today()
     task = Task('uuid', Mock())
     task.set_title('holy graal')
     task.set_text('the knights who says ni')
     task.set_recurring(True, 'other-day')
     task.set_start_date(today)
     task.set_due_date('soon')
     task.set_closed_date(now)
     vtodo = Translator.fill_vtodo(task, 'My Calendar Name', NAMESPACE)
     for field in Translator.fields:
         self.assertTrue(field.is_equal(task, NAMESPACE, vtodo=vtodo.vtodo),
                         f'{field!r} has differing values')
     serialized = vtodo.serialize()
     self.assertTrue(
         f"DTSTART;VALUE=DATE:{today.strftime('%Y%m%d')}" in serialized,
         f"missing from {serialized}")
     self.assertTrue(re.search(r"COMPLETED:[0-9]{8}T[0-9]{6}Z", serialized),
                     f"missing from {serialized}")
     self.assertTrue("DUE;GTGFUZZY=soon" in serialized,
                     f"missing from {serialized}")
     # trying to fill utc only with fuzzy
     task.set_closed_date('someday')
     vtodo = Translator.fill_vtodo(task, 'My Calendar Name', NAMESPACE)
     serialized = vtodo.serialize()
     self.assertTrue("COMPLETED;GTGFUZZY=someday:" in serialized,
                     f"missing from {serialized}")
     # trying to fill utc only with date
     task.set_closed_date(today)
     vtodo = Translator.fill_vtodo(task, 'My Calendar Name', NAMESPACE)
     serialized = vtodo.serialize()
     today_in_utc = now.replace(hour=0, minute=0, second=0)\
         .replace(tzinfo=LOCAL_TIMEZONE).astimezone(UTC)\
         .strftime('%Y%m%dT%H%M%SZ')
     self.assertTrue(f"COMPLETED:{today_in_utc}" in serialized,
                     f"missing {today_in_utc} from {serialized}")
     # emptying date by setting None or no_date
     task.set_closed_date(Date.no_date())
     task.set_due_date(None)
     task.set_start_date('')
     vtodo = Translator.fill_vtodo(task, 'My Calendar Name', NAMESPACE)
     serialized = vtodo.serialize()
     self.assertTrue("CATEGORIES:" not in serialized)
     self.assertTrue("COMPLETED:" not in serialized)
     self.assertTrue("DUE:" not in serialized)
     self.assertTrue("DTSTART:" not in serialized)