def test_make_list(req_context): from database import insert_user from database import make_list insert_user("Test User", "pass", "*****@*****.**") user_id = run_independent_query("SELECT user_id FROM users")[0][0] expected = ("My Title", "My description", user_id) make_list(*expected) rows = run_independent_query("SELECT * FROM lists") assert len(rows) == 1 for val in expected: assert val in rows[0]
def test_delete_list(req_context): from database import insert_user, make_list, insert_list_item from database import delete_list, get_all_users_lists insert_user("Test User", "password", "*****@*****.**") user_id = run_independent_query("SELECT user_id FROM users")[0][0] make_list("Title", "Description", user_id) list_id = run_independent_query("SELECT * FROM lists")[0][0] insert_list_item(list_id, "Do this") delete_list(list_id) lists = get_all_users_lists(user_id) assert len(lists) == 0
def test_update_list_title_test(req_context): from database import insert_user, make_list, update_list_title_text insert_user("Test User", "password", "*****@*****.**") user_id = run_independent_query("SELECT user_id FROM users")[0][0] make_list("Title", "Description", user_id) list_id = run_independent_query("SELECT * FROM lists")[0][0] expected = ("New Title", "New description") update_list_title_text(*expected, list_id=list_id) rows = run_independent_query("SELECT title, description FROM lists") for val in expected: assert val in rows[0]
def test_get_all_lists(req_context): from database import get_all_users_lists, make_list, insert_user insert_user("Test User", "pass", "*****@*****.**") user_id = run_independent_query("SELECT user_id FROM users")[0][0] expected = ("My Title", "My description", user_id) make_list(*expected) lists = get_all_users_lists(user_id) assert len(lists) == 1 for l in lists: assert expected[0] == l['title'] assert expected[1] == l['description']
def test_delete_list_user(req_context): from database import insert_user, make_list, add_list_user from database import delete_list_user, get_all_list_users insert_user("Test User", "password", "*****@*****.**") insert_user("Test User2", "password2", "*****@*****.**") user_id1 = run_independent_query("SELECT user_id FROM users")[0][0] user_id2 = run_independent_query("SELECT user_id FROM users")[1][0] make_list("Title", "Description", user_id1) list_id = run_independent_query("SELECT * FROM lists")[0][0] add_list_user(list_id, user_id2) delete_list_user(list_id, user_id2) list_users = get_all_list_users(list_id) assert len(list_users) == 0
def test_get_all_list_users(req_context): from database import get_all_list_users, make_list, insert_user from database import add_list_user insert_user("Test User", "pass", "*****@*****.**") insert_user("Another User", "pass", "*****@*****.**") user_id1 = run_independent_query("SELECT user_id FROM users")[0][0] user_id2 = run_independent_query("SELECT user_id FROM users")[1][0] make_list("My Title", "My description", user_id1) list_id = run_independent_query("SELECT * FROM lists")[0][0] print list_id, user_id1, user_id2 add_list_user(list_id, user_id2) actual = get_all_list_users(list_id)[0]['list_id'] assert user_id2 == actual
def test_update_checkmark(req_context): from database import insert_user, make_list, insert_list_item from database import update_item_checkmark insert_user("Test User", "password", "*****@*****.**") user_id = run_independent_query("SELECT user_id FROM users")[0][0] make_list("Title", "Description", user_id) list_id = run_independent_query("SELECT * FROM lists")[0][0] insert_list_item(list_id, "Do this") # item_id is second result in query item_id = run_independent_query("SELECT * FROM list_items")[0][1] check_zero = run_independent_query("SELECT checked FROM list_items")[0][0] assert check_zero == 0 update_item_checkmark(1, list_id, item_id) check_one = run_independent_query("SELECT checked FROM list_items")[0][0] assert check_one == 1
def test_add_list_user(req_context): from database import insert_user from database import make_list from database import add_list_user insert_user("Test User", "pass", "*****@*****.**") insert_user("Another User", "pass", "*****@*****.**") user_id1 = run_independent_query("SELECT user_id FROM users")[0][0] user_id2 = run_independent_query("SELECT user_id FROM users")[1][0] make_list("My Title", "My description", user_id1) list_id = run_independent_query("SELECT * FROM lists")[0][0] expected = (list_id, user_id2) add_list_user(*expected) rows = run_independent_query("SELECT * FROM list_users") assert len(rows) == 1 for val in expected: assert val in rows[0]