Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REM-1296: Get list of the batches #12

Merged
merged 5 commits into from
May 14, 2019
Merged

REM-1296: Get list of the batches #12

merged 5 commits into from
May 14, 2019

Conversation

Art17
Copy link
Contributor

@Art17 Art17 commented Apr 16, 2019

Jira references

Description

Get a list of batches — remme batch get-list:

Arguments Type Required Description
ids String No Identifiers to get a list of batches by.
start String No Batch identifier to get a list of batches starting from.
limit Integer No Maximum amount of batches to return.
head String No Block identifier to get a list of batches from.
reverse Bool No Parameter to reverse result.
node-url String No Node URL to apply a command to.
$ remme batch get-list \
      --ids='6bd3382e3deef34d0bc63a7b450c88c7ae00152f5168c7b4dc4357feff6d52175209919cd0710441fa2768f4c12adf97143440ef8414bb5144b9459d78ff3e0e, 7a5daba99d5757adc997ea6a0b1b83263b3c16604dbd83c0153dc01c9fd780af4b570338c2ec60e086b1db58a4397a4dc661d6c93b0a7250fe75642e15b26e81' \
      --start=6bd3382e3deef34d0bc63a7b450c88c7ae00152f5168c7b4dc4357feff6d52175209919cd0710441fa2768f4c12adf97143440ef8414bb5144b9459d78ff3e0e \
      --limit=2 \
      --head=57a7944497ca41f424932ae6b70897e7086652ab98450d4aba6a02a2d891501460947812a41028b8041f087066df6dc7e1100c4b0e5cc94bb58b002f6950eb02 \
      --node-url=node-6-testnet.remme.io \
      --reverse
 "result": {
        "data": [
            {
                "header": {
                    "signer_public_key": "03738df3f4ac3621ba8e89413d3ff4ad036c3a0a4dbb164b695885aab6aab614ad",
                    "transaction_ids": [
                        "ed7baa5ab9bc5ef49077ddd22de3ebef56157f188980edb6401a57729f7226195d849f227fd941cc01c5eeeedd1d9cadf2e48140098422f2cb641044d971a374",
                    ]
                },
                "header_signature": "6bd3382e3deef34d0bc63a7b450c88c7ae00152f5168c7b4dc4357feff6d52175209919cd0710441fa2768f4c12adf97143440ef8414bb5144b9459d78ff3e0e",
                "trace": false,
                "transactions": [
                    {
                        "header": {
                            "batcher_public_key": "03738df3f4ac3621ba8e89413d3ff4ad036c3a0a4dbb164b695885aab6aab614ad",
                            "dependencies": [],
                            "family_name": "sawtooth_settings",
                            "family_version": "1.0",
                            "inputs": [
                                "000000a87cb5eafdcca6a8cde0fb0dec1400c5ab274474a6aa82c1c0cbf0fbcaf64c0b",
                                "000000a87cb5eafdcca6a8cde0fb0dec1400c5ab274474a6aa82c12840f169a04216b7",
                                "000000a87cb5eafdcca6a8cde0fb0dec1400c5ab274474a6aa82c1918142591ba4e8a7",
                                "000000a87cb5eafdcca6a8f82af32160bc5311783bdad381ea57b4e3b0c44298fc1c14"
                            ],
                            "nonce": "",
                            "outputs": [
                                "000000a87cb5eafdcca6a8cde0fb0dec1400c5ab274474a6aa82c1c0cbf0fbcaf64c0b",
                                "000000a87cb5eafdcca6a8f82af32160bc5311783bdad381ea57b4e3b0c44298fc1c14"
                            ],
                            "payload_sha512": "a39230835da9f4ae154abd7197f196acb9ed9a7d4d0bae8de71714bfe4636c8c6516d774e7b721b9d08d2abbafa42b01acdfe0e3c9b6d35ecef7452442e63b49",
                            "signer_public_key": "03738df3f4ac3621ba8e89413d3ff4ad036c3a0a4dbb164b695885aab6aab614ad"
                        },
                        "header_signature": "ed7baa5ab9bc5ef49077ddd22de3ebef56157f188980edb6401a57729f7226195d849f227fd941cc01c5eeeedd1d9cadf2e48140098422f2cb641044d971a374",
                        "payload": "CAESRwoic2F3dG9vdGgudmFsaWRhdG9yLmJhdGNoX2luamVjdG9ycxINcmVtbWVfYmF0Y2hlcxoSMHg5NzBkZGE2MjRlZTFhZmFh"
                    },
                ]
            },
        ],
        "head": "57a7944497ca41f424932ae6b70897e7086652ab98450d4aba6a02a2d891501460947812a41028b8041f087066df6dc7e1100c4b0e5cc94bb58b002f6950eb02",
        "paging": {
            "limit": 2,
            "next": "",
            "start": "6bd3382e3deef34d0bc63a7b450c88c7ae00152f5168c7b4dc4357feff6d52175209919cd0710441fa2768f4c12adf97143440ef8414bb5144b9459d78ff3e0e"
        }
    }
}

@codecov-io
Copy link

codecov-io commented Apr 16, 2019

Codecov Report

Merging #12 into develop will increase coverage by 0.11%.
The diff coverage is 98.11%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #12      +/-   ##
===========================================
+ Coverage    97.31%   97.43%   +0.11%     
===========================================
  Files           55       55              
  Lines          894      973      +79     
===========================================
+ Hits           870      948      +78     
- Misses          24       25       +1
Impacted Files Coverage Δ
cli/batch/service.py 93.75% <100%> (+2.08%) ⬆️
cli/batch/help.py 100% <100%> (ø) ⬆️
cli/batch/forms.py 100% <100%> (ø) ⬆️
cli/batch/cli.py 100% <100%> (ø) ⬆️
cli/generic/forms/fields.py 100% <100%> (ø) ⬆️
cli/batch/interfaces.py 57.14% <50%> (-2.86%) ⬇️
cli/node/cli.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e4c83b...e8ec5b4. Read the comment docs.

README.md Outdated
@@ -76,6 +76,43 @@ $ remme account get-balance \
368440.0
```

### Blockchain info
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you operate some libraries where you see blockchain info, it is ok.
When you provide the independent layer of user experience, you should care about users in own way.

I mean, In the library it is blockchain information, but CLI user expects section batch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Get batch by id.
"""
if re.match(pattern=BATCH_ID_REGEXP, string=id) is None:
click.echo('The following id `{batch_id}` is not valid.'.format(batch_id=id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following id > The following batch id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@batch_commands.command('get-single')
def get_single(id, node_url):
"""
Get batch by id.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id > identifier in all user/business-oriented texts: documentation of products, projects, code documentation, functions names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


GET_BATCH_HEAD_ARGUMENT_HELP_MESSAGE = 'Get batch by head.'

GET_BATCH_REVERSE_ARGUMENT_HELP_MESSAGE = 'Reverse result.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blank lines between the same entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"""


class BlockchainInfoInterface:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same I said in the first message. BlockchainInfo > Batch. Please, fix this anywhere: folder names, files names, classes, variables, etc. except obviously library usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


async def get_batches(self, query=None):
"""
Get all batches from REMChain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMChain > blockchain.

"""
Get all batches from REMChain.

Args:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Args > Arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


Args:
query (dict, optional): dictionary with specific parameters
Returns:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line between documentation sections: arguments, returns, exceptions, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"""
Get batch by id.
"""
# TODO: change to get_batch_by_id after corresponding changes in remme-python-library
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move TODO section of messy comments to the issues, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/constants.py Outdated
@@ -3,6 +3,8 @@
"""
ADDRESS_REGEXP = '[0-9a-f]{70}'

BATCH_ID_REGEXP = '[0-9a-f]{128}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blank line between the same entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Art17 Art17 force-pushed the f-list-batches branch 3 times, most recently from e40fb89 to 44c3680 Compare April 16, 2019 15:13
cli/batch/cli.py Outdated
@batch_commands.command('get-list')
def get_list(id, start, limit, head, reverse, node_url):
"""
List batches.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List batches > Get a list of batches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
if batch_id is not None and re.match(pattern=BATCH_ID_REGEXP, string=batch_id) is None:
click.echo('The following batch id `{batch_id}` is not valid.'.format(batch_id=id))
sys.exit(FAILED_EXIT_FROM_COMMAND)
if limit is not None and limit < 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line between 50 and 51 code lines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
if limit is not None and limit < 0:
click.echo("Limit can't be negative.")
sys.exit(FAILED_EXIT_FROM_COMMAND)
if reverse is not None and reverse not in ("true", "false"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line between 54 and 53.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use also single quotes if possible here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

GET_BATCH_START_ARGUMENT_HELP_MESSAGE = 'Get batch by start.'
GET_BATCH_LIMIT_ARGUMENT_HELP_MESSAGE = 'Limit amount of batches.'
GET_BATCH_HEAD_ARGUMENT_HELP_MESSAGE = 'Get batch by head.'
GET_BATCH_REVERSE_ARGUMENT_HELP_MESSAGE = 'Reverse result.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as here, you should describe the argument, not command. https://github.com/Remmeauth/remme-core-cli/pull/7/files#r276177736

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


async def get_list(self, query=None):
"""
Get all batches from REMChain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all > a list of?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

README.md Outdated
@@ -104,6 +104,29 @@ $ remme account get-balance \
368440.0
```

### Batches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add anchor Batches to the tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

README.md Outdated
@@ -104,6 +104,29 @@ $ remme account get-balance \
368440.0
```

### Batches

Get batches — ``remme batch get-list``:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Get batches — ``remme batch get-list``:
Get list of batches — ``remme batch get-list``:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

README.md Outdated

| Arguments | Type | Required | Description |
| :-------: | :----: | :-------: | --------------------------------------------------- |
| id | String | No | Get batch by its identifier. |
Copy link
Contributor

@anastasiia-bilova anastasiia-bilova Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| id | String | No | Get batch by its identifier. |
| id | String | No | Identifier to get a list of batches by. |

Check all description by this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
"""
Provide implementation of the command line interface's batch commands.
"""
import sys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make alphabetical order of packages.

Copy link
Contributor Author

@Art17 Art17 Apr 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to technical debt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
@click.option('--reverse', type=str, required=False, help=GET_BATCH_REVERSE_ARGUMENT_HELP_MESSAGE)
@click.option('--node-url', type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE)
@batch_commands.command('get-list')
def get_list(id, start, limit, head, reverse, node_url):
Copy link
Contributor

@anastasiia-bilova anastasiia-bilova Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_list(id, start, limit, head, reverse, node_url):
def get_batches(id, start, limit, head, reverse, node_url):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
@click.option('--limit', type=int, required=False, help=GET_BATCH_LIMIT_ARGUMENT_HELP_MESSAGE)
@click.option('--head', type=str, required=False, help=GET_BATCH_HEAD_ARGUMENT_HELP_MESSAGE)
@click.option('--reverse', type=str, required=False, help=GET_BATCH_REVERSE_ARGUMENT_HELP_MESSAGE)
@click.option('--node-url', type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@click.option('--node-url', type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE)
@click.option('--node-url', type=str, required=False, help=NODE_URL_ARGUMENT_HELP_MESSAGE)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
"""
List batches.
"""
for batch_id in (id, start, head):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

head should be a block identifier, not a batch identifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
batch_service = Batch(service=remme)
batches = loop.run_until_complete(batch_service.get_list(query))

click.echo(batches)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do pull from develop, you get a new function dict_to_pretty_json.

Suggested change
click.echo(batches)
click.echo(dict_to_pretty_json(batches))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Art17 Art17 force-pushed the f-list-batches branch 6 times, most recently from d721d21 to 72976b3 Compare April 18, 2019 16:39
cli/constants.py Outdated
@@ -2,6 +2,8 @@
Provide constants for command line interface.
"""
ADDRESS_REGEXP = '[0-9a-f]{70}'
BATCH_ID_REGEXP = '^[0-9a-f]{128}$'
BLOCK_ID_REGEXP = '^[0-9a-f]{128}$'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Art17 Art17 force-pushed the f-list-batches branch 3 times, most recently from 6efe290 to 326892d Compare April 24, 2019 09:27
README.md Outdated
@@ -16,7 +16,7 @@
* [Nodes](#nodes)
* [Configuration file](#configuration-file)
* [Service](#service)
* [Account](#account)
* [Batch](#batch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why account has been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

README.md Outdated
| :-------: | :----: | :-------: | --------------------------------------------------- |
| ids | String | No | Identifiers to get a list of batches by. |
| start | String | No | Parameter to list batches starting from. |
| limit | Integer| No | Parameter to limit amount of batches. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is start an identifier of the block to start paging (inclusive) from?

Parameter to limit amount of batches > Number of transactions to return.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. start - Batch identifier to start listing from.
  2. Maximum amount of batches to return.

README.md Outdated
```bash
$ remme batch get-list \
--ids=[c2eeb94926d3432e41cb5ceed078f78466389e4fe685ec958021a1368f634c035072e434e5d0ff64820dd01fde6e5afc67eb5a9ae6c48d3983ff43abe98aef6b] \
--node-url=159.89.104.9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide the most full example. As here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

raise ValidationError("Invalid reverse field. Should be either 'true' or 'false'.")

@validates('node_url')
def validate_node_url(self, node_url):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this instead.

raise ValidationError(f'The following block id `{head}` is invalid.')

@validates('reverse')
def validate_reverse(self, reverse):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, create custom fields instead of a validation function for now.

We already did the migrations to them.

query (dict, optional): dictionary with specific parameters

Returns:
List of batches.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply to each method you have — #18 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Returns:
List of batches.
"""
return await self.service.blockchain_info.get_batches(query=query)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
'reverse': reverse,
}

batch_service = Batch(service=remme)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Art17 Art17 force-pushed the f-list-batches branch 3 times, most recently from 46e20da to efad12c Compare April 25, 2019 15:38
README.md Outdated
--limit=1 \
--head=56100bf24eed12d2f72fe3c3ccf75fe2f53d87c224d9dda6fb98a1411070b06a40fcf97fccc61cb9c88442953af6ae50344ad7773f1becc6bae108443c18c551 \
--reverse=true \
--node-url=159.89.104.9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use common URL as in other examples — genesis.

strict=True,
required=False,
validate=[
validate.Range(min=1, error="Limit must be greater than 0."),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use single quotes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

List batches validation form.
"""

ids = IdListField(allow_none=True, required=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IdListField > BatchIdentifierListField.

Apply to other cases. For now, we do specific naming like, in the future when we will know then few arguments from different forms could use the same field, we will create a generic one with a generic name.

of batches, reversed result.

Arguments:
query (dict, optional): dictionary with specific parameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dictionary with specific parameters > dictionary with specific parameters..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@implements(BatchInterface)
class Batch:
"""
Implements batch interface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implements batch interface. > Implements batch..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"""
Get a list of batches.

List of batches can be filtered by identifiers, start pagging, identifier of block's head, limit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove List of batches can.. from the interface. Leave in the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

README.md Outdated
--start=6bd3382e3deef34d0bc63a7b450c88c7ae00152f5168c7b4dc4357feff6d52175209919cd0710441fa2768f4c12adf97143440ef8414bb5144b9459d78ff3e0e \
--limit=2 \
--head=57a7944497ca41f424932ae6b70897e7086652ab98450d4aba6a02a2d891501460947812a41028b8041f087066df6dc7e1100c4b0e5cc94bb58b002f6950eb02 \
--node-url=node-genesis-testnet.remme.io \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--node-url=node-genesis-testnet.remme.io \
--reverse \
--node-url=node-genesis-testnet.remme.io

'reverse': reverse,
}

result, errors = Batch(service=remme).get_list(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result, errors = Batch(service=remme).get_list(
result, errors = Batch(service=remme).get_list(query=query)

Implements batch.
"""

def get_list(self, query=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_list(self, query=None):
def get_list(self, query):

"""
self.service = service

def get_list(self, query=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_list(self, query=None):
def get_list(self, query):

query['reverse'] = 'false'

try:
batch_list = loop.run_until_complete(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
batch_list = loop.run_until_complete(
batch_list = loop.run_until_complete(self.service.blockchain_info.get_batches(query=query))

NODE_IP_ADDRESS_FOR_TESTING,
])

command_response = json.loads(result.output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify test case by example.

assert header is not None


def test_get_batches_invalid_head():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create test cases:

  • with valid, but non-existing ids
  • without node url (example)
  • with invalid node url (example)
  • node url with http (example)
  • node url with https (example)

"""
Validate data (list identifiers) that was passed to field.
"""
value = [v.strip() for v in value.split(',')]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return value


class BatchIdField(IdField):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BatchIdField > BatchIdentifierField.

"""
Implements validation of the batch identifier.

Raises a ValidationError if the identifier does not correspond to HEADER_SIGNATURE_REGEXP.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md Outdated
--head=57a7944497ca41f424932ae6b70897e7086652ab98450d4aba6a02a2d891501460947812a41028b8041f087066df6dc7e1100c4b0e5cc94bb58b002f6950eb02 \
--node-url=node-6-testnet.remme.io \
--reverse
"result": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the result not in the dictionary?

{
    'result': ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cli/batch/cli.py Outdated
'node_address': str(node_url) + ':8080',
})

batches, errors = Batch(service=remme).get_list(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
batches, errors = Batch(service=remme).get_list(
result, errors = Batch(service=remme).get_list(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


class GetBatchesListForm(Schema):
"""
Get a list of batch form.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Get a list of batch form.
Get a list of batches form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"""
Provide help messages for command line interface's batch commands.
"""
BATCH_IDS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of batches by.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BATCH_IDS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of batches by.'
BATCH_IDENTIFIERS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of batches by.'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

start (string, optional): batch identifier to get a list of batches starting from.
limit (int, optional): maximum amount of batches to return.
head (string, optional): block identifier to get a list of batches from.
reverse (string, optional): parameter to reverse result.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reverse (string, optional): parameter to reverse result.
reverse (bool, optional): parameter to reverse result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

head (string, optional): block identifier to get a list of batches from.
reverse (string, optional): parameter to reverse result.
"""
reverse = '' if reverse else 'false'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line because it is in the python library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

from cli.utils import dict_to_pretty_json


def test_get_list_batches_with_all_parameters(mocker):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using a mocker in this test? Please, send the command with all parameters to the real test node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

result_header_signature = json.loads(result.output).get('result').get('data')[0].get('header_signature')

assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code
assert isinstance(json.loads(result.output), dict)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is meaningless, remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

assert dict_to_pretty_json(expected_error_message) in result.output


def test_get_list_batches_with_invalid_node_url():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is for a non-existing node URL, but not an invalid node URL. Update documentation.

Suggested change
def test_get_list_batches_with_invalid_node_url():
def test_get_batch_status_with_non_existing_node_url():

Create test for invalid node URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code
assert expected_result == json.loads(result.output).get('result')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create tests for valid, but non-existing parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


def test_get_list_batches_with_non_existing_ids():
"""
Case: get a list of batches by non existing identifiers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non existing > non-existing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

def test_get_list_batches_with_non_existing_ids():
"""
Case: get a list of batches by non existing identifiers.
Expect: list of batches not found error message is returned.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list of batches not found error message is returned. > list of batches not found error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

])

expected_error_message = {
'errors': f'List of batches not found.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove f-string if you haven't passed any argument to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

def test_get_list_batches_with_start():
"""
Case: get a list of batches by batch identifier starting from.
Expect: batches are returned.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batches are returned > batches are returned beginning from the batch with an identifier which matches specified start parameter or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

def test_get_list_batches_with_non_existing_start():
"""
Case: get a list of batches by non-existing batch identifier starting from.
Expect: list of batches not found error message is returned.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list of batches not found error message is returned > list of batches not found error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

def test_get_list_batches_by_head():
"""
Case: get a list of batches by block identifier.
Expect: batches are returned.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check this and other tests for common points I have mentioned on above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

README.md Outdated
--start=6bd3382e3deef34d0bc63a7b450c88c7ae00152f5168c7b4dc4357feff6d52175209919cd0710441fa2768f4c12adf97143440ef8414bb5144b9459d78ff3e0e \
--limit=2 \
--head=57a7944497ca41f424932ae6b70897e7086652ab98450d4aba6a02a2d891501460947812a41028b8041f087066df6dc7e1100c4b0e5cc94bb58b002f6950eb02 \
--node-url=node-6-testnet.remme.io \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--node-url=node-6-testnet.remme.io \
--reverse \
--node-url=node-6-testnet.remme.io

Node URL must be last.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

1,
'--head',
head,
'--node-url',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node URL must be last.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'--reverse',
])

assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add checks, please! (example or like this assert expected_header_signature == result_header_signature)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

NODE_IP_ADDRESS_FOR_TESTING,
])

assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add checks, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

assert expected_header_signature == result_header_signature


def test_get_list_batches_with_non_existing_ids():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make one test case using @pytest.mark.parametrize for all tests with non-existing arguments (ids, start, head), they have the same error message 'List of batches not found.'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

assert dict_to_pretty_json(expected_error_message) in result.output


@pytest.mark.parametrize('command_flag', ('--start', '--head'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@pytest.mark.parametrize('command_flag', ('--start', '--head'))
@pytest.mark.parametrize('command_flag', ('--ids', '--start', '--head'))

Add argument ids to this test case and delete test test_get_list_batches_with_invalid_ids .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code


def test_get_list_batches_with_invalid_limit():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must create a test for negative limit (example) and for an invalid limit count (example).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
]
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the blank line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

NODE_IP_ADDRESS_FOR_TESTING,
])

assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a check like this assert result_header_signature == start.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is for head. Result doesn't include block identifier so there is nothing to compare with head.

'result': batch_data.get('data'),
}

mock_get_batch_by_ids = mocker.patch('cli.batch.service.loop.run_until_complete')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mock_get_batch_by_ids = mocker.patch('cli.batch.service.loop.run_until_complete')
mock_get_batches = mocker.patch('cli.batch.service.loop.run_until_complete')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Art17 Art17 merged commit 2f79f46 into develop May 14, 2019
@delete-merged-branch delete-merged-branch bot deleted the f-list-batches branch May 14, 2019 13:03
@anastasiia-bilova anastasiia-bilova mentioned this pull request May 17, 2019
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants