Skip to content

Commit

Permalink
Merge pull request #276 from skalenetwork/enhancement/SKALE-2922-json…
Browse files Browse the repository at this point in the history
…-formats

Enhancement/skale 2922 json formats
  • Loading branch information
DmytroNazarenko authored Aug 11, 2020
2 parents 6c53da8 + 3417f0a commit 788df14
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cli/exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ def start():


@node_exit.command('status', help="Get exit process status")
def status():
@click.option('--format', '-f', type=click.Choice(['json', 'text']))
def status(format):
status, payload = get_request('exit_status')
if status == 'ok':
exit_status = payload
print_exit_status(exit_status)
if format == 'json':
print(exit_status)
else:
print_exit_status(exit_status)
else:
print_err_response(payload)

Expand Down
6 changes: 3 additions & 3 deletions core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def get_node_info(config, format):
status, payload = get_request('node_info')
if status == 'ok':
node_info = payload['node_info']
if node_info['status'] == NodeStatuses.NOT_CREATED.value:
print(TEXTS['service']['node_not_registered'])
elif format == 'json':
if format == 'json':
print(node_info)
elif node_info['status'] == NodeStatuses.NOT_CREATED.value:
print(TEXTS['service']['node_not_registered'])
else:
print_node_info(node_info)
else:
Expand Down
20 changes: 20 additions & 0 deletions tests/cli/exit_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import requests
from cli.exit import status

from tests.helper import response_mock, run_command_mock


def test_exit_status(config):
payload = {
'status': 'ACTIVE',
'data': [{'name': 'test', 'status': 'ACTIVE'}],
'exit_time': 0
}

resp_mock = response_mock(
requests.codes.ok,
json_data={'payload': payload, 'status': 'ok'}
)
result = run_command_mock('core.helper.requests.get', resp_mock, status, ['--format', 'json'])
assert result.exit_code == 0
assert result.output == "{'status': 'ACTIVE', 'data': [{'name': 'test', 'status': 'ACTIVE'}], 'exit_time': 0}\n" # noqa

0 comments on commit 788df14

Please sign in to comment.