Skip to content

Commit

Permalink
UI test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shweta83 committed Feb 15, 2024
1 parent 55109fb commit df380fb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 24 deletions.
57 changes: 56 additions & 1 deletion tests/foreman/ui/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,62 @@ def test_positive_validate_inherited_cv_lce_ansiblerole(session, target_sat, mod
assert host.name in [host.name for host in matching_hosts]



@pytest.mark.tier2
@pytest.mark.rhel_ver_match('[^6].*')
def test_global_registration_upgrade_subscription_manager(
session, module_activation_key, module_os, rhel_contenthost
):
"""Host registration form produces a correct registration command and
subscription-manager can be updated from a custom repository before
registration is completed.
:id: b7a44f32-90b2-4fd6-b65b-5a3d2a5c5deb
:customerscenario: true
:expectedresults: Host is successfully registered, repo is enabled
on advanced tab and subscription-manager is updated.
:steps:
1. Create activation-key
2. Open the global registration form, add repo and activation key
3. Add 'subscription-manager' to install packages field
4. Check subscription-manager was installed from repo_name
:parametrized: yes
:BZ: 1923320
"""
client = rhel_contenthost
repo_name = 'foreman_register'
rhel_ver = rhel_contenthost.os_version.major
repo_url = settings.repos.get(f'rhel{rhel_ver}_os')
if isinstance(repo_url, dict):
repo_url = repo_url['baseos']
# Ensure subs-man is installed from repo_name by removing existing package.
result = client.execute('rpm --erase --nodeps subscription-manager')
assert result.status == 0
with session:
cmd = session.host.get_register_command(
{
'general.operating_system': module_os.title,
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
'advanced.force': True,
'advanced.install_packages': 'subscription-manager',
'advanced.repository': repo_url,
}
)

# run curl
result = client.execute(cmd)
assert result.status == 0
result = client.execute('yum repolist')
assert repo_name in result.stdout
assert result.status == 0


@pytest.mark.tier4
@pytest.mark.upgrade
def test_positive_bulk_delete_host(session, smart_proxy_location, target_sat, function_org):
Expand Down Expand Up @@ -1740,7 +1796,6 @@ def test_positive_tracer_enable_reload(tracer_install_host, target_sat):
tracer = session.host_new.get_tracer(tracer_install_host.hostname)
assert tracer['title'] == "No applications to restart"


@pytest.mark.tier2
def test_all_hosts_delete(target_sat, function_org, function_location, new_host_ui):
"""Create a host and delete it through All Hosts UI
Expand Down
43 changes: 20 additions & 23 deletions tests/foreman/ui/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from robottelo import constants
from robottelo.config import settings
from robottelo.constants import FAKE_1_CUSTOM_PACKAGE, FAKE_7_CUSTOM_PACKAGE, REPO_TYPE
from robottelo.utils.datafactory import gen_string

pytestmark = pytest.mark.tier1

Expand Down Expand Up @@ -64,7 +65,7 @@ def test_positive_verify_default_values_for_global_registration(
@pytest.mark.tier2
def test_positive_org_loc_change_for_registration(
module_activation_key,
module_org,
module_sca_manifest_org,
module_location,
target_sat,
):
Expand All @@ -76,15 +77,16 @@ def test_positive_org_loc_change_for_registration(
:CaseImportance: Medium
"""
org = module_sca_manifest_org
new_org = target_sat.api.Organization().create()
new_loc = target_sat.api.Location().create()
target_sat.api.ActivationKey(organization=new_org).create()
with target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
session.organization.select(org_name=org.name)
session.location.select(loc_name=module_location.name)
cmd = session.host.get_register_command()
expected_pairs = [
f'organization_id={module_org.id}',
f'organization_id={org.id}',
f'location_id={module_location.id}',
]
for pair in expected_pairs:
Expand All @@ -101,20 +103,16 @@ def test_positive_org_loc_change_for_registration(
assert pair in cmd


def test_negative_global_registration_without_ak(
module_target_sat,
module_org,
module_location,
):
def test_negative_global_registration_without_ak(target_sat, function_org, function_location):
"""Attempt to register a host without ActivationKey
:id: 34122bf3-ae23-47ca-ba3d-da0653d8fd36
:expectedresults: Generate command is disabled without ActivationKey
"""
with module_target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
session.location.select(loc_name=module_location.name)
with target_sat.ui_session() as session:
session.organization.select(org_name=function_org.name)
session.location.select(loc_name=function_location.name)
with pytest.raises(DisabledWidgetError) as context:
session.host.get_register_command()
assert 'Generate registration command button is disabled' in str(context.value)
Expand Down Expand Up @@ -172,6 +170,8 @@ def test_positive_global_registration_end_to_end(
cmd = session.host.get_register_command(
{
'general.operating_system': default_os.title,
'general.organization': module_org.name,
'general.location': smart_proxy_location.name,
'general.activation_keys': module_activation_key.name,
'advanced.update_packages': True,
'advanced.rex_interface': iface,
Expand Down Expand Up @@ -329,6 +329,7 @@ def test_global_registration_form_populate(
{
'general.organization': new_org.name,
'general.operating_system': default_os.title,
'general.activation_keys': new_ak.name,
'general.insecure': True,
},
full_read=True,
Expand All @@ -341,7 +342,7 @@ def test_global_registration_form_populate(
@pytest.mark.usefixtures('enable_capsule_for_registration')
@pytest.mark.no_containers
def test_global_registration_with_gpg_repo_and_default_package(
session, module_activation_key, default_os, default_smart_proxy, rhel8_contenthost
session, module_activation_key, rhel8_contenthost
):
"""Host registration form produces a correct registration command and host is
registered successfully with gpg repo enabled and have default package
Expand Down Expand Up @@ -369,8 +370,6 @@ def test_global_registration_with_gpg_repo_and_default_package(
with session:
cmd = session.host.get_register_command(
{
'general.operating_system': default_os.title,
'general.capsule': default_smart_proxy.name,
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
'advanced.force': True,
Expand Down Expand Up @@ -405,7 +404,7 @@ def test_global_registration_with_gpg_repo_and_default_package(
@pytest.mark.tier3
@pytest.mark.usefixtures('enable_capsule_for_registration')
def test_global_re_registration_host_with_force_ignore_error_options(
session, module_activation_key, default_os, default_smart_proxy, rhel7_contenthost
session, module_activation_key, rhel7_contenthost
):
"""If the ignore_error and force checkbox is checked then registered host can
get re-registered without any error.
Expand All @@ -427,8 +426,6 @@ def test_global_re_registration_host_with_force_ignore_error_options(
with session:
cmd = session.host.get_register_command(
{
'general.operating_system': default_os.title,
'general.capsule': default_smart_proxy.name,
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
'advanced.force': True,
Expand All @@ -447,7 +444,7 @@ def test_global_re_registration_host_with_force_ignore_error_options(
@pytest.mark.tier2
@pytest.mark.usefixtures('enable_capsule_for_registration')
def test_global_registration_token_restriction(
session, module_activation_key, rhel8_contenthost, default_os, default_smart_proxy, target_sat
session, module_activation_key, rhel8_contenthost, module_target_sat
):
"""Global registration token should be only used for registration call, it
should be restricted for any other api calls.
Expand All @@ -467,8 +464,6 @@ def test_global_registration_token_restriction(
with session:
cmd = session.host.get_register_command(
{
'general.operating_system': default_os.title,
'general.capsule': default_smart_proxy.name,
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
}
Expand All @@ -478,8 +473,8 @@ def test_global_registration_token_restriction(
auth_header = re.search(pattern, cmd).group()

# build curl
curl_users = f'curl -X GET -k -H {auth_header} -i {target_sat.url}/api/users/'
curl_hosts = f'curl -X GET -k -H {auth_header} -i {target_sat.url}/api/hosts/'
curl_users = f'curl -X GET -k -H {auth_header} -i {module_target_sat.url}/api/users/'
curl_hosts = f'curl -X GET -k -H {auth_header} -i {module_target_sat.url}/api/hosts/'
for curl_cmd in (curl_users, curl_hosts):
result = client.execute(curl_cmd)
assert result.status == 0
Expand Down Expand Up @@ -522,7 +517,7 @@ def test_positive_host_registration_with_non_admin_user(
role = target_sat.cli.Role.info({'name': 'Register hosts'})
target_sat.cli.User.add_role({'id': user.id, 'role-id': role['id']})

with Session(test_name, user=user.login, password=user_password) as session:
with target_sat.ui_session(test_name, user=user.login, password=user_password) as session:

cmd = session.host_new.get_register_command(
{
Expand Down Expand Up @@ -570,6 +565,8 @@ def test_positive_global_registration_form(
).create()
iface = 'eth0'
with session:
session.organization.select(org_name=module_org.name)
session.location.select(loc_name=smart_proxy_location.name)
cmd = session.host.get_register_command(
{
'advanced.setup_insights': 'Yes (override)' if insights_value else 'No (override)',
Expand Down

0 comments on commit df380fb

Please sign in to comment.