From a3bcd659e3ebcfc627b36df3d822d3352eaa3103 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Mon, 17 Oct 2022 18:55:14 +0200 Subject: [PATCH] (cli) Rename commands name (#430) Adapt tests --- silkaj/auth.py | 2 +- silkaj/blockchain/difficulty.py | 2 +- silkaj/wot/certification.py | 2 +- silkaj/wot/wot.py | 2 +- tests/blockchain/test_verify.py | 4 +++- tests/money/test_tools.py | 4 +++- tests/money/test_transfer.py | 2 +- tests/money/test_transfer_cli.py | 33 +++++++++++++++++--------------- tests/test_cli.py | 2 +- tests/test_end_to_end.py | 16 +++++++++++----- tests/wot/test_membership.py | 2 +- tests/wot/test_revocation.py | 14 +++++++------- 12 files changed, 49 insertions(+), 36 deletions(-) diff --git a/silkaj/auth.py b/silkaj/auth.py index f038f067..ffe766d7 100644 --- a/silkaj/auth.py +++ b/silkaj/auth.py @@ -51,7 +51,7 @@ def has_auth_method(ctx: Context) -> bool: ) -@command("authfile", help="Generate authentication file") +@command("authentication", help="Generate authentication file") @option("--file", default="authfile", show_default=True, help="Path file") def generate_auth_file(file: str) -> None: key = auth_method() diff --git a/silkaj/blockchain/difficulty.py b/silkaj/blockchain/difficulty.py index 09861647..bfcea792 100644 --- a/silkaj/blockchain/difficulty.py +++ b/silkaj/blockchain/difficulty.py @@ -30,7 +30,7 @@ from silkaj.constants import ALL @click.command( - "diffi", + "difficulty", help="Display the current Proof of Work difficulty level to generate the next block", ) def difficulties() -> None: diff --git a/silkaj/wot/certification.py b/silkaj/wot/certification.py index 4cfa31bf..4d9c848a 100644 --- a/silkaj/wot/certification.py +++ b/silkaj/wot/certification.py @@ -33,7 +33,7 @@ from silkaj.public_key import gen_pubkey_checksum, is_pubkey_and_check from silkaj.wot import tools as wot_tools -@click.command("cert", help="Send certification") +@click.command("certification", help="Send certification") @click.argument("uid_pubkey_to_certify") @click.pass_context def send_certification(ctx: click.Context, uid_pubkey_to_certify: str) -> None: diff --git a/silkaj/wot/wot.py b/silkaj/wot/wot.py index 887dca2c..1eb6be7a 100644 --- a/silkaj/wot/wot.py +++ b/silkaj/wot/wot.py @@ -45,7 +45,7 @@ def get_sent_certifications( @click.command( - "wot", + "status", help="Check received and sent certifications and \ consult the membership status of any given identity", ) diff --git a/tests/blockchain/test_verify.py b/tests/blockchain/test_verify.py index 3de8f20b..63b2d48d 100644 --- a/tests/blockchain/test_verify.py +++ b/tests/blockchain/test_verify.py @@ -67,7 +67,9 @@ def test_check_passed_blocks_range(from_block, to_block, capsys, monkeypatch): ) def test_verify_blocks_signatures(from_block, to_block, monkeypatch): monkeypatch.setattr(bma.blockchain, "current", current) - result = CliRunner().invoke(cli.cli, ["verify", str(from_block), str(to_block)]) + result = CliRunner().invoke( + cli.cli, ["blockchain", "verify", str(from_block), str(to_block)] + ) assert result.exit_code == SUCCESS_EXIT_STATUS if to_block == 0: to_block = HEAD_BLOCK diff --git a/tests/money/test_tools.py b/tests/money/test_tools.py index d282d6ef..a31cfb83 100644 --- a/tests/money/test_tools.py +++ b/tests/money/test_tools.py @@ -160,6 +160,7 @@ def test_balance_errors(): result = CliRunner().invoke( cli, [ + "money", "balance", "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", @@ -173,6 +174,7 @@ def test_balance_errors(): result = CliRunner().invoke( cli, [ + "money", "balance", "B", ], @@ -181,6 +183,6 @@ def test_balance_errors(): assert result.exit_code == FAILURE_EXIT_STATUS # no pubkey - result = CliRunner().invoke(cli, ["balance"]) + result = CliRunner().invoke(cli, ["money", "balance"]) assert "You should specify one or many pubkeys" in result.output assert result.exit_code == FAILURE_EXIT_STATUS diff --git a/tests/money/test_transfer.py b/tests/money/test_transfer.py index 7ae642fb..a3ef4eeb 100644 --- a/tests/money/test_transfer.py +++ b/tests/money/test_transfer.py @@ -1060,7 +1060,7 @@ def compute_test_amounts(amounts, mult): def construct_args( amounts, amountsud, allsources, recipients, comment, outputbackchange, yes ): - args_list = ["transfer"] + args_list = ["money", "transfer"] if yes: args_list.append("--yes") if amounts: diff --git a/tests/money/test_transfer_cli.py b/tests/money/test_transfer_cli.py index 33d6b488..ab731e52 100644 --- a/tests/money/test_transfer_cli.py +++ b/tests/money/test_transfer_cli.py @@ -120,44 +120,47 @@ def test_transaction_amount_errors( assert pytest_exit.type == SystemExit +TRANSFER = ["money", "transfer"] + + def test_tx_passed_amount_cli(): # One option - result = CliRunner().invoke(cli, ["transfer", "--amount", "1"]) + result = CliRunner().invoke(cli, TRANSFER + ["--amount", "1"]) assert "Error: A recipient should be passed\n" in result.output assert result.exit_code == 1 - result = CliRunner().invoke(cli, ["transfer", "--amountUD", "1"]) + result = CliRunner().invoke(cli, TRANSFER + ["--amountUD", "1"]) assert "Error: A recipient should be passed\n" in result.output assert result.exit_code == 1 - result = CliRunner().invoke(cli, ["transfer", "--allSources"]) + result = CliRunner().invoke(cli, TRANSFER + ["--allSources"]) assert "Error: A recipient should be passed\n" in result.output assert result.exit_code == 1 # Multiple options - result = CliRunner().invoke(cli, ["transfer", "--amount", 1, "--amountUD", 1]) + result = CliRunner().invoke(cli, TRANSFER + ["--amount", 1, "--amountUD", 1]) assert "Error: Usage" in result.output assert result.exit_code == 2 - result = CliRunner().invoke(cli, ["transfer", "--amount", 1, "--allSources"]) + result = CliRunner().invoke(cli, TRANSFER + ["--amount", 1, "--allSources"]) assert "Error: Usage" in result.output assert result.exit_code == 2 - result = CliRunner().invoke(cli, ["transfer", "--amountUD", 1, "--allSources"]) + result = CliRunner().invoke(cli, TRANSFER + ["--amountUD", 1, "--allSources"]) assert "Error: Usage" in result.output assert result.exit_code == 2 result = CliRunner().invoke( - cli, ["transfer", "--amount", 1, "--amountUD", 1, "--allSources"] + cli, TRANSFER + ["--amount", 1, "--amountUD", 1, "--allSources"] ) assert "Error: Usage" in result.output assert result.exit_code == 2 - result = CliRunner().invoke(cli, ["transfer", "-r", "A"]) + result = CliRunner().invoke(cli, TRANSFER + ["-r", "A"]) assert "Error: amount, amountUD or allSources is not set." in result.output assert result.exit_code == FAILURE_EXIT_STATUS - result = CliRunner().invoke(cli, ["transfer", "-r", "A", "-r", "B", "--allSources"]) + result = CliRunner().invoke(cli, TRANSFER + ["-r", "A", "-r", "B", "--allSources"]) assert ( "Error: the --allSources option can only be used with one recipient." in result.output @@ -165,18 +168,18 @@ def test_tx_passed_amount_cli(): assert result.exit_code == FAILURE_EXIT_STATUS result = CliRunner().invoke( - cli, ["transfer", "-r", "A", "-a", MINIMAL_ABSOLUTE_TX_AMOUNT - 0.001] + cli, TRANSFER + ["-r", "A", "-a", MINIMAL_ABSOLUTE_TX_AMOUNT - 0.001] ) assert "Error: Invalid value for '--amount'" in result.output assert result.exit_code == 2 result = CliRunner().invoke( - cli, ["transfer", "-r", "A", "-d", MINIMAL_RELATIVE_TX_AMOUNT - 0.0000001] + cli, TRANSFER + ["-r", "A", "-d", MINIMAL_RELATIVE_TX_AMOUNT - 0.0000001] ) assert "Error: Invalid value for '--amountUD'" in result.output assert result.exit_code == 2 - result = CliRunner().invoke(cli, ["transfer", "-r", "A", "-a", 1, "-a", 2]) + result = CliRunner().invoke(cli, TRANSFER + ["-r", "A", "-a", 1, "-a", 2]) assert ( "Error: The number of passed recipients is not the same as the passed amounts." in result.output @@ -184,7 +187,7 @@ def test_tx_passed_amount_cli(): assert result.exit_code == FAILURE_EXIT_STATUS result = CliRunner().invoke( - cli, ["transfer", "-r", "A", "-r", "B", "-r", "C", "-a", 1, "-a", 2] + cli, TRANSFER + ["-r", "A", "-r", "B", "-r", "C", "-a", 1, "-a", 2] ) assert ( "Error: The number of passed recipients is not the same as the passed amounts." @@ -197,12 +200,12 @@ def test_tx_passed_amount_cli(): "arguments, auth_method, is_account_filled", [ ( - ["transfer", "--allSources", "-r", "A" * PUBKEY_MIN_LENGTH], + TRANSFER + ["--allSources", "-r", "A" * PUBKEY_MIN_LENGTH], patched_auth_method_truc, False, ), ( - ["transfer", "--allSources", "-r", "A" * PUBKEY_MIN_LENGTH], + TRANSFER + ["--allSources", "-r", "A" * PUBKEY_MIN_LENGTH], patched_auth_method_riri, True, ), diff --git a/tests/test_cli.py b/tests/test_cli.py index 1d3915a0..9ff32881 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -21,7 +21,7 @@ from silkaj.constants import FAILURE_EXIT_STATUS def test_cli_dry_run_display_options_passed_together(): # Run command with dry_run and display options - command = ["--dry-run", "--display", "membership"] + command = ["--dry-run", "--display", "wot", "membership"] result = CliRunner().invoke(cli, args=command) error_msg = "ERROR: display and dry-run options can not be used together\n" diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index 2df18f64..5355548a 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -21,14 +21,14 @@ silkaj = ["poetry", "run", "silkaj"] def test_info(): """tests 'silkaj info' returns a number of members""" - output = check_output(silkaj + ["info"]) + output = check_output(silkaj + ["blockchain", "info"]) assert "Number of members" in output.decode() def test_wot(): - """tests 'silkaj wot' returns a number of members""" + """tests 'silkaj wot status' returns a number of members""" - output = check_output(silkaj + ["wot", "Matograine"]).decode() + output = check_output(silkaj + ["wot", "status", "Matograine"]).decode() assert "Matograine (CmFKubyq…:CQ5) from block #106433-00000340…" in output assert "received_expire" in output assert "received" in output @@ -39,7 +39,7 @@ def test_wot(): def test_id(): """tests 'silkaj lookup' certification on gtest""" - output = check_output(silkaj + ["--gtest", "lookup", "elois"]).decode() + output = check_output(silkaj + ["--gtest", "wot", "lookup", "elois"]).decode() assert "D7CYHJXjaH4j7zRdWngUbsURPnSnjsCYtvo6f8dvW3C" in output @@ -47,7 +47,13 @@ def test_balance(): """tests 'silkaj amount' command on gtest""" output = check_output( - silkaj + ["--gtest", "balance", "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj"] + silkaj + + [ + "--gtest", + "money", + "balance", + "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj", + ] ).decode() assert ( "│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj: │" diff --git a/tests/wot/test_membership.py b/tests/wot/test_membership.py index c41c2d50..da06e11c 100644 --- a/tests/wot/test_membership.py +++ b/tests/wot/test_membership.py @@ -99,7 +99,7 @@ def test_membership_cmd(dry_run, display, confirmation, monkeypatch): command += ["--dry-run"] if display: command += ["--display"] - command += ["membership"] + command += ["wot", "membership"] pass_license = "No\nYes\n" confirmations = pass_license + ("Yes" if confirmation else "No") result = CliRunner().invoke(cli, args=command, input=confirmations) diff --git a/tests/wot/test_revocation.py b/tests/wot/test_revocation.py index 1f952a61..19097807 100644 --- a/tests/wot/test_revocation.py +++ b/tests/wot/test_revocation.py @@ -177,7 +177,7 @@ def test_revocation_cli_dry_run(subcommand, expected_warn, monkeypatch): warning = "WARNING: the document will only be displayed and will not be sent." - command = ["--dry-run", "-gt", "revocation", subcommand] + command = ["--dry-run", "-gt", "wot", "revocation", subcommand] print("command: ", " ".join(command)) # debug file = "revocation.txt" runner = CliRunner() @@ -298,7 +298,7 @@ def test_revocation_cli_save(display, dry_run, file, user_input, expected, monke ) command = display_dry_options(display, dry_run) - subcommand = ["revocation", "save"] + subcommand = ["wot", "revocation", "save"] command.extend(subcommand) if file: command.extend([file]) @@ -415,7 +415,7 @@ def test_revocation_cli_verify( # prepare command command = display_dry_options(display, dry_run) - command.extend(["revocation", "verify"]) + command.extend(["wot", "revocation", "verify"]) if file: command.extend([file]) else: @@ -681,7 +681,7 @@ def test_revocation_cli_publish( # prepare command command = display_dry_options(display, dry_run) - command.extend(["revocation", "publish"]) + command.extend(["wot", "revocation", "publish"]) if file: command.extend([file]) else: @@ -764,7 +764,7 @@ def test_revocation_cli_publish_send_errors( # prepare command command = display_dry_options(display, False) - command.extend(["revocation", "publish"]) + command.extend(["wot", "revocation", "publish"]) if file: command.extend([file]) else: @@ -851,7 +851,7 @@ def test_revocation_cli_revoke( monkeypatch.setattr(bma.wot, "revoke", patched_send_bma_revoke) command = display_dry_options(display, dry_run) - command.extend(["revocation", "revoke"]) + command.extend(["wot", "revocation", "revoke"]) client = client_instance() result = CliRunner().invoke(cli, args=command, input=user_input) @@ -899,7 +899,7 @@ def test_revocation_cli_revoke_errors(display, user_input, doc, expected, monkey monkeypatch.setattr(bma.wot, "revoke", patched_send_bma_revoke_error) command = display_dry_options(display, False) - command.extend(["revocation", "revoke"]) + command.extend(["wot", "revocation", "revoke"]) result = CliRunner().invoke(cli, args=command, input=user_input) for expect in expected: -- GitLab