diff --git a/src/cutecoin/gui/identities_tab.py b/src/cutecoin/gui/identities_tab.py index 646e59bbc0d2f47676cea3022c94ad3277b68665..6b91e26e4f44d02ca50f5aed8b1359442b678c82 100644 --- a/src/cutecoin/gui/identities_tab.py +++ b/src/cutecoin/gui/identities_tab.py @@ -58,6 +58,7 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): direct_connections = QAction(self.tr("Direct connections"), self) direct_connections.triggered.connect(self.search_direct_connections) self.button_search.addAction(direct_connections) + self.button_search.clicked.connect(self.search_text) def change_account(self, account): self.account = account diff --git a/src/cutecoin/tests/certification/test_certification.py b/src/cutecoin/tests/certification/test_certification.py index a732c7386dc3098738d44440ec4dad22b4184436..af9ef7391d42add18d27b976696d6b37daa77dc9 100644 --- a/src/cutecoin/tests/certification/test_certification.py +++ b/src/cutecoin/tests/certification/test_certification.py @@ -64,6 +64,7 @@ class TestCertificationDialog(unittest.TestCase): def test_certification_init_community(self): mock = init_new_community.get_mock() logging.debug(mock.pretend_url) + self.network_manager.set_mock_path(mock.pretend_url) certification_dialog = CertificationDialog(self.application, self.account, self.password_asker) @@ -80,7 +81,6 @@ class TestCertificationDialog(unittest.TestCase): @asyncio.coroutine def exec_test(): yield from asyncio.sleep(1) - self.network_manager.set_mock_path(mock.pretend_url) self.assertEqual(certification_dialog.button_box.button(QDialogButtonBox.Ok).text(), "&Ok") QTest.mouseClick(certification_dialog.radio_pubkey, Qt.LeftButton) QTest.keyClicks(certification_dialog.edit_pubkey, "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") diff --git a/src/cutecoin/tests/identities_tab/__init__.py b/src/cutecoin/tests/identities_tab/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/cutecoin/tests/identities_tab/test_identities_table.py b/src/cutecoin/tests/identities_tab/test_identities_table.py new file mode 100644 index 0000000000000000000000000000000000000000..526a7c94a169f66c0000d71e5d8ef719391b9328 --- /dev/null +++ b/src/cutecoin/tests/identities_tab/test_identities_table.py @@ -0,0 +1,101 @@ +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.identities_tab import IdentitiesTabWidget +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_search_identity_found(self): + mock = nice_blockchain.get_mock() + logging.debug(mock.pretend_url) + self.network_manager.set_mock_path(mock.pretend_url) + identities_tab = IdentitiesTabWidget(self.application) + identities_tab.change_account(self.account) + identities_tab.change_community(self.community) + + @asyncio.coroutine + def exec_test(): + yield from asyncio.sleep(1) + self.assertEqual(mock.get_request(0).method, 'GET') + self.assertEqual(mock.get_request(0).url, + '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') + + # requests 1 to 3 are for getting certifiers-of and certified-by + # on john, + a lookup + + QTest.keyClicks(identities_tab.edit_textsearch, "doe") + QTest.mouseClick(identities_tab.button_search, Qt.LeftButton) + yield from asyncio.sleep(1) + self.assertEqual(mock.get_request(4).method, 'GET') + self.assertEqual(mock.get_request(4).url, + '/wot/lookup/doe') + self.assertEqual(mock.get_request(5).method, 'GET') + self.assertEqual(mock.get_request(5).url, + '/wot/certifiers-of/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn') + self.assertEqual(mock.get_request(6).method, 'GET') + self.assertEqual(mock.get_request(6).url, + '/wot/lookup/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn') + self.assertEqual(identities_tab.table_identities.model().rowCount(), 1) + + self.lp.run_until_complete(exec_test()) + +if __name__ == '__main__': + logging.basicConfig( stream=sys.stderr ) + logging.getLogger().setLevel( logging.DEBUG ) + unittest.main() diff --git a/src/cutecoin/tests/mocks/bma/nice_blockchain.py b/src/cutecoin/tests/mocks/bma/nice_blockchain.py new file mode 100644 index 0000000000000000000000000000000000000000..04bca2ed3133c4fcf12216cdd1ca767b90e7e316 --- /dev/null +++ b/src/cutecoin/tests/mocks/bma/nice_blockchain.py @@ -0,0 +1,119 @@ +from pretenders.client.http import HTTPMock +from pretenders.common.constants import FOREVER + +bma_peering = b"""{ + "version": 1, + "currency": "test_currency", + "endpoints": [ + "BASIC_MERKLED_API localhost 127.0.0.1 50000" + ], + "status": "UP", + "block": "30152-00003E7F9234E7542FCF669B69B0F84FF79CCCD3", + "signature": "cXuqZuDfyHvxYAEUkPH1TQ1M+8YNDpj8kiHGYi3LIaMqEdVqwVc4yQYGivjxFMYyngRfxXkyvqBKZA6rKOulCA==", + "raw": "Version: 1\\nType: Peer\\nCurrency: meta_brouzouf\\nPublicKey: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\\nBlock: 30152-00003E7F9234E7542FCF669B69B0F84FF79CCCD3\\nEndpoints:\\nBASIC_MERKLED_API localhost 127.0.0.1 50000\\n", + "pubkey": "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" +}""" + +bma_lookup_john = b"""{ + "partial": false, + "results": [ + { + "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "uids": [ + { + "uid": "john", + "meta": { + "timestamp": 1441130831 + }, + "self": "ZrHK0cCqrxWReROK0ciiSb45+dRphJa68qFaSjdve8bBdnGAu7+DIu0d+u/fXrNRXuObihOKMBIawaIVPNHqDw==", + "others": [] + } + ], + "signed": [] + } + ] +}""" + +bma_lookup_doe = b"""{ + "partial": false, + "results": [ + { + "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + "uids": [ + { + "uid": "doe", + "meta": { + "timestamp": 1441130831 + }, + "self": "cIkHPQQ5+xTb4cKWv85rcYcZT+E3GDtX8B2nCK9Vs12p2Yz4bVaZiMvBBwisAAy2WBOaqHS3ydpXGtADchOICw==", + "others": [] + } + ], + "signed": [] + } + ] +}""" + +bma_certifiers_of_john = b"""{ + "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "uid": "john", + "isMember": true, + "certifications": [ + ] +}""" + +bma_certified_by_john = b"""{ + "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "uid": "john", + "isMember": true, + "certifications": [ + ] +}""" + + +def get_mock(): + mock = HTTPMock('127.0.0.1', 50000) + + mock.when('GET /network/peering')\ + .reply(body=bma_peering, + times=FOREVER, + headers={'Content-Type': 'application/json'}) + + mock.when('GET /wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ')\ + .reply(body=bma_certifiers_of_john, + status=200, + times=FOREVER, + headers={'Content-Type': 'application/json'}) + + mock.when('GET /wot/certified-by/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ')\ + .reply(body=bma_certified_by_john, + status=200, + times=FOREVER, + headers={'Content-Type': 'application/json'}) + + mock.when('GET /wot/lookup/john')\ + .reply(body=bma_lookup_john, + status=200, + times=FOREVER, + headers={'Content-Type': 'application/json'}) + + mock.when('GET /wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ')\ + .reply(body=bma_lookup_john, + status=200, + times=FOREVER, + headers={'Content-Type': 'application/json'}) + + mock.when('GET /wot/lookup/doe')\ + .reply(body=bma_lookup_doe, + status=200, + times=1, + headers={'Content-Type': 'application/json'}) + + mock.when('GET /wot/lookup/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn')\ + .reply(body=bma_lookup_doe, + status=200, + times=FOREVER, + headers={'Content-Type': 'application/json'}) + + + return mock 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 f48117527b8443d4d40f41f6aeaa176ede18cdb1..73da23fcdd79b9ee539c7ae5c548d2da7ac7f51b 100644 --- a/src/cutecoin/tests/process_cfg_community/test_add_community.py +++ b/src/cutecoin/tests/process_cfg_community/test_add_community.py @@ -44,6 +44,7 @@ class ProcessAddCommunity(unittest.TestCase): def test_add_community_empty_blockchain(self): mock = new_blockchain.get_mock() 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) @@ -60,7 +61,6 @@ class ProcessAddCommunity(unittest.TestCase): @asyncio.coroutine def exec_test(): yield from asyncio.sleep(1) - self.network_manager.set_mock_path(mock.pretend_url) 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)