From 97c363c32964b21d0ff93bc6c02222ef3a1e77ba Mon Sep 17 00:00:00 2001 From: Gaurav Talreja Date: Fri, 31 May 2024 06:36:11 +0530 Subject: [PATCH] Modify test_positive_import_all_roles to cover non-admin scenario (#15171) Signed-off-by: Gaurav Talreja (cherry picked from commit ba922c8078afb9370db578b664ff925f398938df) --- tests/foreman/destructive/test_ansible.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/foreman/destructive/test_ansible.py b/tests/foreman/destructive/test_ansible.py index f48b7e996b0..9c4966f153e 100644 --- a/tests/foreman/destructive/test_ansible.py +++ b/tests/foreman/destructive/test_ansible.py @@ -15,6 +15,8 @@ from fauxfactory import gen_string import pytest +from robottelo.config import settings + pytestmark = [pytest.mark.destructive, pytest.mark.upgrade] @@ -45,7 +47,8 @@ def test_positive_persistent_ansible_cfg_change(target_sat): assert param in target_sat.execute(f'cat {ansible_cfg}').stdout.splitlines() -def test_positive_import_all_roles(target_sat): +@pytest.mark.parametrize('auth_type', ['admin', 'non-admin']) +def test_positive_import_all_roles(request, target_sat, function_org, auth_type): """Import all Ansible roles available by default. :id: 53fe3857-a08f-493d-93c7-3fed331ed391 @@ -63,7 +66,23 @@ def test_positive_import_all_roles(target_sat): :expectedresults: All roles are imported successfully. One role is deleted successfully. """ - with target_sat.ui_session() as session: + username = settings.server.admin_username + password = settings.server.admin_password + if auth_type == 'non-admin': + ansible_manager_role = target_sat.api.Role().search( + query={'search': 'name="Ansible Roles Manager"'} + ) + user = target_sat.api.User( + role=ansible_manager_role, + admin=True, + login=gen_string('alphanumeric'), + password=password, + organization=[function_org], + ).create() + request.addfinalizer(user.delete) + username = user.login + with target_sat.ui_session(user=username, password=password) as session: + session.organization.select(function_org.name) assert session.ansibleroles.import_all_roles() == session.ansibleroles.imported_roles_count assert int(session.ansiblevariables.read_total_variables()) > 0 # The choice of role to be deleted is arbitrary; any of the roles present on Satellite