Skip to content

Commit

Permalink
[6.12.z] UI Utils module depreciation and new ui_factory module (#12642)
Browse files Browse the repository at this point in the history
UI Utils module depreciation and new ui_factory module (#12225)

Depreciation of UI Utils

(cherry picked from commit ab21023)

Co-authored-by: Jitendra Yejare <[email protected]>
  • Loading branch information
Satellite-QE and jyejare authored Sep 19, 2023
1 parent ff5e818 commit e95e3cf
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 53 deletions.
6 changes: 6 additions & 0 deletions robottelo/host_helpers/satellite_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import random
import re
from functools import cache

import requests

Expand All @@ -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
Expand Down Expand Up @@ -351,3 +353,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)
59 changes: 59 additions & 0 deletions robottelo/host_helpers/ui_factory.py
Original file line number Diff line number Diff line change
@@ -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}'
Empty file removed robottelo/ui/__init__.py
Empty file.
47 changes: 0 additions & 47 deletions robottelo/ui/utils.py

This file was deleted.

16 changes: 10 additions & 6 deletions tests/foreman/ui/test_reporttemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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


Expand Down Expand Up @@ -235,7 +234,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
Expand All @@ -249,17 +248,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}
Expand Down

0 comments on commit e95e3cf

Please sign in to comment.