def test_new_streak_from_broken(dbconn, test_task): (conn, taskids_to_delete) = dbconn taskids_to_delete.append(test_task.taskid) taskdb.add_task(rdb=conn, taskid=test_task.taskid, userid=test_task.userid, description=test_task.description) taskdb.complete_today(rdb=conn, taskid=test_task.taskid) taskdb.complete_today(rdb=conn, taskid=test_task.taskid, override_date=(today + one_day)) taskdb.complete_today(rdb=conn, taskid=test_task.taskid, override_date=(today + (one_day * 2))) taskdb.complete_today(rdb=conn, taskid=test_task.taskid, override_date=(today + (one_day * 3))) # this next completion breaks/resets the streak. we missed (one_day * 4), see? taskdb.complete_today(rdb=conn, taskid=test_task.taskid, override_date=(today + (one_day * 5))) test_task.start = datetime.date.today() + (one_day * 5) test_task.end = test_task.start actual_tasks = taskdb.select_tasks_by_user(rdb=conn, userid=test_task.userid) assert len(actual_tasks) == 1 assert actual_tasks[0].get_streak() == 0 assert_tasks_equal(test_task, actual_tasks[0])
def test_mark_today_incomplete_streak(dbconn, test_task): (conn, taskids_to_delete) = dbconn taskids_to_delete.append(test_task.taskid) taskdb.add_task(rdb=conn, taskid=test_task.taskid, userid=test_task.userid, description=test_task.description) taskdb.complete_today(rdb=conn, taskid=test_task.taskid) taskdb.complete_today(rdb=conn, taskid=test_task.taskid, override_date=(today + one_day)) taskdb.complete_today(rdb=conn, taskid=test_task.taskid, override_date=(today + (one_day * 2))) taskdb.complete_today(rdb=conn, taskid=test_task.taskid, override_date=(today + (one_day * 3))) taskdb.mark_incomplete(rdb=conn, taskid=test_task.taskid, override_date=(today + (one_day * 3))) test_task.start = today test_task.end = today + (one_day * 2) actual_tasks = taskdb.select_tasks_by_user(rdb=conn, userid=test_task.userid) assert len(actual_tasks) == 1 assert actual_tasks[0].get_streak() == 2 assert_tasks_equal(test_task, actual_tasks[0])
def test_add_task(dbconn, test_task): (conn, taskids_to_delete) = dbconn taskids_to_delete.append(test_task.taskid) taskdb.add_task(rdb=conn, taskid=test_task.taskid, userid=test_task.userid, description=test_task.description) actual_tasks = taskdb.select_tasks_by_user(rdb=conn, userid=test_task.userid) assert len(actual_tasks) == 1 assert_tasks_equal(test_task, actual_tasks[0])
def test_start_first_streak(dbconn, test_task): (conn, taskids_to_delete) = dbconn taskids_to_delete.append(test_task.taskid) taskdb.add_task(rdb=conn, taskid=test_task.taskid, userid=test_task.userid, description=test_task.description) taskdb.complete_today(rdb=conn, taskid=test_task.taskid) test_task.start = datetime.date.today() test_task.end = test_task.start actual_tasks = taskdb.select_tasks_by_user(rdb=conn, userid=test_task.userid) assert len(actual_tasks) == 1 assert_tasks_equal(test_task, actual_tasks[0])