From a038b3d0321c9ede2db06a93ffffe468eccce859 Mon Sep 17 00:00:00 2001 From: Satellite QE <115476073+Satellite-QE@users.noreply.github.com> Date: Mon, 18 Sep 2023 08:54:29 -0400 Subject: [PATCH] [6.14.z] UI Utils module depreciation and new ui_factory module (#12641) UI Utils module depreciation and new ui_factory module (#12225) Depreciation of UI Utils (cherry picked from commit ab2102352e0137f7148448c764587f71df7ce1d3) Co-authored-by: Jitendra Yejare --- robottelo/host_helpers/satellite_mixins.py | 6 +++ robottelo/host_helpers/ui_factory.py | 59 ++++++++++++++++++++++ robottelo/ui/__init__.py | 0 robottelo/ui/utils.py | 47 ----------------- tests/foreman/ui/test_reporttemplates.py | 16 +++--- 5 files changed, 75 insertions(+), 53 deletions(-) create mode 100644 robottelo/host_helpers/ui_factory.py delete mode 100644 robottelo/ui/__init__.py delete mode 100644 robottelo/ui/utils.py diff --git a/robottelo/host_helpers/satellite_mixins.py b/robottelo/host_helpers/satellite_mixins.py index 8e718f2e71d..bd7bedc7d57 100644 --- a/robottelo/host_helpers/satellite_mixins.py +++ b/robottelo/host_helpers/satellite_mixins.py @@ -3,6 +3,7 @@ import os import random import re +from functools import cache import requests @@ -15,6 +16,7 @@ from robottelo.constants import PUPPET_SATELLITE_INSTALLER from robottelo.host_helpers.api_factory import APIFactory from robottelo.host_helpers.cli_factory import CLIFactory +from robottelo.host_helpers.ui_factory import UIFactory from robottelo.logging import logger from robottelo.utils.installer import InstallerCommand from robottelo.utils.manifest import clone @@ -352,3 +354,7 @@ def api_factory(self): if not getattr(self, '_api_factory', None): self._api_factory = APIFactory(self) return self._api_factory + + @cache + def ui_factory(self, session): + return UIFactory(self, session=session) diff --git a/robottelo/host_helpers/ui_factory.py b/robottelo/host_helpers/ui_factory.py new file mode 100644 index 00000000000..334b4986b24 --- /dev/null +++ b/robottelo/host_helpers/ui_factory.py @@ -0,0 +1,59 @@ +""" +It is not meant to be used directly, but as part of a robottelo.hosts.Satellite instance +Need to pass the existing session object to the ui_factory method as a parameter +example: my_satellite.ui_factory(session).ui_method() +""" +from fauxfactory import gen_string + +from robottelo.constants import DEFAULT_CV +from robottelo.constants import ENVIRONMENT + + +class UIFactory: + """This class is part of a mixin and not to be used directly. See robottelo.hosts.Satellite""" + + def __init__(self, satellite, session=None): + self._satellite = satellite + self._session = session + + def create_fake_host( + self, + host, + interface_id=gen_string('alpha'), + global_parameters=None, + host_parameters=None, + extra_values=None, + new_host_details=False, + ): + if extra_values is None: + extra_values = {} + os_name = f'{host.operatingsystem.name} {host.operatingsystem.major}' + name = host.name if host.name is not None else gen_string('alpha').lower() + values = { + 'host.name': name, + 'host.organization': host.organization.name, + 'host.location': host.location.name, + 'host.lce': ENVIRONMENT, + 'host.content_view': DEFAULT_CV, + 'operating_system.architecture': host.architecture.name, + 'operating_system.operating_system': os_name, + 'operating_system.media_type': 'All Media', + 'operating_system.media': host.medium.name, + 'operating_system.ptable': host.ptable.name, + 'operating_system.root_password': host.root_pass, + 'interfaces.interface.interface_type': 'Interface', + 'interfaces.interface.device_identifier': interface_id, + 'interfaces.interface.mac': host.mac, + 'interfaces.interface.domain': host.domain.name, + 'interfaces.interface.primary': True, + 'interfaces.interface.interface_additional_data.virtual_nic': False, + 'parameters.global_params': global_parameters, + 'parameters.host_params': host_parameters, + 'additional_information.comment': 'Host with fake data', + } + values.update(extra_values) + if new_host_details: + self._session.host_new.create(values) + else: + self._session.host.create(values) + return f'{name}.{host.domain.name}' diff --git a/robottelo/ui/__init__.py b/robottelo/ui/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/robottelo/ui/utils.py b/robottelo/ui/utils.py deleted file mode 100644 index d22bb25dae5..00000000000 --- a/robottelo/ui/utils.py +++ /dev/null @@ -1,47 +0,0 @@ -from fauxfactory import gen_string - -from robottelo.constants import DEFAULT_CV -from robottelo.constants import ENVIRONMENT - - -def create_fake_host( - session, - host, - interface_id=gen_string('alpha'), - global_parameters=None, - host_parameters=None, - extra_values=None, - new_host_details=False, -): - if extra_values is None: - extra_values = {} - os_name = f'{host.operatingsystem.name} {host.operatingsystem.major}' - name = host.name if host.name is not None else gen_string('alpha').lower() - values = { - 'host.name': name, - 'host.organization': host.organization.name, - 'host.location': host.location.name, - 'host.lce': ENVIRONMENT, - 'host.content_view': DEFAULT_CV, - 'operating_system.architecture': host.architecture.name, - 'operating_system.operating_system': os_name, - 'operating_system.media_type': 'All Media', - 'operating_system.media': host.medium.name, - 'operating_system.ptable': host.ptable.name, - 'operating_system.root_password': host.root_pass, - 'interfaces.interface.interface_type': 'Interface', - 'interfaces.interface.device_identifier': interface_id, - 'interfaces.interface.mac': host.mac, - 'interfaces.interface.domain': host.domain.name, - 'interfaces.interface.primary': True, - 'interfaces.interface.interface_additional_data.virtual_nic': False, - 'parameters.global_params': global_parameters, - 'parameters.host_params': host_parameters, - 'additional_information.comment': 'Host with fake data', - } - values.update(extra_values) - if new_host_details: - session.host_new.create(values) - else: - session.host.create(values) - return f'{name}.{host.domain.name}' diff --git a/tests/foreman/ui/test_reporttemplates.py b/tests/foreman/ui/test_reporttemplates.py index f8eed10e58f..ed4c84515f7 100644 --- a/tests/foreman/ui/test_reporttemplates.py +++ b/tests/foreman/ui/test_reporttemplates.py @@ -35,7 +35,6 @@ from robottelo.constants import PRDS from robottelo.constants import REPOS from robottelo.constants import REPOSET -from robottelo.ui.utils import create_fake_host from robottelo.utils.datafactory import gen_string @@ -238,7 +237,7 @@ def test_positive_end_to_end(session, module_org, module_location): @pytest.mark.upgrade @pytest.mark.tier2 -def test_positive_generate_registered_hosts_report(session, module_org, module_location): +def test_positive_generate_registered_hosts_report(target_sat, module_org, module_location): """Use provided Host - Registered Content Hosts report for testing :id: b44d4cd8-a78e-47cf-9993-0bb871ac2c96 @@ -252,17 +251,22 @@ def test_positive_generate_registered_hosts_report(session, module_org, module_l """ # generate Host Status report os_name = 'comma,' + gen_string('alpha') - os = entities.OperatingSystem(name=os_name).create() + os = target_sat.api.OperatingSystem(name=os_name).create() host_cnt = 3 host_templates = [ - entities.Host(organization=module_org, location=module_location, operatingsystem=os) + target_sat.api.Host(organization=module_org, location=module_location, operatingsystem=os) for i in range(host_cnt) ] for host_template in host_templates: host_template.create_missing() - with session: + with target_sat.ui_session() as session: + session.organization.select(module_org.name) + session.location.select(module_location.name) # create multiple hosts to test filtering - host_names = [create_fake_host(session, host_template) for host_template in host_templates] + host_names = [ + target_sat.ui_factory(session).create_fake_host(host_template) + for host_template in host_templates + ] host_name = host_names[1] # pick some that is not first and is not last file_path = session.reporttemplate.generate( 'Host - Registered Content Hosts', values={'hosts_filter': host_name}