def test_empty_wot_tab(self): mock = nice_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) API.reverse_url = pretender_reversed(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()
def setUp(self): self.setUpQuamash() QLocale.setDefault(QLocale("en_GB")) self.identities_registry = IdentitiesRegistry() self.application = Application(self.qapplication, self.lp, self.identities_registry) self.application.preferences['notifications'] = False self.mock_nice_blockchain = nice_blockchain.get_mock(self.lp) self.node = Node(self.mock_nice_blockchain.peer(), "", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk", None, Node.ONLINE, time.time(), {}, "ucoin", "0.14.0", 0) self.network = Network.create(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 : "******" # Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ self.account = Account("testsakia", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", "john", [self.community], [self.wallet], [], self.identities_registry) self.password_asker = PasswordAskerDialog(self.account) self.password_asker.password = "******" self.password_asker.remember = True
def test_search_identity_found(self): mock = nice_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) API.reverse_url = pretender_reversed(mock.pretend_url) identities_tab = IdentitiesTabWidget(self.application) identities_tab.change_account(self.account, self.password_asker) identities_tab.change_community(self.community) future = asyncio.Future() def open_widget(): identities_tab.show() return future def close_dialog(): if identities_tab.isVisible(): identities_tab.close() future.set_result(True) @asyncio.coroutine def exec_test(): yield from asyncio.sleep(2) urls = [mock.get_request(i).url for i in range(0, 7)] self.assertTrue( "/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in urls, msg="Not found in {0}".format(urls), ) self.assertTrue( "/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in urls, msg="Not found in {0}".format(urls) ) self.assertTrue( "/wot/certified-by/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in urls, msg="Not found in {0}".format(urls), ) # 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(2) req = 7 self.assertEqual(mock.get_request(req).method, "GET") self.assertEqual( mock.get_request(req).url, "/blockchain/memberships/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" ) req += 1 self.assertEqual(identities_tab.table_identities.model().rowCount(), 1) yield from asyncio.sleep(2) self.lp.call_soon(close_dialog) asyncio.async(exec_test()) self.lp.call_later(15, close_dialog) self.lp.run_until_complete(open_widget()) mock.delete_mock()
def notest_txhistory_reload(self): mock = nice_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) received_list = [] self.lp.run_until_complete(self.wallet.caches[self.community.currency]. refresh(self.community, received_list)) self.assertEquals(len(received_list), 2) received_value = sum([r.metadata['amount'] for r in received_list]) self.assertEqual(received_value, 60) self.assertEqual(len(self.wallet.dividends(self.community)), 2) dividends_value = sum([ud['amount'] for ud in self.wallet.dividends(self.community)]) self.assertEqual(dividends_value, 15) mock.delete_mock()
def test_identity_certified_by(self): mock = nice_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) API.reverse_url = pretender_reversed(mock.pretend_url) identity = Identity("john", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", 1441130831, LocalState.COMPLETED, BlockchainState.VALIDATED) @asyncio.coroutine def exec_test(): certified = yield from identity.certifiers_of(self.identities_registry, self.community) self.assertEqual(len(certified), 1) self.assertEqual(certified[0]['identity'].uid, "doe") self.lp.run_until_complete(exec_test()) mock.delete_mock()
def test_identity_membership(self): mock = nice_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) API.reverse_url = pretender_reversed(mock.pretend_url) identity = Identity("john", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", 1441130831, LocalState.COMPLETED, BlockchainState.VALIDATED) @asyncio.coroutine def exec_test(): ms = yield from identity.membership(self.community) self.assertEqual(ms["blockNumber"], 0) self.assertEqual(ms["blockHash"], "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709") self.assertEqual(ms["membership"], "IN") self.assertEqual(ms["currency"], "test_currency") self.lp.run_until_complete(exec_test()) mock.delete_mock()
def test_connect_community_wrong_uid(self): mock = nice_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) API.reverse_url = pretender_reversed(mock.pretend_url) self.account.name = "wrong_uid" process_community = ProcessConfigureCommunity(self.application, self.account, None, self.password_asker) 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.assertNotEqual(mock.get_request(0), None) self.assertEqual(mock.get_request(0).method, 'GET') self.assertEqual(mock.get_request(0).url, '/network/peering') self.assertNotEqual(mock.get_request(1), None) self.assertEqual(mock.get_request(1).method, 'GET') self.assertEqual(mock.get_request(1).url, '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') self.assertEqual(process_community.label_error.text(), """Your pubkey or UID is different on the network. Yours : wrong_uid, the network : john""") process_community.close() self.lp.call_later(15, close_dialog) asyncio.async(exec_test()) self.lp.run_until_complete(process_community.async_exec()) self.assertEqual(process_community.result(), QDialog.Rejected) mock.delete_mock()
def test_connect_community_wrong_pubkey(self): mock = nice_blockchain.get_mock(self.lp) time.sleep(2) self.account.pubkey = "wrong_pubkey" process_community = ProcessConfigureCommunity(self.application, self.account, None, self.password_asker) def close_dialog(): if process_community.isVisible(): process_community.close() async def exec_test(): srv, port, url = await mock.create_server() self.addCleanup(srv.close) await 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(port) 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(), port) QTest.mouseClick(process_community.button_connect, Qt.LeftButton) await 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/wrong_pubkey') self.assertEqual(process_community.label_error.text(), """Your pubkey or UID is different on the network. Yours : wrong_pubkey, the network : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ""") await mock.close() process_community.close() self.lp.call_later(15, close_dialog) asyncio.ensure_future(exec_test()) self.lp.run_until_complete(process_community.async_exec()) self.assertEqual(process_community.result(), QDialog.Rejected)
def test_connect_community_wrong_pubkey(self): mock = nice_blockchain.get_mock(self.lp) time.sleep(2) self.account.pubkey = "wrong_pubkey" process_community = ProcessConfigureCommunity(self.application, self.account, None, self.password_asker) def close_dialog(): if process_community.isVisible(): process_community.close() async def exec_test(): srv, port, url = await mock.create_server() self.addCleanup(srv.close) await 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(port) 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(), port) QTest.mouseClick(process_community.button_connect, Qt.LeftButton) await 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/lookup/john') self.assertEqual(process_community.label_error.text(), """Your pubkey or UID is different on the network. Yours : wrong_pubkey, the network : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ""") process_community.close() self.lp.call_later(15, close_dialog) asyncio.ensure_future(exec_test()) self.lp.run_until_complete(process_community.async_exec()) self.assertEqual(process_community.result(), QDialog.Rejected)
def test_transfer_nice_community(self): mock = nice_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) API.reverse_url = pretender_reversed(mock.pretend_url) transfer_dialog = TransferMoneyDialog(self.application, self.account, self.password_asker, self.community, None) self.account.wallets[0].init_cache(self.application, self.community) @asyncio.coroutine def open_dialog(certification_dialog): result = yield from certification_dialog.async_exec() self.assertEqual(result, QDialog.Accepted) def close_dialog(): if transfer_dialog.isVisible(): transfer_dialog.close() @asyncio.coroutine def exec_test(): yield from asyncio.sleep(1) self.account.wallets[0].caches[self.community.currency].available_sources = yield from self.wallet.sources(self.community) QTest.mouseClick(transfer_dialog.radio_pubkey, Qt.LeftButton) QTest.keyClicks(transfer_dialog.edit_pubkey, "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") transfer_dialog.spinbox_amount.setValue(10) QTest.mouseClick(transfer_dialog.button_box.button(QDialogButtonBox.Ok), Qt.LeftButton) yield from asyncio.sleep(1) topWidgets = QApplication.topLevelWidgets() for w in topWidgets: if type(w) is QMessageBox: QTest.keyClick(w, Qt.Key_Enter) self.lp.call_later(15, close_dialog) asyncio.async(exec_test()) self.lp.run_until_complete(open_dialog(transfer_dialog)) mock.delete_mock()
def setUp(self): self.setUpQuamash() QLocale.setDefault(QLocale("en_GB")) self.identities_registry = IdentitiesRegistry() self.application = Application(self.qapplication, self.lp, self.identities_registry) self.application.preferences['notifications'] = False self.mock_nice_blockchain = nice_blockchain.get_mock(self.lp) self.node = Node(self.mock_nice_blockchain.peer(), "", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk", None, Node.ONLINE, time.time(), {}, "duniter", "0.14.0", 0, session=aiohttp.ClientSession()) self.network = Network.create(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 : "******" # Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ self.account = Account("testsakia", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", "john", [self.community], [self.wallet], [], self.identities_registry) self.password_asker = PasswordAskerDialog(self.account) self.password_asker.password = "******" self.password_asker.remember = True