From 6c4c99078f7e18dafd45c2d4444c47f810f6dd35 Mon Sep 17 00:00:00 2001 From: David Moore Date: Tue, 9 Jan 2024 12:28:56 -0500 Subject: [PATCH] Address comments, adjust some assertions --- robottelo/host_helpers/api_factory.py | 6 ++--- tests/foreman/api/test_errata.py | 37 ++++++++++++++------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/robottelo/host_helpers/api_factory.py b/robottelo/host_helpers/api_factory.py index a4f18b0b561..6ca39a224cd 100644 --- a/robottelo/host_helpers/api_factory.py +++ b/robottelo/host_helpers/api_factory.py @@ -677,10 +677,10 @@ def wait_for_errata_applicability_task( for _ in range(max_tries): now = int(time.time()) # Format epoch time for search, one second prior margin of safety - timestamp = datetime.fromtimestamp(from_when - 1).strftime("%m-%d-%Y %H:%M:%S") + timestamp = datetime.fromtimestamp(from_when - 1).strftime('%m-%d-%Y %H:%M:%S') # Long format to match search: ex. 'January 03, 2024 at 03:08:08 PM' - long_format = datetime.strptime(timestamp, "%m-%d-%Y %H:%M:%S").strftime( - "%B %d, %Y at %I:%M:%S %p" + long_format = datetime.strptime(timestamp, '%m-%d-%Y %H:%M:%S').strftime( + '%B %d, %Y at %I:%M:%S %p' ) search_query = ( '( label = Actions::Katello::Applicability::Hosts::BulkGenerate OR' diff --git a/tests/foreman/api/test_errata.py b/tests/foreman/api/test_errata.py index 56770f552e7..08501e9c1e8 100644 --- a/tests/foreman/api/test_errata.py +++ b/tests/foreman/api/test_errata.py @@ -18,15 +18,13 @@ """ # For ease of use hc refers to host-collection throughout this document from time import sleep, time -from robottelo.logging import logger - -# from datetime import datetime import pytest from robottelo import constants from robottelo.config import settings from robottelo.constants import ( DEFAULT_ARCHITECTURE, + DEFAULT_SUBSCRIPTION_NAME, FAKE_1_CUSTOM_PACKAGE, FAKE_2_CUSTOM_PACKAGE, FAKE_2_CUSTOM_PACKAGE_NAME, @@ -869,27 +867,31 @@ def test_positive_install_multiple_in_host( len(updated_packages) > 0 ), f'No applicable packages were found or installed from list: {FAKE_9_YUM_UPDATED_PACKAGES}.' # Each expected erratum and packages installed only once - assert set(updated_packages), f'Expect no repeated packages in install list: {updated_packages}' - assert set(installed_errata), f'Expect no repeated errata in install list: {installed_errata}' + pkg_set = set(updated_packages) + errata_set = set(installed_errata) + assert len(pkg_set) == len(updated_packages), f'Expect no repeat packages in install list: {updated_packages}.' + assert len(errata_set) == len(installed_errata), f'Expected no repeat errata in install list: {installed_errata}.' # Only the expected YUM_9 packages were installed assert set(updated_packages).issubset(set(FAKE_9_YUM_UPDATED_PACKAGES)) # Only the expected YUM_9 errata were updated assert set(installed_errata).issubset(set(FAKE_9_YUM_SECURITY_ERRATUM)) - # Check number of installed errata and unique names matches expected + # Check number of installed errata id(s) matches expected assert len(installed_errata) == len(expected_errata_to_install), ( f'Expected to install {len(expected_errata_to_install)} errata from list: {FAKE_9_YUM_SECURITY_ERRATUM},' f' but installed: {len(installed_errata)}.' ) + # Check sets of installed errata id(s) strings, matches expected assert set(installed_errata) == set(expected_errata_to_install), ( - 'Sets containing unique errata_ids did not match. Actual installs verse Expected installs.' + 'Expected errata id(s) and installed errata id(s) are not the same.' ) - # Check number of updated packages and unique names match expected + # Check number of updated package version filename(s) matches expected assert len(updated_packages) == len(security_packages_to_install), ( f'Expected to install {len(security_packages_to_install)} packages from list: {FAKE_9_YUM_UPDATED_PACKAGES},' f' but installed {len(updated_packages)}.' ) + # Check sets of installed package filename(s) strings, matches expected assert set(updated_packages) == set(security_packages_to_install), ( - 'Sets containing unique package_filenames did not match. Actual installs verse Expected installs.' + 'Expected package version filename(s) and installed package version filenam(s) are not the same.' ) @@ -954,7 +956,7 @@ def test_positive_list_sorted_filtered(custom_repo, target_sat): erratum_list = target_sat.api.Errata(repository=custom_repo['repository-id']).search( query={'order': 'cve DESC', 'per_page': '1000'} ) - # Most of Errata won't have any CVEs. Removing empty CVEs from results + # Most Errata won't have any CVEs. Removing empty CVEs from results erratum_cves = [errata.cves for errata in erratum_list if errata.cves] # Verifying each errata have its CVEs sorted in DESC order for errata_cves in erratum_cves: @@ -978,7 +980,7 @@ def setup_content_rhel8( Raises `AssertionError` if one or more of the setup components read are empty. - :return: if return_result is True: + :return: if return_result is True: otherwise None A dictionary (_result) with the satellite instances of activaton-key, organization, content-view, lifecycle-environment, rh_repo, custom_repo. """ @@ -1017,8 +1019,7 @@ def setup_content_rhel8( assert all( entry for entry in _result.values() ), f'One or more necessary components are not present: {_result}' - if return_result: - return _result + return _result if return_result else None @pytest.mark.tier2 @@ -1319,10 +1320,10 @@ def _set_prerequisites_for_swid_repos(vm): _run_remote_command_on_content_host( f'curl --insecure --remote-name {settings.repos.swid_tools_repo}', vm ) - _run_remote_command_on_content_host("mv *swid*.repo /etc/yum.repos.d", vm) + _run_remote_command_on_content_host('mv *swid*.repo /etc/yum.repos.d', vm) _run_remote_command_on_content_host(r'subscription-manager repos --enable \*', vm) - _run_remote_command_on_content_host("yum install -y swid-tools", vm) - _run_remote_command_on_content_host("dnf install -y dnf-plugin-swidtags", vm) + _run_remote_command_on_content_host('yum install -y swid-tools', vm) + _run_remote_command_on_content_host('yum install -y dnf-plugin-swidtags', vm) def _validate_swid_tags_installed(vm, module_name): @@ -1467,12 +1468,12 @@ def rhel8_module_ak( # Ensure tools repo is enabled in the activation key rhel8_module_ak.content_override( data={ - 'content_overrides': [{'content_label': constants.REPOS['rhst8']['id'], 'value': '1'}] + 'content_overrides': [{'content_label': REPOS['rhst8']['id'], 'value': '1'}] } ) # Fetch available subscriptions subs = module_target_sat.api.Subscription(organization=module_entitlement_manifest_org).search( - query={'search': f'{constants.DEFAULT_SUBSCRIPTION_NAME}'} + query={'search': f'{DEFAULT_SUBSCRIPTION_NAME}'} ) assert subs # Add default subscription to activation key