mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-25 23:10:38 -04:00
Refactor the unit tests to use common, abstracted tests
This commit is contained in:
parent
4e68c62b9c
commit
de9bc975a4
8 changed files with 625 additions and 708 deletions
|
@ -2,19 +2,18 @@
|
|||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import socket
|
||||
import pytest
|
||||
import zipfile
|
||||
import socks
|
||||
import json
|
||||
|
||||
from PyQt5 import QtCore, QtWidgets, QtTest
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
from onionshare.common import Common
|
||||
from onionshare.web import Web
|
||||
from onionshare import onion, strings
|
||||
from onionshare_gui import *
|
||||
|
||||
from .commontests import CommonTests
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
|
||||
class OnionShareGuiTest(unittest.TestCase):
|
||||
|
@ -83,79 +82,86 @@ class OnionShareGuiTest(unittest.TestCase):
|
|||
|
||||
@pytest.mark.run(order=1)
|
||||
def test_gui_loaded(self):
|
||||
'''Test that the GUI actually is shown'''
|
||||
self.assertTrue(self.gui.show)
|
||||
CommonTests.test_gui_loaded(self)
|
||||
|
||||
@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)
|
||||
def test_windowTitle_seen(self):
|
||||
CommonTests.test_windowTitle_seen(self)
|
||||
|
||||
@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))
|
||||
def test_settings_button_is_visible(self):
|
||||
CommonTests.test_settings_button_is_visible(self)
|
||||
|
||||
@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)
|
||||
def test_server_status_bar_is_visible(self):
|
||||
CommonTests.test_server_status_bar_is_visible(self)
|
||||
|
||||
@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)
|
||||
def test_info_widget_is_visible(self):
|
||||
CommonTests.test_info_widget_is_visible(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=6)
|
||||
def test_history_is_visible(self):
|
||||
CommonTests.test_history_is_visible(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=7)
|
||||
def test_server_working_on_start_button_pressed(self):
|
||||
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=8)
|
||||
def test_server_status_indicator_says_starting(self):
|
||||
CommonTests.test_server_status_indicator_says_starting(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=9)
|
||||
def test_settings_button_is_hidden(self):
|
||||
CommonTests.test_settings_button_is_hidden(self)
|
||||
|
||||
@pytest.mark.run(order=10)
|
||||
def test_a_server_is_started(self):
|
||||
CommonTests.test_a_server_is_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=11)
|
||||
def test_a_web_server_is_running(self):
|
||||
CommonTests.test_a_web_server_is_running(self)
|
||||
|
||||
@pytest.mark.run(order=12)
|
||||
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+)')
|
||||
CommonTests.test_have_a_slug(self, 'share', False)
|
||||
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)
|
||||
@pytest.mark.run(order=13)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'share')
|
||||
|
||||
# Should be in SERVER_STOPPED state
|
||||
self.assertEqual(self.gui.share_mode.server_status.status, 0)
|
||||
@pytest.mark.run(order=14)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'share', True)
|
||||
|
||||
@pytest.mark.run(order=8)
|
||||
@pytest.mark.run(order=15)
|
||||
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)
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
# 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=16)
|
||||
def test_server_status_indicator_says_closed(self):
|
||||
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
|
||||
|
||||
@pytest.mark.run(order=9)
|
||||
@pytest.mark.run(order=17)
|
||||
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)
|
||||
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
|
||||
CommonTests.test_server_status_indicator_says_starting(self, 'share')
|
||||
CommonTests.test_a_server_is_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=10)
|
||||
@pytest.mark.run(order=18)
|
||||
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)
|
||||
@pytest.mark.run(order=19)
|
||||
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)
|
||||
CommonTests.test_server_is_stopped(self, 'share', True)
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue