From be336a67dacbe43a6868035d7c703b5459d8d5d3 Mon Sep 17 00:00:00 2001 From: inso <insomniak.fr@gmaiL.com> Date: Fri, 13 Jan 2017 07:49:03 +0100 Subject: [PATCH] Fix tests --- src/sakia/data/connectors/bma.py | 4 ++-- src/sakia/money/quantitative.py | 10 ++-------- .../functional/test_preferences_dialog.py | 2 -- .../technical/test_transactions_service.py | 4 ++-- .../tests/unit/money/test_quantitative.py | 14 ++++++++++++++ .../tests/unit/money/test_quantitative_zsum.py | 18 ++++++++++++------ src/sakia/tests/unit/money/test_relative.py | 18 +++++++++--------- .../tests/unit/money/test_relative_zsum.py | 18 +++++++++--------- 8 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/sakia/data/connectors/bma.py b/src/sakia/data/connectors/bma.py index a7e4ab63..b147cd1c 100644 --- a/src/sakia/data/connectors/bma.py +++ b/src/sakia/data/connectors/bma.py @@ -89,7 +89,7 @@ def _filter_blockchain_data(request, data): :return: """ include_only = { - bma.wot.lookup: "", + bma.wot.lookup: "/nomatch", bma.tx.history: "/history/[send|received]" } if request in include_only: @@ -122,7 +122,7 @@ class BmaConnector: nb_verification = min(max(1, 0.66*len(synced_nodes)), 10) try: # On chercher des reponses jusqu'a obtenir un nombre de noeuds d'accords de 1 à 66% des noeuds, max 10 - while max([len(ans) for ans in answers.values()] + [0]) <= nb_verification: + while max([len(nodes) for nodes in answers.values()] + [0]) <= nb_verification: node = next(nodes_generator) endpoints = filter_endpoints(request, [node]) tries = 0 diff --git a/src/sakia/money/quantitative.py b/src/sakia/money/quantitative.py index dd9419ed..1f4c06da 100644 --- a/src/sakia/money/quantitative.py +++ b/src/sakia/money/quantitative.py @@ -94,12 +94,9 @@ class Quantitative(BaseReferential): dividend, base = self._blockchain_processor.last_ud(self.currency) if show_base: localized_value = Quantitative.to_si(value, base) - else: - localized_value = QLocale().toString(float(value), 'f', 2) - - if show_base: prefix = Quantitative.base_str(base) else: + localized_value = QLocale().toString(float(value), 'f', 2) prefix = "" if units or show_base: @@ -116,12 +113,9 @@ class Quantitative(BaseReferential): dividend, base = self._blockchain_processor.last_ud(self.currency) if show_base: localized_value = Quantitative.to_si(value, base) - else: - localized_value = QLocale().toString(float(value), 'f', 2) - - if show_base: prefix = Quantitative.base_str(base) else: + localized_value = QLocale().toString(float(value), 'f', 2) prefix = "" if units or show_base: diff --git a/src/sakia/tests/functional/test_preferences_dialog.py b/src/sakia/tests/functional/test_preferences_dialog.py index 53dc447a..e9e69371 100644 --- a/src/sakia/tests/functional/test_preferences_dialog.py +++ b/src/sakia/tests/functional/test_preferences_dialog.py @@ -11,5 +11,3 @@ def test_preferences_default(application): assert preferences_dialog.checkbox_proxy.isChecked() == application.parameters.enable_proxy assert preferences_dialog.edit_proxy_address.text() == application.parameters.proxy_address assert preferences_dialog.spinbox_proxy_port.value() == application.parameters.proxy_port - assert preferences_dialog.checkbox_international_system.isChecked() == \ - application.parameters.international_system_of_units diff --git a/src/sakia/tests/technical/test_transactions_service.py b/src/sakia/tests/technical/test_transactions_service.py index 60adbe22..47bd10bd 100644 --- a/src/sakia/tests/technical/test_transactions_service.py +++ b/src/sakia/tests/technical/test_transactions_service.py @@ -16,7 +16,7 @@ async def test_send_tx_then_validate(application_with_one_connection, fake_serve fake_server.forge.forge_block() fake_server.forge.forge_block() new_blocks = fake_server.forge.blocks[-3:] - application_with_one_connection.transactions_services[fake_server.forge.currency].handle_new_blocks(new_blocks) + await application_with_one_connection.transactions_services[fake_server.forge.currency].handle_new_blocks(new_blocks) tx_after_parse = application_with_one_connection.transactions_services[fake_server.forge.currency].transfers(bob.key.pubkey) assert tx_after_parse[-1].state is Transaction.VALIDATED await fake_server.close() @@ -31,7 +31,7 @@ async def test_receive_tx(application_with_one_connection, fake_server, bob, ali fake_server.forge.forge_block() fake_server.forge.forge_block() new_blocks = fake_server.forge.blocks[-3:] - application_with_one_connection.transactions_services[fake_server.forge.currency].handle_new_blocks(new_blocks) + await application_with_one_connection.transactions_services[fake_server.forge.currency].handle_new_blocks(new_blocks) tx_after_parse = application_with_one_connection.transactions_services[fake_server.forge.currency].transfers(bob.key.pubkey) assert tx_after_parse[-1].state is Transaction.VALIDATED assert len(tx_before_send) + 1 == len(tx_after_parse) diff --git a/src/sakia/tests/unit/money/test_quantitative.py b/src/sakia/tests/unit/money/test_quantitative.py index bfb1578b..8ae1f3e4 100644 --- a/src/sakia/tests/unit/money/test_quantitative.py +++ b/src/sakia/tests/unit/money/test_quantitative.py @@ -32,6 +32,9 @@ def test_localized_no_si(application_with_one_connection, bob): def test_localized_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Quantitative(101010000, bob.currency, application_with_one_connection, None) + blockchain = application_with_one_connection.db.blockchains_repo.get_one(currency=bob.currency) + blockchain.last_ud_base = 3 + application_with_one_connection.db.blockchains_repo.update(blockchain) value = referential.localized(units=True, show_base=True) assert value == "1,010.10 x10³ TC" @@ -46,6 +49,9 @@ def test_localized_no_units_no_si(application_with_one_connection, bob): def test_localized_no_units_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Quantitative(101010000, bob.currency, application_with_one_connection, None) + blockchain = application_with_one_connection.db.blockchains_repo.get_one(currency=bob.currency) + blockchain.last_ud_base = 3 + application_with_one_connection.db.blockchains_repo.update(blockchain) value = referential.localized(units=False, show_base=True) assert value == "1,010.10 x10³" @@ -59,6 +65,10 @@ def test_diff_localized_no_si(application_with_one_connection, bob): def test_diff_localized_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Quantitative(101010000, bob.currency, application_with_one_connection, None) + blockchain = application_with_one_connection.db.blockchains_repo.get_one(currency=bob.currency) + blockchain.last_ud_base = 3 + application_with_one_connection.db.blockchains_repo.update(blockchain) + value = referential.diff_localized(units=True, show_base=True) assert value == "1,010.10 x10³ TC" @@ -69,8 +79,12 @@ def test_diff_localized_no_units_no_si(application_with_one_connection, bob): value = referential.diff_localized(units=False, show_base=False) assert value == "1,010,101.10" + def test_diff_localized_no_units_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Quantitative(10100000000, bob.currency, application_with_one_connection, None) + blockchain = application_with_one_connection.db.blockchains_repo.get_one(currency=bob.currency) + blockchain.last_ud_base = 6 + application_with_one_connection.db.blockchains_repo.update(blockchain) value = referential.diff_localized(units=False, show_base=True) assert value == "101.00 x10â¶" diff --git a/src/sakia/tests/unit/money/test_quantitative_zsum.py b/src/sakia/tests/unit/money/test_quantitative_zsum.py index 7f3931fe..2bbe25dc 100644 --- a/src/sakia/tests/unit/money/test_quantitative_zsum.py +++ b/src/sakia/tests/unit/money/test_quantitative_zsum.py @@ -32,21 +32,21 @@ def test_localized_no_si(application_with_one_connection, bob): def test_localized_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = QuantitativeZSum(110 * 1000, bob.currency, application_with_one_connection, None) - value = referential.localized(units=True, international_system=True) + value = referential.localized(units=True, show_base=True) assert value == "1,088.11 Q0 TC" def test_localized_no_units_no_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = QuantitativeZSum(110, bob.currency, application_with_one_connection, None) - value = referential.localized(units=False, international_system=False) + value = referential.localized(units=False, show_base=False) assert value == "-10.79" def test_localized_no_units_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = QuantitativeZSum(110 * 1000, bob.currency, application_with_one_connection, None) - value = referential.localized(units=False, international_system=True) + value = referential.localized(units=False, show_base=True) assert value == "1,088.11 Q0" @@ -59,19 +59,25 @@ def test_diff_localized_no_si(application_with_one_connection, bob): def test_diff_localized_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = QuantitativeZSum(101000000, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=True, international_system=True) + blockchain = application_with_one_connection.db.blockchains_repo.get_one(currency=bob.currency) + blockchain.last_ud_base = 3 + application_with_one_connection.db.blockchains_repo.update(blockchain) + value = referential.diff_localized(units=True, show_base=True) assert value == "1,010.00 x10³ TC" def test_diff_localized_no_units_no_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = QuantitativeZSum(101010110, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=False, international_system=False) + value = referential.diff_localized(units=False, show_base=False) assert value == "1,010,101.10" def test_diff_localized_no_units_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = QuantitativeZSum(101000000, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=False, international_system=True) + blockchain = application_with_one_connection.db.blockchains_repo.get_one(currency=bob.currency) + blockchain.last_ud_base = 3 + application_with_one_connection.db.blockchains_repo.update(blockchain) + value = referential.diff_localized(units=False, show_base=True) assert value == "1,010.00 x10³" diff --git a/src/sakia/tests/unit/money/test_relative.py b/src/sakia/tests/unit/money/test_relative.py index c012c2e8..0bb50bf2 100644 --- a/src/sakia/tests/unit/money/test_relative.py +++ b/src/sakia/tests/unit/money/test_relative.py @@ -34,22 +34,22 @@ def test_localized_no_si(application_with_one_connection, bob): def test_localized_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Relative(1, bob.currency, application_with_one_connection, None) - value = referential.localized(units=True, international_system=True) - assert value == "4.291845 x10â»Â³ UD TC" + value = referential.localized(units=True, show_base=True) + assert value == "0.004292 UD TC" def test_localized_no_units_no_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Relative(11, bob.currency, application_with_one_connection, None) - value = referential.localized(units=False, international_system=False) + value = referential.localized(units=False, show_base=False) assert value == "0.047210" def test_localized_no_units_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Relative(1, bob.currency, application_with_one_connection, None) - value = referential.localized(units=False, international_system=True) - assert value == "4.291845 x10â»Â³ UD" + value = referential.localized(units=False, show_base=True) + assert value == "0.004292" def test_diff_localized_no_si(application_with_one_connection, bob): @@ -62,19 +62,19 @@ def test_diff_localized_no_si(application_with_one_connection, bob): def test_diff_localized_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Relative(1, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=True, international_system=True) + value = referential.diff_localized(units=True, show_base=True) assert value, "9.090909 x10â» UD TC" def test_diff_localized_no_units_no_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Relative(1, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=False, international_system=False) + value = referential.diff_localized(units=False, show_base=False) assert value == "0.004292" def test_diff_localized_no_units_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Relative(1, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=False, international_system=True) - assert value == "4.291845 x10â»Â³ UD" + value = referential.diff_localized(units=False, show_base=True) + assert value == "0.004292" diff --git a/src/sakia/tests/unit/money/test_relative_zsum.py b/src/sakia/tests/unit/money/test_relative_zsum.py index 245b679c..e25b410d 100644 --- a/src/sakia/tests/unit/money/test_relative_zsum.py +++ b/src/sakia/tests/unit/money/test_relative_zsum.py @@ -34,7 +34,7 @@ def test_localized_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) - value = referential.localized(units=True, international_system=True) + value = referential.localized(units=True, show_base=True) assert value == "-4.040487 R0 TC" @@ -42,7 +42,7 @@ def test_localized_no_units_no_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = RelativeZSum(110, bob.currency, application_with_one_connection, None) - value = referential.localized(units=False, international_system=False) + value = referential.localized(units=False, show_base=False) assert value == "-3.526336" @@ -50,8 +50,8 @@ def test_localized_no_units_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) - value = referential.localized(units=False, international_system=True) - assert value == "-4.040487 R0" + value = referential.localized(units=False, show_base=True) + assert value == "-4.040487" def test_diff_localized_no_si(application_with_one_connection, bob): @@ -64,19 +64,19 @@ def test_diff_localized_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=True, international_system=True) - assert value == "4.291845 x10â»Â³ UD TC" + value = referential.diff_localized(units=True, show_base=True) + assert value == "0.004292 UD TC" def test_diff_localized_no_units_no_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = RelativeZSum(90, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=False, international_system=False) + value = referential.diff_localized(units=False, show_base=False) assert value == "0.386266" def test_diff_localized_no_units_with_si(application_with_one_connection, bob): referential = RelativeZSum(90, bob.currency, application_with_one_connection, None) - value = referential.diff_localized(units=False, international_system=True) - assert value == "0.39 UD" + value = referential.diff_localized(units=False, show_base=True) + assert value == "0.39" -- GitLab