From 2bd18eacdc4b9e674cd58d89cc47d940893d1b0c Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Tue, 8 Sep 2015 20:56:26 +0200 Subject: [PATCH] Fix bug when opening transfer dialog --- src/cutecoin/gui/mainwindow.py | 1 - src/cutecoin/gui/transfer.py | 6 ++ .../identities_tab/test_identities_table.py | 1 - src/cutecoin/tests/transfer/__init__.py | 0 src/cutecoin/tests/transfer/test_transfer.py | 98 +++++++++++++++++++ 5 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 src/cutecoin/tests/transfer/__init__.py create mode 100644 src/cutecoin/tests/transfer/test_transfer.py diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index 4a39bec2..67dd4981 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -158,7 +158,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): dialog = TransferMoneyDialog(self.app, self.app.current_account, self.password_asker) - dialog.accepted.connect(self.refresh_wallets) if dialog.exec_() == QDialog.Accepted: self.community_view.tab_history.table_history.model().sourceModel().refresh_transfers() diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py index cbd86f82..273c76ad 100644 --- a/src/cutecoin/gui/transfer.py +++ b/src/cutecoin/gui/transfer.py @@ -149,3 +149,9 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): def recipient_mode_changed(self, pubkey_toggled): self.edit_pubkey.setEnabled(pubkey_toggled) self.combo_contact.setEnabled(not pubkey_toggled) + + def async_exec(self): + future = asyncio.Future() + self.finished.connect(lambda r: future.set_result(r)) + self.open() + return future diff --git a/src/cutecoin/tests/identities_tab/test_identities_table.py b/src/cutecoin/tests/identities_tab/test_identities_table.py index 02dbb053..9bafb74a 100644 --- a/src/cutecoin/tests/identities_tab/test_identities_table.py +++ b/src/cutecoin/tests/identities_tab/test_identities_table.py @@ -84,7 +84,6 @@ class TestIdentitiesTable(unittest.TestCase): identities_tab.close() future.set_result(True) - @asyncio.coroutine def exec_test(): yield from asyncio.sleep(1) diff --git a/src/cutecoin/tests/transfer/__init__.py b/src/cutecoin/tests/transfer/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/cutecoin/tests/transfer/test_transfer.py b/src/cutecoin/tests/transfer/test_transfer.py new file mode 100644 index 00000000..5e50e0e7 --- /dev/null +++ b/src/cutecoin/tests/transfer/test_transfer.py @@ -0,0 +1,98 @@ +import sys +import unittest +import asyncio +import quamash +import time +import logging +from ucoinpy.documents.peer import BMAEndpoint as PyBMAEndpoint +from PyQt5.QtWidgets import QDialog, QDialogButtonBox +from PyQt5.QtCore import QLocale, Qt +from PyQt5.QtTest import QTest +from cutecoin.tests.mocks.bma import nice_blockchain +from cutecoin.tests.mocks.access_manager import MockNetworkAccessManager +from cutecoin.core.registry.identities import IdentitiesRegistry +from cutecoin.gui.transfer import TransferMoneyDialog +from cutecoin.gui.password_asker import PasswordAskerDialog +from cutecoin.core.app import Application +from cutecoin.core import Account, Community, Wallet +from cutecoin.core.net import Network, Node +from cutecoin.core.net.endpoint import BMAEndpoint +from cutecoin.core.net.api.bma.access import BmaAccess +from cutecoin.tests import get_application +from cutecoin.core.net.api import bma as qtbma + + +class TestTransferDialog(unittest.TestCase): + def setUp(self): + self.qapplication = get_application() + self.network_manager = MockNetworkAccessManager() + QLocale.setDefault(QLocale("en_GB")) + self.lp = quamash.QEventLoop(self.qapplication) + asyncio.set_event_loop(self.lp) + self.identities_registry = IdentitiesRegistry({}) + + self.application = Application(self.qapplication, self.lp, self.network_manager, self.identities_registry) + self.application.preferences['notifications'] = False + + self.endpoint = BMAEndpoint(PyBMAEndpoint("", "127.0.0.1", "", 50000)) + self.node = Node(self.network_manager, "test_currency", [self.endpoint], + "", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk", + qtbma.blockchain.Block.null_value, Node.ONLINE, + time.time(), {}, "ucoin", "0.14.0", 0) + self.network = Network.create(self.network_manager, self.node) + self.bma_access = BmaAccess.create(self.network) + self.community = Community("test_currency", self.network, self.bma_access) + + self.wallet = Wallet(0, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "Wallet 1", self.identities_registry) + + # Salt/password : "testcutecoin/testcutecoin" + # Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ + self.account = Account("testcutecoin", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "john", [self.community], [self.wallet], [], self.identities_registry) + + self.password_asker = PasswordAskerDialog(self.account) + self.password_asker.password = "testcutecoin" + self.password_asker.remember = True + + def tearDown(self): + try: + self.lp.close() + finally: + asyncio.set_event_loop(None) + + def test_transfer_nice_community(self): + mock = nice_blockchain.get_mock() + time.sleep(2) + logging.debug(mock.pretend_url) + self.network_manager.set_mock_path(mock.pretend_url) + transfer_dialog = TransferMoneyDialog(self.application, + self.account, + self.password_asker) + + @asyncio.coroutine + def open_dialog(certification_dialog): + result = yield from certification_dialog.async_exec() + self.assertEqual(result, QDialog.Rejected) + + def close_dialog(): + if transfer_dialog.isVisible(): + transfer_dialog.close() + + @asyncio.coroutine + def exec_test(): + yield from asyncio.sleep(1) + self.assertEqual(transfer_dialog.button_box.button(QDialogButtonBox.Ok).text(), "&Ok") + QTest.mouseClick(transfer_dialog.radio_pubkey, Qt.LeftButton) + QTest.keyClicks(transfer_dialog.edit_pubkey, "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") + QTest.mouseClick(transfer_dialog.button_box.button(QDialogButtonBox.Cancel), Qt.LeftButton) + + self.lp.call_later(15, close_dialog) + asyncio.async(exec_test()) + self.lp.run_until_complete(open_dialog(transfer_dialog)) + + +if __name__ == '__main__': + logging.basicConfig(stream=sys.stderr) + logging.getLogger().setLevel(logging.DEBUG) + unittest.main() -- GitLab