2019-11-08 02:57:12 -05:00
import unittest
import os
import requests
import shutil
import tempfile
import secrets
2020-08-21 01:53:43 -04:00
import platform
2022-03-06 17:26:51 -05:00
import sys
2019-11-08 02:57:12 -05:00
2022-10-23 08:09:56 -04:00
from PySide6 import QtCore , QtTest , QtWidgets
2019-11-08 02:57:12 -05:00
2020-10-13 20:28:54 -04:00
from onionshare_cli . common import Common
from onionshare import Application , MainWindow , GuiCommon
from onionshare . tab . mode . share_mode import ShareMode
from onionshare . tab . mode . receive_mode import ReceiveMode
from onionshare . tab . mode . website_mode import WebsiteMode
2021-05-10 01:05:16 -04:00
from onionshare . tab . mode . chat_mode import ChatMode
2019-11-08 02:57:12 -05:00
from onionshare import strings
class GuiBaseTest ( unittest . TestCase ) :
@classmethod
def setUpClass ( cls ) :
2022-03-06 17:26:51 -05:00
common = sys . onionshare_common
qtapp = sys . onionshare_qtapp
2019-11-10 13:10:22 -05:00
# Delete any old test data that might exist
shutil . rmtree ( common . build_data_dir ( ) , ignore_errors = True )
2019-11-08 02:57:12 -05:00
common . gui = GuiCommon ( common , qtapp , local_only = True )
cls . gui = MainWindow ( common , filenames = None )
cls . gui . qtapp = qtapp
# Create some random files to test with
cls . tmpdir = tempfile . TemporaryDirectory ( )
cls . tmpfiles = [ ]
for _ in range ( 10 ) :
filename = os . path . join ( cls . tmpdir . name , f " { secrets . token_hex ( 4 ) } .txt " )
with open ( filename , " w " ) as file :
file . write ( secrets . token_hex ( 10 ) )
cls . tmpfiles . append ( filename )
2019-11-08 12:38:35 -05:00
# A file called "test.txt"
2019-11-08 06:11:30 -05:00
cls . tmpfile_test = os . path . join ( cls . tmpdir . name , " test.txt " )
with open ( cls . tmpfile_test , " w " ) as file :
file . write ( " onionshare " )
2019-11-08 02:57:12 -05:00
2019-11-10 14:33:59 -05:00
# A file called "test2.txt"
cls . tmpfile_test2 = os . path . join ( cls . tmpdir . name , " test2.txt " )
with open ( cls . tmpfile_test2 , " w " ) as file :
file . write ( " onionshare2 " )
2019-11-10 16:51:08 -05:00
# A file called "index.html"
cls . tmpfile_index_html = os . path . join ( cls . tmpdir . name , " index.html " )
with open ( cls . tmpfile_index_html , " w " ) as file :
file . write (
" <html><body><p>This is a test website hosted by OnionShare</p></body></html> "
)
2023-05-30 02:23:31 -04:00
# A file called "test.html"
cls . tmpfile_test_html = os . path . join ( cls . tmpdir . name , " test.html " )
with open ( cls . tmpfile_test_html , " w " ) as file :
file . write (
" <html><body><p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p></body></html> "
)
2019-11-08 12:38:35 -05:00
# A large file
size = 1024 * 1024 * 155
cls . tmpfile_large = os . path . join ( cls . tmpdir . name , " large_file " )
with open ( cls . tmpfile_large , " wb " ) as fout :
fout . write ( os . urandom ( size ) )
2019-11-08 02:57:12 -05:00
@classmethod
def tearDownClass ( cls ) :
2019-11-08 08:36:54 -05:00
# Quit
2020-04-01 18:49:50 -04:00
cls . gui . qtapp . clipboard ( ) . clear ( )
2019-11-10 13:40:23 -05:00
QtCore . QTimer . singleShot ( 200 , cls . gui . close_dialog . accept_button . click )
2019-11-08 03:20:38 -05:00
cls . gui . close ( )
2019-11-08 08:36:54 -05:00
2019-11-08 02:57:12 -05:00
cls . gui . cleanup ( )
# Shared test methods
2019-11-08 06:11:30 -05:00
def verify_new_tab ( self , tab ) :
# Make sure the new tab widget is showing, and no mode has been started
2020-10-14 23:17:08 -04:00
QtTest . QTest . qWait ( 1000 , self . gui . qtapp )
2019-11-08 06:11:30 -05:00
self . assertTrue ( tab . new_tab . isVisible ( ) )
self . assertFalse ( hasattr ( tab , " share_mode " ) )
self . assertFalse ( hasattr ( tab , " receive_mode " ) )
self . assertFalse ( hasattr ( tab , " website_mode " ) )
2020-08-27 17:59:00 -04:00
self . assertFalse ( hasattr ( tab , " chat_mode " ) )
2019-11-08 06:11:30 -05:00
def new_share_tab ( self ) :
tab = self . gui . tabs . widget ( 0 )
self . verify_new_tab ( tab )
# Share files
tab . share_button . click ( )
self . assertFalse ( tab . new_tab . isVisible ( ) )
self . assertTrue ( tab . share_mode . isVisible ( ) )
return tab
def new_share_tab_with_files ( self ) :
tab = self . new_share_tab ( )
# Add files
for filename in self . tmpfiles :
tab . share_mode . server_status . file_selection . file_list . add_file ( filename )
return tab
def new_receive_tab ( self ) :
tab = self . gui . tabs . widget ( 0 )
self . verify_new_tab ( tab )
# Receive files
tab . receive_button . click ( )
self . assertFalse ( tab . new_tab . isVisible ( ) )
self . assertTrue ( tab . receive_mode . isVisible ( ) )
return tab
def new_website_tab ( self ) :
tab = self . gui . tabs . widget ( 0 )
self . verify_new_tab ( tab )
# Publish website
tab . website_button . click ( )
self . assertFalse ( tab . new_tab . isVisible ( ) )
self . assertTrue ( tab . website_mode . isVisible ( ) )
return tab
def new_website_tab_with_files ( self ) :
tab = self . new_website_tab ( )
# Add files
for filename in self . tmpfiles :
tab . website_mode . server_status . file_selection . file_list . add_file ( filename )
return tab
2021-05-10 01:05:16 -04:00
def new_chat_tab ( self ) :
tab = self . gui . tabs . widget ( 0 )
self . verify_new_tab ( tab )
# Chat
tab . chat_button . click ( )
self . assertFalse ( tab . new_tab . isVisible ( ) )
self . assertTrue ( tab . chat_mode . isVisible ( ) )
return tab
2019-11-08 07:06:24 -05:00
def close_all_tabs ( self ) :
for _ in range ( self . gui . tabs . count ( ) ) :
2019-11-08 11:42:49 -05:00
tab = self . gui . tabs . widget ( 0 )
2019-11-10 13:40:23 -05:00
QtCore . QTimer . singleShot ( 200 , tab . close_dialog . accept_button . click )
2019-11-08 07:06:24 -05:00
self . gui . tabs . tabBar ( ) . tabButton ( 0 , QtWidgets . QTabBar . RightSide ) . click ( )
2019-11-08 02:57:12 -05:00
def gui_loaded ( self ) :
""" Test that the GUI actually is shown """
self . assertTrue ( self . gui . show )
def window_title_seen ( self ) :
""" Test that the window title is OnionShare """
self . assertEqual ( self . gui . windowTitle ( ) , " OnionShare " )
def server_status_bar_is_visible ( self ) :
""" Test that the status bar is visible """
self . assertTrue ( self . gui . status_bar . isVisible ( ) )
2019-11-08 06:11:30 -05:00
def mode_settings_widget_is_visible ( self , tab ) :
""" Test that the mode settings are visible """
self . assertTrue ( tab . get_mode ( ) . mode_settings_widget . isVisible ( ) )
def mode_settings_widget_is_hidden ( self , tab ) :
""" Test that the mode settings are hidden when the server starts """
self . assertFalse ( tab . get_mode ( ) . mode_settings_widget . isVisible ( ) )
def click_toggle_history ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that we can toggle Download or Upload history by clicking the toggle button """
2019-11-08 06:11:30 -05:00
currently_visible = tab . get_mode ( ) . history . isVisible ( )
2019-11-08 07:44:52 -05:00
tab . get_mode ( ) . toggle_history . click ( )
2019-11-08 06:11:30 -05:00
self . assertEqual ( tab . get_mode ( ) . history . isVisible ( ) , not currently_visible )
2019-11-08 02:57:12 -05:00
2021-12-17 01:59:34 -05:00
def javascript_is_correct_mime_type ( self , tab , file ) :
""" Test that the javascript file send.js is fetchable and that its MIME type is correct """
path = f " { tab . get_mode ( ) . web . static_url_path } /js/ { file } "
url = f " http://127.0.0.1: { tab . app . port } / { path } "
r = requests . get ( url )
self . assertTrue ( r . headers [ " Content-Type " ] . startswith ( " text/javascript; " ) )
2019-11-08 06:11:30 -05:00
def history_indicator ( self , tab , indicator_count = " 1 " ) :
2021-08-22 16:17:55 -04:00
""" Test that we can make sure the history is toggled off, do an action, and the indicator works """
2019-11-08 02:57:12 -05:00
# Make sure history is toggled off
2019-11-08 06:11:30 -05:00
if tab . get_mode ( ) . history . isVisible ( ) :
2019-11-08 07:44:52 -05:00
tab . get_mode ( ) . toggle_history . click ( )
2019-11-08 06:11:30 -05:00
self . assertFalse ( tab . get_mode ( ) . history . isVisible ( ) )
2019-11-08 02:57:12 -05:00
# Indicator should not be visible yet
2019-11-08 06:11:30 -05:00
self . assertFalse ( tab . get_mode ( ) . toggle_history . indicator_label . isVisible ( ) )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
if type ( tab . get_mode ( ) ) == ReceiveMode :
2019-11-08 02:57:12 -05:00
# Upload a file
2019-11-08 06:11:30 -05:00
files = { " file[] " : open ( self . tmpfiles [ 0 ] , " rb " ) }
url = f " http://127.0.0.1: { tab . app . port } /upload "
2021-08-27 01:52:29 -04:00
requests . post ( url , files = files )
2020-10-14 23:17:08 -04:00
QtTest . QTest . qWait ( 2000 , self . gui . qtapp )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
if type ( tab . get_mode ( ) ) == ShareMode :
2019-11-08 02:57:12 -05:00
# Download files
2019-11-08 06:11:30 -05:00
url = f " http://127.0.0.1: { tab . app . port } /download "
2021-08-27 01:52:29 -04:00
requests . get ( url )
2020-10-14 23:17:08 -04:00
QtTest . QTest . qWait ( 2000 , self . gui . qtapp )
2019-11-08 02:57:12 -05:00
# Indicator should be visible, have a value of "1"
2019-11-08 06:11:30 -05:00
self . assertTrue ( tab . get_mode ( ) . toggle_history . indicator_label . isVisible ( ) )
self . assertEqual (
tab . get_mode ( ) . toggle_history . indicator_label . text ( ) , indicator_count
)
2019-11-08 02:57:12 -05:00
# Toggle history back on, indicator should be hidden again
2019-11-08 07:44:52 -05:00
tab . get_mode ( ) . toggle_history . click ( )
2019-11-08 06:11:30 -05:00
self . assertFalse ( tab . get_mode ( ) . toggle_history . indicator_label . isVisible ( ) )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def history_is_not_visible ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the History section is not visible """
2019-11-08 06:11:30 -05:00
self . assertFalse ( tab . get_mode ( ) . history . isVisible ( ) )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def history_is_visible ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the History section is visible """
2019-11-08 06:11:30 -05:00
self . assertTrue ( tab . get_mode ( ) . history . isVisible ( ) )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def server_working_on_start_button_pressed ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test we can start the service """
# Should be in SERVER_WORKING state
2019-11-08 07:44:52 -05:00
tab . get_mode ( ) . server_status . server_button . click ( )
2019-11-08 06:11:30 -05:00
self . assertEqual ( tab . get_mode ( ) . server_status . status , 1 )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def toggle_indicator_is_reset ( self , tab ) :
self . assertEqual ( tab . get_mode ( ) . toggle_history . indicator_count , 0 )
self . assertFalse ( tab . get_mode ( ) . toggle_history . indicator_label . isVisible ( ) )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def server_status_indicator_says_starting ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the Server Status indicator shows we are Starting """
self . assertEqual (
2019-11-08 06:11:30 -05:00
tab . get_mode ( ) . server_status_label . text ( ) ,
2019-11-08 02:57:12 -05:00
strings . _ ( " gui_status_indicator_share_working " ) ,
)
2019-11-08 06:11:30 -05:00
def server_status_indicator_says_scheduled ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the Server Status indicator shows we are Scheduled """
self . assertEqual (
2019-11-08 06:11:30 -05:00
tab . get_mode ( ) . server_status_label . text ( ) ,
2019-11-08 02:57:12 -05:00
strings . _ ( " gui_status_indicator_share_scheduled " ) ,
)
2019-11-08 06:11:30 -05:00
def server_is_started ( self , tab , startup_time = 2000 ) :
2019-11-08 02:57:12 -05:00
""" Test that the server has started """
2020-10-14 23:17:08 -04:00
QtTest . QTest . qWait ( startup_time , self . gui . qtapp )
2019-11-08 02:57:12 -05:00
# Should now be in SERVER_STARTED state
2019-11-08 06:11:30 -05:00
self . assertEqual ( tab . get_mode ( ) . server_status . status , 2 )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def web_server_is_running ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the web server has started """
try :
2019-11-08 06:11:30 -05:00
requests . get ( f " http://127.0.0.1: { tab . app . port } / " )
2019-11-08 02:57:12 -05:00
self . assertTrue ( True )
except requests . exceptions . ConnectionError :
self . assertTrue ( False )
2019-11-08 06:11:30 -05:00
def add_button_visible ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the add button should be visible """
2020-08-21 01:53:43 -04:00
if platform . system ( ) == " Darwin " :
self . assertTrue (
tab . get_mode ( ) . server_status . file_selection . add_files_button . isVisible ( )
)
self . assertTrue (
tab . get_mode ( ) . server_status . file_selection . add_folder_button . isVisible ( )
)
else :
self . assertTrue (
tab . get_mode ( ) . server_status . file_selection . add_button . isVisible ( )
)
2019-11-08 02:57:12 -05:00
2021-08-31 00:17:23 -04:00
def url_shown ( self , tab ) :
""" Test that the URL is showing """
self . assertTrue ( tab . get_mode ( ) . server_status . url . isVisible ( ) )
2019-11-08 06:11:30 -05:00
def url_description_shown ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the URL label is showing """
2019-11-08 06:11:30 -05:00
self . assertTrue ( tab . get_mode ( ) . server_status . url_description . isVisible ( ) )
2019-11-08 02:57:12 -05:00
2021-08-31 00:17:23 -04:00
def url_instructions_shown ( self , tab ) :
""" Test that the URL instructions for sharing are showing """
self . assertTrue ( tab . get_mode ( ) . server_status . url_instructions . isVisible ( ) )
2021-09-03 17:24:45 -04:00
def private_key_shown ( self , tab ) :
""" Test that the Private Key is showing when not in public mode """
if not tab . settings . get ( " general " , " public " ) :
2021-09-08 22:45:05 -04:00
# Both the private key field and the toggle button should be seen
2021-09-03 17:24:45 -04:00
self . assertTrue ( tab . get_mode ( ) . server_status . private_key . isVisible ( ) )
2022-03-06 17:26:51 -05:00
self . assertTrue (
tab . get_mode ( ) . server_status . client_auth_toggle_button . isVisible ( )
)
self . assertEqual (
tab . get_mode ( ) . server_status . client_auth_toggle_button . text ( ) ,
strings . _ ( " gui_reveal " ) ,
)
2021-09-08 22:45:05 -04:00
# Test that the key is masked unless Reveal is clicked
2022-03-06 17:26:51 -05:00
self . assertEqual (
tab . get_mode ( ) . server_status . private_key . text ( ) ,
" * " * len ( tab . app . auth_string ) ,
)
2021-09-08 22:45:05 -04:00
# Click reveal
tab . get_mode ( ) . server_status . client_auth_toggle_button . click ( )
# The real private key should be revealed
2022-03-06 17:26:51 -05:00
self . assertEqual (
tab . get_mode ( ) . server_status . private_key . text ( ) , tab . app . auth_string
)
self . assertEqual (
tab . get_mode ( ) . server_status . client_auth_toggle_button . text ( ) ,
strings . _ ( " gui_hide " ) ,
)
2021-09-08 22:45:05 -04:00
# Click hide, key should be masked again
tab . get_mode ( ) . server_status . client_auth_toggle_button . click ( )
2022-03-06 17:26:51 -05:00
self . assertEqual (
tab . get_mode ( ) . server_status . private_key . text ( ) ,
" * " * len ( tab . app . auth_string ) ,
)
self . assertEqual (
tab . get_mode ( ) . server_status . client_auth_toggle_button . text ( ) ,
strings . _ ( " gui_reveal " ) ,
)
2021-09-03 17:24:45 -04:00
else :
self . assertFalse ( tab . get_mode ( ) . server_status . private_key . isVisible ( ) )
2021-08-31 00:17:23 -04:00
def client_auth_instructions_shown ( self , tab ) :
"""
Test that the Private Key instructions for sharing
are showing when not in public mode
"""
if not tab . settings . get ( " general " , " public " ) :
self . assertTrue (
tab . get_mode ( ) . server_status . client_auth_instructions . isVisible ( )
)
else :
self . assertFalse (
tab . get_mode ( ) . server_status . client_auth_instructions . isVisible ( )
)
2019-11-08 06:11:30 -05:00
def have_copy_url_button ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the Copy URL button is shown and that the clipboard is correct """
2019-11-08 06:11:30 -05:00
self . assertTrue ( tab . get_mode ( ) . server_status . copy_url_button . isVisible ( ) )
2019-11-08 02:57:12 -05:00
2019-11-08 07:44:52 -05:00
tab . get_mode ( ) . server_status . copy_url_button . click ( )
2019-11-08 06:11:30 -05:00
clipboard = tab . common . gui . qtapp . clipboard ( )
2021-08-27 01:52:29 -04:00
self . assertEqual ( clipboard . text ( ) , f " http://127.0.0.1: { tab . app . port } " )
2019-11-08 02:57:12 -05:00
2021-08-31 00:17:23 -04:00
def have_show_url_qr_code_button ( self , tab ) :
2020-05-31 03:44:57 -04:00
""" Test that the Show QR Code URL button is shown and that it loads a QR Code Dialog """
2020-08-21 01:53:43 -04:00
self . assertTrue (
tab . get_mode ( ) . server_status . show_url_qr_code_button . isVisible ( )
)
2020-05-31 03:44:57 -04:00
def accept_dialog ( ) :
window = tab . common . gui . qtapp . activeWindow ( )
if window :
window . close ( )
QtCore . QTimer . singleShot ( 500 , accept_dialog )
tab . get_mode ( ) . server_status . show_url_qr_code_button . click ( )
2021-08-31 00:17:23 -04:00
def have_show_client_auth_qr_code_button ( self , tab ) :
"""
Test that the Show QR Code Client Auth button is shown when
not in public mode and that it loads a QR Code Dialog .
"""
if not tab . settings . get ( " general " , " public " ) :
self . assertTrue (
tab . get_mode ( ) . server_status . show_client_auth_qr_code_button . isVisible ( )
)
def accept_dialog ( ) :
window = tab . common . gui . qtapp . activeWindow ( )
if window :
window . close ( )
QtCore . QTimer . singleShot ( 500 , accept_dialog )
tab . get_mode ( ) . server_status . show_client_auth_qr_code_button . click ( )
else :
self . assertFalse (
tab . get_mode ( ) . server_status . show_client_auth_qr_code_button . isVisible ( )
)
2019-11-08 06:11:30 -05:00
def server_status_indicator_says_started ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the Server Status indicator shows we are started """
2019-11-08 06:11:30 -05:00
if type ( tab . get_mode ( ) ) == ReceiveMode :
2019-11-08 02:57:12 -05:00
self . assertEqual (
2019-11-08 06:11:30 -05:00
tab . get_mode ( ) . server_status_label . text ( ) ,
2019-11-08 02:57:12 -05:00
strings . _ ( " gui_status_indicator_receive_started " ) ,
)
2019-11-08 06:11:30 -05:00
if type ( tab . get_mode ( ) ) == ShareMode :
2019-11-08 02:57:12 -05:00
self . assertEqual (
2019-11-08 06:11:30 -05:00
tab . get_mode ( ) . server_status_label . text ( ) ,
2019-11-08 02:57:12 -05:00
strings . _ ( " gui_status_indicator_share_started " ) ,
)
2019-11-08 06:11:30 -05:00
def web_page ( self , tab , string ) :
2019-11-08 02:57:12 -05:00
""" Test that the web page contains a string """
2019-11-08 06:11:30 -05:00
url = f " http://127.0.0.1: { tab . app . port } / "
2021-08-27 01:52:29 -04:00
r = requests . get ( url )
2019-11-08 02:57:12 -05:00
self . assertTrue ( string in r . text )
2019-11-08 06:11:30 -05:00
def history_widgets_present ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the relevant widgets are present in the history view after activity has taken place """
2019-11-08 06:11:30 -05:00
self . assertFalse ( tab . get_mode ( ) . history . empty . isVisible ( ) )
self . assertTrue ( tab . get_mode ( ) . history . not_empty . isVisible ( ) )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def counter_incremented ( self , tab , count ) :
2019-11-08 02:57:12 -05:00
""" Test that the counter has incremented """
2019-11-08 06:11:30 -05:00
self . assertEqual ( tab . get_mode ( ) . history . completed_count , count )
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def server_is_stopped ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the server stops when we click Stop """
if (
2019-11-08 06:11:30 -05:00
type ( tab . get_mode ( ) ) == ReceiveMode
or (
type ( tab . get_mode ( ) ) == ShareMode
and not tab . settings . get ( " share " , " autostop_sharing " )
)
or ( type ( tab . get_mode ( ) ) == WebsiteMode )
2021-05-10 01:05:16 -04:00
or ( type ( tab . get_mode ( ) ) == ChatMode )
2019-11-08 02:57:12 -05:00
) :
2019-11-08 07:44:52 -05:00
tab . get_mode ( ) . server_status . server_button . click ( )
2019-11-08 06:11:30 -05:00
self . assertEqual ( tab . get_mode ( ) . server_status . status , 0 )
2020-08-21 01:53:43 -04:00
self . assertFalse (
tab . get_mode ( ) . server_status . show_url_qr_code_button . isVisible ( )
)
2020-07-05 20:37:56 -04:00
self . assertFalse ( tab . get_mode ( ) . server_status . copy_url_button . isVisible ( ) )
self . assertFalse ( tab . get_mode ( ) . server_status . url . isVisible ( ) )
self . assertFalse ( tab . get_mode ( ) . server_status . url_description . isVisible ( ) )
2021-08-31 00:17:23 -04:00
self . assertFalse ( tab . get_mode ( ) . server_status . url_instructions . isVisible ( ) )
2021-09-03 17:24:45 -04:00
self . assertFalse ( tab . get_mode ( ) . server_status . private_key . isVisible ( ) )
2021-08-31 00:17:23 -04:00
self . assertFalse (
tab . get_mode ( ) . server_status . client_auth_instructions . isVisible ( )
)
2020-08-21 01:53:43 -04:00
self . assertFalse (
2021-05-06 04:02:40 -04:00
tab . get_mode ( ) . server_status . copy_client_auth_button . isVisible ( )
2020-08-21 01:53:43 -04:00
)
2021-09-03 17:24:45 -04:00
2019-11-08 06:11:30 -05:00
def web_server_is_stopped ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the web server also stopped """
2020-10-14 23:17:08 -04:00
QtTest . QTest . qWait ( 800 , self . gui . qtapp )
2019-11-08 02:57:12 -05:00
try :
2019-11-08 07:44:52 -05:00
requests . get ( f " http://127.0.0.1: { tab . app . port } / " )
2019-11-08 02:57:12 -05:00
self . assertTrue ( False )
except requests . exceptions . ConnectionError :
self . assertTrue ( True )
2019-11-08 06:11:30 -05:00
def server_status_indicator_says_closed ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the Server Status indicator shows we closed """
2019-11-08 06:11:30 -05:00
if type ( tab . get_mode ( ) ) == ReceiveMode :
2019-11-08 02:57:12 -05:00
self . assertEqual (
2019-11-08 06:11:30 -05:00
tab . get_mode ( ) . server_status_label . text ( ) ,
2019-11-08 02:57:12 -05:00
strings . _ ( " gui_status_indicator_receive_stopped " ) ,
)
2019-11-08 06:11:30 -05:00
if type ( tab . get_mode ( ) ) == ShareMode :
2019-11-08 11:42:49 -05:00
if not tab . settings . get ( " share " , " autostop_sharing " ) :
2019-11-08 02:57:12 -05:00
self . assertEqual (
2019-11-08 06:11:30 -05:00
tab . get_mode ( ) . server_status_label . text ( ) ,
2019-11-08 02:57:12 -05:00
strings . _ ( " gui_status_indicator_share_stopped " ) ,
)
else :
self . assertEqual (
2019-11-08 06:11:30 -05:00
tab . get_mode ( ) . server_status_label . text ( ) ,
2019-11-08 02:57:12 -05:00
strings . _ ( " closing_automatically " ) ,
)
2019-11-08 06:11:30 -05:00
def clear_all_history_items ( self , tab , count ) :
2019-11-08 02:57:12 -05:00
if count == 0 :
2019-11-08 07:44:52 -05:00
tab . get_mode ( ) . history . clear_button . click ( )
2019-11-08 12:38:35 -05:00
self . assertEqual ( len ( tab . get_mode ( ) . history . item_list . items . keys ( ) ) , count )
2019-11-08 02:57:12 -05:00
2019-11-10 16:51:08 -05:00
def file_selection_widget_has_files ( self , tab , num = 3 ) :
""" Test that the number of items in the list is as expected """
self . assertEqual (
tab . get_mode ( ) . server_status . file_selection . get_num_files ( ) , num
)
2020-06-28 16:01:23 -04:00
def add_remove_buttons_hidden ( self , tab ) :
""" Test that the add and remove buttons are hidden when the server starts """
2020-08-21 01:53:43 -04:00
if platform . system ( ) == " Darwin " :
self . assertFalse (
tab . get_mode ( ) . server_status . file_selection . add_files_button . isVisible ( )
)
self . assertFalse (
tab . get_mode ( ) . server_status . file_selection . add_folder_button . isVisible ( )
)
else :
self . assertFalse (
tab . get_mode ( ) . server_status . file_selection . add_button . isVisible ( )
)
2019-11-10 16:51:08 -05:00
self . assertFalse (
2020-06-28 16:01:23 -04:00
tab . get_mode ( ) . server_status . file_selection . remove_button . isVisible ( )
2019-11-10 16:51:08 -05:00
)
2019-11-08 02:57:12 -05:00
# Auto-stop timer tests
2019-11-08 06:11:30 -05:00
def set_timeout ( self , tab , timeout ) :
2019-11-08 02:57:12 -05:00
""" Test that the timeout can be set """
timer = QtCore . QDateTime . currentDateTime ( ) . addSecs ( timeout )
2019-11-08 06:59:20 -05:00
tab . get_mode ( ) . mode_settings_widget . autostop_timer_widget . setDateTime ( timer )
2019-11-08 06:11:30 -05:00
self . assertTrue (
2019-11-08 06:59:20 -05:00
tab . get_mode ( ) . mode_settings_widget . autostop_timer_widget . dateTime ( ) , timer
2019-11-08 06:11:30 -05:00
)
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def autostop_timer_widget_hidden ( self , tab ) :
2019-11-08 02:57:12 -05:00
""" Test that the auto-stop timer widget is hidden when share has started """
2019-11-08 06:11:30 -05:00
self . assertFalse (
2019-11-10 13:40:23 -05:00
tab . get_mode ( ) . mode_settings_widget . autostop_timer_widget . isVisible ( )
2019-11-08 06:11:30 -05:00
)
2019-11-08 02:57:12 -05:00
2019-11-08 06:11:30 -05:00
def server_timed_out ( self , tab , wait ) :
2019-11-08 02:57:12 -05:00
""" Test that the server has timed out after the timer ran out """
2020-10-14 23:17:08 -04:00
QtTest . QTest . qWait ( wait , self . gui . qtapp )
2019-11-08 02:57:12 -05:00
# We should have timed out now
2019-11-08 06:11:30 -05:00
self . assertEqual ( tab . get_mode ( ) . server_status . status , 0 )
2019-11-08 02:57:12 -05:00
2021-05-06 01:24:19 -04:00
def clientauth_is_visible ( self , tab ) :
2021-05-09 22:34:35 -04:00
""" Test that the ClientAuth button is visible and that the clipboard contains its contents """
2021-05-06 01:24:19 -04:00
self . assertTrue (
2021-05-06 04:02:40 -04:00
tab . get_mode ( ) . server_status . copy_client_auth_button . isVisible ( )
2021-05-06 01:24:19 -04:00
)
2021-05-06 04:02:40 -04:00
tab . get_mode ( ) . server_status . copy_client_auth_button . click ( )
2021-05-06 01:24:19 -04:00
clipboard = tab . common . gui . qtapp . clipboard ( )
2022-03-06 17:26:51 -05:00
self . assertEqual (
clipboard . text ( ) , " E2GOT5LTUTP3OAMRCRXO4GSH6VKJEUOXZQUC336SRKAHTTT5OVSA "
)
2021-05-06 01:24:19 -04:00
2021-08-27 19:41:31 -04:00
def clientauth_is_not_visible ( self , tab ) :
""" Test that the ClientAuth button is not visible """
self . assertFalse (
tab . get_mode ( ) . server_status . copy_client_auth_button . isVisible ( )
)
2022-03-06 17:26:51 -05:00
def hit_405 ( self , url , expected_resp , data = { } , methods = [ ] ) :
2021-05-09 21:23:44 -04:00
""" Test various HTTP methods and the response """
for method in methods :
if method == " put " :
2022-03-06 17:26:51 -05:00
r = requests . put ( url , data = data )
2021-05-09 21:23:44 -04:00
if method == " post " :
2022-03-06 17:26:51 -05:00
r = requests . post ( url , data = data )
2021-05-09 21:23:44 -04:00
if method == " delete " :
r = requests . delete ( url )
if method == " options " :
r = requests . options ( url )
self . assertTrue ( expected_resp in r . text )
2022-03-06 17:26:51 -05:00
self . assertFalse ( " Werkzeug " in r . headers )
2021-05-09 21:23:44 -04:00
2019-11-08 02:57:12 -05:00
# Grouped tests follow from here
2019-11-08 03:20:38 -05:00
2019-11-08 02:57:12 -05:00
def run_all_common_setup_tests ( self ) :
self . gui_loaded ( )
self . window_title_seen ( )
self . server_status_bar_is_visible ( )