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]
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
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 ""
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
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()
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()
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
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
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)
def get_all_tasks() -> json: store = Store(DATABASE) all_tasks = store.get_all_tasks() response = {"tasks": all_tasks} return jsonify(response)