def test_import_tasks(self): task100 = Task('Task100') task100.label = "added" task100.unique_id = "1" task101 = Task('Task100') task101.label = "updated" task101.deleted = False task101.unique_id = "1" task102 = Task('Task100') task102.deleted = True task102.label = "deleted" task102.unique_id = "1" tasks_list = [task100, task101, task102] sync_results = self.importer.import_tasks(tasks_list) sync_results_list = sync_results.get_list() self.assertTrue(len(sync_results_list) == 3) print(sync_results_list) self.assertTrue(sync_results_list[0] == SyncAction.ADDED) self.assertTrue(sync_results_list[1] == SyncAction.UPDATED) self.assertTrue(sync_results_list[2] == SyncAction.DELETED)
def test_import_action_can_delete(self): remote_task = Task("Task1") remote_task.external_id = "100" remote_task.deleted = True local_task = Task("Task1") local_task.external_id = "100" local_task.deleted = False action = ImportAction(local_task, remote_task) self.assertTrue(action.can_delete()) self.assertFalse(action.can_update()) self.assertFalse(action.can_insert())
def convert(obj_list: list) -> List[Task]: task_list = list() for obj_dict in obj_list: task = Task(obj_dict["text"]) for key, value in obj_dict.items(): if key == "deleted": value = ast.literal_eval(value) task.deleted = value elif key == "due_date": task.due_date.date_string = value elif key == "done": value = ast.literal_eval(value) task.due_date.completed = value else: setattr(task, key, value) task_list.append(task) return task_list