Skip to content

Commit

Permalink
[tests] cover all queries
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 24, 2024
1 parent cc7461c commit 761574d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 23 deletions.
29 changes: 26 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import time

import allure
Expand All @@ -7,7 +8,7 @@
from tests import client, fake
from tests.helpers import generate_public_key


# Fixtures for Generating New Identifiers
@pytest.fixture()
def GIVEN_new_domain_id():
"""Fixture to provide a new fake domain id."""
Expand Down Expand Up @@ -36,6 +37,7 @@ def GIVEN_new_asset_definition_id(GIVEN_new_asset_id, GIVEN_registered_domain):
with allure.step(f'GIVEN a "{asset_name}" asset'):
return asset_name

# Fixtures for Registering Entities
@pytest.fixture()
def GIVEN_registered_asset_definition(GIVEN_new_asset_definition_id):
"""Fixture to provide a registered asset definition."""
Expand Down Expand Up @@ -73,7 +75,9 @@ def GIVEN_registered_account(GIVEN_new_account_id):
return GIVEN_new_account_id

@pytest.fixture()
def GIVEN_registered_domain_with_registered_accounts(GIVEN_registered_domain, GIVEN_new_account_id):
def GIVEN_registered_domain_with_registered_accounts(
GIVEN_registered_domain,
GIVEN_new_account_id):
"""Fixture to provide a domain with accounts"""
with allure.step(
f'GIVEN client registers the account "{GIVEN_new_account_id}"'):
Expand All @@ -83,4 +87,23 @@ def GIVEN_registered_domain_with_registered_accounts(GIVEN_registered_domain, GI
GIVEN_new_account_id,
[generate_public_key(seed="abcd1122")])]))
time.sleep(2)
return GIVEN_registered_domain
return GIVEN_registered_domain

@pytest.fixture()
def GIVEN_registered_account_with_minted_assets(
GIVEN_registered_asset_definition,
GIVEN_registered_account
):
"""Fixture to provide an account with minted assets"""
asset = (lambda s: re.sub(r'(\b\w+\b)(?=.*\1)', '', s))(
GIVEN_registered_asset_definition + '#' + GIVEN_registered_account)
with allure.step(
f'WHEN client mints an asset "{asset}"'):
(client.submit_executable(
[iroha.Instruction
.mint_asset(
5,
asset,
"Quantity")]))
time.sleep(3)
return GIVEN_registered_account
8 changes: 3 additions & 5 deletions tests/query/test_query_account.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import allure
import time
import pytest

from tests import client


@pytest.fixture(scope="function", autouse=True)
def story_account_register_account():
def story_account_queries_accounts():
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'):
Expand All @@ -22,11 +23,8 @@ 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}"


35 changes: 20 additions & 15 deletions tests/query/test_query_asset.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
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")
def story_account_queries_accounts():
allure.dynamic.story("Account queries accounts")
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):

@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 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)
f'WHEN client queries all accounts in domain "{GIVEN_registered_domain_with_registered_accounts}"'):
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 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}"


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}"
16 changes: 16 additions & 0 deletions tests/query/test_query_domain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import allure
import pytest

from tests import client

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

@allure.label("sdk_test_id", "query_all_domains")
def test_query_all_domains():
with allure.step('WHEN client queries all domains'):
all_domains = client.query_all_domains()
with allure.step('THEN there should be some accounts present'):
assert len(all_domains) > 0, "No domains found in the system"
Empty file added tests/transaction/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 761574d

Please sign in to comment.