From 944fe3ef2901e0d2ad5e44989a3e3c93d65c78d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hellebrandt?= Date: Wed, 13 Mar 2024 14:51:56 +0100 Subject: [PATCH] Close-loop bz2209968 (#14158) --- robottelo/utils/datafactory.py | 18 ++++++ tests/foreman/ui/test_jobinvocation.py | 76 +++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/robottelo/utils/datafactory.py b/robottelo/utils/datafactory.py index c5ccc38ba14..1834e0f87b0 100644 --- a/robottelo/utils/datafactory.py +++ b/robottelo/utils/datafactory.py @@ -364,6 +364,24 @@ def valid_hostgroups_list(): ] +@filtered_datapoint +def valid_hostgroups_list_short(): + """Generates a list of valid host group names. Shorter so they can be nested. + + :return: Returns the valid host group names list + """ + return [ + gen_string('alphanumeric', random.randint(1, 15)), + gen_string('alpha', random.randint(1, 15)), + gen_string('cjk', random.randint(1, 15)), + gen_string('latin1', random.randint(1, 15)), + gen_string('numeric', random.randint(1, 15)), + gen_string('utf8', random.randint(1, 15)), + gen_string('html', random.randint(1, 15)), + gen_string('alphanumeric', random.randint(1, 15)), + ] + + @filtered_datapoint def valid_labels_list(): """Generates a list of valid labels.""" diff --git a/tests/foreman/ui/test_jobinvocation.py b/tests/foreman/ui/test_jobinvocation.py index d79d7ee3355..0394d00a888 100644 --- a/tests/foreman/ui/test_jobinvocation.py +++ b/tests/foreman/ui/test_jobinvocation.py @@ -11,10 +11,15 @@ :CaseImportance: High """ +from collections import OrderedDict + from inflection import camelize import pytest -from robottelo.utils.datafactory import gen_string +from robottelo.utils.datafactory import ( + gen_string, + valid_hostgroups_list_short, +) @pytest.fixture @@ -27,6 +32,75 @@ def module_rhel_client_by_ip(module_org, smart_proxy_location, rhel7_contenthost return rhel7_contenthost +@pytest.mark.tier4 +def test_positive_hostgroups_full_nested_names( + module_org, + smart_proxy_location, + target_sat, +): + """Check that full host group names are displayed when invoking a job + + :id: 2301cd1d-ed82-4168-9f9b-d1661ac8fc5b + + :steps: + + 1. Go to Monitor -> Jobs -> Run job + 2. In "Target hosts and inputs" step, choose "Host groups" targeting + + :expectedresults: Verify that in the dropdown, full hostgroup names are present, e.g. Parent/Child/Grandchild + + :parametrized: yes + + :customerscenario: true + + :BZ: 2209968 + """ + names = valid_hostgroups_list_short() + tree = OrderedDict( + { + 'parent1': {'name': names[0], 'parent': None}, + 'parent2': {'name': names[1], 'parent': None}, + 'child1a': {'name': names[2], 'parent': 'parent1'}, + 'child1b': {'name': names[3], 'parent': 'parent1'}, + 'child2': {'name': names[4], 'parent': 'parent2'}, + 'grandchild1a1': {'name': names[5], 'parent': 'child1a'}, + 'grandchild1a2': {'name': names[6], 'parent': 'child1a'}, + 'grandchild1b': {'name': names[7], 'parent': 'child1b'}, + } + ) + expected_names = [] + for identifier, data in tree.items(): + name = data['name'] + parent_name = None if data['parent'] is None else tree[data['parent']]['name'] + target_sat.cli_factory.hostgroup( + { + 'name': name, + 'parent': parent_name, + 'organization-ids': module_org.id, + 'location-ids': smart_proxy_location.id, + } + ) + expected_name = '' + current = identifier + while current: + expected_name = ( + f"{tree[current]['name']}/{expected_name}" + if expected_name + else tree[current]['name'] + ) + current = tree[current]['parent'] + # we should have something like "parent1/child1a" + expected_names.append(expected_name) + + with target_sat.ui_session() as session: + session.organization.select(module_org.name) + session.location.select(smart_proxy_location.name) + hostgroups = session.jobinvocation.read_hostgroups() + + for name in expected_names: + assert name in hostgroups + + @pytest.mark.tier4 def test_positive_run_default_job_template_by_ip( session, module_org, smart_proxy_location, module_rhel_client_by_ip