From cef83653e4b8025ead20223ef2c3ca116e486a9d Mon Sep 17 00:00:00 2001 From: Anastasiia Bilova Date: Fri, 3 May 2019 16:46:04 +0300 Subject: [PATCH] Add check for test case get swap info, refactor readme --- README.md | 9 ++++----- cli/atomic_swap/help.py | 2 +- cli/generic/forms/fields.py | 2 +- tests/atomic_swap/test_get_info.py | 23 +++++++++++++---------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f1c10e5..70cf3d9 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ * [Requirements](#getting-started-requirements) * [Installation](#installation) * [Usage](#usage) - * [Nodes](#nodes) * [Configuration file](#configuration-file) * [Service](#service) * [Account](#account) @@ -161,10 +160,10 @@ $ remme atomic-swap get-public-key --node-url=node-6-testnet.remme.io Get information about atomic swap by its identifier — ``remme atomic-swap get-info``: -| Arguments | Type | Required | Description | -| :-------: | :----: | :------: | ---------------------------------------------------- | -| id | String | Yes | Swap identifier to get an information about swap by. | -| node-url | String | No | Node URL to apply a command to. | +| Arguments | Type | Required | Description | +| :-------: | :----: | :------: | ------------------------------------------------- | +| id | String | Yes | Swap identifier to get information about swap by. | +| node-url | String | No | Node URL to apply a command to. | ```bash $ remme atomic-swap get-info \ diff --git a/cli/atomic_swap/help.py b/cli/atomic_swap/help.py index d28e82a..69a355d 100644 --- a/cli/atomic_swap/help.py +++ b/cli/atomic_swap/help.py @@ -1,4 +1,4 @@ """ Provide help messages for command line interface's atomic swap commands. """ -SWAP_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Swap identifier to get an information about swap by.' +SWAP_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Swap identifier to get information about swap by.' diff --git a/cli/generic/forms/fields.py b/cli/generic/forms/fields.py index c1e8998..6bce0fd 100644 --- a/cli/generic/forms/fields.py +++ b/cli/generic/forms/fields.py @@ -122,4 +122,4 @@ def _deserialize(self, value, attr, data, **kwargs): if re.match(pattern=SWAP_IDENTIFIER_REGEXP, string=swap_identifier) is None: raise ValidationError(f'The following swap identifier `{swap_identifier}` is invalid.') - return value + return swap_identifier diff --git a/tests/atomic_swap/test_get_info.py b/tests/atomic_swap/test_get_info.py index 2cce2ea..08ce4a3 100644 --- a/tests/atomic_swap/test_get_info.py +++ b/tests/atomic_swap/test_get_info.py @@ -17,36 +17,39 @@ from cli.entrypoint import cli from cli.utils import dict_to_pretty_json +SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE = '033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808' + def test_get_swap_info(): """ Case: get information about atomic swap by its identifier. - Expect: information about swap is returned. + Expect: information about the swap is returned. """ runner = CliRunner() result = runner.invoke(cli, [ 'atomic-swap', 'get-info', '--id', - '033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808', + SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', NODE_27_IN_TESTNET_ADDRESS, ]) swap_info = json.loads(result.output).get('result').get('information') + swap_identifier = swap_info.get('swap_id') assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code + assert SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE == swap_identifier assert re.match(pattern=ADDRESS_REGEXP, string=swap_info.get('sender_address')) is not None assert re.match(pattern=ADDRESS_REGEXP, string=swap_info.get('receiver_address')) is not None - assert re.match(pattern=SWAP_IDENTIFIER_REGEXP, string=swap_info.get('swap_id')) is not None - assert isinstance(int(float(swap_info.get('amount'))), int) + assert re.match(pattern=SWAP_IDENTIFIER_REGEXP, string=swap_identifier) is not None assert isinstance(swap_info.get('is_initiator'), bool) def test_get_swap_info_without_node_url(mocker, swap_info): """ - Case: get information about atomic swap by its without passing node URL. - Expect: information about swap is returned from node on localhost. + Case: get information about atomic swap by its identifier without passing node URL. + Expect: information about the swap is returned from node on localhost. """ mock_swap_get_info = mocker.patch('cli.atomic_swap.service.loop.run_until_complete') mock_swap_get_info.return_value = swap_info @@ -56,7 +59,7 @@ def test_get_swap_info_without_node_url(mocker, swap_info): 'atomic-swap', 'get-info', '--id', - '033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808', + SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, ]) expected_result = { @@ -135,7 +138,7 @@ def test_get_swap_info_non_existing_node_url(): 'atomic-swap', 'get-info', '--id', - '033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808', + SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', non_existing_node_url, ]) @@ -160,7 +163,7 @@ def test_get_swap_info_invalid_node_url(): 'atomic-swap', 'get-info', '--id', - '033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808', + SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', invalid_node_url, ]) @@ -188,7 +191,7 @@ def test_get_swap_info_node_url_with_protocol(node_url_with_protocol): 'atomic-swap', 'get-info', '--id', - '033402fe1346742486b15a3a9966eb5249271025fc7fb0b37ed3fdb4bcce6808', + SWAP_IDENTIFIER_PRESENTED_ON_THE_TEST_NODE, '--node-url', node_url_with_protocol, ])