Skip to content
Snippets Groups Projects
Commit a3bcd659 authored by Moul's avatar Moul
Browse files

(cli) Rename commands name (#430)

Adapt tests
parent 49b46036
No related branches found
No related tags found
1 merge request!219Organize commands into subcommands (#430)
...@@ -51,7 +51,7 @@ def has_auth_method(ctx: Context) -> bool: ...@@ -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") @option("--file", default="authfile", show_default=True, help="Path file")
def generate_auth_file(file: str) -> None: def generate_auth_file(file: str) -> None:
key = auth_method() key = auth_method()
......
...@@ -30,7 +30,7 @@ from silkaj.constants import ALL ...@@ -30,7 +30,7 @@ from silkaj.constants import ALL
@click.command( @click.command(
"diffi", "difficulty",
help="Display the current Proof of Work difficulty level to generate the next block", help="Display the current Proof of Work difficulty level to generate the next block",
) )
def difficulties() -> None: def difficulties() -> None:
......
...@@ -33,7 +33,7 @@ from silkaj.public_key import gen_pubkey_checksum, is_pubkey_and_check ...@@ -33,7 +33,7 @@ from silkaj.public_key import gen_pubkey_checksum, is_pubkey_and_check
from silkaj.wot import tools as wot_tools 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.argument("uid_pubkey_to_certify")
@click.pass_context @click.pass_context
def send_certification(ctx: click.Context, uid_pubkey_to_certify: str) -> None: def send_certification(ctx: click.Context, uid_pubkey_to_certify: str) -> None:
......
...@@ -45,7 +45,7 @@ def get_sent_certifications( ...@@ -45,7 +45,7 @@ def get_sent_certifications(
@click.command( @click.command(
"wot", "status",
help="Check received and sent certifications and \ help="Check received and sent certifications and \
consult the membership status of any given identity", consult the membership status of any given identity",
) )
......
...@@ -67,7 +67,9 @@ def test_check_passed_blocks_range(from_block, to_block, capsys, monkeypatch): ...@@ -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): def test_verify_blocks_signatures(from_block, to_block, monkeypatch):
monkeypatch.setattr(bma.blockchain, "current", current) 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 assert result.exit_code == SUCCESS_EXIT_STATUS
if to_block == 0: if to_block == 0:
to_block = HEAD_BLOCK to_block = HEAD_BLOCK
......
...@@ -160,6 +160,7 @@ def test_balance_errors(): ...@@ -160,6 +160,7 @@ def test_balance_errors():
result = CliRunner().invoke( result = CliRunner().invoke(
cli, cli,
[ [
"money",
"balance", "balance",
"BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh",
"BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh",
...@@ -173,6 +174,7 @@ def test_balance_errors(): ...@@ -173,6 +174,7 @@ def test_balance_errors():
result = CliRunner().invoke( result = CliRunner().invoke(
cli, cli,
[ [
"money",
"balance", "balance",
"B", "B",
], ],
...@@ -181,6 +183,6 @@ def test_balance_errors(): ...@@ -181,6 +183,6 @@ def test_balance_errors():
assert result.exit_code == FAILURE_EXIT_STATUS assert result.exit_code == FAILURE_EXIT_STATUS
# no pubkey # 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 "You should specify one or many pubkeys" in result.output
assert result.exit_code == FAILURE_EXIT_STATUS assert result.exit_code == FAILURE_EXIT_STATUS
...@@ -1060,7 +1060,7 @@ def compute_test_amounts(amounts, mult): ...@@ -1060,7 +1060,7 @@ def compute_test_amounts(amounts, mult):
def construct_args( def construct_args(
amounts, amountsud, allsources, recipients, comment, outputbackchange, yes amounts, amountsud, allsources, recipients, comment, outputbackchange, yes
): ):
args_list = ["transfer"] args_list = ["money", "transfer"]
if yes: if yes:
args_list.append("--yes") args_list.append("--yes")
if amounts: if amounts:
......
...@@ -120,44 +120,47 @@ def test_transaction_amount_errors( ...@@ -120,44 +120,47 @@ def test_transaction_amount_errors(
assert pytest_exit.type == SystemExit assert pytest_exit.type == SystemExit
TRANSFER = ["money", "transfer"]
def test_tx_passed_amount_cli(): def test_tx_passed_amount_cli():
# One option # 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 "Error: A recipient should be passed\n" in result.output
assert result.exit_code == 1 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 "Error: A recipient should be passed\n" in result.output
assert result.exit_code == 1 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 "Error: A recipient should be passed\n" in result.output
assert result.exit_code == 1 assert result.exit_code == 1
# Multiple options # 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 "Error: Usage" in result.output
assert result.exit_code == 2 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 "Error: Usage" in result.output
assert result.exit_code == 2 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 "Error: Usage" in result.output
assert result.exit_code == 2 assert result.exit_code == 2
result = CliRunner().invoke( result = CliRunner().invoke(
cli, ["transfer", "--amount", 1, "--amountUD", 1, "--allSources"] cli, TRANSFER + ["--amount", 1, "--amountUD", 1, "--allSources"]
) )
assert "Error: Usage" in result.output assert "Error: Usage" in result.output
assert result.exit_code == 2 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 "Error: amount, amountUD or allSources is not set." in result.output
assert result.exit_code == FAILURE_EXIT_STATUS 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 ( assert (
"Error: the --allSources option can only be used with one recipient." "Error: the --allSources option can only be used with one recipient."
in result.output in result.output
...@@ -165,18 +168,18 @@ def test_tx_passed_amount_cli(): ...@@ -165,18 +168,18 @@ def test_tx_passed_amount_cli():
assert result.exit_code == FAILURE_EXIT_STATUS assert result.exit_code == FAILURE_EXIT_STATUS
result = CliRunner().invoke( 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 "Error: Invalid value for '--amount'" in result.output
assert result.exit_code == 2 assert result.exit_code == 2
result = CliRunner().invoke( 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 "Error: Invalid value for '--amountUD'" in result.output
assert result.exit_code == 2 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 ( assert (
"Error: The number of passed recipients is not the same as the passed amounts." "Error: The number of passed recipients is not the same as the passed amounts."
in result.output in result.output
...@@ -184,7 +187,7 @@ def test_tx_passed_amount_cli(): ...@@ -184,7 +187,7 @@ def test_tx_passed_amount_cli():
assert result.exit_code == FAILURE_EXIT_STATUS assert result.exit_code == FAILURE_EXIT_STATUS
result = CliRunner().invoke( 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 ( assert (
"Error: The number of passed recipients is not the same as the passed amounts." "Error: The number of passed recipients is not the same as the passed amounts."
...@@ -197,12 +200,12 @@ def test_tx_passed_amount_cli(): ...@@ -197,12 +200,12 @@ def test_tx_passed_amount_cli():
"arguments, auth_method, is_account_filled", "arguments, auth_method, is_account_filled",
[ [
( (
["transfer", "--allSources", "-r", "A" * PUBKEY_MIN_LENGTH], TRANSFER + ["--allSources", "-r", "A" * PUBKEY_MIN_LENGTH],
patched_auth_method_truc, patched_auth_method_truc,
False, False,
), ),
( (
["transfer", "--allSources", "-r", "A" * PUBKEY_MIN_LENGTH], TRANSFER + ["--allSources", "-r", "A" * PUBKEY_MIN_LENGTH],
patched_auth_method_riri, patched_auth_method_riri,
True, True,
), ),
......
...@@ -21,7 +21,7 @@ from silkaj.constants import FAILURE_EXIT_STATUS ...@@ -21,7 +21,7 @@ from silkaj.constants import FAILURE_EXIT_STATUS
def test_cli_dry_run_display_options_passed_together(): def test_cli_dry_run_display_options_passed_together():
# Run command with dry_run and display options # 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) result = CliRunner().invoke(cli, args=command)
error_msg = "ERROR: display and dry-run options can not be used together\n" error_msg = "ERROR: display and dry-run options can not be used together\n"
......
...@@ -21,14 +21,14 @@ silkaj = ["poetry", "run", "silkaj"] ...@@ -21,14 +21,14 @@ silkaj = ["poetry", "run", "silkaj"]
def test_info(): def test_info():
"""tests 'silkaj info' returns a number of members""" """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() assert "Number of members" in output.decode()
def test_wot(): 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 "Matograine (CmFKubyq…:CQ5) from block #106433-00000340…" in output
assert "received_expire" in output assert "received_expire" in output
assert "received" in output assert "received" in output
...@@ -39,7 +39,7 @@ def test_wot(): ...@@ -39,7 +39,7 @@ def test_wot():
def test_id(): def test_id():
"""tests 'silkaj lookup' certification on gtest""" """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 assert "D7CYHJXjaH4j7zRdWngUbsURPnSnjsCYtvo6f8dvW3C" in output
...@@ -47,7 +47,13 @@ def test_balance(): ...@@ -47,7 +47,13 @@ def test_balance():
"""tests 'silkaj amount' command on gtest""" """tests 'silkaj amount' command on gtest"""
output = check_output( output = check_output(
silkaj + ["--gtest", "balance", "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj"] silkaj
+ [
"--gtest",
"money",
"balance",
"3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj",
]
).decode() ).decode()
assert ( assert (
"│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj: │" "│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj: │"
......
...@@ -99,7 +99,7 @@ def test_membership_cmd(dry_run, display, confirmation, monkeypatch): ...@@ -99,7 +99,7 @@ def test_membership_cmd(dry_run, display, confirmation, monkeypatch):
command += ["--dry-run"] command += ["--dry-run"]
if display: if display:
command += ["--display"] command += ["--display"]
command += ["membership"] command += ["wot", "membership"]
pass_license = "No\nYes\n" pass_license = "No\nYes\n"
confirmations = pass_license + ("Yes" if confirmation else "No") confirmations = pass_license + ("Yes" if confirmation else "No")
result = CliRunner().invoke(cli, args=command, input=confirmations) result = CliRunner().invoke(cli, args=command, input=confirmations)
......
...@@ -177,7 +177,7 @@ def test_revocation_cli_dry_run(subcommand, expected_warn, monkeypatch): ...@@ -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." 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 print("command: ", " ".join(command)) # debug
file = "revocation.txt" file = "revocation.txt"
runner = CliRunner() runner = CliRunner()
...@@ -298,7 +298,7 @@ def test_revocation_cli_save(display, dry_run, file, user_input, expected, monke ...@@ -298,7 +298,7 @@ def test_revocation_cli_save(display, dry_run, file, user_input, expected, monke
) )
command = display_dry_options(display, dry_run) command = display_dry_options(display, dry_run)
subcommand = ["revocation", "save"] subcommand = ["wot", "revocation", "save"]
command.extend(subcommand) command.extend(subcommand)
if file: if file:
command.extend([file]) command.extend([file])
...@@ -415,7 +415,7 @@ def test_revocation_cli_verify( ...@@ -415,7 +415,7 @@ def test_revocation_cli_verify(
# prepare command # prepare command
command = display_dry_options(display, dry_run) command = display_dry_options(display, dry_run)
command.extend(["revocation", "verify"]) command.extend(["wot", "revocation", "verify"])
if file: if file:
command.extend([file]) command.extend([file])
else: else:
...@@ -681,7 +681,7 @@ def test_revocation_cli_publish( ...@@ -681,7 +681,7 @@ def test_revocation_cli_publish(
# prepare command # prepare command
command = display_dry_options(display, dry_run) command = display_dry_options(display, dry_run)
command.extend(["revocation", "publish"]) command.extend(["wot", "revocation", "publish"])
if file: if file:
command.extend([file]) command.extend([file])
else: else:
...@@ -764,7 +764,7 @@ def test_revocation_cli_publish_send_errors( ...@@ -764,7 +764,7 @@ def test_revocation_cli_publish_send_errors(
# prepare command # prepare command
command = display_dry_options(display, False) command = display_dry_options(display, False)
command.extend(["revocation", "publish"]) command.extend(["wot", "revocation", "publish"])
if file: if file:
command.extend([file]) command.extend([file])
else: else:
...@@ -851,7 +851,7 @@ def test_revocation_cli_revoke( ...@@ -851,7 +851,7 @@ def test_revocation_cli_revoke(
monkeypatch.setattr(bma.wot, "revoke", patched_send_bma_revoke) monkeypatch.setattr(bma.wot, "revoke", patched_send_bma_revoke)
command = display_dry_options(display, dry_run) command = display_dry_options(display, dry_run)
command.extend(["revocation", "revoke"]) command.extend(["wot", "revocation", "revoke"])
client = client_instance() client = client_instance()
result = CliRunner().invoke(cli, args=command, input=user_input) 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 ...@@ -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) monkeypatch.setattr(bma.wot, "revoke", patched_send_bma_revoke_error)
command = display_dry_options(display, False) command = display_dry_options(display, False)
command.extend(["revocation", "revoke"]) command.extend(["wot", "revocation", "revoke"])
result = CliRunner().invoke(cli, args=command, input=user_input) result = CliRunner().invoke(cli, args=command, input=user_input)
for expect in expected: for expect in expected:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment