Skip to content
Snippets Groups Projects
Commit 1ce249ad authored by Dimas FM's avatar Dimas FM
Browse files

Update test case to kill mutant

parent 11c513cc
No related merge requests found
...@@ -4,11 +4,12 @@ from tUtils import login_test_user ...@@ -4,11 +4,12 @@ from tUtils import login_test_user
import pytest, sqlite3 import pytest, sqlite3
username = "TestUser" username = "TestUser"
otherUsername = "TestOtherUser"
post_id = 1 post_id = 1
comment_content = "HelloComment" comment_content = "HelloComment"
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup_data (): def owned_comment():
print("\nInserting mock comment") print("\nInserting mock comment")
connection = sqlite3.connect(DB_COMMENTS_ROOT) connection = sqlite3.connect(DB_COMMENTS_ROOT)
cursor = connection.cursor() cursor = connection.cursor()
...@@ -22,20 +23,45 @@ def setup_data (): ...@@ -22,20 +23,45 @@ def setup_data ():
1707854995, 1707854995,
), ),
) )
id = cursor.lastrowid
connection.commit() connection.commit()
latest_comment_id = get_newest_comment() yield id
yield
print('\nDeleting comment') print('\nDeleting comment')
comment_id = get_newest_comment()
connection = sqlite3.connect(DB_COMMENTS_ROOT) connection = sqlite3.connect(DB_COMMENTS_ROOT)
cursor = connection.cursor() 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() 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) browser = playwright.chromium.launch(headless=USE_HEADLESS)
context = browser.new_context() context = browser.new_context()
page = context.new_page() page = context.new_page()
...@@ -43,16 +69,19 @@ def test_delete_comment(playwright: Playwright) -> None: ...@@ -43,16 +69,19 @@ def test_delete_comment(playwright: Playwright) -> None:
page = login_test_user(page) page = login_test_user(page)
page.wait_for_url(URL + '/') page.wait_for_url(URL + '/')
page.goto(URL + '/post/' + str(post_id)) page.goto(URL + '/post/' + str(post_id))
while page.locator("[name=commentDeleteButton]").count() > 0: while page.locator("[name=commentDeleteButton]").count() > 0:
page.locator("[name=commentDeleteButton]").first.click() 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() context.close()
browser.close() browser.close()
def get_newest_comment(): def get_newest_comment():
connection = sqlite3.connect(DB_COMMENTS_ROOT) connection = sqlite3.connect(DB_COMMENTS_ROOT)
cursor = connection.cursor() cursor = connection.cursor()
...@@ -69,3 +98,16 @@ def get_newest_comment(): ...@@ -69,3 +98,16 @@ def get_newest_comment():
connection.close() connection.close()
return comment_id 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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment