From c8808d167c1ce5d72271f58e4a1488c353e8f9bf Mon Sep 17 00:00:00 2001 From: vsedmik <46570670+vsedmik@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:57:59 +0200 Subject: [PATCH] Fix AK tests assertion errors (#16220) * Fix AK tests assertion errors * Use default_rhel_version and content_hosts fixture * Remove obsoleted settings decorator --- tests/foreman/cli/test_activationkey.py | 41 +++++++++++++++---------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/tests/foreman/cli/test_activationkey.py b/tests/foreman/cli/test_activationkey.py index 77d8127444a..f2e9ddd6785 100644 --- a/tests/foreman/cli/test_activationkey.py +++ b/tests/foreman/cli/test_activationkey.py @@ -15,7 +15,6 @@ from random import choice import re -from broker import Broker from fauxfactory import gen_alphanumeric, gen_string import pytest @@ -23,7 +22,6 @@ from robottelo.config import settings from robottelo.constants import PRDS, REPOS, REPOSET from robottelo.exceptions import CLIFactoryError, CLIReturnCodeError -from robottelo.hosts import ContentHost from robottelo.utils.datafactory import ( invalid_values_list, parametrized, @@ -204,9 +202,13 @@ def test_positive_create_content_and_check_enabled(module_org, module_target_sat {'url': settings.repos.yum_0.url, 'organization-id': module_org.id} ) content = module_target_sat.cli.ActivationKey.product_content( - {'id': result['activationkey-id'], 'organization-id': module_org.id} + { + 'id': result['activationkey-id'], + 'organization-id': module_org.id, + 'content-access-mode-all': 1, + } ) - assert content[0]['default-enabled?'] == 'true' + assert content[0]['default-enabled?'] == 'false' @pytest.mark.tier2 @@ -592,7 +594,8 @@ def test_negative_update_usage_limit(module_org, module_target_sat): @pytest.mark.tier3 @pytest.mark.upgrade -def test_positive_usage_limit(module_org, module_location, target_sat): +@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) +def test_positive_usage_limit(module_org, module_location, target_sat, content_hosts): """Test that Usage limit actually limits usage :id: 00ded856-e939-4140-ac84-91b6a8643623 @@ -610,6 +613,7 @@ def test_positive_usage_limit(module_org, module_location, target_sat): :CaseImportance: Critical """ + max_hosts = 1 env = target_sat.cli_factory.make_lifecycle_environment({'organization-id': module_org.id}) new_cv = target_sat.cli_factory.make_content_view({'organization-id': module_org.id}) target_sat.cli.ContentView.publish({'id': new_cv['id']}) @@ -622,17 +626,16 @@ def test_positive_usage_limit(module_org, module_location, target_sat): 'lifecycle-environment-id': env['id'], 'content-view': new_cv['name'], 'organization-id': module_org.id, - 'max-hosts': '1', + 'max-hosts': max_hosts, } ) - with Broker(nick='rhel7', host_class=ContentHost, _count=2) as clients: - vm1, vm2 = clients - vm1.register(module_org, module_location, new_ak['name'], target_sat) - assert vm1.subscribed - result = vm2.register(module_org, module_location, new_ak['name'], target_sat) - assert not vm2.subscribed - assert result.status == 70 - assert len(result.stderr) > 0 + vm1, vm2 = content_hosts + vm1.register(module_org, module_location, new_ak['name'], target_sat) + assert vm1.subscribed + result = vm2.register(module_org, module_location, new_ak['name'], target_sat) + assert not vm2.subscribed + assert result.status, 'Second registration was expected to fail' + assert f"Max Hosts ({max_hosts}) reached for activation key '{new_ak.name}'" in result.stderr @pytest.mark.tier2 @@ -728,7 +731,7 @@ def test_positive_add_redhat_product(function_entitlement_manifest_org, target_s @pytest.mark.tier3 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_add_custom_product(module_org, module_target_sat): +def test_positive_add_custom_product(function_org, module_target_sat): """Test that custom product can be associated to Activation Keys :id: 96ace967-e165-4069-8ff7-f54c4c822de0 @@ -739,11 +742,15 @@ def test_positive_add_custom_product(module_org, module_target_sat): :BZ: 1426386 """ result = module_target_sat.cli_factory.setup_org_for_a_custom_repo( - {'url': settings.repos.yum_0.url, 'organization-id': module_org.id} + {'url': settings.repos.yum_0.url, 'organization-id': function_org.id} ) repo = module_target_sat.cli.Repository.info({'id': result['repository-id']}) content = module_target_sat.cli.ActivationKey.product_content( - {'id': result['activationkey-id'], 'organization-id': module_org.id} + { + 'id': result['activationkey-id'], + 'organization-id': function_org.id, + 'content-access-mode-all': 1, + } ) assert content[0]['name'] == repo['name']