From 4cbbe261eee5b5ffa02e93d2924fefe72391e630 Mon Sep 17 00:00:00 2001 From: alexstroke Date: Mon, 25 Dec 2023 18:43:08 +0400 Subject: [PATCH] [refactor] refactor with lints Signed-off-by: alexstroke <111361420+astrokov7@users.noreply.github.com> --- client_cli/pytests/common/helpers.py | 19 ++++--- client_cli/pytests/common/settings.py | 1 + client_cli/pytests/models/account.py | 1 + client_cli/pytests/models/asset.py | 1 + client_cli/pytests/models/domain.py | 1 + client_cli/pytests/src/client_cli/__init__.py | 2 +- .../pytests/src/client_cli/client_cli.py | 54 +++++++++++-------- .../pytests/src/client_cli/configuration.py | 16 +++--- client_cli/pytests/src/client_cli/have.py | 24 ++++++--- client_cli/pytests/src/client_cli/iroha.py | 13 ++--- client_cli/pytests/src/client_cli/match.py | 1 + client_cli/pytests/test/__init__.py | 37 +++++-------- client_cli/pytests/test/accounts/conftest.py | 20 +++---- .../accounts/test_accounts_query_filters.py | 4 +- .../test/accounts/test_register_accounts.py | 1 + .../test/accounts/test_set_key_value_pair.py | 1 + client_cli/pytests/test/assets/conftest.py | 34 +++++------- .../test/assets/test_assets_query_filters.py | 4 +- .../assets/test_register_asset_definitions.py | 1 + .../test/assets/test_unregister_asset.py | 1 + client_cli/pytests/test/atomicity/conftest.py | 7 ++- ...ultiple_instructions_within_transaction.py | 1 + ...st_pair_instructions_within_transaction.py | 1 + ...t_wrong_instructions_within_transaction.py | 1 + client_cli/pytests/test/conftest.py | 34 ++++++++---- client_cli/pytests/test/domains/conftest.py | 24 ++++----- .../domains/test_domains_query_filters.py | 4 +- .../test/domains/test_transfer_domains.py | 3 +- client_cli/pytests/test/roles/conftest.py | 8 ++- .../pytests/test/roles/test_register_roles.py | 1 + client_cli/pytests/test/triggers/conftest.py | 6 +-- 31 files changed, 168 insertions(+), 158 deletions(-) diff --git a/client_cli/pytests/common/helpers.py b/client_cli/pytests/common/helpers.py index 7dde9db0e13..4aefaf582eb 100644 --- a/client_cli/pytests/common/helpers.py +++ b/client_cli/pytests/common/helpers.py @@ -5,24 +5,26 @@ import binascii import json import random -import string import re +import string from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey + from common.consts import ReservedChars, fake -def extract_hash(string): + +def extract_hash(stdout): """ Extracts a SHA-256 hash from the given string. - :param string: The string from which to extract the hash. + :param stdout: The string from which to extract the hash. :return: The extracted hash if found, otherwise None. """ - if not isinstance(string, str) or not string.strip(): + if not isinstance(stdout, str) or not stdout.strip(): return None pattern = r'"([A-Fa-f0-9]{64})"' - match = re.search(pattern, string) + match = re.search(pattern, stdout) return match.group(1) if match else None def read_isi_from_json(file_path): @@ -32,7 +34,7 @@ def read_isi_from_json(file_path): :param file_path: Path to the JSON file containing ISI instruction. :return: Dictionary with ISI instruction. """ - with open(file_path, 'r') as file: + with open(file_path, 'r', encoding='utf-8') as file: isi_data = json.load(file) return isi_data @@ -46,7 +48,7 @@ def write_isi_to_json(isi_data, file_path): """ if not isinstance(isi_data, list): isi_data = [isi_data] - with open(file_path, 'w') as file: + with open(file_path, 'w', encoding='utf-8') as file: json.dump(isi_data, file, indent=4) def generate_random_string_with_reserved_char(): @@ -93,7 +95,8 @@ def generate_random_string_without_reserved_chars(length): """ Generate a random string with the specified length, excluding reserved characters. """ - allowed_chars = [c for c in [*string.ascii_letters, *string.digits] if c not in ReservedChars.ALL.value] + allowed_chars = \ + [c for c in [*string.ascii_letters, *string.digits] if c not in ReservedChars.ALL.value] return generate_random_string(length, allowed_chars) diff --git a/client_cli/pytests/common/settings.py b/client_cli/pytests/common/settings.py index b7b8e6cadf3..81dd124c191 100644 --- a/client_cli/pytests/common/settings.py +++ b/client_cli/pytests/common/settings.py @@ -4,6 +4,7 @@ """ import os + from dotenv import load_dotenv load_dotenv() diff --git a/client_cli/pytests/models/account.py b/client_cli/pytests/models/account.py index 0f2835eb7e9..b191dbbbcfd 100644 --- a/client_cli/pytests/models/account.py +++ b/client_cli/pytests/models/account.py @@ -3,6 +3,7 @@ """ from dataclasses import dataclass + @dataclass class Account: """ diff --git a/client_cli/pytests/models/asset.py b/client_cli/pytests/models/asset.py index 5d2269091e1..8b4fff03363 100644 --- a/client_cli/pytests/models/asset.py +++ b/client_cli/pytests/models/asset.py @@ -4,6 +4,7 @@ from dataclasses import dataclass + @dataclass class AssetDefinition: """ diff --git a/client_cli/pytests/models/domain.py b/client_cli/pytests/models/domain.py index cf3528ba338..6f1111c5879 100644 --- a/client_cli/pytests/models/domain.py +++ b/client_cli/pytests/models/domain.py @@ -3,6 +3,7 @@ """ from dataclasses import dataclass + @dataclass class Domain: """ diff --git a/client_cli/pytests/src/client_cli/__init__.py b/client_cli/pytests/src/client_cli/__init__.py index f907e8b5009..dd9bea09b2a 100644 --- a/client_cli/pytests/src/client_cli/__init__.py +++ b/client_cli/pytests/src/client_cli/__init__.py @@ -2,7 +2,7 @@ This module initializes the Iroha client and configuration using environment variables. """ -from common.settings import PATH_CONFIG_CLIENT_CLI, PORT_MIN, PORT_MAX +from common.settings import PATH_CONFIG_CLIENT_CLI, PORT_MAX, PORT_MIN from src.client_cli.client_cli import ClientCli from src.client_cli.configuration import Config from src.client_cli.iroha import Iroha diff --git a/client_cli/pytests/src/client_cli/client_cli.py b/client_cli/pytests/src/client_cli/client_cli.py index c8714ffd171..36e87bc3014 100644 --- a/client_cli/pytests/src/client_cli/client_cli.py +++ b/client_cli/pytests/src/client_cli/client_cli.py @@ -4,14 +4,15 @@ """ import shlex import subprocess -from time import sleep, monotonic -from typing import Callable from pathlib import Path +from time import monotonic, sleep +from typing import Callable import allure -from common.helpers import read_isi_from_json, write_isi_to_json, extract_hash -from common.settings import PATH_CONFIG_CLIENT_CLI, CLIENT_CLI_PATH, BASE_DIR, ROOT_DIR +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 src.client_cli.configuration import Config @@ -67,7 +68,8 @@ def wait_for(self, condition: Callable[[], bool], timeout=None): start_time = monotonic() while not condition(): if monotonic() - start_time > timeout: - raise TimeoutError(f"Expected condition to be satisfied after waiting for '{timeout}' seconds.") + raise TimeoutError( + f"Expected condition to be satisfied after waiting for '{timeout}' seconds.") sleep(0.25) def reset(self): @@ -109,16 +111,14 @@ def list_all(self): self.command.append('all') return self - def list_filter(self, filter): + def list_filter(self, filter_criteria): """ - Appends the 'list all' command to the command list. - - :return: The current ClientCli object. - :rtype: ClientCli + Appends the 'list filter' command to the command list. + :param filter_criteria: Criteria to filter the list. """ - self.command.append('list'), + self.command.append('list') self.command.append('filter') - self.command.append(filter) + self.command.append(filter_criteria) return self def domain(self, domain: str): @@ -240,39 +240,45 @@ def definition(self, asset: str, domain: str, value_type: str): def register_trigger(self, account): """ - Creates a JSON file for the register_trigger with a specified account and executes it using the Iroha CLI. + Creates a JSON file for the register trigger and executes it using the Iroha CLI. :param account: The account to be used in the register_trigger. :type account: str """ - json_template_path = Path(BASE_DIR) / 'pytests' / 'common' / 'json_isi_examples' / 'register_trigger.json' + json_template_path = ( + Path(BASE_DIR)/'pytests'/'common'/'json_isi_examples'/'register_trigger.json') trigger_data = read_isi_from_json(str(json_template_path)) trigger_data[0]["Register"]["Trigger"]["action"]["authority"] = str(account) json_temp_file_path = Path(ROOT_DIR) / 'isi_register_trigger.json' write_isi_to_json(trigger_data, str(json_temp_file_path)) - self._execute_pipe(['cat', str(json_temp_file_path)], [self.BASE_PATH] + self.BASE_FLAGS + ['json']) + self._execute_pipe( + ['cat', str(json_temp_file_path)], + [self.BASE_PATH] + self.BASE_FLAGS + ['json']) return self def unregister_asset(self, asset_id): """ - Creates a JSON file for the unregister asset with a specified object_id and executes it using the Iroha CLI. + Creates a JSON file for the unregister asset and executes it using the Iroha CLI. :param asset_id: The object ID to be used in the unregister_asset. :type asset_id: str """ - json_template_path = Path(BASE_DIR) / 'pytests' / 'common' / 'json_isi_examples' / 'unregister_asset.json' + json_template_path = ( + Path(BASE_DIR) /'pytests'/'common'/'json_isi_examples'/'unregister_asset.json') asset_data = read_isi_from_json(str(json_template_path)) asset_data[0]["Unregister"]["Asset"]["object_id"] = str(asset_id) json_temp_file_path = Path(ROOT_DIR) / 'isi_unregister_asset.json' write_isi_to_json(asset_data, str(json_temp_file_path)) - self._execute_pipe(['cat', str(json_temp_file_path)], [self.BASE_PATH] + self.BASE_FLAGS + ['json']) + self._execute_pipe( + ['cat', str(json_temp_file_path)], + [self.BASE_PATH] + self.BASE_FLAGS + ['json']) return self @@ -307,15 +313,16 @@ def execute(self, command=None): self._execute_single(command) self.command = [self.BASE_PATH] + self.BASE_FLAGS - self.intention = None return self def _execute_pipe(self, cmd1, cmd2): """ Executes two commands connected by a pipe. """ - with subprocess.Popen(cmd1, stdout=subprocess.PIPE) as proc1, \ - subprocess.Popen(cmd2, stdin=proc1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc2: + with (subprocess.Popen( + cmd1, stdout=subprocess.PIPE) as proc1, + subprocess.Popen( + cmd2, stdin=proc1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc2): self.stdout, self.stderr = proc2.communicate() self.hash = extract_hash(self.stdout) self._attach_allure_reports() @@ -324,7 +331,8 @@ def _execute_single(self, command): """ Executes a single command. """ - with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as process: + with subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as process: self.stdout, self.stderr = process.communicate() self.hash = extract_hash(self.stdout) self._attach_allure_reports() @@ -354,4 +362,4 @@ def config(self, value): :param value: The new configuration object. :type value: Config """ - self._config = value \ No newline at end of file + self._config = value diff --git a/client_cli/pytests/src/client_cli/configuration.py b/client_cli/pytests/src/client_cli/configuration.py index caa828f0ad3..d581377b830 100644 --- a/client_cli/pytests/src/client_cli/configuration.py +++ b/client_cli/pytests/src/client_cli/configuration.py @@ -5,13 +5,13 @@ import json import os import random -from urllib.parse import urlparse class Config: """ - Configuration class to handle Iroha network configuration. The class provides methods for loading - the configuration from a file, updating the TORII_API_URL with a random port number from the specified + Configuration class to handle Iroha network configuration. + The class provides methods for loading the configuration from a file, + updating the TORII_API_URL with a random port number from the specified range, and accessing the configuration values. :param port_min: The minimum port number for the TORII_API_URL. @@ -44,7 +44,8 @@ def generate_by_peers(self, peers_configs_dir): Generate configuration files for each port in the range from port_min to port_max. """ if self._config is None: - raise ValueError("No configuration loaded. Use load(path_config_client_cli) to load the configuration.") + raise ValueError( + "No configuration loaded. Use load() method to load the configuration.") if self.port_min >= self.port_max: raise ValueError("port_min must be less than port_max.") @@ -66,14 +67,13 @@ def select_random_peer_config(self): :return: None """ - peers_configs = glob.glob('path/to/peers/configs/*.json') # Replace with the actual directory path + peers_configs = glob.glob('path/to/peers/configs/*.json') if not peers_configs: - raise ValueError("Peer configuration files not found. First generate them using generate_by_peers.") + raise ValueError( + "Peer configuration files not found. First generate them using generate_by_peers.") - # Select a random configuration file chosen_config_file = random.choice(peers_configs) - # Use the load method to load the selected configuration self.load(chosen_config_file) @property diff --git a/client_cli/pytests/src/client_cli/have.py b/client_cli/pytests/src/client_cli/have.py index 3bb51878891..9bd87b1f314 100644 --- a/client_cli/pytests/src/client_cli/have.py +++ b/client_cli/pytests/src/client_cli/have.py @@ -3,12 +3,20 @@ """ import json + import allure from src.client_cli import client_cli, iroha, match def expected_in_actual(expected, actual) -> bool: + """ + Check if the expected result is present in the actual result. + + :param expected: The expected result. + :param actual: The actual result. + :return: True if expected is in actual, False otherwise. + """ allure.attach( json.dumps(actual), name='actual', @@ -28,7 +36,7 @@ def domain(expected, owned_by=None): :param expected: The expected domain object. :param owned_by: The owner of the domain, default is None. - :return: True if the domain is present (and owned by the specified owner if provided), False otherwise. + :return: True if the domain is present and owned by the specified owner if provided. """ def domain_in_domains() -> bool: @@ -70,7 +78,9 @@ def asset_definition(expected): expected_domain = expected.split('#')[1] def asset_definition_in_asset_definitions() -> bool: - asset_definitions = iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected_domain}"}}}}').asset_definitions() + asset_definitions = ( + iroha.list_filter( + f'{{"Identifiable": {{"Is": "{expected_domain}"}}}}').asset_definitions()) return expected_in_actual(expected, asset_definitions) return client_cli.wait_for(asset_definition_in_asset_definitions) @@ -100,15 +110,15 @@ def asset_has_quantity(expected_asset_id, expected_quantity): """ def check_quantity() -> bool: - assets = iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected_asset_id}"}}}}').assets() + assets = iroha.list_filter( + f'{{"Identifiable": {{"Is": "{expected_asset_id}"}}}}').assets() actual_quantity = None - for asset in assets: - if asset == expected_asset_id: + for asset_item in assets: + if asset_item == expected_asset_id: actual_quantity = assets.get(expected_asset_id, {})["value"]["Quantity"] break - if actual_quantity is None: - raise Exception(f"Asset with ID {expected_asset_id} not found.") + raise ValueError(f"Asset with ID {expected_asset_id} not found.") allure.attach( json.dumps(actual_quantity), diff --git a/client_cli/pytests/src/client_cli/iroha.py b/client_cli/pytests/src/client_cli/iroha.py index c0505edb6d6..1e0ec2f7164 100644 --- a/client_cli/pytests/src/client_cli/iroha.py +++ b/client_cli/pytests/src/client_cli/iroha.py @@ -4,7 +4,8 @@ import json from typing import Dict, List -from src.client_cli.client_cli import ClientCli, Config + +from src.client_cli.client_cli import ClientCli class Iroha(ClientCli): @@ -13,14 +14,6 @@ class Iroha(ClientCli): for interacting with the Iroha network. """ - def __init__(self, config: Config): - """ - :param config: A configuration object containing the details for the client. - :type config: Config - :param path: The path where the client executable is located. - :type path: str - """ - super().__init__(config) def _execute_command(self, command_name: str): """ @@ -42,7 +35,7 @@ def should(self, *args, **kwargs): """ return self - def should_not(func): + def should_not(self, func): """ Decorator that inverts the result of the check function. diff --git a/client_cli/pytests/src/client_cli/match.py b/client_cli/pytests/src/client_cli/match.py index 4aa9b65cadf..8eb122942bc 100644 --- a/client_cli/pytests/src/client_cli/match.py +++ b/client_cli/pytests/src/client_cli/match.py @@ -4,6 +4,7 @@ import allure + def client_cli_have_error(expected: str, actual: str): """ Checks if the command-line client has the expected error. diff --git a/client_cli/pytests/test/__init__.py b/client_cli/pytests/test/__init__.py index f2d4ec61f84..c26a3db8577 100644 --- a/client_cli/pytests/test/__init__.py +++ b/client_cli/pytests/test/__init__.py @@ -2,31 +2,18 @@ This module provides access to fixtures for testing. """ from .conftest import ( - before_all, - before_each, - GIVEN_127_lenght_name, - GIVEN_128_lenght_name, - GIVEN_129_lenght_name, + GIVEN_127_lenght_name, GIVEN_128_lenght_name, GIVEN_129_lenght_name, + GIVEN_big_quantity_value_type, + GIVEN_currently_account_quantity_with_two_quantity_of_asset, + GIVEN_currently_authorized_account, GIVEN_fake_asset_name, GIVEN_fake_name, + GIVEN_key_with_invalid_character_in_key, GIVEN_minted_asset_quantity, + GIVEN_not_existing_name, GIVEN_public_key, + GIVEN_quantity_asset_for_account, GIVEN_quantity_value, + GIVEN_quantity_value_type, GIVEN_random_character, GIVEN_registered_account, + GIVEN_registered_asset_definition_with_big_quantity_value_type, GIVEN_registered_asset_definition_with_quantity_value_type, GIVEN_registered_asset_definition_with_store_value_type, - GIVEN_registered_domain_with_uppercase_letter, - GIVEN_registered_domain, - GIVEN_fake_asset_name, - GIVEN_fake_name, - GIVEN_key_with_invalid_character_in_key, - GIVEN_not_existing_name, - GIVEN_public_key, - GIVEN_quantity_value, - GIVEN_random_character, - GIVEN_string_with_reserved_character, - GIVEN_big_quantity_value_type, - GIVEN_registered_asset_definition_with_big_quantity_value_type, - GIVEN_129_lenght_name, - GIVEN_string_with_whitespaces, - GIVEN_quantity_value_type, - GIVEN_store_value_type, - GIVEN_currently_authorized_account, - GIVEN_minted_asset_quantity, - GIVEN_quantity_asset_for_account, - GIVEN_currently_account_quantity_with_two_quantity_of_asset) + GIVEN_registered_domain, GIVEN_registered_domain_with_uppercase_letter, + GIVEN_store_value_type, GIVEN_string_with_reserved_character, + GIVEN_string_with_whitespaces, before_all, before_each) diff --git a/client_cli/pytests/test/accounts/conftest.py b/client_cli/pytests/test/accounts/conftest.py index be0c3822dfe..f745f3b07be 100644 --- a/client_cli/pytests/test/accounts/conftest.py +++ b/client_cli/pytests/test/accounts/conftest.py @@ -1,18 +1,12 @@ -import pytest +from test import (GIVEN_127_lenght_name, GIVEN_129_lenght_name, + GIVEN_fake_name, GIVEN_key_with_invalid_character_in_key, + GIVEN_not_existing_name, GIVEN_public_key, + GIVEN_random_character, GIVEN_registered_account, + GIVEN_registered_domain, before_all, before_each) + import allure +import pytest -from test import ( - before_all, - before_each, - GIVEN_127_lenght_name, - GIVEN_129_lenght_name, - GIVEN_registered_account, - GIVEN_registered_domain, - GIVEN_fake_name, - GIVEN_key_with_invalid_character_in_key, - GIVEN_not_existing_name, - GIVEN_public_key, - GIVEN_random_character) @pytest.fixture(scope="function", autouse=True) def account_test_setup(): diff --git a/client_cli/pytests/test/accounts/test_accounts_query_filters.py b/client_cli/pytests/test/accounts/test_accounts_query_filters.py index 89a636696e0..4e443196337 100644 --- a/client_cli/pytests/test/accounts/test_accounts_query_filters.py +++ b/client_cli/pytests/test/accounts/test_accounts_query_filters.py @@ -1,7 +1,9 @@ import json + import allure -from src.client_cli import iroha, client_cli +from src.client_cli import client_cli, iroha + # using existing account to have at least one account in response def test_filter_by_domain(GIVEN_registered_account): diff --git a/client_cli/pytests/test/accounts/test_register_accounts.py b/client_cli/pytests/test/accounts/test_register_accounts.py index 6a7184624a6..467ff0c614c 100644 --- a/client_cli/pytests/test/accounts/test_register_accounts.py +++ b/client_cli/pytests/test/accounts/test_register_accounts.py @@ -4,6 +4,7 @@ from common.consts import Stderr from src.client_cli import client_cli, have, iroha + @pytest.fixture(scope="function", autouse=True) def story_account_register_account(): allure.dynamic.story('Account registers an account') diff --git a/client_cli/pytests/test/accounts/test_set_key_value_pair.py b/client_cli/pytests/test/accounts/test_set_key_value_pair.py index a63ed15e263..96a1021bdc1 100644 --- a/client_cli/pytests/test/accounts/test_set_key_value_pair.py +++ b/client_cli/pytests/test/accounts/test_set_key_value_pair.py @@ -1,6 +1,7 @@ import allure import pytest + @pytest.fixture(scope="function", autouse=True) def story_client_change_account_metadata(): allure.dynamic.story("Account set key value pair") diff --git a/client_cli/pytests/test/assets/conftest.py b/client_cli/pytests/test/assets/conftest.py index fe44c451a07..02ec6a257d6 100644 --- a/client_cli/pytests/test/assets/conftest.py +++ b/client_cli/pytests/test/assets/conftest.py @@ -1,28 +1,18 @@ -import pytest -import allure - from test import ( - before_all, - before_each, - GIVEN_registered_account, + GIVEN_129_lenght_name, GIVEN_big_quantity_value_type, + GIVEN_currently_account_quantity_with_two_quantity_of_asset, + GIVEN_currently_authorized_account, GIVEN_fake_asset_name, GIVEN_fake_name, + GIVEN_minted_asset_quantity, GIVEN_not_existing_name, GIVEN_public_key, + GIVEN_quantity_asset_for_account, GIVEN_quantity_value, + GIVEN_quantity_value_type, GIVEN_registered_account, + GIVEN_registered_asset_definition_with_big_quantity_value_type, GIVEN_registered_asset_definition_with_quantity_value_type, GIVEN_registered_asset_definition_with_store_value_type, - GIVEN_registered_domain, - GIVEN_fake_asset_name, - GIVEN_fake_name, - GIVEN_public_key, - GIVEN_129_lenght_name, - GIVEN_quantity_value, - GIVEN_quantity_value_type, - GIVEN_store_value_type, - GIVEN_big_quantity_value_type, - GIVEN_registered_asset_definition_with_big_quantity_value_type, - GIVEN_not_existing_name, - GIVEN_currently_authorized_account, - GIVEN_currently_account_quantity_with_two_quantity_of_asset, - GIVEN_minted_asset_quantity, - GIVEN_quantity_asset_for_account, - before_each) + GIVEN_registered_domain, GIVEN_store_value_type, before_all, before_each) + +import allure +import pytest + @pytest.fixture(scope="function", autouse=True) def asset_test_setup(): diff --git a/client_cli/pytests/test/assets/test_assets_query_filters.py b/client_cli/pytests/test/assets/test_assets_query_filters.py index 789f27d2f1f..3e58a547e8e 100644 --- a/client_cli/pytests/test/assets/test_assets_query_filters.py +++ b/client_cli/pytests/test/assets/test_assets_query_filters.py @@ -1,7 +1,9 @@ import json + import allure -from src.client_cli import iroha, client_cli +from src.client_cli import client_cli, iroha + # using existing account with asset to have at least one in response def test_filter_by_domain(GIVEN_currently_account_quantity_with_two_quantity_of_asset): diff --git a/client_cli/pytests/test/assets/test_register_asset_definitions.py b/client_cli/pytests/test/assets/test_register_asset_definitions.py index 29c086f6006..218325437d5 100644 --- a/client_cli/pytests/test/assets/test_register_asset_definitions.py +++ b/client_cli/pytests/test/assets/test_register_asset_definitions.py @@ -4,6 +4,7 @@ from common.consts import Stderr from src.client_cli import client_cli, have, iroha + @pytest.fixture(scope="function", autouse=True) def story_account_registers_asset_definitions(): allure.dynamic.story('Account registers an asset definition') diff --git a/client_cli/pytests/test/assets/test_unregister_asset.py b/client_cli/pytests/test/assets/test_unregister_asset.py index 17d7e3525bf..920a96c0665 100644 --- a/client_cli/pytests/test/assets/test_unregister_asset.py +++ b/client_cli/pytests/test/assets/test_unregister_asset.py @@ -3,6 +3,7 @@ from src.client_cli import client_cli, have, iroha + @pytest.fixture(scope="function", autouse=True) def story_account_unregisters_asset(): allure.dynamic.story('Account unregisters an asset') diff --git a/client_cli/pytests/test/atomicity/conftest.py b/client_cli/pytests/test/atomicity/conftest.py index 97a31e8a608..79113e2abd5 100644 --- a/client_cli/pytests/test/atomicity/conftest.py +++ b/client_cli/pytests/test/atomicity/conftest.py @@ -1,9 +1,8 @@ -import pytest +from test import before_all, before_each + import allure +import pytest -from test import ( - before_all, - before_each) @pytest.fixture(scope="function", autouse=True) def atomicity_test_setup(): diff --git a/client_cli/pytests/test/atomicity/test_multiple_instructions_within_transaction.py b/client_cli/pytests/test/atomicity/test_multiple_instructions_within_transaction.py index c05a70430ab..551cdcd7f0f 100644 --- a/client_cli/pytests/test/atomicity/test_multiple_instructions_within_transaction.py +++ b/client_cli/pytests/test/atomicity/test_multiple_instructions_within_transaction.py @@ -1,6 +1,7 @@ import allure import pytest + @pytest.fixture(scope="function", autouse=True) def story_client_sends_multiple_instructions_within_transaction(): allure.dynamic.story('Client sends a multiple instructions within transaction') diff --git a/client_cli/pytests/test/atomicity/test_pair_instructions_within_transaction.py b/client_cli/pytests/test/atomicity/test_pair_instructions_within_transaction.py index 679c7b0cfe1..5d650495211 100644 --- a/client_cli/pytests/test/atomicity/test_pair_instructions_within_transaction.py +++ b/client_cli/pytests/test/atomicity/test_pair_instructions_within_transaction.py @@ -1,6 +1,7 @@ import allure import pytest + @pytest.fixture(scope="function", autouse=True) def story_client_sends_pair_instructions_within_transaction(): allure.dynamic.story('Client sends a pair instructions within transaction') diff --git a/client_cli/pytests/test/atomicity/test_wrong_instructions_within_transaction.py b/client_cli/pytests/test/atomicity/test_wrong_instructions_within_transaction.py index 66422357536..5e1df2dcfeb 100644 --- a/client_cli/pytests/test/atomicity/test_wrong_instructions_within_transaction.py +++ b/client_cli/pytests/test/atomicity/test_wrong_instructions_within_transaction.py @@ -1,6 +1,7 @@ import allure import pytest + @pytest.fixture(scope="function", autouse=True) def story_send_pair_instructions_within_transaction(): allure.dynamic.story('Client sends a wrong instruction in transaction') diff --git a/client_cli/pytests/test/conftest.py b/client_cli/pytests/test/conftest.py index badedc7eaa7..101612ef90e 100644 --- a/client_cli/pytests/test/conftest.py +++ b/client_cli/pytests/test/conftest.py @@ -1,4 +1,5 @@ # pylint: disable=redefined-outer-name +# pylint: disable=invalid-name """ This module contains pytest fixtures for testing. """ @@ -7,13 +8,17 @@ from common.consts import ValueTypes from common.helpers import * -from models import Account, AssetDefinition, Domain, Asset -from src.client_cli import client_cli, config from common.settings import PEERS_CONFIGS_PATH +from models import Account, Asset, AssetDefinition, Domain +from src.client_cli import client_cli, config + # General fixtures @pytest.fixture(scope='session', autouse=True) def before_all(): + """Initial setup for all test sessions. + This fixture generates configurations based on peers and is automatically + used for every test session.""" config.generate_by_peers(PEERS_CONFIGS_PATH) yield @@ -66,7 +71,8 @@ def GIVEN_currently_authorized_account(): name=config.account_name, domain=config.account_domain, public_key=config.public_key) - with allure.step(f'GIVEN the currently authorized account "{account.name}" in the "{account.domain}" domain'): + with allure.step(f'GIVEN the currently authorized account "{account.name}" ' + f'in the "{account.domain}" domain'): return account @pytest.fixture() @@ -150,6 +156,8 @@ def GIVEN_minted_asset_quantity( GIVEN_registered_asset_definition_with_quantity_value_type, GIVEN_registered_account, GIVEN_quantity_value): + """Fixture to create and return an asset with a specified quantity. + It takes a registered asset definition, a registered account, and a quantity value.""" asset = Asset(account=GIVEN_registered_account, definition=GIVEN_registered_asset_definition_with_quantity_value_type, value=GIVEN_quantity_value) @@ -231,8 +239,13 @@ def GIVEN_random_character(): @pytest.fixture() def GIVEN_random_invalid_base64_character(): - """Fixture to provide a random invalid base64 character (not a-z,A-Z,0-9,+,/,=).""" - letter = random.choice([ch for ch in string.printable if not (ch.isalpha() or ch.isdigit() or ch == "=" or ch == "+" or ch == "/")]) + """Fixture to provide a random invalid base64 character + (not a-z,A-Z,0-9,+,/,=). + """ + invalid_chars = [ch for ch in string.printable + if not (ch.isalpha() or ch.isdigit() + or ch in ["=", "+", "/"])] + letter = random.choice(invalid_chars) with allure.step(f'GIVEN a "{letter}" name'): return letter @@ -242,7 +255,9 @@ def GIVEN_key_with_invalid_character_in_key( GIVEN_public_key, GIVEN_random_invalid_base64_character): """Fixture to provide a public key with an invalid character.""" - invalid_key = key_with_invalid_character_in_key(GIVEN_public_key, GIVEN_random_invalid_base64_character) + invalid_key = key_with_invalid_character_in_key( + GIVEN_public_key, + GIVEN_random_invalid_base64_character) with allure.step(f'GIVEN an invalid key "{invalid_key}"'): return invalid_key @@ -276,19 +291,19 @@ def GIVEN_quantity_value(): @pytest.fixture() def GIVEN_128_lenght_name(): ident = generate_random_string_without_reserved_chars(128) - with allure.step(f'GIVEN a name with 128 lenght "{ident}"'): + with allure.step(f'GIVEN a name with 128 length "{ident}"'): return ident @pytest.fixture() def GIVEN_129_lenght_name(): ident = generate_random_string_without_reserved_chars(129) - with allure.step(f'GIVEN a name with 129 lenght "{ident}"'): + with allure.step(f'GIVEN a name with 129 length "{ident}"'): return ident @pytest.fixture() def GIVEN_127_lenght_name(): ident = generate_random_string_without_reserved_chars(127) - with allure.step(f'GIVEN a name with 127 lenght "{ident}"'): + with allure.step(f'GIVEN a name with 127 length "{ident}"'): return ident @pytest.fixture() @@ -304,4 +319,3 @@ def GIVEN_string_with_whitespaces(): new_string = generate_random_string_with_whitespace() with allure.step(f'GIVEN a "{new_string}" string'): return new_string - diff --git a/client_cli/pytests/test/domains/conftest.py b/client_cli/pytests/test/domains/conftest.py index 67865b1d268..7ac0a156283 100644 --- a/client_cli/pytests/test/domains/conftest.py +++ b/client_cli/pytests/test/domains/conftest.py @@ -1,20 +1,14 @@ -import pytest +from test import (GIVEN_128_lenght_name, GIVEN_129_lenght_name, + GIVEN_currently_authorized_account, GIVEN_fake_name, + GIVEN_public_key, GIVEN_random_character, + GIVEN_registered_account, GIVEN_registered_domain, + GIVEN_registered_domain_with_uppercase_letter, + GIVEN_string_with_reserved_character, + GIVEN_string_with_whitespaces, before_all, before_each) + import allure +import pytest -from test import ( - before_all, - before_each, - GIVEN_128_lenght_name, - GIVEN_129_lenght_name, - GIVEN_registered_domain, - GIVEN_fake_name, - GIVEN_random_character, - GIVEN_string_with_reserved_character, - GIVEN_string_with_whitespaces, - GIVEN_registered_domain_with_uppercase_letter, - GIVEN_currently_authorized_account, - GIVEN_registered_account, - GIVEN_public_key) @pytest.fixture(scope="function", autouse=True) def domain_test_setup(): diff --git a/client_cli/pytests/test/domains/test_domains_query_filters.py b/client_cli/pytests/test/domains/test_domains_query_filters.py index 5bd99a150cf..ee9eeaa6d32 100644 --- a/client_cli/pytests/test/domains/test_domains_query_filters.py +++ b/client_cli/pytests/test/domains/test_domains_query_filters.py @@ -1,7 +1,9 @@ import json + import allure -from src.client_cli import iroha, client_cli +from src.client_cli import client_cli, iroha + def test_filter_by_domain(GIVEN_registered_domain): def condition(): diff --git a/client_cli/pytests/test/domains/test_transfer_domains.py b/client_cli/pytests/test/domains/test_transfer_domains.py index c69ec407ed5..bfdd8ff1ad0 100644 --- a/client_cli/pytests/test/domains/test_transfer_domains.py +++ b/client_cli/pytests/test/domains/test_transfer_domains.py @@ -1,7 +1,8 @@ import allure import pytest -from src.client_cli import client_cli, iroha, have +from src.client_cli import client_cli, have, iroha + @pytest.fixture(scope="function", autouse=True) def story_account_transfers_domain(): diff --git a/client_cli/pytests/test/roles/conftest.py b/client_cli/pytests/test/roles/conftest.py index 0a8c861af9f..44cb325154e 100644 --- a/client_cli/pytests/test/roles/conftest.py +++ b/client_cli/pytests/test/roles/conftest.py @@ -1,10 +1,8 @@ -import pytest +from test import GIVEN_fake_name, before_all, before_each + import allure +import pytest -from test import ( - before_all, - before_each, - GIVEN_fake_name) @pytest.fixture(scope="function", autouse=True) def role_test_setup(): diff --git a/client_cli/pytests/test/roles/test_register_roles.py b/client_cli/pytests/test/roles/test_register_roles.py index 95ad445c85b..c476c3a6137 100644 --- a/client_cli/pytests/test/roles/test_register_roles.py +++ b/client_cli/pytests/test/roles/test_register_roles.py @@ -1,6 +1,7 @@ import allure import pytest + @pytest.fixture(scope="function", autouse=True) def story_account_registers_roles(): allure.dynamic.story('Account registers a role') diff --git a/client_cli/pytests/test/triggers/conftest.py b/client_cli/pytests/test/triggers/conftest.py index 27e8fcc6d82..5a8df78eedb 100644 --- a/client_cli/pytests/test/triggers/conftest.py +++ b/client_cli/pytests/test/triggers/conftest.py @@ -1,8 +1,8 @@ -import pytest +from test import GIVEN_currently_authorized_account + import allure +import pytest -from test import ( - GIVEN_currently_authorized_account) @pytest.fixture(scope="function", autouse=True) def trigger_test_setup():