From 9423953c794ad7cd5f1f8fe42da540451e593cb8 Mon Sep 17 00:00:00 2001 From: alexstroke <111361420+astrokov7@users.noreply.github.com> Date: Thu, 16 Nov 2023 18:26:31 +0400 Subject: [PATCH] [fix] Fix transfer domain pytest Signed-off-by: alexstroke <111361420+astrokov7@users.noreply.github.com> --- client/tests/integration/domain_owner.rs | 5 +++ client_cli/pytests/src/client_cli/have.py | 15 +++++-- client_cli/pytests/test/domains/conftest.py | 3 ++ .../test/domains/test_transfer_domains.py | 42 +++++++++---------- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/client/tests/integration/domain_owner.rs b/client/tests/integration/domain_owner.rs index 5ebdda473d6..ab3f48e23b8 100644 --- a/client/tests/integration/domain_owner.rs +++ b/client/tests/integration/domain_owner.rs @@ -270,6 +270,11 @@ fn domain_owner_trigger_permissions() -> Result<()> { Ok(()) } +#[deprecated( + since = "2.0.0-pre-rc.20", + note = "This test suite is deprecated, use test_transfer_domains.py instead" +)] +#[ignore = "migrated to client cli python tests"] #[test] fn domain_owner_transfer() -> Result<()> { let (_rt, _peer, test_client) = ::new().with_port(11_100).start_with_runtime(); diff --git a/client_cli/pytests/src/client_cli/have.py b/client_cli/pytests/src/client_cli/have.py index e9946303056..3bb51878891 100644 --- a/client_cli/pytests/src/client_cli/have.py +++ b/client_cli/pytests/src/client_cli/have.py @@ -21,17 +21,26 @@ def expected_in_actual(expected, actual) -> bool: return expected in actual -def domain(expected): +def domain(expected, owned_by=None): """ Check if the expected domain is present in the list of domains. + Optionally checks if the domain is owned by a specific owner. :param expected: The expected domain object. - :return: True if the domain is present, False otherwise. + :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. """ def domain_in_domains() -> bool: domains = iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected}"}}}}').domains() - return expected_in_actual(expected, domains) + if not expected_in_actual(expected, domains): + return False + if owned_by: + domain_info = domains.get(expected) + if not domain_info or domain_info.get('owned_by') != str(owned_by): + return False + + return True return client_cli.wait_for(domain_in_domains) diff --git a/client_cli/pytests/test/domains/conftest.py b/client_cli/pytests/test/domains/conftest.py index 38016b6a130..470411fe5a5 100644 --- a/client_cli/pytests/test/domains/conftest.py +++ b/client_cli/pytests/test/domains/conftest.py @@ -10,6 +10,9 @@ GIVEN_string_with_reserved_character, GIVEN_string_with_whitespaces, GIVEN_existing_domain_with_uppercase_letter, + GIVEN_currently_authorized_account, + GIVEN_new_one_existing_account, + GIVEN_public_key, before_each) @pytest.fixture(scope="function", autouse=True) diff --git a/client_cli/pytests/test/domains/test_transfer_domains.py b/client_cli/pytests/test/domains/test_transfer_domains.py index 4076eaaa2de..ac8cb4d0f3d 100644 --- a/client_cli/pytests/test/domains/test_transfer_domains.py +++ b/client_cli/pytests/test/domains/test_transfer_domains.py @@ -1,30 +1,26 @@ import allure +import pytest -from src.client_cli import client_cli, iroha -import json +from src.client_cli import client_cli, iroha, have + +@pytest.fixture(scope="function", autouse=True) +def story_account_transfers_domain(): + allure.dynamic.story('Account transfers a domain') + allure.dynamic.label('permission', 'no_permission_required') @allure.label('sdk_test_id', 'transfer_domain_successfully') -def test_transfer_domain_successfully( - GIVEN_currently_authorized_account, - GIVEN_new_one_existing_account, - GIVEN_new_one_existing_domain, +def test_transfer_domain( + GIVEN_currently_authorized_account, + GIVEN_new_one_existing_account, + GIVEN_new_one_existing_domain, ): with allure.step( - f'WHEN client_cli transfers this domain from {GIVEN_currently_authorized_account} to {GIVEN_new_one_existing_account}'): - client_cli.execute(f'domain transfer --from={GIVEN_currently_authorized_account} --to={GIVEN_new_one_existing_account} --id={GIVEN_new_one_existing_domain.name}') + f'WHEN {GIVEN_currently_authorized_account} transfers domains ' + f'to {GIVEN_new_one_existing_account}'): + client_cli.execute(f'domain transfer ' + f'--from={GIVEN_currently_authorized_account} ' + f'--to={GIVEN_new_one_existing_account} ' + f'--id={GIVEN_new_one_existing_domain.name}') with allure.step( - f'THEN {GIVEN_new_one_existing_account} should own this domain {GIVEN_new_one_existing_domain}'): - def condition(): - owned_by = GIVEN_new_one_existing_account - domain_name = GIVEN_new_one_existing_domain.name - with allure.step( - f'WHEN client_cli query domains filtered by name "{domain_name}"'): - domains = iroha.list_filter(f'{{"Identifiable": {{"Is": "{domain_name}"}}}}').domains() - with allure.step( - f'THEN Iroha should return only return domains with "{domain_name}" name'): - allure.attach( - json.dumps(domains), - name='domains', - attachment_type=allure.attachment_type.JSON) - return len(domains) != 0 and all(domains[key]["id"] == domain_name and domains[key]["owned_by"] == owned_by for key in domains) - client_cli.wait_for(condition) + f'THEN {GIVEN_new_one_existing_account} should own {GIVEN_new_one_existing_domain}'): + iroha.should(have.domain(GIVEN_new_one_existing_domain.name, owned_by=GIVEN_new_one_existing_account))