diff --git a/db/comments.db b/db/comments.db index 84da0de56087a793d7d2cf995cd9e3d75969306c..fd2b7e0535582f9d89f5562a9a6eaad51937fdaf 100644 Binary files a/db/comments.db and b/db/comments.db differ diff --git a/db/posts.db b/db/posts.db index d5609799f8e8aaf9c96733ec0313aec501fc0343..958049138d4edc61900bb88c7a90fb96edc23746 100644 Binary files a/db/posts.db and b/db/posts.db differ diff --git a/db/users.db b/db/users.db index 1d71d8eea81106b5bf79922e6351faa0b868b826..ecf05cea946872dd37d496304363400cd4401438 100644 Binary files a/db/users.db and b/db/users.db differ diff --git a/tests/sandbox.py b/tests/sandbox.py new file mode 100644 index 0000000000000000000000000000000000000000..d53ba6d39074669253e3100170b700a9306a539e --- /dev/null +++ b/tests/sandbox.py @@ -0,0 +1,23 @@ +from playwright.sync_api import Playwright, sync_playwright, expect +from tConstant import URL, DB_COMMENTS_ROOT, USE_HEADLESS +from tUtils import login_test_user + +post_id = 1 + +def run(playwright: Playwright): + browser = playwright.chromium.launch(headless=False) + context = browser.new_context() + page = context.new_page() + page.goto(URL) + + page = login_test_user(page) + + page.wait_for_url(URL + '/') + page.goto(URL + '/post/' + str(post_id)) + page.locator("[name=commentDeleteButton]").click() + + context.close() + browser.close() + +with sync_playwright() as playwright: + run(playwright) \ No newline at end of file diff --git a/tests/test_delete_comment.py b/tests/test_delete_comment.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..eb3f3f96df4b65078d80004c8eac975137a30ae3 100644 --- a/tests/test_delete_comment.py +++ b/tests/test_delete_comment.py @@ -0,0 +1,70 @@ +from playwright.sync_api import Playwright, sync_playwright, expect +from tConstant import URL, DB_COMMENTS_ROOT, USE_HEADLESS +from tUtils import login_test_user +import pytest, sqlite3 + +username = "TestUser" +post_id = 1 +comment_content = "HelloComment" + +@pytest.fixture(autouse=True) +def setup_data (): + print("\nInserting mock comment") + connection = sqlite3.connect(DB_COMMENTS_ROOT) + cursor = connection.cursor() + cursor.execute( + "insert into comments(post,comment,user,timeStamp) \ + values(?, ?, ?, ?)", + ( + post_id, + comment_content, + username, + 1707854995, + ), + ) + connection.commit() + + latest_comment_id = get_newest_comment() + yield + print('\nDeleting comment') + + comment_id = get_newest_comment() + connection = sqlite3.connect(DB_COMMENTS_ROOT) + cursor = connection.cursor() + cursor.execute('DELETE FROM comments where id = ?', [(comment_id)]) + connection.commit() + + +def test_delete_comment(playwright: Playwright) -> None: + browser = playwright.chromium.launch(headless=USE_HEADLESS) + context = browser.new_context() + page = context.new_page() + page.goto(URL) + + page = login_test_user(page) + + page.wait_for_url(URL + '/') + page.goto(URL + '/post/' + str(post_id)) + page.locator("[name=commentDeleteButton]").click() + + expect(page.get_by_text(comment_content)).not_to_be_visible() + + context.close() + browser.close() + +def get_newest_comment(): + connection = sqlite3.connect(DB_COMMENTS_ROOT) + cursor = connection.cursor() + query = ''' + SELECT id FROM comments where id = ( + SELECT max(id) FROM comments + ) + ''' + comment_id = -1 + + for row in cursor.execute(query): + comment_id = row[0] + + connection.close() + return comment_id +