def test_store_task(resource): user_id = resource TaskRepo.add_task(description="This is a task", user=user_id) tasks = TaskRepo.get_all_tasks() assert len(tasks) == 1 assert tasks[0]["description"] == "This is a task" assert tasks[0]["status"] == "todo"
def test_delete_task(resource): user_id = resource task_to_del = TaskRepo.add_task(description="This is a task", user=user_id) TaskRepo.add_task(description="This is another task", user=user_id) assert len(TaskRepo.get_all_tasks()) == 2 assert TaskRepo.delete_task(task_to_del["id"], user_id) == True remaining_tasks = TaskRepo.get_all_tasks() assert len(remaining_tasks) == 1 assert remaining_tasks[0]["description"] == "This is another task"
def test_store_project(resource): user_id = resource TaskRepo.add_task(description="Task1", user=user_id) TaskRepo.add_task(description="Task2", user=user_id) tasks = list(map(lambda t: t["id"], TaskRepo.get_all_tasks())) ProjectRepo.add_project(description="ProjectA", tasks=tasks, user=user_id) projects = ProjectRepo.get_all_projects() assert len(projects) == 1 assert projects[0]["description"] == "ProjectA" assert len(projects[0]["tasks"]) == 2 assert projects[0]["tasks"][0]["id"] in tasks assert projects[0]["tasks"][1]["id"] in tasks
def test_toggle_task_todo_to_done(resource): user_id = resource TaskRepo.add_task(description="This is a task", user=user_id) tasks = TaskRepo.get_all_tasks() assert len(tasks) == 1 assert tasks[0]["description"] == "This is a task" assert tasks[0]["status"] == "todo" assert TaskRepo.toggle_task(str(tasks[0]["id"])) == True tasks = TaskRepo.get_all_tasks() assert len(tasks) == 1 assert tasks[0]["description"] == "This is a task" assert tasks[0]["status"] == "done"
def test_task_to_project(resource): user_id = resource task = TaskRepo.add_task(description="Thing", user=user_id) project = TaskRepo.task_to_project(task["id"], user_id) # No more tasks assert len(TaskRepo.get_all_tasks()) == 0 # Project used to be the task assert project is not None assert project["description"] == "Thing"
def test_delete_project_task_bad(resource): """ Should not be able to delete a task if it does not belong to the project """ user_id = resource proj = ProjectRepo.add_project(description="ProjectA", user=user_id, tasks=[]) task = TaskRepo.add_task(description="Task1", user=user_id) assert ProjectRepo.delete_project_task(proj["id"], task["id"], user_id) == False
def task_add(): uid = current_user.get_obj_id() payload = request.get_json() if "description" not in payload: res = {"success": False} else: res = {} added_task = TaskRepo.add_task(payload["description"], uid) if added_task: res["success"] = True res["data"] = added_task else: res["success"] = False return json.dumps(res)