Skip to content

Commit

Permalink
Removing the direct Airgun imports from robottelo
Browse files Browse the repository at this point in the history
  • Loading branch information
omkarkhatavkar committed Jan 9, 2024
1 parent 4d309c2 commit 64b33d9
Show file tree
Hide file tree
Showing 19 changed files with 4,352 additions and 365 deletions.
29 changes: 29 additions & 0 deletions pytest_fixtures/core/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
from requests.exceptions import HTTPError

from robottelo.hosts import Satellite
from robottelo.logging import logger


Expand Down Expand Up @@ -70,3 +71,31 @@ def test_foo(autosession):
"""
with target_sat.ui_session(test_name, ui_user.login, ui_user.password) as started_session:
yield started_session


@pytest.fixture(autouse=True)
def ui_session_record_property(request, record_property):
"""
Autouse fixture to set the record_property attribute for Satellite instances in the test.
This fixture iterates over all fixtures in the current test node
(excluding the current fixture) and sets the record_property attribute
for instances of the Satellite class.
Args:
request: The pytest request object.
record_property: The value to set for the record_property attribute.
"""
test_directories = [
'tests/foreman/destructive',
'tests/foreman/ui',
'tests/foreman/sanity',
'tests/foreman/virtwho',
]
test_file_path = request.node.fspath.strpath
if any(directory in test_file_path for directory in test_directories):
for fixture in request.node.fixturenames:
if request.fixturename != fixture:
if isinstance(request.getfixturevalue(fixture), Satellite):
sat = request.getfixturevalue(fixture)
sat.record_property = record_property
140 changes: 74 additions & 66 deletions tests/foreman/ui/test_activationkey.py

Large diffs are not rendered by default.

28 changes: 17 additions & 11 deletions tests/foreman/ui/test_bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
:Upstream: No
"""
from airgun.exceptions import NoSuchElementException
from airgun.session import Session
from fauxfactory import gen_string
from nailgun import entities
import pytest

from robottelo.config import user_nailgun_config
Expand Down Expand Up @@ -98,7 +96,9 @@ def test_positive_end_to_end(session, ui_entity):


@pytest.mark.tier2
def test_positive_create_bookmark_public(session, ui_entity, default_viewer_role, test_name):
def test_positive_create_bookmark_public(
session, ui_entity, default_viewer_role, test_name, module_target_sat
):
"""Create and check visibility of the (non)public bookmarks
:id: 93139529-7690-429b-83fe-3dcbac4f91dc
Expand Down Expand Up @@ -132,7 +132,9 @@ def test_positive_create_bookmark_public(session, ui_entity, default_viewer_role
{'name': name, 'query': gen_string('alphanumeric'), 'public': name == public_name}
)
assert any(d['Name'] == name for d in session.bookmark.search(name))
with Session(test_name, default_viewer_role.login, default_viewer_role.password) as session:
with module_target_sat.ui_session(
test_name, default_viewer_role.login, default_viewer_role.password
) as session:
assert any(d['Name'] == public_name for d in session.bookmark.search(public_name))
assert not session.bookmark.search(nonpublic_name)

Expand Down Expand Up @@ -193,15 +195,15 @@ def test_positive_update_bookmark_public(
controller=ui_entity['controller'],
public=name == public_name,
).create()
with Session(
with target_sat.ui_session(
test_name, default_viewer_role.login, default_viewer_role.password
) as non_admin_session:
assert any(d['Name'] == public_name for d in non_admin_session.bookmark.search(public_name))
assert not non_admin_session.bookmark.search(nonpublic_name)
with session:
session.bookmark.update(public_name, {'public': False})
session.bookmark.update(nonpublic_name, {'public': True})
with Session(
with target_sat.ui_session(
test_name, default_viewer_role.login, default_viewer_role.password
) as non_admin_session:
assert any(
Expand All @@ -211,7 +213,7 @@ def test_positive_update_bookmark_public(


@pytest.mark.tier2
def test_negative_delete_bookmark(ui_entity, default_viewer_role, test_name):
def test_negative_delete_bookmark(ui_entity, default_viewer_role, test_name, module_target_sat):
"""Simple removal of a bookmark query without permissions
:id: 1a94bf2b-bcc6-4663-b70d-e13244a0783b
Expand All @@ -232,8 +234,10 @@ def test_negative_delete_bookmark(ui_entity, default_viewer_role, test_name):
:CaseLevel: Integration
"""
bookmark = entities.Bookmark(controller=ui_entity['controller'], public=True).create()
with Session(
bookmark = module_target_sat.api.Bookmark(
controller=ui_entity['controller'], public=True
).create()
with module_target_sat.ui_session(
test_name, default_viewer_role.login, default_viewer_role.password
) as non_admin_session:
assert non_admin_session.bookmark.search(bookmark.name)[0]['Name'] == bookmark.name
Expand All @@ -243,7 +247,7 @@ def test_negative_delete_bookmark(ui_entity, default_viewer_role, test_name):


@pytest.mark.tier2
def test_negative_create_with_duplicate_name(session, ui_entity):
def test_negative_create_with_duplicate_name(session, ui_entity, module_target_sat):
"""Create bookmark with duplicate name
:id: 18168c9c-bdd1-4839-a506-cf9b06c4ab44
Expand All @@ -263,7 +267,9 @@ def test_negative_create_with_duplicate_name(session, ui_entity):
:CaseLevel: Integration
"""
query = gen_string('alphanumeric')
bookmark = entities.Bookmark(controller=ui_entity['controller'], public=True).create()
bookmark = module_target_sat.api.Bookmark(
controller=ui_entity['controller'], public=True
).create()
with session:
existing_bookmark = session.bookmark.search(bookmark.name)[0]
assert existing_bookmark['Name'] == bookmark.name
Expand Down
3 changes: 1 addition & 2 deletions tests/foreman/ui/test_branding.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
:Upstream: No
"""
from airgun.session import Session
import pytest


Expand All @@ -38,7 +37,7 @@ def test_verify_satellite_login_screen_info(target_sat):
:BZ: 1315849, 1367495, 1372436, 1502098, 1540710, 1582476, 1724738,
1959135, 2076979, 1687250, 1686540, 1742872, 1805642, 2105949
"""
with Session(login=False) as session:
with target_sat.ui_session(login=False) as session:
version = session.login.read_sat_version()
assert f'Version {target_sat.version}' == version['login_text']
assert 'Beta' not in version['login_text'], '"Beta" should not be there'
48 changes: 26 additions & 22 deletions tests/foreman/ui/test_contenthost.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import re
from urllib.parse import urlparse

from airgun.session import Session
from fauxfactory import gen_integer, gen_string
from nailgun import entities
import pytest

from robottelo.config import setting_is_set, settings
Expand All @@ -49,8 +47,10 @@


@pytest.fixture(scope='module', autouse=True)
def host_ui_default():
settings_object = entities.Setting().search(query={'search': 'name=host_details_ui'})[0]
def host_ui_default(module_target_sat):
settings_object = module_target_sat.api.Setting().search(
query={'search': 'name=host_details_ui'}
)[0]
settings_object.value = 'No'
settings_object.update({'value'})
yield
Expand All @@ -59,10 +59,10 @@ def host_ui_default():


@pytest.fixture(scope='module')
def module_org():
org = entities.Organization(simple_content_access=False).create()
def module_org(module_target_sat):
org = module_target_sat.api.Organization(simple_content_access=False).create()
# adding remote_execution_connect_by_ip=Yes at org level
entities.Parameter(
module_target_sat.api.Parameter(
name='remote_execution_connect_by_ip',
value='Yes',
organization=org.id,
Expand All @@ -89,9 +89,9 @@ def vm_module_streams(module_repos_collection_with_manifest, rhel8_contenthost,
return rhel8_contenthost


def set_ignore_facts_for_os(value=False):
def set_ignore_facts_for_os(module_target_sat, value=False):
"""Helper to set 'ignore_facts_for_operatingsystem' setting"""
ignore_setting = entities.Setting().search(
ignore_setting = module_target_sat.api.Setting().search(
query={'search': 'name="ignore_facts_for_operatingsystem"'}
)[0]
ignore_setting.value = str(value)
Expand Down Expand Up @@ -626,7 +626,7 @@ def test_positive_remove_package_group(session, default_location, vm):
indirect=True,
)
def test_positive_search_errata_non_admin(
session, default_location, vm, test_name, default_viewer_role
default_location, vm, test_name, default_viewer_role, module_target_sat
):
"""Search for host's errata by non-admin user with enough permissions
Expand All @@ -644,7 +644,7 @@ def test_positive_search_errata_non_admin(
:CaseLevel: System
"""
vm.run(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}')
with Session(
with module_target_sat.ui_session(
test_name, user=default_viewer_role.login, password=default_viewer_role.password
) as session:
session.location.select(default_location.name)
Expand Down Expand Up @@ -795,7 +795,9 @@ def test_positive_host_re_registration_with_host_rename(
],
indirect=True,
)
def test_positive_check_ignore_facts_os_setting(session, default_location, vm, module_org, request):
def test_positive_check_ignore_facts_os_setting(
session, default_location, vm, module_org, request, module_target_sat
):
"""Verify that 'Ignore facts for operating system' setting works
properly
Expand Down Expand Up @@ -830,9 +832,9 @@ def test_positive_check_ignore_facts_os_setting(session, default_location, vm, m
major = str(gen_integer(15, 99))
minor = str(gen_integer(1, 9))
expected_os = f'RedHat {major}.{minor}'
set_ignore_facts_for_os(False)
set_ignore_facts_for_os(module_target_sat, False)
host = (
entities.Host()
module_target_sat.api.Host()
.search(query={'search': f'name={vm.hostname} and organization_id={module_org.id}'})[0]
.read()
)
Expand All @@ -841,7 +843,7 @@ def test_positive_check_ignore_facts_os_setting(session, default_location, vm, m
# Get host current operating system value
os = session.contenthost.read(vm.hostname, widget_names='details')['details']['os']
# Change necessary setting to true
set_ignore_facts_for_os(True)
set_ignore_facts_for_os(module_target_sat, True)
# Add cleanup function to roll back setting to default value
request.addfinalizer(set_ignore_facts_for_os)
# Read all facts for corresponding host
Expand All @@ -858,7 +860,7 @@ def test_positive_check_ignore_facts_os_setting(session, default_location, vm, m
# Check that host OS was not changed due setting was set to true
assert os == updated_os
# Put it to false and re-run the process
set_ignore_facts_for_os(False)
set_ignore_facts_for_os(module_target_sat, False)
host.upload_facts(data={'name': vm.hostname, 'facts': facts})
session.contenthost.search('')
updated_os = session.contenthost.read(vm.hostname, widget_names='details')['details']['os']
Expand Down Expand Up @@ -897,8 +899,8 @@ def test_positive_virt_who_hypervisor_subscription_status(
:CaseLevel: System
"""
org = entities.Organization().create()
lce = entities.LifecycleEnvironment(organization=org).create()
org = target_sat.api.Organization().create()
lce = target_sat.api.LifecycleEnvironment(organization=org).create()
# TODO move this to either hack around virt-who service or use an env-* compute resource
provisioning_server = settings.libvirt.libvirt_hostname
# Create a new virt-who config
Expand Down Expand Up @@ -969,7 +971,9 @@ def test_positive_virt_who_hypervisor_subscription_status(
],
indirect=True,
)
def test_module_stream_actions_on_content_host(session, default_location, vm_module_streams):
def test_module_stream_actions_on_content_host(
session, default_location, vm_module_streams, module_target_sat
):
"""Check remote execution for module streams actions e.g. install, remove, disable
works on content host. Verify that correct stream module stream
get installed/removed.
Expand All @@ -984,7 +988,7 @@ def test_module_stream_actions_on_content_host(session, default_location, vm_mod
"""
stream_version = '5.21'
run_remote_command_on_content_host('dnf -y upload-profile', vm_module_streams)
entities.Parameter(
module_target_sat.api.Parameter(
name='remote_execution_connect_by_ip',
value='Yes',
parameter_type='boolean',
Expand Down Expand Up @@ -1783,7 +1787,7 @@ def test_pagination_multiple_hosts_multiple_pages(session, module_host_template,


@pytest.mark.tier3
def test_search_for_virt_who_hypervisors(session, default_location):
def test_search_for_virt_who_hypervisors(session, default_location, module_target_sat):
"""
Search the virt_who hypervisors with hypervisor=True or hypervisor=False.
Expand All @@ -1799,7 +1803,7 @@ def test_search_for_virt_who_hypervisors(session, default_location):
:CaseImportance: Medium
"""
org = entities.Organization().create()
org = module_target_sat.api.Organization().create()
with session:
session.organization.select(org.name)
session.location.select(default_location.name)
Expand Down
Loading

0 comments on commit 64b33d9

Please sign in to comment.