Skip to content

Commit

Permalink
fix: iroha_cli pytests
Browse files Browse the repository at this point in the history
Signed-off-by: Nurzhan Sakén <[email protected]>
  • Loading branch information
nxsaken committed Aug 13, 2024
1 parent 18a9a04 commit 59851dd
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 46 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/iroha2-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:

env:
CARGO_TERM_COLOR: always
CLIENT_CLI_DIR: "/__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/test"
IROHA_CLI_DIR: "/__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/test"
DOCKER_COMPOSE_PATH: defaults
TEST_DIR: "tmp/test"
IROHA_BIN: "iroha"
Expand Down Expand Up @@ -209,8 +209,8 @@ jobs:
- name: Run Client CLI Tests
working-directory: iroha_cli/pytests
env:
CLIENT_CLI_BINARY: ../../${{ env.TEST_DIR }}/${{ env.IROHA_BIN }}
CLIENT_CLI_CONFIG: ../../${{ env.TEST_DIR }}/client.toml
IROHA_CLI_BINARY: ../../${{ env.TEST_DIR }}/${{ env.IROHA_BIN }}
IROHA_CLI_CONFIG: ../../${{ env.TEST_DIR }}/client.toml
run: ${{ env.POETRY_PATH }} run pytest
- name: Wipe docker-compose.yml containers
if: always()
Expand Down
12 changes: 6 additions & 6 deletions iroha_cli/pytests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ The test model has the following structure:
3. Configure the tests by creating the following `.env` file in _this_ (`<repo root>/iroha_cli/pytests/`) directory:

```shell
CLIENT_CLI_BINARY=/path/to/iroha_cli
CLIENT_CLI_CONFIG=/path/to/client.toml
IROHA_CLI_BINARY=/path/to/iroha_cli
IROHA_CLI_CONFIG=/path/to/client.toml
TORII_API_PORT_MIN=8080
TORII_API_PORT_MAX=8083
```
Expand Down Expand Up @@ -119,7 +119,7 @@ To do so, perform the following steps:
4. Proceed with _Step 2_ of the [Using Test Suites](#using-test-suites) instructions.

> [!NOTE]
> Don't forget to specify the path to the directory created for the `iroha` binary and its `client.toml` configuration file (see Step 3) in the `CLIENT_CLI_DIR` variable of the `.env` file.
> Don't forget to specify the path to the directory created for the `iroha` binary and its `client.toml` configuration file (see Step 3) in the `IROHA_CLI_DIR` variable of the `.env` file.
> For details, see [Tests Configuration](#tests-configuration) below.
### Poetry Configuration
Expand Down Expand Up @@ -156,16 +156,16 @@ Tests are configured via environment variables. These variables can be optionall

The variables:

- `CLIENT_CLI_DIR` — Specifies a path to a directory containing the `iroha` binary and its `client.toml` configuration file.\
- `IROHA_CLI_DIR` — Specifies a path to a directory containing the `iroha` binary and its `client.toml` configuration file.\
Set to `/iroha_cli`, by default.
- `TORII_API_PORT_MIN`/`TORII_API_PORT_MAX` — This pair specifies the range of local ports through which the Iroha 2 peers are deployed. A randomly selected port from the specified range is used for each test.\
Set to `8080` and `8083` respectively, by default.

**Example**:

```shell
CLIENT_CLI_BINARY=/path/to/iroha_cli
CLIENT_CLI_CONFIG=/path/to/client.toml
IROHA_CLI_BINARY=/path/to/iroha_cli
IROHA_CLI_CONFIG=/path/to/client.toml
TORII_API_PORT_MIN=8080
TORII_API_PORT_MAX=8083
```
Expand Down
6 changes: 3 additions & 3 deletions iroha_cli/pytests/common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

ROOT_DIR = os.environ.get("CLIENT_CLI_DIR", BASE_DIR)
ROOT_DIR = os.environ.get("IROHA_CLI_DIR", BASE_DIR)

PATH_CONFIG_CLIENT_CLI = os.environ["CLIENT_CLI_CONFIG"]
CLIENT_CLI_PATH = os.environ["CLIENT_CLI_BINARY"]
PATH_CONFIG_IROHA_CLI = os.environ["IROHA_CLI_CONFIG"]
IROHA_CLI_PATH = os.environ["IROHA_CLI_BINARY"]
PEERS_CONFIGS_PATH = os.path.join(ROOT_DIR, "peers_configs")

PORT_MIN = int(os.getenv("TORII_API_PORT_MIN", "8080"))
Expand Down
4 changes: 2 additions & 2 deletions iroha_cli/pytests/src/client_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
This module initializes the Iroha client and configuration using environment variables.
"""

from common.settings import PATH_CONFIG_CLIENT_CLI, PORT_MAX, PORT_MIN
from common.settings import PATH_CONFIG_IROHA_CLI, PORT_MAX, PORT_MIN
from src.iroha_cli.iroha_cli import IrohaCli
from src.iroha_cli.configuration import Config
from src.iroha_cli.iroha import Iroha

config = Config(PORT_MIN, PORT_MAX)
config.load(PATH_CONFIG_CLIENT_CLI)
config.load(PATH_CONFIG_IROHA_CLI)
iroha_cli = IrohaCli(config)
iroha = Iroha(config)
6 changes: 3 additions & 3 deletions iroha_cli/pytests/src/client_cli/client_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import allure # type: ignore

from common.helpers import extract_hash, read_isi_from_json, write_isi_to_json
from common.settings import BASE_DIR, CLIENT_CLI_PATH, PATH_CONFIG_CLIENT_CLI, ROOT_DIR
from common.settings import BASE_DIR, IROHA_CLI_PATH, PATH_CONFIG_IROHA_CLI, ROOT_DIR
from src.iroha_cli.configuration import Config


Expand All @@ -21,8 +21,8 @@ class IrohaCli:
A class to represent the Iroha client command line interface.
"""

BASE_PATH = CLIENT_CLI_PATH
BASE_FLAGS = ["--config=" + PATH_CONFIG_CLIENT_CLI]
BASE_PATH = IROHA_CLI_PATH
BASE_FLAGS = ["--config=" + PATH_CONFIG_IROHA_CLI]

def __init__(self, config: Config):
"""
Expand Down
18 changes: 9 additions & 9 deletions iroha_cli/pytests/src/client_cli/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ def __init__(self, port_min, port_max):
self.port_max = port_max
self._envs = dict()

def load(self, path_config_client_cli):
def load(self, path_config_iroha_cli):
"""
Load the configuration from the given config file.
:param path_config_client_cli: The path to the configuration file.
:type path_config_client_cli: str
:param path_config_iroha_cli: The path to the configuration file.
:type path_config_iroha_cli: str
:raises IOError: If the file does not exist.
"""
if not os.path.exists(path_config_client_cli):
raise IOError(f"No config file found at {path_config_client_cli}")
if not os.path.exists(path_config_iroha_cli):
raise IOError(f"No config file found at {path_config_iroha_cli}")

if not os.path.isfile(path_config_client_cli):
raise IOError(f"The path is not a file: {path_config_client_cli}")
if not os.path.isfile(path_config_iroha_cli):
raise IOError(f"The path is not a file: {path_config_iroha_cli}")

with open(path_config_client_cli, "r", encoding="utf-8") as config_file:
with open(path_config_iroha_cli, "r", encoding="utf-8") as config_file:
self._config = tomlkit.load(config_file)
self.file = path_config_client_cli
self.file = path_config_iroha_cli

def generate_by_peers(self, peers_configs_dir):
"""
Expand Down
2 changes: 1 addition & 1 deletion iroha_cli/pytests/src/client_cli/have.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ def error(expected):
:param expected: The expected error message.
:return: True if the error is present, False otherwise.
"""
return match.client_cli_have_error(expected=expected, actual=iroha_cli.stderr)
return match.iroha_cli_have_error(expected=expected, actual=iroha_cli.stderr)
2 changes: 1 addition & 1 deletion iroha_cli/pytests/src/client_cli/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import allure # type: ignore


def client_cli_have_error(expected: str, actual: str):
def iroha_cli_have_error(expected: str, actual: str):
"""
Checks if the command-line client has the expected error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
def test_filter_by_domain(GIVEN_registered_account):
def condition():
domain = GIVEN_registered_account.domain
with allure.step(
f"WHEN iroha_cli query accounts " f'in the "{domain}" domain'
):
with allure.step(f"WHEN iroha_cli query accounts " f'in the "{domain}" domain'):
accounts = iroha.list_filter(
{"Identifiable": {"EndsWith": f"@{domain}"}}
).accounts()
Expand Down
4 changes: 2 additions & 2 deletions iroha_cli/pytests/test/accounts/test_register_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def test_register_account_with_invalid_character_in_key(
with allure.step(
"WHEN iroha_cli tries to register an account with invalid character in the key"
):
client_cli.register().account(
iroha_cli.register().account(
signatory=GIVEN_key_with_invalid_character_in_key,
domain=GIVEN_registered_domain.name,
)
with allure.step("THEN iroha_cli should have the error"):
client_cli.should(have.error(Stderr.INVALID_CHARACTER.value))
iroha_cli.should(have.error(Stderr.INVALID_CHARACTER.value))
12 changes: 5 additions & 7 deletions iroha_cli/pytests/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def GIVEN_registered_account(GIVEN_registered_domain, GIVEN_public_key):
with allure.step(
f'GIVEN the account "{GIVEN_public_key}" in the "{GIVEN_registered_domain.name}" domain'
):
iroha_cli.register().account(
signatory=account.signatory, domain=account.domain
)
iroha_cli.register().account(signatory=account.signatory, domain=account.domain)
return account


Expand Down Expand Up @@ -145,7 +143,7 @@ def GIVEN_numeric_asset_for_account(
domain=asset.definition.domain,
type_=asset.definition.type_,
)
client_cli.mint().asset(
iroha_cli.mint().asset(
account=account,
asset_definition=asset.definition,
value_of_type=asset.value,
Expand All @@ -168,7 +166,7 @@ def GIVEN_registered_asset_definition_with_numeric_type(
f'GIVEN the asset_definition "{GIVEN_fake_asset_name}" '
f'in the "{GIVEN_registered_domain.name}" domain'
):
client_cli.register().asset_definition(
iroha_cli.register().asset_definition(
asset=asset_def.name,
domain=asset_def.domain,
type_=asset_def.type_,
Expand All @@ -190,7 +188,7 @@ def GIVEN_minted_asset_quantity(
definition=GIVEN_registered_asset_definition_with_numeric_type,
value=GIVEN_numeric_value,
)
client_cli.mint().asset(
iroha_cli.mint().asset(
account=asset.account,
asset_definition=asset.definition,
value_of_type=asset.value,
Expand All @@ -212,7 +210,7 @@ def GIVEN_registered_asset_definition_with_store_type(
f'GIVEN the asset_definition "{GIVEN_fake_asset_name}" '
f'in the "{GIVEN_registered_domain.name}" domain'
):
client_cli.register().asset_definition(
iroha_cli.register().asset_definition(
asset=asset_def.name,
domain=asset_def.domain,
type=asset_def.type,
Expand Down
12 changes: 6 additions & 6 deletions iroha_cli/pytests/test/domains/test_register_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_register_existing_domain_uppercase_with_uppercase_letter(
f"WHEN iroha_cli registers an existing domain, "
f'but with uppercase letter "{GIVEN_registered_domain_with_uppercase_letter.name}"'
):
client_cli.register().domain(GIVEN_registered_domain_with_uppercase_letter.name)
iroha_cli.register().domain(GIVEN_registered_domain_with_uppercase_letter.name)
with allure.step(
f'THEN Iroha should have the domain name "{GIVEN_registered_domain_with_uppercase_letter.name}"'
):
Expand All @@ -61,7 +61,7 @@ def test_register_one_letter_domain(GIVEN_random_character):
with allure.step(
f'WHEN iroha_cli registers the one letter domain "{GIVEN_random_character}"'
):
client_cli.register().domain(GIVEN_random_character)
iroha_cli.register().domain(GIVEN_random_character)
with allure.step(f'THEN Iroha should have the domain "{GIVEN_random_character}"'):
iroha.should(have.domain(GIVEN_random_character))

Expand All @@ -72,20 +72,20 @@ def test_register_domain_with_reserved_character(GIVEN_string_with_reserved_char
f'WHEN iroha_cli registers a domain "'
f'{GIVEN_string_with_reserved_character}" with reserved characters'
):
client_cli.register().domain(GIVEN_string_with_reserved_character)
iroha_cli.register().domain(GIVEN_string_with_reserved_character)
with allure.step(
f'THEN iroha_cli should has the domain error: "{Stderr.RESERVED_CHARACTER.value}"'
):
client_cli.should(have.error(Stderr.RESERVED_CHARACTER.value))
iroha_cli.should(have.error(Stderr.RESERVED_CHARACTER.value))


@allure.label("sdk_test_id", "register_domain_with_whitespaces")
def test_register_domain_with_whitespaces(GIVEN_string_with_whitespaces):
with allure.step(
f'WHEN iroha_cli registers a domain "{GIVEN_string_with_whitespaces}" with whitespaces'
):
client_cli.register().domain(GIVEN_string_with_whitespaces)
iroha_cli.register().domain(GIVEN_string_with_whitespaces)
with allure.step(
f'THEN iroha_cli should has the domain error: "{Stderr.WHITESPACES.value}"'
):
client_cli.should(have.error(Stderr.WHITESPACES.value))
iroha_cli.should(have.error(Stderr.WHITESPACES.value))

0 comments on commit 59851dd

Please sign in to comment.