From 1ce249adf33d5d24163d9d7ccdbe4697a9b9a0b7 Mon Sep 17 00:00:00 2001 From: Dimas FM <dimasfaid@gmail.com> Date: Tue, 30 Apr 2024 07:20:16 +0700 Subject: [PATCH] Update test case to kill mutant --- tests/test_delete_comment.py | 56 +++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/tests/test_delete_comment.py b/tests/test_delete_comment.py index 37029b3..2e3074c 100644 --- a/tests/test_delete_comment.py +++ b/tests/test_delete_comment.py @@ -4,11 +4,12 @@ from tUtils import login_test_user import pytest, sqlite3 username = "TestUser" +otherUsername = "TestOtherUser" post_id = 1 comment_content = "HelloComment" @pytest.fixture(autouse=True) -def setup_data (): +def owned_comment(): print("\nInserting mock comment") connection = sqlite3.connect(DB_COMMENTS_ROOT) cursor = connection.cursor() @@ -22,20 +23,45 @@ def setup_data (): 1707854995, ), ) + id = cursor.lastrowid + connection.commit() - latest_comment_id = get_newest_comment() - yield + yield id 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)]) + cursor.execute('DELETE FROM comments where id = ?', [(id)]) + connection.commit() + +@pytest.fixture(autouse=True) +def others_comment(): + 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, + otherUsername, + 1707854995, + ), + ) + id = cursor.lastrowid + connection.commit() + yield id + print('\nDeleting comment') + connection = sqlite3.connect(DB_COMMENTS_ROOT) + cursor = connection.cursor() + cursor.execute('DELETE FROM comments where id = ?', [(id)]) + connection.commit() -def test_delete_comment(playwright: Playwright) -> None: +def test_delete_comment(playwright: Playwright, owned_comment, others_comment) -> None: browser = playwright.chromium.launch(headless=USE_HEADLESS) context = browser.new_context() page = context.new_page() @@ -43,16 +69,19 @@ def test_delete_comment(playwright: Playwright) -> None: page = login_test_user(page) + page.wait_for_url(URL + '/') page.goto(URL + '/post/' + str(post_id)) while page.locator("[name=commentDeleteButton]").count() > 0: page.locator("[name=commentDeleteButton]").first.click() - expect(page.get_by_text(comment_content)).not_to_be_visible() + assert is_comment_exist(owned_comment) == False + assert is_comment_exist(others_comment) == True context.close() browser.close() + def get_newest_comment(): connection = sqlite3.connect(DB_COMMENTS_ROOT) cursor = connection.cursor() @@ -69,3 +98,16 @@ def get_newest_comment(): connection.close() return comment_id +def is_comment_exist(id): + connection = sqlite3.connect(DB_COMMENTS_ROOT) + cursor = connection.cursor() + query = ''' + SELECT * FROM comments where id = ? + ''' + exist = False + + for row in cursor.execute(query,[(id)]): + exist = True + + connection.close() + return exist \ No newline at end of file -- GitLab