Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
Nits from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Nov 12, 2020
1 parent a14a2a3 commit 6b8b597
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
18 changes: 8 additions & 10 deletions teos/cli/teos_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def run(self, command_name, raw_args):
else:
return e.details()
except InvalidParameter as e:
return e.msg if not e.kwargs else f"{e.msg}. Error arguments: {e.kwargs}"
error_message = e.msg if not e.kwargs else f"{e.msg}. Error arguments: {e.kwargs}"
return error_message + "\n\n" + show_usage()
except Exception as e:
return f"Unknown error occurred: {str(e)}"

Expand Down Expand Up @@ -247,9 +248,9 @@ def run(rpc_client, opts_args):
opts, args = opts_args

if not args:
return "No user_id was given"
raise InvalidParameter("No user_id was given")
if len(args) > 1:
return f"Expected only one argument, not {len(args)}"
raise InvalidParameter(f"Expected only one argument, not {len(args)}")

return rpc_client.get_user(args[0])

Expand Down Expand Up @@ -347,13 +348,10 @@ def run():
sys.exit("{}".format(e))

if command in CLI.COMMANDS:
try:
cli = CLI(data_dir, command_line_conf)
result = cli.run(command, command_args)
if result:
print(result)
except InvalidParameter:
sys.exit(show_usage())
cli = CLI(data_dir, command_line_conf)
result = cli.run(command, command_args)
if result:
print(result)
elif not command:
sys.exit("No command provided. Use help to check the list of available commands")
else:
Expand Down
8 changes: 5 additions & 3 deletions test/teos/e2e/test_cli_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_get_all_appointments(teosd, rpc_client):
assert len(watching) == 0 and len(responding) == 0

# Register a user
available_slots, subscription_expiry = teos_client.register(user_id, teos_id, teos_base_endpoint)
teos_client.register(user_id, teos_id, teos_base_endpoint)

# After that we can build an appointment and send it to the tower
commitment_tx, commitment_txid, penalty_tx = create_txs()
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_get_users(teosd, rpc_client):
_, teos_id = teosd

# Register a user
available_slots, subscription_expiry = teos_client.register(user_id, teos_id, teos_base_endpoint)
teos_client.register(user_id, teos_id, teos_base_endpoint)

users = json.loads(rpc_client.get_users())

Expand All @@ -109,9 +109,11 @@ def test_get_user(teosd, rpc_client):
user = json.loads(rpc_client.get_user(user_id))

assert set(user.keys()) == set(["appointments", "available_slots", "subscription_expiry"])
assert user["available_slots"] == available_slots
assert user["subscription_expiry"] == subscription_expiry


def test_get_user_non_existing(teosd, rpc_client):
# Get a user that does not exist
with pytest.raises(InvalidParameter):
json.loads(rpc_client.get_user("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"))
rpc_client.get_user("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00")
6 changes: 3 additions & 3 deletions test/teos/unit/cli/test_teos_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_run_rpcerror_other(cli, monkeypatch):


def test_run_invalid_parameter(cli, monkeypatch):
assert "Invalid parameter" == cli.run("mock_command_invalid_parameter", [])
assert "Invalid parameter" in cli.run("mock_command_invalid_parameter", [])


def test_run_exception(cli, monkeypatch):
Expand Down Expand Up @@ -136,8 +136,8 @@ def test_get_user(cli, monkeypatch):
rpc_client_mock = MagicMock(cli.rpc_client)
monkeypatch.setattr(cli, "rpc_client", rpc_client_mock)

assert cli.run("get_user", []) == "No user_id was given"
assert cli.run("get_user", ["1", "2"]) == "Expected only one argument, not 2"
assert "No user_id was given" in cli.run("get_user", [])
assert "Expected only one argument, not 2" in cli.run("get_user", ["1", "2"])

# the previous calls should not have called the rpc client, since the arguments number was wrong
cli.run("get_user", ["42"])
Expand Down

0 comments on commit 6b8b597

Please sign in to comment.