Fix tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py tests

This commit is contained in:
Micah Lee 2018-09-30 18:19:25 -07:00
parent a1f5b5964a
commit c10500148b
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
4 changed files with 75 additions and 73 deletions

View File

@ -3,11 +3,60 @@ import requests
import socket
import socks
import zipfile
import json
import shutil
from PyQt5 import QtCore, QtTest
from onionshare import strings
from onionshare.common import Common
from onionshare.settings import Settings
from onionshare.onion import Onion
from onionshare.web import Web
from onionshare_gui import Application, OnionShare, OnionShareGui
class CommonTests(object):
@staticmethod
def set_up(test_settings):
'''Create GUI with given settings'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.settings = Settings(common)
common.define_css()
strings.load_strings(common)
# Get all of the settings in test_settings
test_settings['downloads_dir'] = '/tmp/OnionShare'
for key, val in common.settings.default_settings.items():
if key not in test_settings:
test_settings[key] = val
# Start the Onion
testonion = Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, True, 0)
web = Web(common, False, True)
settings_filename = '/tmp/testsettings.json'
open(settings_filename, 'w').write(json.dumps(test_settings))
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True)
return gui
@staticmethod
def tear_down():
try:
os.remove('/tmp/test.txt')
shutil.rmtree('/tmp/OnionShare')
except:
pass
def test_gui_loaded(self):
'''Test that the GUI actually is shown'''
self.assertTrue(self.gui.show)
@ -32,7 +81,7 @@ class CommonTests(object):
self.assertFalse(self.gui.share_mode.info_widget.isVisible())
def test_info_widget_is_visible(self, mode):
'''Test that the info widget along top of screen is shown'''
'''Test that the info widget along top of screen is shown'''
if mode == 'receive':
self.assertTrue(self.gui.receive_mode.info_widget.isVisible())
if mode == 'share':
@ -69,9 +118,9 @@ class CommonTests(object):
def test_server_status_indicator_says_starting(self, mode):
'''Test that the Server Status indicator shows we are Starting'''
if mode == 'receive':
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working'))
if mode == 'share':
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working'))
def test_settings_button_is_hidden(self):
'''Test that the settings button is hidden when the server starts'''
@ -123,9 +172,9 @@ class CommonTests(object):
def test_server_status_indicator_says_started(self, mode):
'''Test that the Server Status indicator shows we are started'''
if mode == 'receive':
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started', True))
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started'))
if mode == 'share':
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started', True))
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started'))
def test_web_page(self, mode, string, public_mode):
'''Test that the web page contains a string'''
@ -195,12 +244,12 @@ class CommonTests(object):
def test_server_status_indicator_says_closed(self, mode, stay_open):
'''Test that the Server Status indicator shows we closed'''
if mode == 'receive':
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped', True))
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped'))
if mode == 'share':
if stay_open:
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped', True))
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped'))
else:
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically', True))
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically'))
# Auto-stop timer tests
def test_set_timeout(self, mode, timeout):
@ -304,4 +353,3 @@ class CommonTests(object):
def test_add_button_visible(self):
'''Test that the add button should be visible'''
self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible())

View File

@ -8,6 +8,7 @@ import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.settings import Settings
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
@ -18,65 +19,15 @@ class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, True, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": True,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
"receive_allow_receiver_shutdown": True
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True)
cls.gui = CommonTests.set_up(test_settings)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
os.remove('/tmp/OnionShare/test.txt')
os.remove('/tmp/OnionShare/test-2.txt')
CommonTests.tear_down()
@pytest.mark.run(order=1)
def test_gui_loaded(self):

View File

@ -32,7 +32,7 @@ class CommonTests(object):
self.assertFalse(self.gui.share_mode.info_widget.isVisible())
def test_info_widget_is_visible(self, mode):
'''Test that the info widget along top of screen is shown'''
'''Test that the info widget along top of screen is shown'''
if mode == 'receive':
self.assertTrue(self.gui.receive_mode.info_widget.isVisible())
if mode == 'share':
@ -69,9 +69,9 @@ class CommonTests(object):
def test_server_status_indicator_says_starting(self, mode):
'''Test that the Server Status indicator shows we are Starting'''
if mode == 'receive':
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working'))
if mode == 'share':
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working'))
def test_settings_button_is_hidden(self):
'''Test that the settings button is hidden when the server starts'''
@ -126,9 +126,9 @@ class CommonTests(object):
def test_server_status_indicator_says_started(self, mode):
'''Test that the Server Status indicator shows we are started'''
if mode == 'receive':
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started', True))
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started'))
if mode == 'share':
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started', True))
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started'))
def test_web_page(self, mode, string, public_mode):
'''Test that the web page contains a string'''
@ -201,12 +201,12 @@ class CommonTests(object):
def test_server_status_indicator_says_closed(self, mode, stay_open):
'''Test that the Server Status indicator shows we closed'''
if mode == 'receive':
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped', True))
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped'))
if mode == 'share':
if stay_open:
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped', True))
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped'))
else:
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically', True))
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically'))
def test_cancel_the_share(self, mode):
'''Test that we can cancel this share before it's started up '''
@ -354,6 +354,6 @@ class CommonTests(object):
self.gui.app.onion.cleanup(stop_tor=True)
QtTest.QTest.qWait(2500)
if mode == 'share':
self.assertTrue(self.gui.share_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost', True))
self.assertTrue(self.gui.share_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))
if mode == 'receive':
self.assertTrue(self.gui.receive_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost', True))
self.assertTrue(self.gui.receive_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))

View File

@ -151,7 +151,10 @@ def time_strftime(monkeypatch):
@pytest.fixture
def common_obj():
return common.Common()
_common = common.Common()
_common.settings = settings.Settings(_common)
strings.load_strings(_common)
return _common
@pytest.fixture
def settings_obj(sys_onionshare_dev_mode, platform_linux):