diff --git a/src/cutecoin/gui/wot_tab.py b/src/cutecoin/gui/wot_tab.py index 5f0d41deacdcc21b14750826f840715efbb83adf..173daa0d72132ce0ea6ea1d85582a049b693e247 100644 --- a/src/cutecoin/gui/wot_tab.py +++ b/src/cutecoin/gui/wot_tab.py @@ -207,15 +207,16 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): """ Reset graph scene to wallet identity """ - self.draw_graph( - self.account.identity(self.community) - ) + if self.account: + self.draw_graph( + self.account.identity(self.community) + ) def refresh(self): """ Refresh graph scene to current metadata """ - if self._current_identity != None: + if self._current_identity: self.draw_graph(self._current_identity) else: self.reset() diff --git a/src/cutecoin/tests/gui/wot_tab/__init__.py b/src/cutecoin/tests/gui/wot_tab/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..39ab2a0b56350baad834cb7fb0cfecb8223e1fcd --- /dev/null +++ b/src/cutecoin/tests/gui/wot_tab/__init__.py @@ -0,0 +1 @@ +__author__ = 'inso' diff --git a/src/cutecoin/tests/gui/wot_tab/test_wot_tab.py b/src/cutecoin/tests/gui/wot_tab/test_wot_tab.py new file mode 100644 index 0000000000000000000000000000000000000000..ce6584278c161b0e5e7e208d5a020142682961ee --- /dev/null +++ b/src/cutecoin/tests/gui/wot_tab/test_wot_tab.py @@ -0,0 +1,99 @@ +import sys +import unittest +import asyncio +import quamash +import logging +import time +from ucoinpy.documents.peer import BMAEndpoint as PyBMAEndpoint +from PyQt5.QtWidgets import QDialog +from PyQt5.QtCore import QLocale, Qt +from PyQt5.QtTest import QTest +from cutecoin.core.net.api import bma as qtbma +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.wot_tab import WotTabWidget +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 + + +class TestIdentitiesTable(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_empty_wot_tab(self): + mock = nice_blockchain.get_mock() + time.sleep(2) + logging.debug(mock.pretend_url) + self.network_manager.set_mock_path(mock.pretend_url) + wot_tab = WotTabWidget(self.application) + future = asyncio.Future() + + def open_widget(): + wot_tab.show() + return future + + @asyncio.coroutine + def async_open_widget(): + yield from open_widget() + + def close_dialog(): + if wot_tab.isVisible(): + wot_tab.close() + future.set_result(True) + + @asyncio.coroutine + def exec_test(): + yield from asyncio.sleep(1) + self.assertTrue(wot_tab.isVisible()) + self.lp.call_soon(close_dialog) + + asyncio.async(exec_test()) + self.lp.call_later(15, close_dialog) + self.lp.run_until_complete(async_open_widget()) + mock.delete_mock() + +if __name__ == '__main__': + logging.basicConfig( stream=sys.stderr ) + logging.getLogger().setLevel( logging.DEBUG ) + unittest.main()