1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-19 12:36:23 -07:00
gochan/tools/selenium_testing/tests/test_posting.py

132 lines
5.3 KiB
Python
Raw Normal View History

from os import path
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
2023-05-19 12:52:01 -07:00
from . import SeleniumTestCase
from ..util.posting import make_post, delete_post, send_post, threadRE
from ..util import qr
2024-12-14 16:43:18 -08:00
2023-05-19 12:52:01 -07:00
class TestPosting(SeleniumTestCase):
2024-12-10 17:03:37 -08:00
@classmethod
def setUpClass(cls):
super().setUpClass()
def checkBoards(self, board1:bool, board2:bool = False):
if board1:
self.assertTrue(self.options.board_exists(self.options.board1), f"Confirming that /{self.options.board1}/ exists")
if board2:
self.assertTrue(self.options.board_exists(self.options.board2), f"Confirming that /{self.options.board2}/ exists")
def test_qr(self):
2024-12-14 16:43:18 -08:00
board_info = self.options.board_info(self.options.board1)
2024-12-10 17:03:37 -08:00
self.options.goto_page(self.options.board1)
elem = self.driver.find_element(by=By.ID, value="board-subtitle")
2024-12-14 16:43:18 -08:00
self.assertIn(board_info['meta_description'], elem.text, "Verify that we're on the correct board")
qr.openQR(self.driver)
2024-12-14 16:43:18 -08:00
self.assertTrue(qr.qrIsVisible(self.driver), "Confirm that the QR box was properly opened")
qr.closeQR(self.driver)
2024-12-14 16:43:18 -08:00
self.assertFalse(qr.qrIsVisible(self.driver), "Confirm that the QR box was properly closed")
def test_makeThread(self):
self.checkBoards(True)
2024-12-10 17:03:37 -08:00
make_post(self.options, self.options.board1, self)
threadID = threadRE.findall(self.driver.current_url)[0][1]
cur_url = self.driver.current_url
2023-05-19 12:52:01 -07:00
delete_post(self.options, int(threadID), "")
WebDriverWait(self.driver, 10).until(
EC.url_changes(cur_url))
self.assertNotIn("Error :c", self.driver.title, "No errors when we try to delete the post we just made")
2024-12-14 16:43:18 -08:00
def test_moveThread(self):
self.checkBoards(True, True)
2024-12-10 17:03:37 -08:00
self.options.goto_page(self.options.board1)
WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "form#postform input[type=submit]")))
form = self.driver.find_element(by=By.CSS_SELECTOR, value="form#postform")
send_post(form,
2023-05-19 12:52:01 -07:00
self.options.name,
self.options.email,
self.options.subject,
self.options.message % self.driver.name,
2023-05-19 12:52:01 -07:00
path.abspath(self.options.upload_path),
self.options.post_password)
2024-12-14 16:43:18 -08:00
WebDriverWait(self.driver, 10).until(EC.url_matches(threadRE))
cur_url = self.driver.current_url
threadID = threadRE.findall(cur_url)[0][1]
2025-02-18 19:50:41 -08:00
self.driver.find_element(by=By.CSS_SELECTOR, value=f"input#check{threadID}").click()
cur_url = self.driver.current_url
2024-12-14 16:43:18 -08:00
self.driver.find_element(by=By.CSS_SELECTOR, value="input[name=move_btn]").click()
# wait for response to move_btn
2025-02-18 19:50:41 -08:00
WebDriverWait(self.driver, 10).until(EC.title_contains(f"Move thread #{threadID}"))
2024-12-14 16:43:18 -08:00
self.driver.find_element(by=By.CSS_SELECTOR, value="input[type=submit]").click()
# wait for response to move request (domove=1)
WebDriverWait(self.driver, 10).until(
EC.url_matches(threadRE))
2024-12-14 16:43:18 -08:00
expected_title = self.options.board_info(self.options.board2)['title']
self.assertEqual(
2024-12-14 16:43:18 -08:00
self.driver.find_element(by=By.CSS_SELECTOR, value="h1#board-title").text,
f"/{self.options.board2}/ - {expected_title}",
"Verify that we properly moved the thread to /test2/"
)
form = self.driver.find_element(by=By.CSS_SELECTOR, value="form#postform")
send_post(form,
2023-05-19 12:52:01 -07:00
self.options.name,
self.options.email,
"",
"Reply to thread after it was moved",
2023-05-19 12:52:01 -07:00
path.abspath(self.options.upload_path),
self.options.post_password)
2023-05-19 12:52:01 -07:00
delete_post(self.options, int(threadID), "")
2024-12-14 16:43:18 -08:00
WebDriverWait(self.driver, 10).until(EC.url_changes(cur_url))
self.assertNotIn("Error :c", self.driver.title, "No errors when we try to delete the moved thread")
def test_cyclic(self):
self.assertTrue(self.options.board_exists(self.options.cyclic_board), f"Confirming that /{self.options.cyclic_board}/ exists")
2025-01-19 11:41:11 -08:00
self.options.goto_page(self.options.cyclic_board)
2025-01-19 11:41:11 -08:00
WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "form#postform input[type=submit]")))
form = self.driver.find_element(by=By.CSS_SELECTOR, value="form#postform")
2025-01-19 12:12:31 -08:00
form.find_element(by=By.NAME, value="cyclic").click()
2025-01-19 11:41:11 -08:00
send_post(form,
self.options.name,
"noko",
"Cyclic thread test",
"Cyclic thread OP",
2025-01-19 11:41:11 -08:00
path.abspath(self.options.upload_path),
self.options.post_password)
WebDriverWait(self.driver, 10).until(EC.url_matches(threadRE))
for r in range(self.options.cyclic_count + 2):
2025-01-19 11:41:11 -08:00
form = self.driver.find_element(by=By.CSS_SELECTOR, value="form#postform")
send_post(form,
self.options.name,
"noko",
"",
f"Reply {r+1}",
path.abspath(self.options.upload_path),
self.options.post_password)
WebDriverWait(self.driver, 10).until(EC.url_matches(threadRE))
# go to the thread and make sure that the first two replies are pruned
cur_url = self.driver.current_url
threadID = threadRE.findall(cur_url)[0][1]
replies = self.driver.find_elements(by=By.CSS_SELECTOR, value="div.reply")
self.assertEqual(len(replies), self.options.cyclic_count, f"Verify that the cyclic thread has the correct number of replies (CyclicThreadNumPosts in /{self.options.cyclic_board}/board.json must be set to {self.options.cyclic_count})")
2025-01-19 12:12:31 -08:00
self.assertEqual(replies[0].find_element(by=By.CSS_SELECTOR, value="div.post-text").text, "Reply 3", "Verify that the first reply is the third post")
2025-01-19 11:41:11 -08:00
delete_post(self.options, int(threadID), self.options.post_password)