Skip to content
Snippets Groups Projects
Commit 4ec183b6 authored by inso's avatar inso
Browse files

Fix connect with an existing account

parent e9956d52
Branches
Tags
No related merge requests found
......@@ -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.next()
self.config_dialog.community = community
self.config_dialog.next()
else:
self.config_dialog.label_error.setText(self.tr("Could not connect."))
@pyqtSlot()
def check_connect(self):
......
......@@ -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)
......@@ -97,7 +97,103 @@ class ProcessAddCommunity(unittest.TestCase):
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_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))
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))
if __name__ == '__main__':
logging.basicConfig( stream=sys.stderr )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment