示例#1
0
 def test_taskid_gets_entered_in_database(self):
     store = Store(DATABASE)
     store.add_task(task1)
     taskids = DB.cursor.execute("""SELECT * FROM tasks;""").fetchall()
     tasklogs = DB.cursor.execute("""SELECT * FROM tasklog;""").fetchall()
     # DB.commit()
     assert task1.id in [i[0] for i in taskids]
     assert task1.id in [i[0] for i in tasklogs]
示例#2
0
 def test_tasks_default_to_unfinished(self):
     store = Store(DATABASE)
     task = task2
     store.add_task(task)
     finished = DB.cursor.execute(
         """SELECT done FROM tasklog WHERE taskid = ?""",
         [task.id]).fetchone()[0]
     assert finished == 0
示例#3
0
文件: app.py 项目: ntbloom/pomodoro
def hello() -> str:
    test = request.args.get("test")
    if test == "basic-connection":
        return "hello world"
    if test == "database":
        store = Store(DATABASE)
        return "no errors thrown in Store instantiation"
    if test == "two-plus-two":
        store = Store(DATABASE)
        four = store.cursor.execute("""SELECT 2+2;""").fetchone()[0]
        return str(four)
    return ""
示例#4
0
 def test_create_task_from_json(self):
     rawjson = json.dumps({
         "id": "123",
         "short": "this is short",
         "desc": "this is longer",
         "done": 0
     })
     expected = Task("123", "this is short", "this is longer", 0)
     actual = Store.create_task_from_json(rawjson)
     assert actual == expected
示例#5
0
文件: app.py 项目: ntbloom/pomodoro
def add_task() -> Response:
    print(f"\n\n{request.headers}\n\n{request.is_json}")
    payload = request.get_json()
    print(f"\n\nPAYLOAD={payload}\n\n")
    store = Store(DATABASE)
    task = store.create_task_from_json(payload)
    store.add_task(task)
    try:
        assert task.id in store.get_all_taskids()
        return Response(status=200)
    except AssertionError:
        return Response(status=500)
    finally:
        store.close()
示例#6
0
文件: app.py 项目: ntbloom/pomodoro
def finish_task() -> Response:
    taskid = request.args.get("taskid")
    store = Store(DATABASE)
    store.mark_task_as_finished(taskid)
    try:
        assert store.get_task_info(taskid)["done"] == 1
        return Response(status=200)
    except AssertionError:
        return Response(status=500)
    finally:
        store.close()
示例#7
0
 def test_get_task_info(self):
     store = Store(DATABASE)
     tasks = [task1, task2, task3]
     for i in tasks:
         store.add_task(i)
     expected_task_info = store.make_dict(task1)
     actual_task_info = store.get_task_info(task1.id)
     assert actual_task_info == expected_task_info
示例#8
0
 def test_finishing_a_task(self):
     store = Store(DATABASE)
     task = task3
     store.add_task(task)
     store.mark_task_as_finished(task.id)
     finished = DB.cursor.execute(
         """SELECT done FROM tasklog WHERE taskid = ?""",
         [task.id]).fetchone()[0]
     assert finished == 1
示例#9
0
文件: app.py 项目: ntbloom/pomodoro
def get_task() -> json:
    """simple getter method using REST"""
    store = Store(DATABASE)
    all_tasks = store.get_all_taskids()
    taskid = request.args.get("taskid")
    if taskid == "sample-for-testing":
        return "passing connection test"
    if taskid not in all_tasks:
        return Response(status=404)
    task = store.get_task_info(taskid)
    store.close()
    return jsonify(task)
示例#10
0
文件: app.py 项目: ntbloom/pomodoro
def get_all_tasks() -> json:
    store = Store(DATABASE)
    all_tasks = store.get_all_tasks()
    response = {"tasks": all_tasks}
    return jsonify(response)