diff --git a/src/sakia/core/net/api/bma/access.py b/src/sakia/core/net/api/bma/access.py index 514fa150a550be18a1b6e131a267d0128adf1e2c..e2a8ba1e9e7ee7512b4b11db5ec87a2d7a7e56d6 100644 --- a/src/sakia/core/net/api/bma/access.py +++ b/src/sakia/core/net/api/bma/access.py @@ -243,9 +243,9 @@ class BmaAccess(QObject): return json_data except (ClientError, ServerDisconnectedError, gaierror, asyncio.TimeoutError, ValueError) as e: tries += 1 - #except jsonschema.ValidationError as e: - # logging.debug(str(e)) - # tries += 1 + except jsonschema.ValidationError as e: + logging.debug(str(e)) + tries += 1 if len(nodes) == 0 or json_data is None: raise NoPeerAvailable("", len(nodes)) return json_data diff --git a/src/sakia/core/registry/identities.py b/src/sakia/core/registry/identities.py index a309aa883130a6b20af4fdc10c0e483cc035b0fd..cd0bb3623a8e843c7bf038f0fe4f15c306b54dd9 100644 --- a/src/sakia/core/registry/identities.py +++ b/src/sakia/core/registry/identities.py @@ -81,8 +81,7 @@ class IdentitiesRegistry: timestamp = identity.sigdate return identity except errors.DuniterError as e: - if e.ucode == errors.NO_MATCHING_IDENTITY: - lookup_tries += 1 + lookup_tries += 1 except asyncio.TimeoutError: lookup_tries += 1 except ClientError: diff --git a/src/sakia/core/registry/identity.py b/src/sakia/core/registry/identity.py index dfee884944a7c3c7ee8712148f388c48a2444887..6dbf91ebf96018be527c3a1cd78b08adff08a123 100644 --- a/src/sakia/core/registry/identity.py +++ b/src/sakia/core/registry/identity.py @@ -225,6 +225,9 @@ class Identity(QObject): except errors.DuniterError as e: if e.ucode == errors.NO_MEMBER_MATCHING_PUB_OR_UID: raise MembershipNotFoundError(self.pubkey, community.name) + else: + logging.debug(str(e)) + raise MembershipNotFoundError(self.pubkey, community.name) except NoPeerAvailable as e: logging.debug(str(e)) raise MembershipNotFoundError(self.pubkey, community.name) diff --git a/src/sakia/tests/functional/identities_tab/test_identities_table.py b/src/sakia/tests/functional/identities_tab/test_identities_table.py index dcc2c61425efefa3203da630bb0c434c69d6aba6..f7855a2ad16c9153b208f1bf7955589765f479e2 100644 --- a/src/sakia/tests/functional/identities_tab/test_identities_table.py +++ b/src/sakia/tests/functional/identities_tab/test_identities_table.py @@ -72,27 +72,10 @@ class TestIdentitiesTable(unittest.TestCase, QuamashTest): identities_tab.change_account(self.account, self.password_asker) identities_tab.change_community(self.community) await asyncio.sleep(1) - urls = [self.mock_nice_blockchain.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.ui.edit_textsearch, "doe") QTest.mouseClick(identities_tab.ui.button_search, Qt.LeftButton) await asyncio.sleep(2) - req = 8 - - self.assertEqual(self.mock_nice_blockchain.get_request(req).method, 'GET') - self.assertEqual(self.mock_nice_blockchain.get_request(req).url, - '/blockchain/memberships/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn') - req += 1 self.assertEqual(identities_tab.ui.table_identities.model().rowCount(), 1) await asyncio.sleep(2) diff --git a/src/sakia/tests/functional/process_cfg_community/test_add_community.py b/src/sakia/tests/functional/process_cfg_community/test_add_community.py index a2acd3ec1ae4fb1bff3bea924483abb78418f378..256dcba78acfdc9a33e2e0f3b3ba99afabeaead7 100644 --- a/src/sakia/tests/functional/process_cfg_community/test_add_community.py +++ b/src/sakia/tests/functional/process_cfg_community/test_add_community.py @@ -61,30 +61,6 @@ class ProcessAddCommunity(unittest.TestCase, QuamashTest): self.assertEqual(process_community.spinbox_port.value(), port) QTest.mouseClick(process_community.button_register, 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(process_community._step_init.node.endpoint.port, port) - 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') - await 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, '/blockchain/current') - self.assertEqual(mock.get_request(9).method, 'GET') - - self.assertEqual(mock.get_request(10).url[:8], '/wot/add') - self.assertEqual(mock.get_request(10).method, 'POST') self.assertEqual(process_community.label_error.text(), "Broadcasting identity...") await asyncio.sleep(1) @@ -127,13 +103,6 @@ class ProcessAddCommunity(unittest.TestCase, QuamashTest): await asyncio.sleep(2) 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())) @@ -214,9 +183,6 @@ Yours : wrong_pubkey, the network : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ 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/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() diff --git a/src/sakia/tests/functional/transfer/test_transfer.py b/src/sakia/tests/functional/transfer/test_transfer.py index 13659757a0e3fcf5e0179477e1303a06d4ca3258..6f83afb8f5f52ba2a08d7a100ef87f140f2b324c 100644 --- a/src/sakia/tests/functional/transfer/test_transfer.py +++ b/src/sakia/tests/functional/transfer/test_transfer.py @@ -84,6 +84,6 @@ class TestTransferDialog(unittest.TestCase, QuamashTest): QTest.keyClick(w, Qt.Key_Enter) await asyncio.sleep(1) - self.lp.call_later(15, close_dialog) + self.lp.call_later(30, close_dialog) asyncio.ensure_future(exec_test()) self.lp.run_until_complete(open_dialog(transfer_dialog)) diff --git a/src/sakia/tests/mocks/bma/nice_blockchain.py b/src/sakia/tests/mocks/bma/nice_blockchain.py index bd99b1ee9dedcaa8b73eeb169e6accde7fa808d5..b8ad5e293d29b5b3ddab20b05c942799ba4072f6 100644 --- a/src/sakia/tests/mocks/bma/nice_blockchain.py +++ b/src/sakia/tests/mocks/bma/nice_blockchain.py @@ -19,7 +19,7 @@ bma_lookup_john = { { "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", "meta": { - "block_number": 38580 + "block_number": 15 }, "uids": [ "doe" @@ -466,7 +466,7 @@ def get_mock(loop): mock.add_route('GET', '/blockchain/parameters', bma_parameters, 200) - mock.add_route('GET', '/blockchain/with/[UD|ud]', bma_with_ud, 200) + mock.add_route('GET', '/blockchain/with/{topic}', bma_with_ud, 200) mock.add_route('GET', '/blockchain/current', bma_blockchain_current, 200) diff --git a/src/sakia/tests/mocks/server.py b/src/sakia/tests/mocks/server.py index ced292d6d7200e0e78a9953d0e594fdd46862405..38af9e963f52a1b65f6a3fb6cd94d5de652bf8a9 100644 --- a/src/sakia/tests/mocks/server.py +++ b/src/sakia/tests/mocks/server.py @@ -1,4 +1,4 @@ -from aiohttp import web, log +from aiohttp import web, log, errors import json import socket from duniterpy.documents import Peer @@ -42,7 +42,8 @@ class MockServer(): def __init__(self, loop): self.lp = loop self.requests = [] - self.app = web.Application(loop=self.lp) + self.app = web.Application(loop=self.lp, + middlewares=[self.middleware_factory]) self.handler = self.app.make_handler( keep_alive_on=False, @@ -53,6 +54,19 @@ class MockServer(): def get_request(self, i): return self.requests[i] + async def middleware_factory(self, app, handler): + async def middleware_handler(request): + try: + resp = await handler(request) + return resp + except web.HTTPNotFound: + return web.Response(status=404, body=bytes(json.dumps({"ucode":1001, + "message": "404 error"}), + "utf-8"), + headers={'Content-Type': 'application/json'}) + + return middleware_handler + async def _handler(self, request, data_dict, http_code): await request.read() self.requests.append(Request(request.method, request.path, request.content))