Skip to content

Commit

Permalink
[refactor]: Remove redundant methods from pytest
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara authored and appetrosyan committed Jul 31, 2023
1 parent d71d548 commit 6c3b833
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 79 deletions.
8 changes: 4 additions & 4 deletions client_cli/pytests/src/client_cli/have.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def domain(expected):
"""
return match.iroha_have_domain(
expected=expected,
actual=lambda: iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected}"}}}}').domains().get_domains())
actual=lambda: iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected}"}}}}').domains())


def account(expected):
Expand All @@ -26,7 +26,7 @@ def account(expected):
"""
return match.iroha_have_account(
expected=expected,
actual=lambda: iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected}"}}}}').accounts().get_accounts())
actual=lambda: iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected}"}}}}').accounts())


def asset_definition(expected):
Expand All @@ -39,7 +39,7 @@ def asset_definition(expected):
expected_domain = expected.split('#')[1]
return match.iroha_have_asset_definition(
expected=expected,
actual=lambda: iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected_domain}"}}}}').asset_definitions().get_asset_definitions())
actual=lambda: iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected_domain}"}}}}').asset_definitions())


def asset(expected):
Expand All @@ -51,7 +51,7 @@ def asset(expected):
"""
return match.iroha_have_asset(
expected=expected,
actual=lambda: iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected}"}}}}').assets().get_assets())
actual=lambda: iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected}"}}}}').assets())


def error(expected):
Expand Down
99 changes: 24 additions & 75 deletions client_cli/pytests/src/client_cli/iroha.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import json
from typing import Any, Dict, List, Union
from typing import Dict, List
from src.client_cli.client_cli import ClientCli, Config


Expand All @@ -21,11 +21,6 @@ def __init__(self, config: Config):
:type path: str
"""
super().__init__(config)
self._storage: Union[Dict, List] = {}
self._domains: Union[Dict, List] = {}
self._accounts: Union[Dict, List] = {}
self._assets: Union[Dict, List] = {}
self._asset_definitions: Dict[str, Any] = {}

def _execute_command(self, command_name: str):
"""
Expand All @@ -48,103 +43,57 @@ def should(self, _expected):
"""
return self

def domains(self):
def domains(self) -> List[str]:
"""
Retrieve domains from the Iroha network and store them in the _domains attribute.
Retrieve domains from the Iroha network and return then as list of ids.
:return: The current Iroha object.
:rtype: Iroha
"""
self._execute_command('domain')
self._storage = json.loads(self.stdout)
self._domains = [self._storage["id"] for self._storage in self._storage]
return self
domains = json.loads(self.stdout)
domains = [domain["id"] for domain in domains]
return domains

def accounts(self):
def accounts(self) -> List[str]:
"""
Retrieve accounts from the Iroha network and store them in the _accounts attribute.
Retrieve accounts from the Iroha network and return them as list of ids.
:return: The current Iroha object.
:rtype: Iroha
"""
self._execute_command('account')
self._accounts = json.loads(self.stdout)
self._accounts = [self._accounts["id"] for self._accounts in self._accounts]
return self
accounts = json.loads(self.stdout)
accounts = [account["id"] for account in accounts]
return accounts

def assets(self):
def assets(self) -> List[str]:
"""
Retrieve assets from the Iroha network and store them in the _assets attribute.
Retrieve assets from the Iroha network and return them as list of ids.
:return: The current Iroha object.
:rtype: Iroha
"""
self._execute_command('asset')
self._assets = json.loads(self.stdout)
self._assets = [self._assets["id"] for self._assets in self._assets]
return self
assets = json.loads(self.stdout)
assets = [asset["id"] for asset in assets]
return assets

def asset_definitions(self):
def asset_definitions(self) -> Dict[str, str]:
"""
Retrieve asset definitions from the Iroha network
and store them in the _asset_definitions attribute.
and return them as map where ids are keys and value types are values
:return: The current Iroha object.
:rtype: Iroha
"""
self._execute_command('domain')
self._storage = json.loads(self.stdout)
self._asset_definitions = {}
for obj in self._storage:
asset_defs = obj.get('asset_definitions')
domains = json.loads(self.stdout)
asset_definitions = {}
for domain in domains:
asset_defs = domain.get('asset_definitions')
for asset_def in asset_defs.values():
value_type = asset_def.get('value_type')
if value_type:
self._asset_definitions[asset_def['id']] = value_type
return self

def get_domains(self):
"""
Get the list of domains.
:return: A list of domain IDs.
:rtype: list
"""
return self._domains

def get_accounts(self):
"""
Get the list of accounts.
:return: A list of account IDs.
:rtype: list
"""
return self._accounts

def get_asset_definitions(self):
"""
Get the dictionary of asset definitions.
:return: A dictionary containing asset definition IDs as keys
and their value types as values.
:rtype: dict
"""
return self._asset_definitions

def get_assets(self):
"""
Get the list of assets.
:return: A list of asset IDs.
:rtype: list
"""
return self._assets

def get_storage(self):
"""
Get the storage data.
:return: The storage data in its current form.
:rtype: str
"""
return self._storage
asset_definitions[asset_def['id']] = value_type
return asset_definitions

0 comments on commit 6c3b833

Please sign in to comment.