From 3387923bffb3432a77fd48e3fa9acbb79cf79946 Mon Sep 17 00:00:00 2001
From: Dimas FM <dimasfaid@gmail.com>
Date: Fri, 3 May 2024 22:29:32 +0700
Subject: [PATCH] refactor test cases into one files

---
 db/comments.db                       | Bin 24576 -> 24576 bytes
 db/posts.db                          | Bin 15060992 -> 15060992 bytes
 db/users.db                          | Bin 53248 -> 53248 bytes
 templates/tailwindUI/post.html.jinja |   2 +-
 tests/conftest.py                    |   2 +-
 tests/functions/delete_comment.py    |   8 ++---
 tests/test_comment.py                |  34 ++++++++++++++++++++
 tests/test_create_comment.py         |  46 ---------------------------
 tests/test_create_post.py            |  23 --------------
 tests/test_delete_comment.py         |  37 ---------------------
 tests/test_delete_post.py            |  33 -------------------
 tests/test_edit_post.py              |  23 --------------
 tests/test_post.py                   |  43 +++++++++++++++++++++++++
 tests/utils/__init__.py              |   2 ++
 tests/utils/delete_comment.py        |   9 ++++++
 tests/utils/delete_post.py           |   2 +-
 tests/utils/is_post_exist.py         |  16 ++++++++++
 17 files changed, 111 insertions(+), 169 deletions(-)
 create mode 100644 tests/test_comment.py
 delete mode 100644 tests/test_create_comment.py
 delete mode 100644 tests/test_create_post.py
 delete mode 100644 tests/test_delete_comment.py
 delete mode 100644 tests/test_delete_post.py
 delete mode 100644 tests/test_edit_post.py
 create mode 100644 tests/test_post.py
 create mode 100644 tests/utils/delete_comment.py
 create mode 100644 tests/utils/is_post_exist.py

diff --git a/db/comments.db b/db/comments.db
index 3b4680d0878fb201e5136b1f329efd2f2301f6d8..986328e8d39c5d6c219826486584b02fe6c8e2a1 100644
GIT binary patch
delta 110
zcmZoTz}Rqrae_4Cp@}lijE6QR%-3fO-ekZcAj8e_jDhbg?>e4nuKS$j96D^fSvRrf
zv1+kAV_CFW!J&zT$th%VfvY{MDU+R35QN3p;S>mFnQVXT6aZo|n`~dQ*)fWfar16B
GS4jYvIwLdy

delta 94
zcmZoTz}Rqrae_4C%84@0j4L-L%-3i1-DJQbAj84BiGlAd?>e4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ozz}&Ead4e?K%ZW11j4wAP*dAhHuG&2RP$Dk?lnV;S

delta 27
jcmZozz}&Ead4e?Ku8A_vjJq}_*dAhH%Gf;rP$Dk?jpqth

diff --git a/templates/tailwindUI/post.html.jinja b/templates/tailwindUI/post.html.jinja
index 5cd33eb..e49e907 100644
--- a/templates/tailwindUI/post.html.jinja
+++ b/templates/tailwindUI/post.html.jinja
@@ -79,7 +79,7 @@
   <!-- Comments Section -->
   <div>
     {% for comment in comments %}
-    <div class="flex flex-col mx-auto mt-8 mb-4 p-2 max-w-lg">
+    <div data-testid="comment-{{ comment[0] }}" class="flex flex-col mx-auto mt-8 mb-4 p-2 max-w-lg">
       <div class="flex w-full justify-between">
         <div class="mx-2">
           <a href="/user/{{ comment[3] }}" class="flex items-center hover:text-rose-500 duration-150 select-none">
diff --git a/tests/conftest.py b/tests/conftest.py
index e711c66..6e80a3d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -6,7 +6,7 @@ from playwright.sync_api import sync_playwright, Browser
 @pytest.fixture(scope="session")
 def browser():
     with sync_playwright() as p:
-        browser = p.chromium.launch(headless=USE_HEADLESS)
+        browser = p.chromium.launch(headless=False)
         yield browser
         print('\nClosing Browser')
         browser.close()
diff --git a/tests/functions/delete_comment.py b/tests/functions/delete_comment.py
index 0e2b59a..2eb71a2 100644
--- a/tests/functions/delete_comment.py
+++ b/tests/functions/delete_comment.py
@@ -1,9 +1,9 @@
 from playwright.sync_api import Page
 from tests.utils import URL
 
-def delete_comment(page: Page, post_id: int) -> Page:
+def delete_comment(page: Page, post_id: int, comment_id: int) -> Page:
   page.goto(URL + '/post/' + str(post_id))
-  while page.locator("[name=commentDeleteButton]").count() > 0:
-    page.locator("[name=commentDeleteButton]").first.click()
-
+  comment_section = page.get_by_test_id(f"comment-{str(comment_id)}")
+  comment_section.locator("[name=commentDeleteButton]").click()
+  
   return page
\ No newline at end of file
diff --git a/tests/test_comment.py b/tests/test_comment.py
new file mode 100644
index 0000000..9c2f2da
--- /dev/null
+++ b/tests/test_comment.py
@@ -0,0 +1,34 @@
+# Import the playwright module and the constants file
+from playwright.sync_api import expect, Page
+import pytest
+from tests.utils import URL, UserTest, delete_comment_utils, is_comment_exist
+from tests.functions import login, create_comment, new_comment, delete_comment
+
+@pytest.fixture(autouse=True)
+def user ():
+  user = UserTest("User_A")
+  yield user
+
+# Define a function that takes a playwright object as an argument
+def test_create_comment(page: Page, user: UserTest) -> None:
+  page.goto(URL)
+
+  page = login(page, user)    
+
+  page, comment_id = create_comment(page, 1)
+
+  expect(page.get_by_test_id(f"comment-{str(comment_id)}")).to_be_visible()
+
+  delete_comment_utils(comment_id)
+
+def test_delete_comment(page: Page, user: UserTest) -> None:
+  post_id = 1
+  
+  page.goto(URL)
+  
+  page = login(page, user)
+  page, comment_id = create_comment(page, post_id)
+
+  page = delete_comment(page, post_id, comment_id)
+      
+  assert is_comment_exist(comment_id) == False
\ No newline at end of file
diff --git a/tests/test_create_comment.py b/tests/test_create_comment.py
deleted file mode 100644
index 54d6b51..0000000
--- a/tests/test_create_comment.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# Import the playwright module and the constants file
-from playwright.sync_api import Playwright, expect, Page
-import pytest, sqlite3
-from tests.utils import USE_HEADLESS, URL, DB_COMMENTS_ROOT, UserTest
-from tests.functions import login, create_comment, new_comment
-
-@pytest.fixture(autouse=True)
-def user ():
-  user = UserTest("User_A")
-  yield user
-
-@pytest.fixture(autouse=True)
-def delete_comment():
-  yield
-  print('\nDeleting created comment')
-  connection = sqlite3.connect(DB_COMMENTS_ROOT)
-  cursor = connection.cursor()
-  comment_id = get_newest_comment()
-  cursor.execute('DELETE FROM comments where id = ?', [(comment_id)])
-  connection.commit()
-
-# Define a function that takes a playwright object as an argument
-def test_create_comment(page: Page, user: UserTest) -> None:
-    page.goto(URL)
-
-    page = login(page, user)    
-
-    page, comment_id = create_comment(page, 1)
-
-    expect(page.get_by_text(new_comment)).to_be_visible()
-
-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
\ No newline at end of file
diff --git a/tests/test_create_post.py b/tests/test_create_post.py
deleted file mode 100644
index 808535c..0000000
--- a/tests/test_create_post.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from playwright.sync_api import Playwright, expect, Page
-import pytest
-from tests.utils import USE_HEADLESS, URL, UserTest, delete_post
-from tests.functions import login, create_post
-
-@pytest.fixture(autouse=True)
-def user ():
-  user = UserTest("User_A")
-  yield user
-
-# Define a function that takes a playwright object as an argument
-def test_create_post(page: Page, user: UserTest) -> None:
-    page.goto(URL)
-
-    page = login(page, user)
-
-    page, post_id = create_post(page)
-
-    response = page.request.get(URL + '/post/' + str(post_id))
-    expect(response).to_be_ok()
-
-    delete_post(post_id)
-
diff --git a/tests/test_delete_comment.py b/tests/test_delete_comment.py
deleted file mode 100644
index b97d901..0000000
--- a/tests/test_delete_comment.py
+++ /dev/null
@@ -1,37 +0,0 @@
-from playwright.sync_api import Playwright, expect, Page
-
-from tests.utils import URL, DB_COMMENTS_ROOT, USE_HEADLESS, UserTest
-from tests.functions import login, create_comment, delete_comment
-import pytest, sqlite3
-
-post_id = 1
-
-@pytest.fixture(autouse=True)
-def user():
-   user = UserTest("User_A")
-   yield user
-
-def test_delete_comment(page: Page, user) -> None:
-    page.goto(URL)
-    
-    page = login(page, user)
-    page, comment_id = create_comment(page, post_id)
-
-
-    page = delete_comment(page, post_id)
-       
-    assert is_comment_exist(comment_id) == False
-
-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
diff --git a/tests/test_delete_post.py b/tests/test_delete_post.py
deleted file mode 100644
index b0bd239..0000000
--- a/tests/test_delete_post.py
+++ /dev/null
@@ -1,33 +0,0 @@
-from playwright.sync_api import Playwright, expect, Page
-import pytest, sqlite3
-from tests.utils import USE_HEADLESS, URL, DB_POSTS_ROOT, UserTest, delete_post
-from tests.functions import login, create_post, delete_post
-
-@pytest.fixture(autouse=True)
-def user ():
-  user = UserTest("User_A")
-  yield user
-
-
-def test_delete_post(page: Page, user) -> None:
-    page.goto(URL)
-    
-    page = login(page, user)
-    page, post_id = create_post(page)
-    page = delete_post(page, post_id)
-
-    assert is_post_exist(post_id) == False
-
-def is_post_exist(id):
-    connection = sqlite3.connect(DB_POSTS_ROOT)
-    cursor = connection.cursor()
-    query = '''
-      SELECT * FROM posts where id = ?
-      '''
-    exist = False
-
-    for row in cursor.execute(query,[(id)]):
-      exist = True
-
-    connection.close()
-    return exist
\ No newline at end of file
diff --git a/tests/test_edit_post.py b/tests/test_edit_post.py
deleted file mode 100644
index 822c464..0000000
--- a/tests/test_edit_post.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from playwright.sync_api import Playwright, expect, Page
-
-import pytest
-from tests.utils import USE_HEADLESS, URL, DB_POSTS_ROOT, UserTest, delete_post
-from tests.functions import login, create_post, edit_post, new_title
-
-@pytest.fixture(autouse=True)
-def user ():
-  user = UserTest("User_A")
-  yield user
-
-def test_edit_post(page: Page, user) -> None:
-    page.goto(URL)
-    
-    page = login(page, user)
-    page, post_id = create_post(page)
-
-    page = edit_post(page, post_id)
-
-    expect(page).to_have_url(URL + '/post/' + str(post_id))
-    expect(page).to_have_title(new_title)
-
-    delete_post(post_id)
\ No newline at end of file
diff --git a/tests/test_post.py b/tests/test_post.py
new file mode 100644
index 0000000..44821f3
--- /dev/null
+++ b/tests/test_post.py
@@ -0,0 +1,43 @@
+from playwright.sync_api import Page, expect
+import pytest
+from tests.utils import URL, UserTest, delete_post_utils, is_post_exist
+from tests.functions import login, create_post, delete_post, edit_post, new_title
+
+@pytest.fixture(autouse=True)
+def user ():
+  user = UserTest("User_A")
+  yield user
+
+def test_create_post(page: Page, user: UserTest) -> None:
+    page.goto(URL)
+
+    page = login(page, user)
+
+    page, post_id = create_post(page)
+
+    response = page.request.get(URL + '/post/' + str(post_id))
+    expect(response).to_be_ok()
+
+    delete_post_utils(post_id)
+
+def test_delete_post(page: Page, user) -> None:
+    page.goto(URL)
+    
+    page = login(page, user)
+    page, post_id = create_post(page)
+    page = delete_post(page, post_id)
+
+    assert is_post_exist(post_id) == False
+
+def test_edit_post(page: Page, user) -> None:
+    page.goto(URL)
+    
+    page = login(page, user)
+    page, post_id = create_post(page)
+
+    page = edit_post(page, post_id)
+
+    expect(page).to_have_url(URL + '/post/' + str(post_id))
+    expect(page).to_have_title(new_title)
+
+    delete_post_utils(post_id)
\ No newline at end of file
diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py
index 2403e91..f616f16 100644
--- a/tests/utils/__init__.py
+++ b/tests/utils/__init__.py
@@ -4,4 +4,6 @@ from .get_newest_comment import *
 from .get_newest_post import *
 from .is_comment_exist import *
 from .is_user_exist import *
+from .is_post_exist import *
+from .delete_comment import *
 from .user import *
\ No newline at end of file
diff --git a/tests/utils/delete_comment.py b/tests/utils/delete_comment.py
new file mode 100644
index 0000000..3f8db2e
--- /dev/null
+++ b/tests/utils/delete_comment.py
@@ -0,0 +1,9 @@
+import sqlite3
+from tests.utils import DB_COMMENTS_ROOT, get_newest_comment
+
+def delete_comment_utils(comment_id):
+  print('\nDeleting created comment')
+  connection = sqlite3.connect(DB_COMMENTS_ROOT)
+  cursor = connection.cursor()
+  cursor.execute('DELETE FROM comments where id = ?', [(comment_id)])
+  connection.commit()
\ No newline at end of file
diff --git a/tests/utils/delete_post.py b/tests/utils/delete_post.py
index a0ebf8a..b915c11 100644
--- a/tests/utils/delete_post.py
+++ b/tests/utils/delete_post.py
@@ -1,7 +1,7 @@
 import sqlite3
 from tests.utils import DB_POSTS_ROOT
 
-def delete_post (post_id: int):
+def delete_post_utils (post_id: int):
     print('\nDeleting newest post')
     connection = sqlite3.connect(DB_POSTS_ROOT)
     cursor = connection.cursor()
diff --git a/tests/utils/is_post_exist.py b/tests/utils/is_post_exist.py
new file mode 100644
index 0000000..bd358c0
--- /dev/null
+++ b/tests/utils/is_post_exist.py
@@ -0,0 +1,16 @@
+import sqlite3
+from tests.utils import DB_POSTS_ROOT
+
+def is_post_exist(id):
+    connection = sqlite3.connect(DB_POSTS_ROOT)
+    cursor = connection.cursor()
+    query = '''
+      SELECT * FROM posts where id = ?
+      '''
+    exist = False
+
+    for row in cursor.execute(query,[(id)]):
+      exist = True
+
+    connection.close()
+    return exist
\ No newline at end of file
-- 
GitLab