New package: bitmessageqt.tests

any test cases from it will be added to tests.core test suite if possible,
e.g. PyQt is functional. TestSupport - minimal test case for support module
to reproduce #1633.
This commit is contained in:
Dmitri Bogomolov 2020-06-09 17:14:26 +03:00
parent ea109bc21e
commit d6953eb450
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
5 changed files with 80 additions and 4 deletions

View File

@ -363,11 +363,12 @@ class Main(object):
while state.shutdown == 0: while state.shutdown == 0:
time.sleep(1) time.sleep(1)
if ( if (
state.testmode and time.time() - state.testmode
state.last_api_response >= 30 and time.time() - state.last_api_response >= 30
): ):
self.stop() self.stop()
elif not state.enableGUI: elif not state.enableGUI:
state.enableGUI = True
# pylint: disable=relative-import # pylint: disable=relative-import
from tests import core as test_core from tests import core as test_core
test_core_result = test_core.run() test_core_result = test_core.run()

View File

@ -0,0 +1,6 @@
"""bitmessageqt tests"""
from main import TestMain
from support import TestSupport
__all__ = ["TestMain", "TestSupport"]

View File

@ -0,0 +1,30 @@
"""Common definitions for bitmessageqt tests"""
import unittest
from PyQt4 import QtCore, QtGui
import bitmessageqt
from tr import _translate
class TestBase(unittest.TestCase):
"""Base class for bitmessageqt test case"""
def setUp(self):
self.app = QtGui.QApplication([])
self.window = bitmessageqt.MyForm()
def tearDown(self):
self.app.deleteLater()
class TestMain(unittest.TestCase):
"""Test case for main window - basic features"""
def test_translate(self):
"""Check the results of _translate() with various args"""
self.assertIsInstance(
_translate("MainWindow", "Test"),
QtCore.QString
)

View File

@ -0,0 +1,33 @@
# from PyQt4 import QtTest
import sys
from shared import isAddressInMyAddressBook
from main import TestBase
class TestSupport(TestBase):
"""A test case for support module"""
SUPPORT_ADDRESS = 'BM-2cUdgkDDAahwPAU6oD2A7DnjqZz3hgY832'
SUPPORT_SUBJECT = 'Support request'
def test(self):
"""trigger menu action "Contact Support" and check the result"""
ui = self.window.ui
self.assertEqual(ui.lineEditTo.text(), '')
self.assertEqual(ui.lineEditSubject.text(), '')
ui.actionSupport.trigger()
self.assertTrue(
isAddressInMyAddressBook(self.SUPPORT_ADDRESS))
self.assertEqual(
ui.tabWidget.currentIndex(), ui.tabWidget.indexOf(ui.send))
self.assertEqual(
ui.lineEditTo.text(), self.SUPPORT_ADDRESS)
self.assertEqual(
ui.lineEditSubject.text(), self.SUPPORT_SUBJECT)
self.assertIn(
sys.version, ui.textEditMessage.toPlainText())

View File

@ -30,7 +30,6 @@ try:
except ImportError: except ImportError:
stem_version = None stem_version = None
knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat') knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat')
@ -245,7 +244,14 @@ class TestCore(unittest.TestCase):
def run(): def run():
"""Starts all tests defined in this module""" """Starts all tests defined in this module"""
loader = unittest.TestLoader() loader = unittest.defaultTestLoader
loader.sortTestMethodsUsing = None loader.sortTestMethodsUsing = None
suite = loader.loadTestsFromTestCase(TestCore) suite = loader.loadTestsFromTestCase(TestCore)
try:
import bitmessageqt.tests
except ImportError:
pass
else:
qt_tests = loader.loadTestsFromModule(bitmessageqt.tests)
suite.addTests(qt_tests)
return unittest.TextTestRunner(verbosity=2).run(suite) return unittest.TextTestRunner(verbosity=2).run(suite)