2023-05-18 14:25:30 -07:00
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
2023-05-18 14:25:30 -07:00
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-18 14:25:30 -07: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 ( )
2024-12-14 15:37:43 -08:00
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 " )
2023-05-18 14:25:30 -07:00
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 )
2023-05-19 12:55:51 -07:00
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 " )
2023-05-19 12:55:51 -07:00
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 " )
2023-05-19 12:55:51 -07:00
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 " )
2023-05-18 14:25:30 -07:00
def test_makeThread ( self ) :
2024-12-14 15:37:43 -08:00
self . checkBoards ( True )
2024-12-10 17:03:37 -08:00
make_post ( self . options , self . options . board1 , self )
2023-05-19 12:55:51 -07:00
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 ) , " " )
2023-05-19 12:55:51 -07:00
WebDriverWait ( self . driver , 10 ) . until (
2023-05-18 14:25:30 -07:00
EC . url_changes ( cur_url ) )
2023-05-19 12:55:51 -07:00
self . assertNotIn ( " Error :c " , self . driver . title , " No errors when we try to delete the post we just made " )
2023-05-18 14:25:30 -07:00
2024-12-14 16:43:18 -08:00
2023-05-18 14:25:30 -07:00
def test_moveThread ( self ) :
2024-12-14 15:37:43 -08:00
self . checkBoards ( True , True )
2023-05-18 14:25:30 -07:00
2024-12-10 17:03:37 -08:00
self . options . goto_page ( self . options . board1 )
2023-05-19 12:55:51 -07:00
WebDriverWait ( self . driver , 10 ) . until (
2023-05-18 14:25:30 -07:00
EC . element_to_be_clickable ( ( By . CSS_SELECTOR , " form#postform input[type=submit] " ) ) )
2023-05-19 12:55:51 -07:00
form = self . driver . find_element ( by = By . CSS_SELECTOR , value = " form#postform " )
2023-05-18 14:25:30 -07:00
send_post ( form ,
2023-05-19 12:52:01 -07:00
self . options . name ,
self . options . email ,
self . options . subject ,
2023-05-19 12:55:51 -07:00
self . options . message % self . driver . name ,
2023-05-19 12:52:01 -07:00
path . abspath ( self . options . upload_path ) ,
2024-12-12 17:56:39 -08:00
self . options . post_password )
2024-12-14 16:43:18 -08:00
WebDriverWait ( self . driver , 10 ) . until ( EC . url_matches ( threadRE ) )
2023-05-18 14:25:30 -07:00
2023-05-19 12:55:51 -07:00
cur_url = self . driver . current_url
2023-05-18 14:25:30 -07:00
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 ( )
2023-05-19 12:55:51 -07:00
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 ( )
2023-05-18 14:25:30 -07:00
# 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 } " ) )
2023-05-18 14:25:30 -07:00
2024-12-14 16:43:18 -08:00
self . driver . find_element ( by = By . CSS_SELECTOR , value = " input[type=submit] " ) . click ( )
2023-05-18 14:25:30 -07:00
# wait for response to move request (domove=1)
2023-05-19 12:55:51 -07:00
WebDriverWait ( self . driver , 10 ) . until (
2023-05-18 14:25:30 -07:00
EC . url_matches ( threadRE ) )
2024-12-14 16:43:18 -08:00
expected_title = self . options . board_info ( self . options . board2 ) [ ' title ' ]
2023-05-18 14:25:30 -07:00
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/ "
)
2023-05-18 14:25:30 -07:00
2023-05-19 12:55:51 -07:00
form = self . driver . find_element ( by = By . CSS_SELECTOR , value = " form#postform " )
2023-05-18 14:25:30 -07:00
send_post ( form ,
2023-05-19 12:52:01 -07:00
self . options . name ,
self . options . email ,
2023-05-18 14:25:30 -07:00
" " ,
" Reply to thread after it was moved " ,
2023-05-19 12:52:01 -07:00
path . abspath ( self . options . upload_path ) ,
2024-12-12 17:56:39 -08:00
self . options . post_password )
2023-05-18 14:25:30 -07:00
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 " )
2023-05-18 14:25:30 -07:00
2025-01-19 11:58:18 -08:00
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
2025-01-19 11:58:18 -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 " ,
2025-01-19 11:58:18 -08:00
" 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 ) )
2025-01-19 11:58:18 -08:00
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 " )
2025-01-19 12:18:05 -08:00
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 )