Skip to content

Commit

Permalink
[refactor] tests decomposition
Browse files Browse the repository at this point in the history
Signed-off-by: alexstroke <111361420+astrokov7@users.noreply.github.com>
  • Loading branch information
Aleksandr Strokov authored and AlexStroke committed Apr 8, 2024
1 parent 495d3f4 commit 81ba9ad
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 39 deletions.
22 changes: 21 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from tests import client, fake
from tests.helpers import generate_public_key


@pytest.fixture()
Expand All @@ -19,11 +20,30 @@ def GIVEN_new_account_id(GIVEN_registered_domain):
with allure.step(f'GIVEN a "{name}" name'):
return name

@pytest.fixture()
def GIVEN_new_asset_id():
"""Fixture to provide a new asset id."""
asset_name = str(len(client.query_all_assets())) + fake.word()[:3].upper()
with allure.step(f'GIVEN a "{asset_name}" asset'):
return asset_name

@pytest.fixture()
def GIVEN_registered_domain(GIVEN_new_domain_id):
"""Fixture to provide registered domain in Iroha"""
with allure.step(f'GIVEN registered domain name "{GIVEN_new_domain_id}"'):
(client.submit_executable(
[iroha.Instruction
.register_domain(GIVEN_new_domain_id)]))
return GIVEN_new_domain_id
return GIVEN_new_domain_id

@pytest.fixture()
def GIVEN_registered_domain_with_registered_accounts(GIVEN_registered_domain, GIVEN_new_account_id):
"""Fixture to provide domain with accounts"""
with allure.step(
f'WHEN client registers the account "{GIVEN_new_account_id}"'):
(client.submit_executable(
[iroha.Instruction
.register_account(
GIVEN_new_account_id,
[generate_public_key(seed="abcd1122")])]))
return GIVEN_registered_domain
Empty file added tests/query/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions tests/query/test_query_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import allure
import time
import pytest

from tests import client

@pytest.fixture(scope="function", autouse=True)
def story_account_register_account():
allure.dynamic.story("Account queries accounts")
allure.dynamic.label("permission", "no_permission_required")

@allure.label("sdk_test_id", "query_all_accounts")
def test_query_all_accounts():
with allure.step('WHEN client queries all accounts'):
all_accounts = client.query_all_accounts()
with allure.step('THEN there should be some accounts present'):
assert len(all_accounts) > 0, "No accounts found in the system"


@allure.label("sdk_test_id", "query_all_accounts_in_domain")
def test_query_all_accounts_in_domain(
GIVEN_registered_domain_with_registered_accounts):
with allure.step(
f'WHEN client queries all accounts in domain "{GIVEN_registered_domain_with_registered_accounts}"'):
time.sleep(3)
accounts_in_domain = client.query_all_accounts_in_domain(GIVEN_registered_domain_with_registered_accounts)
with allure.step(
f'THEN the response should be a non-empty list of accounts in domain "{GIVEN_registered_domain_with_registered_accounts}"'):
assert isinstance(accounts_in_domain, list) and accounts_in_domain, \
f"Expected a non-empty list of accounts in the domain {GIVEN_registered_domain_with_registered_accounts}, got {accounts_in_domain}"


25 changes: 25 additions & 0 deletions tests/query/test_query_asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import allure
import time
import pytest

from tests import client

@pytest.fixture(scope="function", autouse=True)
def story_account_register_account():
allure.dynamic.story("Account queries assets")
allure.dynamic.label("permission", "no_permission_required")

@pytest.mark.xfail(reason="TO DO")
@allure.label("sdk_test_id", "query_all_assets_owned_by_account")
def test_query_all_assets_owned_by_account(
GIVEN_registered_account_with_assets):
with allure.step(
f'WHEN client queries all assets owned by account "{GIVEN_registered_account_with_assets}"'):
time.sleep(3)
assets_owned_by_account = client.query_all_assets_owned_by_account(GIVEN_registered_account_with_assets)
with allure.step(
f'THEN the response should be a non-empty list of assets owned by account "{GIVEN_registered_account_with_assets}"'):
assert isinstance(assets_owned_by_account, list) and assets_owned_by_account, \
f"Expected a non-empty list of assets owned by account {GIVEN_registered_account_with_assets}, got {assets_owned_by_account}"


33 changes: 1 addition & 32 deletions tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,4 @@ def test_register_account(
time.sleep(3)
with allure.step(
f'THEN Iroha should have the "{GIVEN_new_account_id}" account'):
assert GIVEN_new_account_id in client.query_all_accounts()

def test_register_account_but_use_query_all():
client = start_client()

new_account_key_pair = iroha.KeyGenConfiguration.default().use_seed_hex("abcd1144").generate()

accounts = client.query_all_accounts()

print("Listing all accounts...")
for a in accounts:
print(" - ", a,)

new_account_id = "white_rabbit_query_all_test_" + str(len(accounts)) + "@wonderland"

assert new_account_id not in accounts

register = iroha.Instruction.register_account(new_account_id, [new_account_key_pair.public_key])

client.submit_executable([register])

for x in range(30):
accounts = client.query_all_accounts()

if new_account_id in accounts:
break

time.sleep(1)


assert new_account_id in accounts

assert GIVEN_new_account_id in client.query_all_accounts()
14 changes: 9 additions & 5 deletions tests/test_asset.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import allure
import iroha
import time

import pytest

from tests import client

@pytest.fixture(scope="function", autouse=True)
def story_account_register_asset():
allure.dynamic.story("Account registers an asset")
allure.dynamic.label("permission", "no_permission_required")

def test_register_asset():
def test_register_asset(
GIVEN_new_asset_id):
assets = client.query_all_assets_owned_by_account("alice@wonderland")

print("Listing all assets owned by alice@wonderland...")
for a in assets:
print(" - ", a, )

asset_definition_id = "time_" + str(len(assets)) + "#wonderland"
asset_id = "time_" + str(len(assets)) + "##alice@wonderland"
assert asset_id not in assets
Expand Down
2 changes: 1 addition & 1 deletion tests/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def test_register_domain(
(client.submit_executable(
[iroha.Instruction
.register_domain(GIVEN_new_domain_id)]))
time.sleep(2)
time.sleep(3)
with allure.step(f'THEN Iroha should have the domain name "{GIVEN_new_domain_id}"'):
assert GIVEN_new_domain_id in client.query_all_domains()

0 comments on commit 81ba9ad

Please sign in to comment.