diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py index 55481d5b581a94453a39957595bed86ef196375d..ab6217d234110f9918bccaa060d78a4b73e84862 100644 --- a/src/cutecoin/gui/process_cfg_community.py +++ b/src/cutecoin/gui/process_cfg_community.py @@ -61,11 +61,15 @@ class StepPageInit(Step): logging.debug("Is valid ? ") self.node = yield from Node.from_address(self.config_dialog.app.network_manager, None, server, port) if self.node: - identity = yield from self.app.identities_registry.future_find(self.account.pubkey, self.community) + community = Community.create(self.app.network_manager, self.node) + identity = yield from self.app.identities_registry.future_find(self.account.pubkey, community) if identity.blockchain_state == BlockchainState.NOT_FOUND: self.config_dialog.label_error.setText(self.tr("Could not find your identity on the network.")) + else: + self.config_dialog.community = community + self.config_dialog.next() else: - self.next() + self.config_dialog.label_error.setText(self.tr("Could not connect.")) @pyqtSlot() def check_connect(self): 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 d7acee187cfdb1f8c7616839e79861e3ce072c90..dfb224a1995140fbaaedcae1dcd627429fcc674e 100644 --- a/src/cutecoin/tests/process_cfg_community/test_add_community.py +++ b/src/cutecoin/tests/process_cfg_community/test_add_community.py @@ -7,7 +7,7 @@ import time from PyQt5.QtWidgets import QDialog from PyQt5.QtCore import QLocale, Qt from PyQt5.QtTest import QTest -from cutecoin.tests.mocks.bma import new_blockchain +from cutecoin.tests.mocks.bma import new_blockchain, nice_blockchain from cutecoin.tests.mocks.access_manager import MockNetworkAccessManager from cutecoin.core.registry.identities import IdentitiesRegistry from cutecoin.gui.process_cfg_community import ProcessConfigureCommunity @@ -42,7 +42,7 @@ class ProcessAddCommunity(unittest.TestCase): finally: asyncio.set_event_loop(None) - def test_add_community_empty_blockchain(self): + def test_register_community_empty_blockchain(self): mock = new_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) @@ -99,6 +99,105 @@ class ProcessAddCommunity(unittest.TestCase): self.lp.run_until_complete(open_dialog(process_community)) mock.delete_mock() + def test_connect_community_empty_blockchain(self): + mock = new_blockchain.get_mock() + time.sleep(2) + logging.debug(mock.pretend_url) + self.network_manager.set_mock_path(mock.pretend_url) + process_community = ProcessConfigureCommunity(self.application, + self.account, + None, self.password_asker) + + @asyncio.coroutine + def open_dialog(process_community): + result = yield from process_community.async_exec() + self.assertEqual(result, QDialog.Rejected) + + def close_dialog(): + if process_community.isVisible(): + process_community.close() + + @asyncio.coroutine + def exec_test(): + yield from asyncio.sleep(1) + QTest.mouseClick(process_community.lineedit_server, Qt.LeftButton) + QTest.keyClicks(process_community.lineedit_server, "127.0.0.1") + QTest.mouseDClick(process_community.spinbox_port, Qt.LeftButton) + process_community.spinbox_port.setValue(50000) + self.assertEqual(process_community.stacked_pages.currentWidget(), + process_community.page_node, + msg="Current widget : {0}".format(process_community.stacked_pages.currentWidget().objectName())) + self.assertEqual(process_community.lineedit_server.text(), "127.0.0.1") + self.assertEqual(process_community.spinbox_port.value(), 50000) + QTest.mouseClick(process_community.button_connect, Qt.LeftButton) + yield from asyncio.sleep(1) + self.assertEqual(mock.get_request(0).method, 'GET') + self.assertEqual(mock.get_request(0).url, '/network/peering') + self.assertEqual(mock.get_request(1).method, 'GET') + self.assertEqual(mock.get_request(1).url, + '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') + for i in range(2, 5): + self.assertEqual(mock.get_request(i).method, 'GET') + self.assertEqual(mock.get_request(i).url, + '/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') + self.assertEqual(process_community.stacked_pages.currentWidget(), + process_community.page_node, + msg="Current widget : {0}".format(process_community.stacked_pages.currentWidget().objectName())) + self.assertEqual(process_community.label_error.text(), "Could not find your identity on the network.") + process_community.close() + + self.lp.call_later(15, close_dialog) + asyncio.async(exec_test()) + self.lp.run_until_complete(open_dialog(process_community)) + mock.delete_mock() + + def test_connect_community_nice_blockchain(self): + mock = nice_blockchain.get_mock() + time.sleep(2) + logging.debug(mock.pretend_url) + self.network_manager.set_mock_path(mock.pretend_url) + process_community = ProcessConfigureCommunity(self.application, + self.account, + None, self.password_asker) + + @asyncio.coroutine + def open_dialog(process_community): + result = yield from process_community.async_exec() + self.assertEqual(result, QDialog.Accepted) + + def close_dialog(): + if process_community.isVisible(): + process_community.close() + + @asyncio.coroutine + def exec_test(): + yield from asyncio.sleep(1) + QTest.mouseClick(process_community.lineedit_server, Qt.LeftButton) + QTest.keyClicks(process_community.lineedit_server, "127.0.0.1") + QTest.mouseDClick(process_community.spinbox_port, Qt.LeftButton) + process_community.spinbox_port.setValue(50000) + self.assertEqual(process_community.stacked_pages.currentWidget(), + process_community.page_node, + msg="Current widget : {0}".format(process_community.stacked_pages.currentWidget().objectName())) + self.assertEqual(process_community.lineedit_server.text(), "127.0.0.1") + self.assertEqual(process_community.spinbox_port.value(), 50000) + QTest.mouseClick(process_community.button_connect, Qt.LeftButton) + yield from asyncio.sleep(1) + self.assertEqual(mock.get_request(0).method, 'GET') + self.assertEqual(mock.get_request(0).url, '/network/peering') + self.assertEqual(mock.get_request(1).method, 'GET') + self.assertEqual(mock.get_request(1).url, + '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') + self.assertEqual(process_community.stacked_pages.currentWidget(), + process_community.page_add_nodes, + msg="Current widget : {0}".format(process_community.stacked_pages.currentWidget().objectName())) + QTest.mouseClick(process_community.button_next, Qt.LeftButton) + + self.lp.call_later(15, close_dialog) + asyncio.async(exec_test()) + self.lp.run_until_complete(open_dialog(process_community)) + mock.delete_mock() + if __name__ == '__main__': logging.basicConfig( stream=sys.stderr ) logging.getLogger().setLevel( logging.DEBUG )