Add persistent slug test. Add test of clipboard contents in Share mode. Remove travis stuff that I couldn't get to work

This commit is contained in:
Miguel Jacq 2018-09-22 17:47:38 +10:00
parent d48d780686
commit 9a505af3bb
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
4 changed files with 167 additions and 10 deletions

View File

@ -9,8 +9,7 @@ python:
# command to install dependencies
install:
- pip install -r install/requirements.txt
- pip install pytest-cov coveralls flake8 pytest-faulthandler pytest-ordering pytest-qt
- sudo apt-get install python3-pytest
- pip install pytest-cov coveralls flake8
before_script:
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
@ -18,6 +17,5 @@ before_script:
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# command to run tests
script: pytest --cov=onionshare test/
script: cd unit_tests && bash run_unit_tests_travis.sh
after_success:
- coveralls

View File

@ -8,7 +8,7 @@ import zipfile
import socks
import json
from PyQt5 import QtCore, QtWidgets, QtTest
from PyQt5 import QtCore, QtWidgets, QtTest, QtGui
from onionshare.common import Common
from onionshare.web import Web
@ -197,8 +197,11 @@ class OnionShareGuiTest(unittest.TestCase):
@pytest.mark.run(order=20)
def test_have_copy_url_button(self):
'''Test that the Copy URL button is shown'''
'''Test that the Copy URL button is shown and can be copied to clipboard'''
self.assertTrue(self.gui.share_mode.server_status.copy_url_button.isVisible())
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.copy_url_button, QtCore.Qt.LeftButton)
clipboard = self.gui.qtapp.clipboard()
self.assertEquals(clipboard.text(), 'http://127.0.0.1:{}/{}'.format(self.gui.app.port, self.gui.share_mode.server_status.web.slug))
@pytest.mark.run(order=21)
def test_server_status_indicator_says_sharing(self):

View File

@ -0,0 +1,161 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import socket
import pytest
import zipfile
import socks
import json
from PyQt5 import QtCore, QtWidgets, QtTest
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
app = QtWidgets.QApplication(sys.argv)
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
slug = ''
@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": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": True,
"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"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
'''Test that the GUI actually is shown'''
self.assertTrue(self.gui.show)
@pytest.mark.run(order=2)
def test_server_working_on_start_button_pressed(self):
'''Test we can start the service'''
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
# Should be in SERVER_WORKING state
self.assertEqual(self.gui.share_mode.server_status.status, 1)
@pytest.mark.run(order=3)
def test_server_status_indicator_says_starting(self):
'''Test that the Server Status indicator shows we are Starting'''
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
@pytest.mark.run(order=4)
def test_a_server_is_started(self):
'''Test that the server has started'''
QtTest.QTest.qWait(2000)
# Should now be in SERVER_STARTED state
self.assertEqual(self.gui.share_mode.server_status.status, 2)
@pytest.mark.run(order=5)
def test_a_web_server_is_running(self):
'''Test that the web server has started'''
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.assertEqual(sock.connect_ex(('127.0.0.1',self.gui.app.port)), 0)
@pytest.mark.run(order=6)
def test_have_a_slug(self):
'''Test that we have a valid slug'''
self.assertRegex(self.gui.share_mode.server_status.web.slug, r'(\w+)-(\w+)')
global slug
slug = self.gui.share_mode.server_status.web.slug
@pytest.mark.run(order=7)
def test_server_can_be_stopped(self):
'''Test we can stop the service'''
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
# Should be in SERVER_STOPPED state
self.assertEqual(self.gui.share_mode.server_status.status, 0)
@pytest.mark.run(order=8)
def test_web_service_is_stopped(self):
'''Test that the web server also stopped'''
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
QtTest.QTest.qWait(4000)
# We should be closed by now. Fail if not!
self.assertNotEqual(sock.connect_ex(('127.0.0.1',self.gui.app.port)), 0)
@pytest.mark.run(order=9)
def test_server_started_again(self):
'''Test we can start the service again'''
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(2000)
# Should now be in SERVER_STARTED state
self.assertEqual(self.gui.share_mode.server_status.status, 2)
@pytest.mark.run(order=10)
def test_have_same_slug(self):
'''Test that we have the same slug'''
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
@pytest.mark.run(order=11)
def test_server_is_stopped_again(self):
'''Test that we can stop the server'''
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(1000)
self.assertEqual(self.gui.share_mode.server_status.status, 0)
if __name__ == "__main__":
unittest.main()

View File

@ -1,5 +0,0 @@
#!/bin/bash
for test in `ls -1 | egrep ^onionshare_`; do
xvfb-run pytest-3 $test -vvv || exit 1
done