Skip to content

Commit

Permalink
[refactor] list_filter() accepts native Python dict` for more rea…
Browse files Browse the repository at this point in the history
…dable

Signed-off-by: alexstroke <[email protected]>
  • Loading branch information
alexstroke authored and AlexStroke committed Feb 20, 2024
1 parent 1861a2d commit b2b4ce1
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 76 deletions.
74 changes: 37 additions & 37 deletions client_cli/pytests/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions client_cli/pytests/src/client_cli/client_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def list_filter(self, filter_criteria):
"""
self.command.append("list")
self.command.append("filter")
self.command.append(filter_criteria)
self.command.append(str(filter_criteria))
return self

def domain(self, domain: str):
Expand Down Expand Up @@ -358,18 +358,18 @@ def _execute_pipe(self, cmd1, cmd2):
"""
Executes two commands connected by a pipe.
"""
with (subprocess.Popen(
cmd1,
stdout=subprocess.PIPE,
env=self.config.env
) as proc1,
with (
subprocess.Popen(
cmd1, stdout=subprocess.PIPE, env=self.config.env
) as proc1,
subprocess.Popen(
cmd2,
stdin=proc1.stdout,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=self.config.env
) as proc2):
env=self.config.env,
) as proc2,
):
self.stdout, self.stderr = proc2.communicate()
self.transaction_hash = extract_hash(self.stdout)
self._attach_allure_reports()
Expand All @@ -379,11 +379,11 @@ def _execute_single(self, command):
Executes a single command.
"""
with subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
env=self.config.env
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
env=self.config.env,
) as process:
self.stdout, self.stderr = process.communicate()
self.transaction_hash = extract_hash(self.stdout)
Expand Down
10 changes: 6 additions & 4 deletions client_cli/pytests/src/client_cli/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load(self, path_config_client_cli):
"""
if not os.path.exists(path_config_client_cli):
raise IOError(f"No config file found at {path_config_client_cli}")
with open(path_config_client_cli, 'r', encoding='utf-8') as config_file:
with open(path_config_client_cli, "r", encoding="utf-8") as config_file:
self._config = tomlkit.load(config_file)
self.file = path_config_client_cli

Expand Down Expand Up @@ -92,7 +92,9 @@ def randomise_torii_url(self):
"""
parsed_url = urlparse(self._config["torii_url"])
random_port = random.randint(self.port_min, self.port_max)
self._envs["TORII_URL"] = parsed_url._replace(netloc=f"{parsed_url.hostname}:{random_port}").geturl()
self._envs["TORII_URL"] = parsed_url._replace(
netloc=f"{parsed_url.hostname}:{random_port}"
).geturl()

@property
def torii_url(self):
Expand Down Expand Up @@ -124,7 +126,7 @@ def account_id(self):
:return: The ACCOUNT_ID.
:rtype: str
"""
return self._config['account']["id"]
return self._config["account"]["id"]

@property
def account_name(self):
Expand Down Expand Up @@ -154,4 +156,4 @@ def public_key(self):
:return: The public key.
:rtype: str
"""
return self._config["account"]['public_key'].split('ed0120')[1]
return self._config["account"]["public_key"].split("ed0120")[1]
21 changes: 12 additions & 9 deletions client_cli/pytests/src/client_cli/iroha.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ def domains(self) -> Dict[str, Dict]:
:return: List of domains ids.
:rtype: List[str]
"""
self._execute_command('domain')
try:
domains = json.loads(self.stdout)
except json.decoder.JSONDecodeError as e:
print(f"JSON decode error occurred with this input:", self.stdout)
print(f"STDERR:", self.stderr)
raise
domains_dict = { domain["id"]: domain for domain in domains }
return domains_dict
self._execute_command("domain")
if self.stdout is not None:
try:
domains = json.loads(self.stdout)
except json.decoder.JSONDecodeError:
print("JSON decode error occurred with this input:", self.stdout)
print("STDERR:", self.stderr)
raise
domains_dict = {domain["id"]: domain for domain in domains}
return domains_dict
else:
return {}

def accounts(self) -> List[str]:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def condition():
f"WHEN client_cli query accounts " f'in the "{domain}" domain'
):
accounts = iroha.list_filter(
f'{{"Identifiable": {{"EndsWith": "@{domain}"}}}}'
{"Identifiable": {"EndsWith": f"@{domain}"}}
).accounts()
with allure.step("THEN Iroha should return only accounts with this domain"):
allure.attach(
Expand All @@ -31,7 +31,7 @@ def condition():
name = GIVEN_registered_account.name
with allure.step(f'WHEN client_cli query accounts with name "{name}"'):
accounts = iroha.list_filter(
f'{{"Identifiable": {{"StartsWith": "{name}@"}}}}'
{"Identifiable": {"StartsWith": f"{name}@"}}
).accounts()
with allure.step("THEN Iroha should return only accounts with this name"):
allure.attach(
Expand All @@ -53,7 +53,7 @@ def condition():
f'WHEN client_cli query accounts with account id "{account_id}"'
):
accounts = iroha.list_filter(
f'{{"Identifiable": {{"Is": "{account_id}"}}}}'
{"Identifiable": {"Is": account_id}}
).accounts()
with allure.step("THEN Iroha should return only accounts with this id"):
allure.attach(
Expand Down
20 changes: 13 additions & 7 deletions client_cli/pytests/test/assets/test_assets_query_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ def condition():
)
with allure.step(f"WHEN client_cli query assets" f'in the "{domain}" domain'):
assets = iroha.list_filter(
'{"Or": [{"Identifiable": {"Contains": "#' + domain + '#"}}, '
'{"And": [{"Identifiable": {"Contains": "##"}}, '
'{"Identifiable": {"EndsWith": "@' + domain + '"}}]}]}'
{
"Or": [
{"Identifiable": {"Contains": f"#{domain}#"}},
{
"And": [
{"Identifiable": {"Contains": "##"}},
{"Identifiable": {"EndsWith": f"@{domain}"}},
]
},
]
}
).assets()
with allure.step("THEN Iroha should return only assets with this domain"):
allure.attach(
Expand All @@ -40,7 +48,7 @@ def condition():
)
with allure.step(f'WHEN client_cli query assets with name "{name}"'):
assets = iroha.list_filter(
f'{{"Identifiable": {{"StartsWith": "{name}#"}}}}'
{"Identifiable": {"StartsWith": f"{name}#"}}
).assets()
with allure.step("THEN Iroha should return only assets with this name"):
allure.attach(
Expand All @@ -66,9 +74,7 @@ def condition():
+ GIVEN_currently_authorized_account.domain
)
with allure.step(f'WHEN client_cli query assets with asset id "{asset_id}"'):
assets = iroha.list_filter(
f'{{"Identifiable": {{"Is": "{asset_id}"}}}}'
).assets()
assets = iroha.list_filter({"Identifiable": {"Is": asset_id}}).assets()
with allure.step("THEN Iroha should return only assets with this id"):
allure.attach(
json.dumps(assets),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def condition():
with allure.step(
f'WHEN client_cli query domains filtered by name "{domain_name}"'
):
domains = iroha.list_filter(
f'{{"Identifiable": {{"Is": "{domain_name}"}}}}'
).domains()
domains = iroha.list_filter({"Identifiable": {"Is": domain_name}}).domains()
with allure.step(
f'THEN Iroha should return only return domains with "{domain_name}" name'
):
Expand Down

0 comments on commit b2b4ce1

Please sign in to comment.