From b7c268e99aeedba869875497c6a9d6929bc33ea0 Mon Sep 17 00:00:00 2001 From: Insoleet <insomniak.fr@gmail.com> Date: Mon, 7 Sep 2015 11:50:41 +0200 Subject: [PATCH] Force IdentitiesRegistry in test to start empty --- .../tests/certification/test_certification.py | 2 +- .../identities_tab/test_identities_table.py | 31 +++++++-- .../tests/mocks/bma/init_new_community.py | 2 +- .../tests/mocks/bma/new_blockchain.py | 2 +- .../tests/mocks/bma/nice_blockchain.py | 64 ++++++++++++++++++- .../process_cfg_account/test_add_account.py | 2 +- .../test_add_community.py | 2 +- 7 files changed, 92 insertions(+), 13 deletions(-) diff --git a/src/cutecoin/tests/certification/test_certification.py b/src/cutecoin/tests/certification/test_certification.py index af9ef739..2f8870d4 100644 --- a/src/cutecoin/tests/certification/test_certification.py +++ b/src/cutecoin/tests/certification/test_certification.py @@ -29,7 +29,7 @@ class TestCertificationDialog(unittest.TestCase): QLocale.setDefault(QLocale("en_GB")) self.lp = quamash.QEventLoop(self.qapplication) asyncio.set_event_loop(self.lp) - self.identities_registry = IdentitiesRegistry() + self.identities_registry = IdentitiesRegistry({}) self.application = Application(self.qapplication, self.lp, self.network_manager, self.identities_registry) self.application.preferences['notifications'] = False diff --git a/src/cutecoin/tests/identities_tab/test_identities_table.py b/src/cutecoin/tests/identities_tab/test_identities_table.py index 98cb718d..2e36df4c 100644 --- a/src/cutecoin/tests/identities_tab/test_identities_table.py +++ b/src/cutecoin/tests/identities_tab/test_identities_table.py @@ -29,7 +29,7 @@ class TestIdentitiesTable(unittest.TestCase): QLocale.setDefault(QLocale("en_GB")) self.lp = quamash.QEventLoop(self.qapplication) asyncio.set_event_loop(self.lp) - self.identities_registry = IdentitiesRegistry() + self.identities_registry = IdentitiesRegistry({}) self.application = Application(self.qapplication, self.lp, self.network_manager, self.identities_registry) self.application.preferences['notifications'] = False @@ -65,9 +65,21 @@ class TestIdentitiesTable(unittest.TestCase): mock = nice_blockchain.get_mock() logging.debug(mock.pretend_url) self.network_manager.set_mock_path(mock.pretend_url) + future = asyncio.Future() identities_tab = IdentitiesTabWidget(self.application) - identities_tab.change_account(self.account) - identities_tab.change_community(self.community) + + def start_widget(): + identities_tab.change_account(self.account) + identities_tab.change_community(self.community) + identities_tab.show() + return future + + @asyncio.coroutine + def close_widget(): + yield from asyncio.sleep(15) + if identities_tab.isVisible(): + identities_tab.close() + future.set_result(False) @asyncio.coroutine def exec_test(): @@ -81,8 +93,8 @@ class TestIdentitiesTable(unittest.TestCase): QTest.keyClicks(identities_tab.edit_textsearch, "doe") QTest.mouseClick(identities_tab.button_search, Qt.LeftButton) - yield from asyncio.sleep(3) - self.assertEqual(mock.get_request(4).method, 'GET') + 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') @@ -90,10 +102,15 @@ class TestIdentitiesTable(unittest.TestCase): '/wot/certifiers-of/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn') self.assertEqual(mock.get_request(6).method, 'GET') self.assertEqual(mock.get_request(6).url, - '/wot/lookup/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn') + '/wot/lookup/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn')""" self.assertEqual(identities_tab.table_identities.model().rowCount(), 1) + identities_tab.close() + future.set_result(True) - self.lp.run_until_complete(exec_test()) + asyncio.async(exec_test()) + asyncio.async(close_widget()) + self.lp.run_until_complete(start_widget()) + self.assertTrue(future.result()) if __name__ == '__main__': logging.basicConfig( stream=sys.stderr ) diff --git a/src/cutecoin/tests/mocks/bma/init_new_community.py b/src/cutecoin/tests/mocks/bma/init_new_community.py index cb4700e3..7ee75076 100644 --- a/src/cutecoin/tests/mocks/bma/init_new_community.py +++ b/src/cutecoin/tests/mocks/bma/init_new_community.py @@ -76,7 +76,7 @@ bma_lookup_test_patrick = b"""{ def get_mock(): - mock = HTTPMock('127.0.0.1', 50000) + mock = HTTPMock('127.0.0.1', 50000, timeout=FOREVER) mock.when('GET /network/peering')\ .reply(body=bma_peering, diff --git a/src/cutecoin/tests/mocks/bma/new_blockchain.py b/src/cutecoin/tests/mocks/bma/new_blockchain.py index fe43d5d2..1c9e02e8 100644 --- a/src/cutecoin/tests/mocks/bma/new_blockchain.py +++ b/src/cutecoin/tests/mocks/bma/new_blockchain.py @@ -30,7 +30,7 @@ bma_wot_add = b"""{ }""" def get_mock(): - mock = HTTPMock('127.0.0.1', 50000) + mock = HTTPMock('127.0.0.1', 50000, timeout=FOREVER) mock.when('GET /network/peering')\ .reply(body=bma_peering, diff --git a/src/cutecoin/tests/mocks/bma/nice_blockchain.py b/src/cutecoin/tests/mocks/bma/nice_blockchain.py index 04bca2ed..bf9962bf 100644 --- a/src/cutecoin/tests/mocks/bma/nice_blockchain.py +++ b/src/cutecoin/tests/mocks/bma/nice_blockchain.py @@ -70,15 +70,66 @@ bma_certified_by_john = b"""{ ] }""" +bma_parameters = b"""{ + "currency": "test_currency", + "c": 0.1, + "dt": 86400, + "ud0": 100, + "sigDelay": 604800, + "sigValidity": 2629800, + "sigQty": 3, + "sigWoT": 3, + "msValidity": 2629800, + "stepMax": 3, + "medianTimeBlocks": 11, + "avgGenTime": 600, + "dtDiffEval": 20, + "blocksRot": 144, + "percentRot": 0.67 +}""" + +bma_blockchain_current = b"""{ + "version": 1, + "nonce": 6909, + "number": 3, + "powMin": 4, + "time": 1441618206, + "medianTime": 1441614759, + "membersCount": 20, + "monetaryMass": 11711349901120, + "currency": "test_currency", + "issuer": "EPs9qX7HmCDy6ptUoMLpTzbh9toHu4au488pBTU9DN6y", + "signature": "kz/34w1cG+8tYacuPXf3FPmsFwrvtWkwp1POLJuX1P0zYaB9Tuu7iyYJzMQS0Xa3vwuWRqfz+fgyoCGnBjBLBQ==", + "hash": "0000CB4E9CCDE6F579135331C97F13903E8B6E21", + "parameters": "", + "previousHash": "00003BDA844D77EEE7CF32A6C3C87F2ACBFCFCBB", + "previousIssuer": "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk", + "dividend": null, + "membersChanges": [ ], + "identities": [ ], + "joiners": [ ], + "actives": [ ], + "leavers": [ ], + "excluded": [ ], + "certifications": [ ], + "transactions": [ ], + "raw": "Version: 1\nType: Block\nCurrency: meta_brouzouf\nNonce: 6909\nNumber: 30898\nPoWMin: 4\nTime: 1441618206\nMedianTime: 1441614759\nIssuer: EPs9qX7HmCDy6ptUoMLpTzbh9toHu4au488pBTU9DN6y\nPreviousHash: 00003BDA844D77EEE7CF32A6C3C87F2ACBFCFCBB\nPreviousIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\nMembersCount: 20\nIdentities:\nJoiners:\nActives:\nLeavers:\nExcluded:\nCertifications:\nTransactions:\n" +}""" def get_mock(): - mock = HTTPMock('127.0.0.1', 50000) + mock = HTTPMock('127.0.0.1', 50000, timeout=FOREVER) mock.when('GET /network/peering')\ .reply(body=bma_peering, times=FOREVER, headers={'Content-Type': 'application/json'}) + mock.when('GET /blockchain/parameters')\ + .reply(body=bma_parameters, + status=200, + times=FOREVER, + headers={'Content-Type': 'application/json'}) + mock.when('GET /wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ')\ .reply(body=bma_certifiers_of_john, status=200, @@ -115,5 +166,16 @@ def get_mock(): times=FOREVER, headers={'Content-Type': 'application/json'}) + mock.when('GET /wot/certifiers-of/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn')\ + .reply(body=b"No member matching this pubkey or uid", + status=404, + times=FOREVER, + headers={'Content-Type': 'application/json'}) + + mock.when('GET /blockchain/memberships/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn')\ + .reply(body=b"No member matching this pubkey or uid", + status=404, + times=FOREVER, + headers={'Content-Type': 'application/json'}) return mock diff --git a/src/cutecoin/tests/process_cfg_account/test_add_account.py b/src/cutecoin/tests/process_cfg_account/test_add_account.py index a34e07d6..cc8f6593 100644 --- a/src/cutecoin/tests/process_cfg_account/test_add_account.py +++ b/src/cutecoin/tests/process_cfg_account/test_add_account.py @@ -23,7 +23,7 @@ class ProcessAddCommunity(unittest.TestCase): QLocale.setDefault(QLocale("en_GB")) self.lp = quamash.QEventLoop(self.qapplication) asyncio.set_event_loop(self.lp) - self.identities_registry = IdentitiesRegistry() + self.identities_registry = IdentitiesRegistry({}) self.application = Application(self.qapplication, self.lp, self.network_manager, self.identities_registry) self.application.preferences['notifications'] = False 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 f08df4be..1c70ef50 100644 --- a/src/cutecoin/tests/process_cfg_community/test_add_community.py +++ b/src/cutecoin/tests/process_cfg_community/test_add_community.py @@ -23,7 +23,7 @@ class ProcessAddCommunity(unittest.TestCase): QLocale.setDefault(QLocale("en_GB")) self.lp = quamash.QEventLoop(self.qapplication) asyncio.set_event_loop(self.lp) - self.identities_registry = IdentitiesRegistry() + self.identities_registry = IdentitiesRegistry({}) self.application = Application(self.qapplication, self.lp, self.network_manager, self.identities_registry) self.application.preferences['notifications'] = False -- GitLab