def test_translate_from_vtodo(self): DESCRIPTION = Translator.fields[1] self.assertEqual(DESCRIPTION.dav_name, 'description') todo = self._get_todo(VTODO_GRAND_CHILD) self.assertEqual(todo.instance.vtodo.serialize(), VTODO_GRAND_CHILD) self.assertEqual(date(2020, 12, 24), todo.instance.vtodo.contents['due'][0].value) uid = UID_FIELD.get_dav(todo) self.assertTrue(isinstance(uid, str), f"should be str is {uid!r}") self.assertEqual(uid, UID_FIELD.get_dav(vtodo=todo.instance.vtodo)) task = Task(uid, Mock()) Translator.fill_task(todo, task, NAMESPACE) self.assertEqual('date', task.get_due_date().accuracy.value) vtodo = Translator.fill_vtodo(task, todo.parent.name, NAMESPACE) for field in Translator.fields: if field.dav_name in DAV_IGNORE: continue self.assertTrue(field.is_equal(task, NAMESPACE, todo)) self.assertTrue(field.is_equal(task, NAMESPACE, vtodo=vtodo.vtodo)) vtodo.vtodo.contents['description'][0].value = 'changed value' self.assertTrue( DESCRIPTION.is_equal(task, NAMESPACE, todo), 'same ' 'hashes should prevent changes on vTodo to be noticed') task.set_text(task.get_text() + 'more content') self.assertFalse(DESCRIPTION.is_equal(task, NAMESPACE, todo))
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)