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 test_certification_init_community(self): mock = init_new_community.get_mock() time.sleep(2) logging.debug(mock.pretend_url) API.reverse_url = pretender_reversed(mock.pretend_url) certification_dialog = CertificationDialog(self.application, self.account, self.password_asker) @asyncio.coroutine def open_dialog(certification_dialog): result = yield from certification_dialog.async_exec() self.assertEqual(result, QDialog.Accepted) def close_dialog(): if certification_dialog.isVisible(): certification_dialog.close() @asyncio.coroutine def exec_test(): yield from asyncio.sleep(1) QTest.mouseClick(certification_dialog.radio_pubkey, Qt.LeftButton) QTest.keyClicks(certification_dialog.edit_pubkey, "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") QTest.mouseClick(certification_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(certification_dialog)) mock.delete_mock()
def test_register_community_empty_blockchain(self): mock = new_blockchain.get_mock() time.sleep(2) logging.debug(mock.pretend_url) API.reverse_url = pretender_reversed(mock.pretend_url) 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_register, 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') yield from asyncio.sleep(5) self.assertEqual(mock.get_request(5).method, 'GET') self.assertEqual(mock.get_request(5).url, '/wot/certifiers-of/john') for i in range(6, 9): self.assertEqual(mock.get_request(i).method, 'GET') self.assertEqual(mock.get_request(i).url, '/wot/lookup/john') self.assertEqual(mock.get_request(9).url[:8], '/wot/add') self.assertEqual(mock.get_request(9).method, 'POST') self.assertEqual(process_community.label_error.text(), "Broadcasting identity...") yield from asyncio.sleep(1) 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(process_community.async_exec()) self.assertEqual(process_community.result(), QDialog.Accepted) mock.delete_mock()
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 test_identity_corrupted_membership(self): mock = corrupted.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(): with self.assertRaises(MembershipNotFoundError): yield from identity.membership(self.community) self.lp.run_until_complete(exec_test()) 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_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()