diff --git a/run_tests.py b/run_tests.py index 3f2ee70a70f921a0e4612737b0c7efb8a5e25a3e..e7d2d9b9880524981361aef300c4833f121187ed 100644 --- a/run_tests.py +++ b/run_tests.py @@ -3,10 +3,11 @@ import os import unittest import subprocess import time +import shlex -cmd = 'python -m pretenders.server.server --host 0.0.0.0 --port 50000' +cmd = 'python -m pretenders.server.server --host 127.0.0.1 --port 50000' -p = subprocess.Popen(cmd) +p = subprocess.Popen(shlex.split(cmd)) time.sleep(2) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib'))) diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py index 33e34f84cc7bc9d8c3c79884dae2710716f286e0..68ba299c89755d0490c7cec1811c9a4a989fc31d 100644 --- a/src/cutecoin/gui/process_cfg_community.py +++ b/src/cutecoin/gui/process_cfg_community.py @@ -52,6 +52,7 @@ class StepPageInit(Step): @pyqtSlot() def check_node(self): + logging.debug("Check node") asyncio.async(self.coroutine_check_node()) def is_valid(self): diff --git a/src/cutecoin/tests/mocks/bma/new_blockchain.py b/src/cutecoin/tests/mocks/bma/new_blockchain.py index 819a597efd58f866e72c97f18f776e76f1207e9c..fda4ecd554d727a93340d3f3e5e6b2b78c9b92f1 100644 --- a/src/cutecoin/tests/mocks/bma/new_blockchain.py +++ b/src/cutecoin/tests/mocks/bma/new_blockchain.py @@ -83,7 +83,7 @@ bma_peering = b"""{ def get_mock(): # Assume a running server # Initialise the mock client and clear all responses - mock = HTTPMock('localhost', 50000) + mock = HTTPMock('127.0.0.1', 50000) mock.when('GET /network/peering')\ .reply(body=bma_peering, diff --git a/src/cutecoin/tests/process_cfg_community/test_add_community.py b/src/cutecoin/tests/process_cfg_community/test_add_community.py index 2fdea39fd81fe997ed92bc0a0650f17c46d5c0c0..70a95dcd551552b6a623de9f07ed225ba10f964b 100644 --- a/src/cutecoin/tests/process_cfg_community/test_add_community.py +++ b/src/cutecoin/tests/process_cfg_community/test_add_community.py @@ -16,11 +16,40 @@ from cutecoin.core.app import Application from cutecoin.core.account import Account from cutecoin.tests import get_application + class ProcessAddCommunity(unittest.TestCase): + test_instance = None + @staticmethod + def async_exception_handler(loop, context): + """ + An exception handler which exists the program if the exception + was not catch + :param loop: the asyncio loop + :param context: the exception context + """ + message = context.get('message') + if not message: + message = 'Unhandled exception in event loop' + + try: + exception = context['exception'] + except KeyError: + exc_info = False + else: + exc_info = (type(exception), exception, exception.__traceback__) + + log_lines = [message] + for key in [k for k in sorted(context) if k not in {'message', 'exception'}]: + log_lines.append('{}: {!r}'.format(key, context[key])) + + unittest.TestCase.fail(ProcessAddCommunity.test_instance, '\n'.join(log_lines)) + def setUp(self): + ProcessAddCommunity.test_instance = self self.qapplication = get_application() QLocale.setDefault(QLocale("en_GB")) self.lp = quamash.QEventLoop(self.qapplication) + self.lp.set_exception_handler(ProcessAddCommunity.async_exception_handler) asyncio.set_event_loop(self.lp) self.application = Application(self.qapplication, self.lp, None, None) @@ -35,21 +64,24 @@ class ProcessAddCommunity(unittest.TestCase): asyncio.set_event_loop(None) def test_add_community_empty_blockchain(self): + asyncio.set_event_loop(self.lp) + self.lp.run_forever() mock = new_blockchain.get_mock() - self.process_community = ProcessConfigureCommunity(self.application, self.account, None, self.password_asker) + self.process_community = ProcessConfigureCommunity(self.application, + self.account, None, + self.password_asker) QTest.mouseClick(self.process_community.lineedit_add_address, Qt.LeftButton) - QTest.keyClicks(self.process_community.lineedit_add_address, "localhost") + QTest.keyClicks(self.process_community.lineedit_add_address, "127.0.0.1") QTest.mouseDClick(self.process_community.spinbox_add_port, Qt.LeftButton) self.process_community.spinbox_add_port.setValue(50000) - self.assertEqual(self.process_community.lineedit_add_address.text(), "localhost") + self.assertEqual(self.process_community.lineedit_add_address.text(), "127.0.0.1") self.assertEqual(self.process_community.spinbox_add_port.value(), 50000) QTest.mouseClick(self.process_community.button_checknode, Qt.LeftButton) - time.sleep(1) + self.lp.run_forever() + QTest.qSleep(10000) self.assertEqual(mock.get_request(0).method, 'GET') self.assertEqual(mock.get_request(0).url, '/network/peering') self.assertEqual(self.process_community.button_checknode.text(), "Ok !") if __name__ == '__main__': - logging.basicConfig( stream=sys.stderr ) - logging.getLogger().setLevel( logging.DEBUG ) unittest.main() diff --git a/src/cutecoin/tests/qapp.py b/src/cutecoin/tests/qapp.py index d3e1a8f657a8d8a72ca386ba3b2e8e7313d44fbb..07210312cdf304380b9bdab087ea106dc91c54b5 100644 --- a/src/cutecoin/tests/qapp.py +++ b/src/cutecoin/tests/qapp.py @@ -1,6 +1,7 @@ _application_ = [] + def get_application(): """Get the singleton QApplication""" from PyQt5.QtWidgets import QApplication