From 428cbd2296c3191136cf91bf9d1fc449643218ca Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Sat, 5 Sep 2015 18:51:02 +0200 Subject: [PATCH] Working on tests, stuck due to a quamash bug --- src/cutecoin/core/account.py | 2 +- src/cutecoin/core/net/api/bma/__init__.py | 10 +++++++++- src/cutecoin/core/registry/identities.py | 4 +++- src/cutecoin/gui/process_cfg_community.py | 12 +++++++++++- src/cutecoin/tests/mocks/access_manager.py | 6 ++++-- .../process_cfg_community/test_add_community.py | 9 +++++---- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index b26ad98b..3491a551 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -298,7 +298,7 @@ class Account(QObject): key = SigningKey(self.salt, password) selfcert.sign([key]) logging.debug("Key publish : {0}".format(selfcert.signed_raw())) - replies = community.broadcast(qtbma.wot.Add, {}, {'pubkey': self.pubkey, + replies = community.bma_access.broadcast(qtbma.wot.Add, {}, {'pubkey': self.pubkey, 'self_': selfcert.signed_raw(), 'other': []}) for r in replies: diff --git a/src/cutecoin/core/net/api/bma/__init__.py b/src/cutecoin/core/net/api/bma/__init__.py index 00af271a..9e6132c0 100644 --- a/src/cutecoin/core/net/api/bma/__init__.py +++ b/src/cutecoin/core/net/api/bma/__init__.py @@ -6,6 +6,7 @@ from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply from PyQt5.QtCore import QUrl, QUrlQuery, QTimer, QObject, pyqtSlot import logging import asyncio +import json logger = logging.getLogger("ucoin") @@ -126,7 +127,14 @@ class API(object): logging.debug("POST : {0}".format(kwargs)) post_data = QUrlQuery() for k, v in kwargs.items(): - post_data.addQueryItem(k.replace("+", "%2b"), v.replace("+", "%2b")) + if type(k) is str: + k = k.replace("+", "%2b") + if type(v) is str: + v = v.replace("+", "%2b") + else: + v = json.dumps(v) + v = v.replace("+", "%2b") + post_data.addQueryItem(k, v) url = QUrl(self.reverse_url(path)) url.setQuery(post_data) diff --git a/src/cutecoin/core/registry/identities.py b/src/cutecoin/core/registry/identities.py index 65657dee..3e733a05 100644 --- a/src/cutecoin/core/registry/identities.py +++ b/src/cutecoin/core/registry/identities.py @@ -70,7 +70,9 @@ class IdentitiesRegistry: def handle_certifiersof_reply(reply, tries=0): err = reply.error() # https://github.com/ucoin-io/ucoin/issues/146 - if reply.error() == QNetworkReply.NoError or reply.error() == QNetworkReply.ProtocolInvalidOperationError: + if reply.error() == QNetworkReply.NoError \ + or reply.error() == QNetworkReply.ContentNotFoundError \ + or reply.error() == QNetworkReply.ProtocolInvalidOperationError: status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) if status_code == 200: strdata = bytes(reply.readAll()).decode('utf-8') diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py index 09395217..9c9edbc1 100644 --- a/src/cutecoin/gui/process_cfg_community.py +++ b/src/cutecoin/gui/process_cfg_community.py @@ -211,13 +211,23 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): QApplication.restoreOverrideCursor() self.add_community_and_close() + @pyqtSlot(int, str) + def handle_broadcast(self, error_code, text): + if self.app.preferences['notifications']: + toast.display(self.tr("UID broadcast"), self.tr("Identity broadcasted to the network")) + else: + QMessageBox.information(self, self.tr("UID broadcast"), self.tr("Identity broadcasted to the network")) + self.account.certification_broadcasted.disconnect() + self.account.broadcast_error.disconnect(self.handle_error) + QApplication.restoreOverrideCursor() + @pyqtSlot(int, str) def handle_error(self, error_code, text): if self.app.preferences['notifications']: toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) else: QMessageBox.critical(self, self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) - self.account.certification_broadcasted.disconnect() + self.account.selfcert_broadcasted.disconnect() self.account.broadcast_error.disconnect(self.handle_error) QApplication.restoreOverrideCursor() diff --git a/src/cutecoin/tests/mocks/access_manager.py b/src/cutecoin/tests/mocks/access_manager.py index 9b4521b0..75490984 100644 --- a/src/cutecoin/tests/mocks/access_manager.py +++ b/src/cutecoin/tests/mocks/access_manager.py @@ -19,7 +19,9 @@ class MockNetworkAccessManager(QNetworkAccessManager): return super().get(request) def post(self, request, post_data): - path = request.url().path() + url = request.url() + path = url.path() path = self.mock_path + path - request.setPath(path) + url.setPath(path) + request.setUrl(url) return super().post(request, post_data) \ No newline at end of file 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 692878c0..6b7b588c 100644 --- a/src/cutecoin/tests/process_cfg_community/test_add_community.py +++ b/src/cutecoin/tests/process_cfg_community/test_add_community.py @@ -5,7 +5,7 @@ import asyncio import quamash import logging import time -from PyQt5.QtWidgets import QMenu, QApplication +from PyQt5.QtWidgets import QMessageBox from PyQt5.QtCore import QLocale, Qt from PyQt5.QtTest import QTest from cutecoin.tests.mocks.bma import new_blockchain @@ -71,9 +71,10 @@ class ProcessAddCommunity(unittest.TestCase): self.assertEqual(mock.get_request(1).url, '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') self.assertEqual(mock.get_request(2).method, 'GET') self.assertEqual(mock.get_request(2).url, '/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') - for widget in QApplication.topLevelWidgets(): - if isinstance(widget, PyQt5.QtWidgets.QMessageBox): - QTest.keyClick(widget, Qt.KeyEnter) + for widget in quamash.QApplication.topLevelWidgets(): + if isinstance(widget, QMessageBox): + QTest.mouseClick(widget.button(QMessageBox.Yes), Qt.LeftButton) + yield from asyncio.sleep(3) self.lp.run_until_complete(asyncio.wait_for(exec_test(), timeout=10)) -- GitLab