diff --git a/pytest_fixtures/core/ui.py b/pytest_fixtures/core/ui.py index f87f4cec0ad..298632f59f6 100644 --- a/pytest_fixtures/core/ui.py +++ b/pytest_fixtures/core/ui.py @@ -2,6 +2,7 @@ import pytest from requests.exceptions import HTTPError +from robottelo.hosts import Satellite from robottelo.logging import logger @@ -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 diff --git a/tests/foreman/ui/test_activationkey.py b/tests/foreman/ui/test_activationkey.py index 19e163c6cb8..a0aded422ac 100644 --- a/tests/foreman/ui/test_activationkey.py +++ b/tests/foreman/ui/test_activationkey.py @@ -18,10 +18,8 @@ """ import random -from airgun.session import Session from broker import Broker from fauxfactory import gen_string -from nailgun import entities import pytest from robottelo import constants @@ -33,7 +31,7 @@ @pytest.mark.e2e @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_end_to_end_crud(session, module_org): +def test_positive_end_to_end_crud(session, module_org, module_target_sat): """Perform end to end testing for activation key component :id: b6b98c45-e41e-4c7a-9be4-997273b7e24d @@ -46,7 +44,7 @@ def test_positive_end_to_end_crud(session, module_org): """ name = gen_string('alpha') new_name = gen_string('alpha') - cv = entities.ContentView(organization=module_org).create() + cv = module_target_sat.api.ContentView(organization=module_org).create() cv.publish() with session: # Create activation key with content view and LCE assigned @@ -98,7 +96,7 @@ def test_positive_end_to_end_register( :CaseImportance: High """ org = function_entitlement_manifest_org - lce = entities.LifecycleEnvironment(organization=org).create() + lce = target_sat.api.LifecycleEnvironment(organization=org).create() repos_collection.setup_content(org.id, lce.id, upload_manifest=False) ak_name = repos_collection.setup_content_data['activation_key']['name'] @@ -184,7 +182,7 @@ def test_positive_search_scoped(session, module_org, target_sat): @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_create_with_host_collection(session, module_org): +def test_positive_create_with_host_collection(session, module_org, module_target_sat): """Create Activation key with Host Collection :id: 0e4ad2b4-47a7-4087-828f-2b0535a97b69 @@ -194,7 +192,7 @@ def test_positive_create_with_host_collection(session, module_org): :CaseLevel: Integration """ name = gen_string('alpha') - hc = entities.HostCollection(organization=module_org).create() + hc = module_target_sat.api.HostCollection(organization=module_org).create() with session: session.activationkey.create({'name': name, 'lce': {constants.ENVIRONMENT: True}}) assert session.activationkey.search(name)[0]['Name'] == name @@ -245,21 +243,21 @@ def test_positive_add_host_collection_non_admin(module_org, test_name, target_sa :CaseLevel: Integration """ ak_name = gen_string('alpha') - hc = entities.HostCollection(organization=module_org).create() + hc = target_sat.api.HostCollection(organization=module_org).create() # Create non-admin user with specified permissions - roles = [entities.Role().create()] + roles = [target_sat.api.Role().create()] user_permissions = { 'Katello::ActivationKey': constants.PERMISSIONS['Katello::ActivationKey'], 'Katello::HostCollection': constants.PERMISSIONS['Katello::HostCollection'], } - viewer_role = entities.Role().search(query={'search': 'name="Viewer"'})[0] + viewer_role = target_sat.api.Role().search(query={'search': 'name="Viewer"'})[0] roles.append(viewer_role) target_sat.api_factory.create_role_permissions(roles[0], user_permissions) password = gen_string('alphanumeric') - user = entities.User( + user = target_sat.api.User( admin=False, role=roles, password=password, organization=[module_org] ).create() - with Session(test_name, user=user.login, password=password) as session: + with target_sat.ui_session(test_name, user=user.login, password=password) as session: session.activationkey.create({'name': ak_name, 'lce': {constants.ENVIRONMENT: True}}) assert session.activationkey.search(ak_name)[0]['Name'] == ak_name session.activationkey.add_host_collection(ak_name, hc.name) @@ -281,21 +279,21 @@ def test_positive_remove_host_collection_non_admin(module_org, test_name, target :CaseLevel: Integration """ ak_name = gen_string('alpha') - hc = entities.HostCollection(organization=module_org).create() + hc = target_sat.api.HostCollection(organization=module_org).create() # Create non-admin user with specified permissions - roles = [entities.Role().create()] + roles = [target_sat.api.Role().create()] user_permissions = { 'Katello::ActivationKey': constants.PERMISSIONS['Katello::ActivationKey'], 'Katello::HostCollection': constants.PERMISSIONS['Katello::HostCollection'], } - viewer_role = entities.Role().search(query={'search': 'name="Viewer"'})[0] + viewer_role = target_sat.api.Role().search(query={'search': 'name="Viewer"'})[0] roles.append(viewer_role) target_sat.api_factory.create_role_permissions(roles[0], user_permissions) password = gen_string('alphanumeric') - user = entities.User( + user = target_sat.api.User( admin=False, role=roles, password=password, organization=[module_org] ).create() - with Session(test_name, user=user.login, password=password) as session: + with target_sat.ui_session(test_name, user=user.login, password=password) as session: session.activationkey.create({'name': ak_name, 'lce': {constants.ENVIRONMENT: True}}) assert session.activationkey.search(ak_name)[0]['Name'] == ak_name session.activationkey.add_host_collection(ak_name, hc.name) @@ -582,8 +580,8 @@ def test_positive_add_rh_and_custom_products( custom_product_name = gen_string('alpha') repo_name = gen_string('alpha') org = function_entitlement_manifest_org - product = entities.Product(name=custom_product_name, organization=org).create() - repo = entities.Repository(name=repo_name, product=product).create() + product = target_sat.api.Product(name=custom_product_name, organization=org).create() + repo = target_sat.api.Repository(name=repo_name, product=product).create() rhel_repo_id = target_sat.api_factory.enable_rhrepo_and_fetchid( basearch=rh_repo['basearch'], org_id=org.id, @@ -593,7 +591,7 @@ def test_positive_add_rh_and_custom_products( releasever=rh_repo['releasever'], ) for repo_id in [rhel_repo_id, repo.id]: - entities.Repository(id=repo_id).sync() + target_sat.api.Repository(id=repo_id).sync() with session: session.organization.select(org.name) session.activationkey.create( @@ -638,19 +636,21 @@ def test_positive_fetch_product_content(target_sat, function_entitlement_manifes reposet=constants.REPOSET['rhst7'], releasever=None, ) - rh_repo = entities.Repository(id=rh_repo_id).read() + rh_repo = target_sat.api.Repository(id=rh_repo_id).read() rh_repo.sync() - custom_product = entities.Product(organization=org).create() - custom_repo = entities.Repository( + custom_product = target_sat.api.Product(organization=org).create() + custom_repo = target_sat.api.Repository( name=gen_string('alphanumeric').upper(), # first letter is always # uppercase on product content page, workarounding it for # successful checks product=custom_product, ).create() custom_repo.sync() - cv = entities.ContentView(organization=org, repository=[rh_repo_id, custom_repo.id]).create() + cv = target_sat.api.ContentView( + organization=org, repository=[rh_repo_id, custom_repo.id] + ).create() cv.publish() - ak = entities.ActivationKey(content_view=cv, organization=org).create() + ak = target_sat.api.ActivationKey(content_view=cv, organization=org).create() with session: session.organization.select(org.name) for subscription in (constants.DEFAULT_SUBSCRIPTION_NAME, custom_product.name): @@ -663,7 +663,7 @@ def test_positive_fetch_product_content(target_sat, function_entitlement_manifes @pytest.mark.e2e @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_access_non_admin_user(session, test_name): +def test_positive_access_non_admin_user(session, test_name, target_sat): """Access activation key that has specific name and assigned environment by user that has filter configured for that specific activation key @@ -680,24 +680,26 @@ def test_positive_access_non_admin_user(session, test_name): """ ak_name = gen_string('alpha') non_searchable_ak_name = gen_string('alpha') - org = entities.Organization().create() + org = target_sat.api.Organization().create() envs_list = ['STAGING', 'DEV', 'IT', 'UAT', 'PROD'] for name in envs_list: - entities.LifecycleEnvironment(name=name, organization=org).create() + target_sat.api.LifecycleEnvironment(name=name, organization=org).create() env_name = random.choice(envs_list) - cv = entities.ContentView(organization=org).create() + cv = target_sat.api.ContentView(organization=org).create() cv.publish() content_view_version = cv.read().version[0] content_view_version.promote( - data={'environment_ids': [entities.LifecycleEnvironment(name=env_name).search()[0].id]} + data={ + 'environment_ids': [target_sat.api.LifecycleEnvironment(name=env_name).search()[0].id] + } ) # Create new role - role = entities.Role().create() + role = target_sat.api.Role().create() # Create filter with predefined activation keys search criteria envs_condition = ' or '.join(['environment = ' + s for s in envs_list]) - entities.Filter( + target_sat.api.Filter( organization=[org], - permission=entities.Permission().search( + permission=target_sat.api.Permission().search( filters={'name': 'view_activation_keys'}, query={'search': 'resource_type="Katello::ActivationKey"'}, ), @@ -706,20 +708,24 @@ def test_positive_access_non_admin_user(session, test_name): ).create() # Add permissions for Organization and Location - entities.Filter( - permission=entities.Permission().search(query={'search': 'resource_type="Organization"'}), + target_sat.api.Filter( + permission=target_sat.api.Permission().search( + query={'search': 'resource_type="Organization"'} + ), role=role, ).create() - entities.Filter( - permission=entities.Permission().search(query={'search': 'resource_type="Location"'}), + target_sat.api.Filter( + permission=target_sat.api.Permission().search(query={'search': 'resource_type="Location"'}), role=role, ).create() # Create new user with a configured role - default_loc = entities.Location().search(query={'search': f'name="{constants.DEFAULT_LOC}"'})[0] + default_loc = target_sat.api.Location().search( + query={'search': f'name="{constants.DEFAULT_LOC}"'} + )[0] user_login = gen_string('alpha') user_password = gen_string('alpha') - entities.User( + target_sat.api.User( role=[role], admin=False, login=user_login, @@ -740,7 +746,7 @@ def test_positive_access_non_admin_user(session, test_name): env_name ][env_name] - 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: session.organization.select(org.name) session.location.select(constants.DEFAULT_LOC) assert session.activationkey.search(ak_name)[0]['Name'] == ak_name @@ -751,7 +757,7 @@ def test_positive_access_non_admin_user(session, test_name): @pytest.mark.tier2 -def test_positive_remove_user(session, module_org, test_name): +def test_positive_remove_user(session, module_org, test_name, module_target_sat): """Delete any user who has previously created an activation key and check that activation key still exists @@ -764,9 +770,11 @@ def test_positive_remove_user(session, module_org, test_name): ak_name = gen_string('alpha') # Create user password = gen_string('alpha') - user = entities.User(admin=True, default_organization=module_org, password=password).create() + user = module_target_sat.api.User( + admin=True, default_organization=module_org, password=password + ).create() # Create Activation Key using new user credentials - with Session(test_name, user.login, password) as non_admin_session: + with module_target_sat.ui_session(test_name, user.login, password) as non_admin_session: non_admin_session.activationkey.create( {'name': ak_name, 'lce': {constants.ENVIRONMENT: True}} ) @@ -778,7 +786,7 @@ def test_positive_remove_user(session, module_org, test_name): @pytest.mark.tier2 -def test_positive_add_docker_repo_cv(session, module_org): +def test_positive_add_docker_repo_cv(session, module_org, module_target_sat): """Add docker repository to a non-composite content view and publish it. Then create an activation key and associate it with the Docker content view. @@ -790,13 +798,13 @@ def test_positive_add_docker_repo_cv(session, module_org): :CaseLevel: Integration """ - lce = entities.LifecycleEnvironment(organization=module_org).create() - repo = entities.Repository( + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + repo = module_target_sat.api.Repository( content_type=constants.REPO_TYPE['docker'], - product=entities.Product(organization=module_org).create(), + product=module_target_sat.api.Product(organization=module_org).create(), url=constants.CONTAINER_REGISTRY_HUB, ).create() - content_view = entities.ContentView( + content_view = module_target_sat.api.ContentView( composite=False, organization=module_org, repository=[repo] ).create() content_view.publish() @@ -813,7 +821,7 @@ def test_positive_add_docker_repo_cv(session, module_org): @pytest.mark.tier2 -def test_positive_add_docker_repo_ccv(session, module_org): +def test_positive_add_docker_repo_ccv(session, module_org, module_target_sat): """Add docker repository to a non-composite content view and publish it. Then add this content view to a composite content view and publish it. Create an activation key and associate it with the composite Docker content @@ -826,19 +834,19 @@ def test_positive_add_docker_repo_ccv(session, module_org): :CaseLevel: Integration """ - lce = entities.LifecycleEnvironment(organization=module_org).create() - repo = entities.Repository( + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + repo = module_target_sat.api.Repository( content_type=constants.REPO_TYPE['docker'], - product=entities.Product(organization=module_org).create(), + product=module_target_sat.api.Product(organization=module_org).create(), url=constants.CONTAINER_REGISTRY_HUB, ).create() - content_view = entities.ContentView( + content_view = module_target_sat.api.ContentView( composite=False, organization=module_org, repository=[repo] ).create() content_view.publish() cvv = content_view.read().version[0].read() cvv.promote(data={'environment_ids': lce.id, 'force': False}) - composite_cv = entities.ContentView( + composite_cv = module_target_sat.api.ContentView( component=[cvv], composite=True, organization=module_org ).create() composite_cv.publish() @@ -872,8 +880,8 @@ def test_positive_add_host(session, module_org, rhel6_contenthost, target_sat): :CaseLevel: System """ - ak = entities.ActivationKey( - environment=entities.LifecycleEnvironment( + ak = target_sat.api.ActivationKey( + environment=target_sat.api.LifecycleEnvironment( name=constants.ENVIRONMENT, organization=module_org ).search()[0], organization=module_org, @@ -912,7 +920,7 @@ def test_positive_delete_with_system(session, rhel6_contenthost, target_sat): cv_name = gen_string('alpha') env_name = gen_string('alpha') product_name = gen_string('alpha') - org = entities.Organization().create() + org = target_sat.api.Organization().create() # Helper function to create and promote CV to next environment repo_id = target_sat.api_factory.create_sync_custom_repo( product_name=product_name, org_id=org.id @@ -1049,12 +1057,12 @@ def test_positive_host_associations(session, target_sat): :CaseLevel: System """ - org = entities.Organization().create() + org = target_sat.api.Organization().create() org_entities = target_sat.cli_factory.setup_org_for_a_custom_repo( {'url': settings.repos.yum_1.url, 'organization-id': org.id} ) - ak1 = entities.ActivationKey(id=org_entities['activationkey-id']).read() - ak2 = entities.ActivationKey( + ak1 = target_sat.api.ActivationKey(id=org_entities['activationkey-id']).read() + ak2 = target_sat.api.ActivationKey( content_view=org_entities['content-view-id'], environment=org_entities['lifecycle-environment-id'], organization=org.id, @@ -1117,10 +1125,10 @@ def test_positive_service_level_subscription_with_custom_product( entities_ids = target_sat.cli_factory.setup_org_for_a_custom_repo( {'url': settings.repos.yum_1.url, 'organization-id': org.id} ) - product = entities.Product(id=entities_ids['product-id']).read() - activation_key = entities.ActivationKey(id=entities_ids['activationkey-id']).read() + product = target_sat.api.Product(id=entities_ids['product-id']).read() + activation_key = target_sat.api.ActivationKey(id=entities_ids['activationkey-id']).read() # add the default RH subscription - subscription = entities.Subscription(organization=org).search( + subscription = target_sat.api.Subscription(organization=org).search( query={'search': f'name="{constants.DEFAULT_SUBSCRIPTION_NAME}"'} )[0] activation_key.add_subscriptions(data={'quantity': 1, 'subscription_id': subscription.id}) @@ -1150,7 +1158,7 @@ def test_positive_service_level_subscription_with_custom_product( @pytest.mark.run_in_one_thread @pytest.mark.tier2 -def test_positive_delete_manifest(session, function_entitlement_manifest_org): +def test_positive_delete_manifest(session, function_entitlement_manifest_org, target_sat): """Check if deleting a manifest removes it from Activation key :id: 512d8e41-b937-451e-a9c6-840457d3d7d4 @@ -1167,9 +1175,9 @@ def test_positive_delete_manifest(session, function_entitlement_manifest_org): """ org = function_entitlement_manifest_org # Create activation key - activation_key = entities.ActivationKey(organization=org).create() + activation_key = target_sat.api.ActivationKey(organization=org).create() # Associate a manifest to the activation key - subscription = entities.Subscription(organization=org).search( + subscription = target_sat.api.Subscription(organization=org).search( query={'search': f'name="{constants.DEFAULT_SUBSCRIPTION_NAME}"'} )[0] activation_key.add_subscriptions(data={'quantity': 1, 'subscription_id': subscription.id}) diff --git a/tests/foreman/ui/test_bookmarks.py b/tests/foreman/ui/test_bookmarks.py index 180a0bf205e..691f31b3d43 100644 --- a/tests/foreman/ui/test_bookmarks.py +++ b/tests/foreman/ui/test_bookmarks.py @@ -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 @@ -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 @@ -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) @@ -193,7 +195,7 @@ 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)) @@ -201,7 +203,7 @@ def test_positive_update_bookmark_public( 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( @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/foreman/ui/test_branding.py b/tests/foreman/ui/test_branding.py index 3067614e02a..1b1cea7e4de 100644 --- a/tests/foreman/ui/test_branding.py +++ b/tests/foreman/ui/test_branding.py @@ -16,7 +16,6 @@ :Upstream: No """ -from airgun.session import Session import pytest @@ -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' diff --git a/tests/foreman/ui/test_contenthost.py b/tests/foreman/ui/test_contenthost.py index 80a0eedf3a9..5af537c8dfb 100644 --- a/tests/foreman/ui/test_contenthost.py +++ b/tests/foreman/ui/test_contenthost.py @@ -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 @@ -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 @@ -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, @@ -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) @@ -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 @@ -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) @@ -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 @@ -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() ) @@ -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 @@ -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'] @@ -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 @@ -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. @@ -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', @@ -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. @@ -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) diff --git a/tests/foreman/ui/test_contentview_old.py b/tests/foreman/ui/test_contentview_old.py new file mode 100644 index 00000000000..0b846771257 --- /dev/null +++ b/tests/foreman/ui/test_contentview_old.py @@ -0,0 +1,3849 @@ +"""Test class for Old Content View UI + +Feature details: https://fedorahosted.org/katello/wiki/ContentViews + + +:Requirement: Contentview + +:CaseAutomation: Automated + +:CaseComponent: ContentViews + +:team: Phoenix-content + +:CaseImportance: High + +""" +import datetime +from random import randint + +from airgun.exceptions import InvalidElementStateException, NoSuchElementException +from nailgun.entity_mixins import call_entity_method_with_timeout +from navmazing import NavigationTriesExceeded +from productmd.common import parse_nvra +import pytest + +from robottelo import constants +from robottelo.cli.contentview import ContentView +from robottelo.config import settings +from robottelo.constants import ( + CONTAINER_REGISTRY_HUB, + CONTAINER_UPSTREAM_NAME, + DEFAULT_ARCHITECTURE, + DEFAULT_CV, + DEFAULT_PTABLE, + ENVIRONMENT, + FAKE_0_CUSTOM_PACKAGE, + FAKE_1_CUSTOM_PACKAGE, + FAKE_2_CUSTOM_PACKAGE, + FAKE_9_YUM_SECURITY_ERRATUM_COUNT, + FILTER_CONTENT_TYPE, + FILTER_ERRATA_TYPE, + FILTER_TYPE, + PERMISSIONS, + PRDS, + REPO_TYPE, + REPOS, + REPOSET, +) +from robottelo.utils.datafactory import gen_string + +VERSION = 'Version 1.0' + + +@pytest.fixture(scope='module') +def module_org(module_target_sat): + return module_target_sat.api.Organization().create() + + +@pytest.fixture(scope='module') +def module_prod(module_org, module_target_sat): + return module_target_sat.api.Product(organization=module_org).create() + + +@pytest.mark.tier2 +def test_positive_add_custom_content(session, module_target_sat): + """Associate custom content in a view + + :id: 7128fc8b-0e8c-4f00-8541-2ca2399650c8 + + :setup: Sync custom content + + :expectedresults: Custom content can be seen in a view + + :CaseImportance: Critical + """ + org = module_target_sat.api.Organization().create() + cv_name = gen_string('alpha') + repo_name = gen_string('alpha') + product = module_target_sat.api.Product(organization=org).create() + module_target_sat.api.Repository(name=repo_name, product=product).create() + with session: + session.organization.select(org_name=org.name) + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, repo_name) + cv = session.contentview.read(cv_name) + assert cv['repositories']['resources']['assigned'][0]['Name'] == repo_name + + +@pytest.mark.tier2 +@pytest.mark.upgrade +def test_positive_end_to_end(session, module_target_sat, module_org, target_sat): + """Create content view with yum repo, publish it and promote it to Library + +1 env + + :id: 74c1b00d-c582-434f-bf73-588532588d50 + + :steps: + 1. Create Product/repo and Sync it + 2. Create CV and add created repo in step1 + 3. Publish and promote it to 'Library' + 4. Promote it to next environment + + :expectedresults: content view is created, updated with repo publish and + promoted to next selected env + + :CaseImportance: High + """ + repo_name = gen_string('alpha') + env_name = gen_string('alpha') + cv_name = gen_string('alpha') + # Creates a CV along with product and sync'ed repository + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + # Create Life-cycle environment + session.lifecycleenvironment.create({'name': env_name}) + # Create content-view + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + # Add repository to selected CV + session.contentview.add_yum_repo(cv_name, repo_name) + # Publish and promote CV to next environment + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + result = session.contentview.promote(cv_name, VERSION, env_name) + assert f'Promoted to {env_name}' in result['Status'] + + +@pytest.mark.tier2 +def test_positive_publish_version_changes_in_source_env(session, module_target_sat, module_org): + """When publishing new version to environment, version gets updated + + :id: 576ac8b4-7efe-4267-a672-868a5f3eb28a + + :steps: + 1. publish a view and then promote it to a new environment + 2. republish a new version of a CV and then promote it once more + + :expectedresults: Content view version is updated in source + environment. + + :CaseImportance: High + """ + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + cv = module_target_sat.api.ContentView(organization=module_org).create() + with session: + result = session.contentview.publish(cv.name) + assert result['Version'] == 'Version 1.0' + result = session.contentview.promote(cv.name, 'Version 1.0', lce.name) + # Check that content view version 1.0 promoted to both environments + assert ENVIRONMENT in result['Environments'] + assert lce.name in result['Environments'] + # Re-publish content view + result = session.contentview.publish(cv.name) + assert result['Version'] == 'Version 2.0' + # Check that content view version 1.0 is still promoted to last environment, + # but new published version is promoted to default one + assert result['Environments'] == ENVIRONMENT + cv_values = session.contentview.read(cv.name, widget_names='versions') + env = [ + version['Environments'] + for version in cv_values['versions']['table'] + if version['Version'] == 'Version 1.0' + ][0] + assert env == lce.name + # Promote new version to last environment + result = session.contentview.promote(cv.name, 'Version 2.0', lce.name) + # Check that new content view version promoted to both environments and + # content view version 1.0 has not promoted to any version at all + assert ENVIRONMENT in result['Environments'] + assert lce.name in result['Environments'] + cv_values = session.contentview.read(cv.name, widget_names='versions') + assert not [ + version['Environments'] + for version in cv_values['versions']['table'] + if version['Version'] == 'Version 1.0' + ] + + +@pytest.mark.tier2 +def test_positive_repo_count_for_composite_cv(session, module_target_sat, module_org, target_sat): + """Create some content views with synchronized repositories and + promoted to one lce. Add them to composite content view and check repo + count for it. + + :id: 4b8d5def-a593-4f6c-9856-e5f32fb80164 + + :expectedresults: repository count for composite content view should + be the sum of archived repositories across all content views. + + :BZ: 1431778 + + :CaseImportance: High + """ + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + ccv_name = gen_string('alpha') + repo_name = gen_string('alpha') + # Create a product and sync'ed repository + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + # Creates a composite CV + session.contentview.create({'name': ccv_name, 'composite_view': True}) + # Create three content-views and add synced repo to them + for _ in range(3): + cv_name = module_target_sat.api.ContentView(organization=module_org).create().name + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + # Add repository to selected CV + session.contentview.add_yum_repo(cv_name, repo_name) + # Publish content view + session.contentview.publish(cv_name) + # Check that repo count for cv is equal to 1 + assert session.contentview.search(cv_name)[0]['Repositories'] == '1' + # Promote content view + result = session.contentview.promote(cv_name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + # Add content view to composite one + session.contentview.add_cv(ccv_name, cv_name) + # Publish composite content view + session.contentview.publish(ccv_name) + # Check that composite cv has three repositories in the table as we + # were using one repository for each content view + assert session.contentview.search(ccv_name)[0]['Repositories'] == '3' + + +@pytest.mark.run_in_one_thread +@pytest.mark.skip_if_not_set('fake_manifest') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_create_composite( + session, module_prod, module_entitlement_manifest_org, target_sat +): + """Create a composite content views + + :id: 550f1970-5cbd-4571-bb7b-17e97639b715 + + :setup: sync multiple content source/types (RH, custom, etc.) + + :expectedresults: Composite content views are created + + :CaseImportance: High + """ + org = module_entitlement_manifest_org + cv_name1 = gen_string('alpha') + cv_name2 = gen_string('alpha') + composite_name = gen_string('alpha') + rh_repo = { + 'name': REPOS['rhst7']['name'], + 'product': PRDS['rhel'], + 'reposet': REPOSET['rhst7'], + 'basearch': 'x86_64', + 'releasever': None, + } + docker_repo = target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + + target_sat.api_factory.enable_sync_redhat_repo(rh_repo, org.id) + docker_repo.sync() + with session: + session.organization.select(org.name) + # Create content views + for cv_name in (cv_name1, cv_name2): + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_docker_repo(cv_name1, docker_repo.name) + cv1 = session.contentview.read(cv_name1) + assert cv1['docker_repositories']['resources']['assigned'][0]['Name'] == docker_repo.name + session.contentview.publish(cv_name1) + session.contentview.add_yum_repo(cv_name2, rh_repo['name']) + session.contentview.publish(cv_name2) + session.contentview.create({'name': composite_name, 'composite_view': True}) + for cv_name in (cv_name1, cv_name2): + session.contentview.add_cv(composite_name, cv_name) + composite_cv = session.contentview.read(composite_name) + assert {cv_name1, cv_name2} == { + cv['Name'] for cv in composite_cv['content_views']['resources']['assigned'] + } + + +@pytest.mark.run_in_one_thread +@pytest.mark.skip_if_not_set('fake_manifest') +@pytest.mark.tier2 +def test_positive_add_rh_content( + session, module_target_sat, function_entitlement_manifest_org, target_sat +): + """Add Red Hat content to a content view + + :id: c370fd79-0c0d-4685-99cb-848556c786c1 + + :setup: Sync RH content + + :expectedresults: RH Content can be seen in a view + + :CaseImportance: Critical + """ + cv_name = gen_string('alpha') + rh_repo = { + 'name': REPOS['rhst7']['name'], + 'product': PRDS['rhel'], + 'reposet': REPOSET['rhst7'], + 'basearch': 'x86_64', + 'releasever': None, + } + # Create new org to import manifest + org = function_entitlement_manifest_org + target_sat.api_factory.enable_sync_redhat_repo(rh_repo, org.id) + with session: + # Create content-view + session.organization.select(org.name) + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, rh_repo['name']) + cv = session.contentview.read(cv_name) + assert cv['repositories']['resources']['assigned'][0]['Name'] == rh_repo['name'] + + +@pytest.mark.tier2 +def test_positive_add_docker_repo(session, module_target_sat, module_org, module_prod): + """Add one Docker-type repository to a non-composite content view + + :id: 2868cfd5-d27e-4db9-b4a3-2827e31d1601 + + :expectedresults: The repo is added to a non-composite content view + + :CaseImportance: High + """ + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org + ).create() + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + with session: + session.contentview.add_docker_repo(content_view.name, repo.name) + cv = session.contentview.read(content_view.name, 'docker_repositories') + assert cv['docker_repositories']['resources']['assigned'][0]['Name'] == repo.name + + +@pytest.mark.tier2 +def test_positive_add_docker_repos(session, module_target_sat, module_org, module_prod): + """Add multiple Docker-type repositories to a non-composite + content view. + + :id: 60d0ea23-fe8c-49f3-bed9-cc062ab1118d + + :expectedresults: The repos are added to a non-composite content + view. + + :CaseImportance: Low + """ + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org + ).create() + repos = [ + module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + for _ in range(randint(2, 3)) + ] + with session: + for repo in repos: + session.contentview.add_docker_repo(content_view.name, repo.name) + cv = session.contentview.read(content_view.name, 'docker_repositories') + assert {repo.name for repo in repos} == { + repo['Name'] for repo in cv['docker_repositories']['resources']['assigned'] + } + + +@pytest.mark.tier2 +def test_positive_add_synced_docker_repo(session, module_target_sat, module_org, module_prod): + """Create and sync a docker repository, then add it to content view + + :id: 338a7ed4-9e10-4bc0-8666-5c8cd0ff0504 + + :expectedresults: Synchronized docker repository was successfully added + to content view. + + :CaseImportance: High + """ + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org + ).create() + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + with session: + result = session.sync_status.synchronize([(module_prod.name, repo.name)]) + assert result[0] == 'Syncing Complete.' + session.contentview.add_docker_repo(content_view.name, repo.name) + cv = session.contentview.read(content_view.name, 'docker_repositories') + assert cv['docker_repositories']['resources']['assigned'][0]['Name'] == repo.name + assert cv['docker_repositories']['resources']['assigned'][0]['Sync State'] == 'Success' + + +@pytest.mark.tier2 +def test_positive_add_docker_repo_to_ccv(session, module_target_sat, module_org, module_prod): + """Add one docker repository to a composite content view + + :id: 76b68407-b429-4ad7-b8b5-bfde327a0404 + + :expectedresults: The repository is added to a content view which + is then added to a composite content view. + + :CaseImportance: High + """ + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org + ).create() + composite_cv = module_target_sat.api.ContentView( + composite=True, organization=module_org + ).create() + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + with session: + session.contentview.add_docker_repo(content_view.name, repo.name) + result = session.contentview.publish(content_view.name) + assert result['Version'] == VERSION + session.contentview.add_cv(composite_cv.name, content_view.name) + ccv = session.contentview.read(composite_cv.name, 'content_views') + assert ccv['content_views']['resources']['assigned'][0]['Name'] == content_view.name + assert '1 Repositories' in ccv['content_views']['resources']['assigned'][0]['Content'] + + +@pytest.mark.tier2 +def test_positive_add_docker_repos_to_ccv(session, module_target_sat, module_org, module_prod): + """Add multiple docker repositories to a composite content view. + + :id: 30187102-7106-45de-a68b-e32fbaecedb9 + + :expectedresults: The repository is added to a random number of content + views which are then added to a composite content view. + + :CaseImportance: Low + """ + cvs = [] + for _ in range(randint(2, 3)): + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org, repository=[repo] + ).create() + content_view.publish() + cvs.append(content_view.name) + composite_cv = module_target_sat.api.ContentView( + composite=True, organization=module_org + ).create() + with session: + for cv in cvs: + session.contentview.add_cv(composite_cv.name, cv) + ccv = session.contentview.read(composite_cv.name, 'content_views') + assert set(cvs) == {cv['Name'] for cv in ccv['content_views']['resources']['assigned']} + assert all( + '1 Repositories' in cv['Content'] + for cv in ccv['content_views']['resources']['assigned'] + ) + + +@pytest.mark.tier2 +def test_positive_publish_with_docker_repo(session, module_target_sat, module_org, module_prod): + """Add docker repository to content view and publish it once. + + :id: 2004b2d4-177b-47de-9e61-bcfb58f05f88 + + :expectedresults: The repo is added to a content view which is then + successfully published. + + :CaseImportance: High + """ + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org + ).create() + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + with session: + session.contentview.add_docker_repo(content_view.name, repo.name) + result = session.contentview.publish(content_view.name) + assert result['Version'] == VERSION + cv = session.contentview.read(content_view.name, 'versions') + assert cv['versions']['table'][0]['Version'] == VERSION + + +@pytest.mark.tier2 +def test_positive_publish_with_docker_repo_composite( + session, module_target_sat, module_org, module_prod +): + """Add docker repository to composite content view and publish it once. + + :id: 7aad525a-a9d3-4100-9611-ca02c6a95a22 + + :expectedresults: The docker repository is added to a content view + which is then published only once and then added to a composite + content view which is also published only once. + + :CaseImportance: High + """ + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org, repository=[repo] + ).create() + content_view.publish() + composite_cv = module_target_sat.api.ContentView( + composite=True, organization=module_org + ).create() + with session: + session.contentview.add_cv(composite_cv.name, content_view.name) + result = session.contentview.publish(composite_cv.name) + assert result['Version'] == VERSION + ccv = session.contentview.read(composite_cv.name, 'content_views') + assert '1 Repositories' in ccv['content_views']['resources']['assigned'][0]['Content'] + + +@pytest.mark.tier2 +def test_positive_publish_multiple_with_docker_repo( + session, module_target_sat, module_org, module_prod +): + """Add docker repository to content view and publish it multiple times. + + :id: acc703b7-6e99-48d7-96ce-ea0985409ef9 + + :expectedresults: Content view with docker repo is successfully published + multiple times. + + :CaseImportance: Low + """ + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org, repository=[repo] + ).create() + with session: + for version in range(randint(2, 5)): + result = session.contentview.publish(content_view.name) + assert result['Version'] == f'Version {version + 1}.0' + + +@pytest.mark.tier2 +def test_positive_publish_multiple_with_docker_repo_composite( + session, module_target_sat, module_org, module_prod +): + """Add docker repository to composite content view and publish it multiple times. + + :id: 07755bff-9071-45e5-b861-77a5c2fed3d9 + + :expectedresults: Composite content view with docker repo is successfully + published multiple times. + + :CaseImportance: Low + """ + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org, repository=[repo] + ).create() + content_view.publish() + composite_cv = module_target_sat.api.ContentView( + composite=True, organization=module_org + ).create() + with session: + session.contentview.add_cv(composite_cv.name, content_view.name) + for version in range(randint(2, 5)): + result = session.contentview.publish(composite_cv.name) + assert result['Version'] == f'Version {version + 1}.0' + + +@pytest.mark.tier2 +def test_positive_promote_with_docker_repo(session, module_target_sat, module_org, module_prod): + """Add docker repository to content view and publish it. + Then promote it to the next available lifecycle environment. + + :id: c7e8c4a2-9676-429b-a452-f50d7bdd78b3 + + :expectedresults: Docker repository is promoted to content view + found in the specific lifecycle-environment. + + :CaseImportance: High + """ + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org, repository=[repo] + ).create() + content_view.publish() + with session: + result = session.contentview.promote(content_view.name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + assert lce.name in result['Environments'] + + +@pytest.mark.tier2 +def test_positive_promote_multiple_with_docker_repo( + session, module_target_sat, module_org, module_prod +): + """Add docker repository to content view and publish it. + Then promote it to multiple available lifecycle-environments. + + :id: c23d582e-502c-49ac-83f7-dcf0f192cbc6 + + :expectedresults: Docker repository is promoted to content view + found in the specific lifecycle-environments. + + :CaseImportance: Low + """ + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org, repository=[repo] + ).create() + content_view.publish() + with session: + for _ in range(randint(2, 3)): + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + result = session.contentview.promote(content_view.name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + assert lce.name in result['Environments'] + + +@pytest.mark.tier2 +def test_positive_promote_with_docker_repo_composite( + session, module_target_sat, module_org, module_prod +): + """Add docker repository to composite content view and publish it. + Then promote it to the next available lifecycle-environment. + + :id: 1c7817c7-60b5-4383-bc6f-2878c2b27fa5 + + :expectedresults: Docker repository is promoted to content view + found in the specific lifecycle-environment. + + :CaseImportance: High + """ + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org, repository=[repo] + ).create() + content_view.publish() + content_view = content_view.read() + composite_cv = module_target_sat.api.ContentView( + component=[content_view.version[-1]], composite=True, organization=module_org + ).create() + composite_cv.publish() + with session: + result = session.contentview.promote(composite_cv.name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + assert lce.name in result['Environments'] + + +@pytest.mark.tier2 +@pytest.mark.upgrade +def test_positive_promote_multiple_with_docker_repo_composite( + session, module_target_sat, module_org, module_prod +): + """Add docker repository to composite content view and publish it + Then promote it to the multiple available lifecycle environments. + + :id: b735b1fa-3d60-4fc0-92d2-4af0ab003097 + + :expectedresults: Docker repository is promoted to content view + found in the specific lifecycle-environments. + + :CaseImportance: Low + """ + repo = module_target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + content_view = module_target_sat.api.ContentView( + composite=False, organization=module_org, repository=[repo] + ).create() + content_view.publish() + content_view = content_view.read() + composite_cv = module_target_sat.api.ContentView( + component=[content_view.version[-1]], composite=True, organization=module_org + ).create() + composite_cv.publish() + with session: + for _ in range(randint(2, 3)): + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + result = session.contentview.promote(composite_cv.name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + assert lce.name in result['Environments'] + + +@pytest.mark.tier2 +def test_negative_add_components_to_non_composite(session, module_target_sat): + """Attempt to associate components to a non-composite content view + + :id: fa3e6aea-7ee3-46a6-a5ba-248de3c20a8f + + :expectedresults: User cannot add components to the view + + :CaseImportance: Low + """ + cv1_name = gen_string('alpha') + cv2_name = gen_string('alpha') + with session: + session.contentview.create({'name': cv1_name}) + for cv_name in (cv1_name, cv2_name): + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + with pytest.raises(AssertionError) as context: + session.contentview.add_cv(cv1_name, cv2_name) + assert 'Could not find "Content Views" tab' in str(context.value) + + +@pytest.mark.tier2 +def test_positive_add_unpublished_cv_to_composite(session, module_target_sat): + """Attempt to associate unpublished non-composite content view with + composite content view. + + :id: dc253606-3425-489d-bc01-266787d36841 + + :steps: + + 1. Create an empty non-composite content view. Do not publish it. + 2. Create a new composite content view + + :expectedresults: Non-composite content view is added to composite one + + :CaseImportance: Low + + :BZ: 1367123 + """ + unpublished_cv_name = gen_string('alpha') + composite_cv_name = gen_string('alpha') + with session: + # Create unpublished component CV + session.contentview.create({'name': unpublished_cv_name}) + assert session.contentview.search(unpublished_cv_name)[0]['Name'] == unpublished_cv_name + # Create composite CV + session.contentview.create({'name': composite_cv_name, 'composite_view': True}) + assert session.contentview.search(composite_cv_name)[0]['Name'] == composite_cv_name + # Add unpublished content view to composite one + session.contentview.add_cv(composite_cv_name, unpublished_cv_name) + + +@pytest.mark.tier3 +def test_positive_add_non_composite_cv_to_composite(session, module_target_sat): + """Attempt to associate both published and unpublished non-composite + content views with composite content view. + + :id: 93307c2a-a03f-44fa-972d-43f6e40b9de6 + + :steps: + + 1. Create an empty non-composite content view. Do not publish it + 2. Create a second non-composite content view. Publish it. + 3. Create a new composite content view. + 4. Add the published non-composite content view to the composite + content view. + 5. Add the unpublished non-composite content view to the composite + content view. + + :expectedresults: + + 1. Unpublished non-composite content view is successfully added to + composite content view. + 2. Published non-composite content view is successfully added to + composite content view. + 3. Composite content view is successfully published + + :BZ: 1367123 + + :CaseImportance: High + """ + published_cv_name = gen_string('alpha') + unpublished_cv_name = gen_string('alpha') + composite_cv_name = gen_string('alpha') + with session: + # Create a published component content view + session.contentview.create({'name': published_cv_name}) + assert session.contentview.search(published_cv_name)[0]['Name'] == published_cv_name + result = session.contentview.publish(published_cv_name) + assert result['Version'] == VERSION + # Create an unpublished component content view + session.contentview.create({'name': unpublished_cv_name}) + assert session.contentview.search(unpublished_cv_name)[0]['Name'] == unpublished_cv_name + # Create a composite content view + session.contentview.create({'name': composite_cv_name, 'composite_view': True}) + assert session.contentview.search(composite_cv_name)[0]['Name'] == composite_cv_name + # Add the published content view to the composite one + session.contentview.add_cv(composite_cv_name, published_cv_name) + # Add the unpublished content view to the composite one + session.contentview.add_cv(composite_cv_name, unpublished_cv_name) + # assert that the version of unpublished content view added to + # composite one is "Latest (Currently no version)" + composite_cv = session.contentview.read(composite_cv_name) + assigned_cvs = composite_cv['content_views']['resources']['assigned'] + unpublished_cv = next(cv for cv in assigned_cvs if cv['Name'] == unpublished_cv_name) + assert unpublished_cv['Version'] == 'Latest (Currently no version)' + # Publish the composite content view + result = session.contentview.publish(composite_cv_name) + assert result['Version'] == VERSION + + +@pytest.mark.tier3 +def test_positive_check_composite_cv_addition_list_versions(session, module_target_sat): + """Create new content view and publish two times. After that remove + first content view version from the list and try to add that view to + composite one. Check what content view version is going to be added + + :id: ffd4ac4a-4152-433a-a411-567bab115b05 + + :expectedresults: second non-composite content view version should be + listed as default one to be added to composite view + + :BZ: 1411074 + + :CaseImportance: Low + """ + non_composite_cv = gen_string('alpha') + composite_cv = gen_string('alpha') + with session: + # Create unpublished component CV + session.contentview.create({'name': non_composite_cv}) + assert session.contentview.search(non_composite_cv)[0]['Name'] == non_composite_cv + # Publish content view two times to have two versions + for _ in range(2): + session.contentview.publish(non_composite_cv) + # Delete first version for cv + session.contentview.remove_version(non_composite_cv, VERSION) + # Create composite CV + session.contentview.create({'name': composite_cv, 'composite_view': True}) + assert session.contentview.search(composite_cv)[0]['Name'] == composite_cv + ccv_values = session.contentview.read(composite_cv, 'content_views') + cv_values = [ + cv + for cv in ccv_values['content_views']['resources']['unassigned'] + if cv['Name'] == non_composite_cv + ] + assert len(cv_values) == 1 + assert cv_values[0]['Version'] == 'Always Use Latest (Currently 2.0) 2.0' + + +@pytest.mark.tier2 +def test_negative_add_dupe_repos(session, module_target_sat, module_org, target_sat): + """attempt to associate the same repo multiple times within a + content view + + :id: 24b98075-fca6-4d80-a778-066193c71e7f + + :expectedresults: User cannot add repos multiple times to the view + + :CaseImportance: Low + """ + cv_name = gen_string('alpha') + repo_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, repo_name) + with pytest.raises(NoSuchElementException) as context: + session.contentview.add_yum_repo(cv_name, repo_name) + error_message = str(context.value) + assert 'Could not find an element' in error_message + assert 'checkbox' in error_message + + +@pytest.mark.tier2 +def test_positive_publish_with_custom_content(session, module_target_sat, module_org, target_sat): + """Attempt to publish a content view containing custom content + + :id: 66b5efc7-2e43-438e-bd80-a754814222f9 + + :setup: Multiple environments for an org; custom content synced + + :expectedresults: Content view can be published + + :CaseImportance: Critical + """ + repo_name = gen_string('alpha') + cv_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, repo_name) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + cv = session.contentview.read(cv_name) + assert cv['versions']['table'][0]['Version'] == VERSION + + +@pytest.mark.run_in_one_thread +@pytest.mark.skip_if_not_set('fake_manifest') +@pytest.mark.tier2 +def test_positive_publish_with_rh_content( + session, module_target_sat, function_entitlement_manifest_org, target_sat +): + """Attempt to publish a content view containing RH content + + :id: bd24dc13-b6c4-4a9b-acb2-cd6df30f436c + + :setup: RH content synced + + :expectedresults: Content view can be published + + :CaseImportance: Critical + """ + cv_name = gen_string('alpha') + rh_repo = { + 'name': REPOS['rhst7']['name'], + 'product': PRDS['rhel'], + 'reposet': REPOSET['rhst7'], + 'basearch': 'x86_64', + 'releasever': None, + } + org = function_entitlement_manifest_org + target_sat.api_factory.enable_sync_redhat_repo(rh_repo, org.id) + with session: + session.organization.select(org.name) + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, rh_repo['name']) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + cv = session.contentview.read(cv_name) + assert cv['versions']['table'][0]['Version'] == VERSION + + +@pytest.mark.run_in_one_thread +@pytest.mark.skip_if_not_set('fake_manifest') +@pytest.mark.tier2 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_publish_composite_with_custom_content( + session, function_entitlement_manifest_org, target_sat +): + """Attempt to publish composite content view containing custom content + + :id: 73947204-408e-4e2e-b87f-ba2e52ee50b6 + + :setup: Multiple environments for an org; custom content synced + + :expectedresults: Composite content view can be published + + :CaseImportance: High + """ + cv1_name = gen_string('alpha') + cv2_name = gen_string('alpha') + cv_composite_name = gen_string('alpha') + custom_repo1_name = gen_string('alpha') + custom_repo2_name = gen_string('alpha') + custom_repo1_url = settings.repos.yum_0.url + custom_repo2_url = settings.repos.yum_1.url + org = function_entitlement_manifest_org + product = target_sat.api.Product(organization=org).create() + rh7_repo = { + 'name': REPOS['rhst7']['name'], + 'product': PRDS['rhel'], + 'reposet': REPOSET['rhst7'], + 'basearch': 'x86_64', + 'releasever': None, + } + # Create docker repos and sync + docker_repo1 = target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=product, content_type=REPO_TYPE['docker'] + ).create() + docker_repo2 = target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=product, content_type=REPO_TYPE['docker'] + ).create() + docker_repo1.sync() + docker_repo2.sync() + # Enable and sync RH repository + target_sat.api_factory.enable_sync_redhat_repo(rh7_repo, org.id) + # Create custom yum repositories + for name, url in ( + (custom_repo1_name, custom_repo1_url), + (custom_repo2_name, custom_repo2_url), + ): + target_sat.api_factory.create_sync_custom_repo(repo_name=name, repo_url=url, org_id=org.id) + with session: + session.organization.select(org.name) + # create the first content view + session.contentview.create({'name': cv1_name}) + assert session.contentview.search(cv1_name)[0]['Name'] == cv1_name + # add repositories to first content view + for repo_name in (rh7_repo['name'], custom_repo1_name): + session.contentview.add_yum_repo(cv1_name, repo_name) + # add the first docker repo to first content view + session.contentview.add_docker_repo(cv1_name, docker_repo1.name) + # publish the first content + result = session.contentview.publish(cv1_name) + assert result['Version'] == VERSION + # create the second content view + session.contentview.create({'name': cv2_name}) + assert session.contentview.search(cv2_name)[0]['Name'] == cv2_name + # add repositories to the second content view + session.contentview.add_yum_repo(cv2_name, custom_repo2_name) + # add the second docker repo to the second content view + session.contentview.add_docker_repo(cv2_name, docker_repo2.name) + # publish the second content + result = session.contentview.publish(cv2_name) + assert result['Version'] == VERSION + # create a composite content view + session.contentview.create({'name': cv_composite_name, 'composite_view': True}) + assert session.contentview.search(cv_composite_name)[0]['Name'] == cv_composite_name + # add the first and second content views to the composite one + for cv_name in (cv1_name, cv2_name): + session.contentview.add_cv(cv_composite_name, cv_name) + # publish the composite content view + result = session.contentview.publish(cv_composite_name) + assert result['Version'] == VERSION + ccv = session.contentview.read(cv_composite_name) + assert ccv['versions']['table'][0]['Version'] == VERSION + + +@pytest.mark.tier2 +def test_positive_publish_version_changes_in_target_env( + session, module_target_sat, module_org, target_sat +): + # Dev notes: + # If Dev has version x, then when I promote version y into + # Dev, version x goes away (ie when I promote version 1 to Dev, + # version 3 goes away) + """When publishing new version to environment, version gets updated + + :id: c9fa3def-baa2-497f-b6a6-f3b2d72d1ce9 + + :setup: Multiple environments for an org; multiple versions of a content + view created/published + + :steps: + 1. publish a view to an environment noting the CV version + 2. edit and republish a new version of a CV + + :expectedresults: Content view version is updated in target environment. + + :CaseImportance: High + """ + cv_name = gen_string('alpha') + # will promote environment to 3 versions + versions_count = 3 + versions = (f'Version {ver + 1}.0' for ver in range(versions_count)) + # create environment lifecycle + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + repo_names = [gen_string('alphanumeric') for _ in range(versions_count)] + # before each content view publishing add a new repository + for repo_name in repo_names: + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + # create content view + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + # begin publishing content view and promoting environment over all + # the defined versions + for repo_name in repo_names: + version = next(versions) + # add the repository to the created content view + session.contentview.add_yum_repo(cv_name, repo_name) + # publish the content view + result = session.contentview.publish(cv_name) + # assert the content view successfully published + assert result['Version'] == version + # # assert that Library is in environments of this version + assert ENVIRONMENT in result['Environments'] + # assert that env_name is not in environments of this version + assert lce.name not in result['Environments'] + # promote content view environment to this version + result = session.contentview.promote(cv_name, version, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + # assert that Library is still in environments of this version + assert ENVIRONMENT in result['Environments'] + # assert that env_name is in environments of this version + assert lce.name in result['Environments'] + + +@pytest.mark.tier2 +def test_positive_promote_with_custom_content(session, module_target_sat, module_org, target_sat): + """Attempt to promote a content view containing custom content, + check dashboard + + :id: 7c2fd8f0-c83f-4725-8953-9590112fae50 + + :setup: Multiple environments for an org; custom content synced + + :expectedresults: Content view can be promoted + + :BZ: 1361793 + + :CaseImportance: Critical + """ + repo_name = gen_string('alpha') + cv_name = gen_string('alpha') + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, repo_name) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + result = session.contentview.promote(cv_name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + # dashboard + values = session.dashboard.search(f'lifecycle_environment={lce.name}') + assert cv_name in values['ContentViews']['content_views'][0]['Content View'] + values = session.dashboard.read('ContentViews') + assert cv_name in values['content_views'][0]['Content View'] + assert values['content_views'][0]['Task'] == f'Promoted to {lce.name}' + assert 'Success' in values['content_views'][0]['Status'] + assert cv_name in values['content_views'][1]['Content View'] + assert values['content_views'][1]['Task'] == 'Published new version' + assert 'Success' in values['content_views'][1]['Status'] + module_target_sat.api.LifecycleEnvironment(id=lce.id).delete() + values = session.dashboard.search(f'lifecycle_environment={lce.name}') + assert cv_name in values['ContentViews']['content_views'][0]['Content View'] + + +@pytest.mark.run_in_one_thread +@pytest.mark.skip_if_not_set('fake_manifest') +@pytest.mark.tier2 +def test_positive_promote_with_rh_content( + session, module_target_sat, function_entitlement_manifest_org, target_sat +): + """Attempt to promote a content view containing RH content + + :id: 82f71639-3580-49fd-bd5a-8dba568b98d1 + + :setup: Multiple environments for an org; RH content synced + + :expectedresults: Content view can be promoted + + :CaseImportance: Critical + """ + cv_name = gen_string('alpha') + rh_repo = { + 'name': REPOS['rhst7']['name'], + 'product': PRDS['rhel'], + 'reposet': REPOSET['rhst7'], + 'basearch': 'x86_64', + 'releasever': None, + } + org = function_entitlement_manifest_org + target_sat.api_factory.enable_sync_redhat_repo(rh_repo, org.id) + lce = module_target_sat.api.LifecycleEnvironment(organization=org).create() + with session: + session.organization.select(org.name) + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, rh_repo['name']) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + result = session.contentview.promote(cv_name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + + +@pytest.mark.run_in_one_thread +@pytest.mark.skip_if_not_set('fake_manifest') +@pytest.mark.tier2 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_promote_composite_with_custom_content( + session, function_entitlement_manifest_org, target_sat +): + """Attempt to promote composite content view containing custom content + + :id: 35efbd83-d32e-4831-9d5b-1adb15289f54 + + :setup: Multiple environments for an org; custom content synced + + :steps: create a composite view containing multiple content types + + :expectedresults: Composite content view can be promoted + + :CaseImportance: High + """ + cv1_name = gen_string('alpha') + cv2_name = gen_string('alpha') + cv_composite_name = gen_string('alpha') + custom_repo1_name = gen_string('alpha') + custom_repo2_name = gen_string('alpha') + custom_repo1_url = settings.repos.yum_0.url + custom_repo2_url = settings.repos.yum_1.url + org = function_entitlement_manifest_org + product = target_sat.api.Product(organization=org).create() + rh7_repo = { + 'name': REPOS['rhst7']['name'], + 'product': PRDS['rhel'], + 'reposet': REPOSET['rhst7'], + 'basearch': 'x86_64', + 'releasever': None, + } + # create a life cycle environment + lce = target_sat.api.LifecycleEnvironment(organization=org).create() + # Enable and sync RH repository + target_sat.api_factory.enable_sync_redhat_repo(rh7_repo, org.id) + # Create custom yum repositories + for name, url in ( + (custom_repo1_name, custom_repo1_url), + (custom_repo2_name, custom_repo2_url), + ): + target_sat.api_factory.create_sync_custom_repo(repo_name=name, repo_url=url, org_id=org.id) + # Create docker repo and sync + docker_repo1 = target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=product, content_type=REPO_TYPE['docker'] + ).create() + docker_repo2 = target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, + product=product, + content_type=REPO_TYPE['docker'], + docker_upstream_name='quay/busybox', + ).create() + docker_repo1.sync() + docker_repo2.sync() + with session: + session.organization.select(org.name) + # create the first content view + session.contentview.create({'name': cv1_name}) + assert session.contentview.search(cv1_name)[0]['Name'] == cv1_name + # add repositories to first content view + for repo_name in (rh7_repo['name'], custom_repo1_name): + session.contentview.add_yum_repo(cv1_name, repo_name) + # add the first docker repo to first content view + session.contentview.add_docker_repo(cv1_name, docker_repo1.name) + # publish the first content + result = session.contentview.publish(cv1_name) + assert result['Version'] == VERSION + # create the second content view + session.contentview.create({'name': cv2_name}) + assert session.contentview.search(cv2_name)[0]['Name'] == cv2_name + # add repositories to the second content view + session.contentview.add_yum_repo(cv2_name, custom_repo2_name) + # add second docker to the second content view + session.contentview.add_docker_repo(cv1_name, docker_repo2.name) + # publish the second content + result = session.contentview.publish(cv2_name) + assert result['Version'] == VERSION + # create a composite content view + session.contentview.create({'name': cv_composite_name, 'composite_view': True}) + assert session.contentview.search(cv_composite_name)[0]['Name'] == cv_composite_name + # add the first and second content views to the composite one + for cv_name in (cv1_name, cv2_name): + session.contentview.add_cv(cv_composite_name, cv_name) + # publish the composite content view + result = session.contentview.publish(cv_composite_name) + assert result['Version'] == VERSION + # promote the composite content view + result = session.contentview.promote(cv_composite_name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.run_in_one_thread +@pytest.mark.tier2 +def test_positive_publish_rh_content_with_errata_by_date_filter( + session, module_target_sat, target_sat +): + """Publish a CV, containing only RH repo, having errata excluding by + date filter + + :BZ: 1455990, 1492114 + + :id: b4c120b6-129f-4344-8634-df5858c10fef + + :customerscenario: true + + :expectedresults: Errata exclusion by date filter doesn't affect + packages - errata was successfully filtered out, however packages + are still present + + :CaseImportance: High + """ + version = 'Version 2.0' + org = module_target_sat.api.Organization().create() + lce = module_target_sat.api.LifecycleEnvironment(organization=org).create() + repos_collection = target_sat.cli_factory.RepositoryCollection( + distro='rhel6', repositories=[target_sat.cli_factory.VirtualizationAgentsRepository()] + ) + repos_collection.setup_content( + org.id, lce.id, download_policy='immediate', upload_manifest=True + ) + cv = module_target_sat.api.ContentView( + id=repos_collection.setup_content_data['content_view']['id'] + ).read() + cvf = module_target_sat.api.ErratumContentViewFilter( + content_view=cv, inclusion=False, repository=[repos_collection.repos_info[0]['id']] + ).create() + module_target_sat.api.ContentViewFilterRule( + content_view_filter=cvf, + start_date='2011-01-01', + types=['security', 'enhancement', 'bugfix'], + ).create() + cv.publish() + with session: + session.organization.select(org.name) + version = session.contentview.read_version(cv.name, version) + assert len(version['rpm_packages']['table']) + assert not version.get('errata') or not len(version['errata']['table']) + + +@pytest.mark.tier3 +def test_negative_add_same_package_filter_twice(session, module_target_sat, module_org, target_sat): + """Update version of package inside exclusive cv package filter + + :id: 5a97de5a-679e-4150-adf7-b4a28290b834 + + :expectedresults: Same package filter can not be added again + + :CaseImportance: High + """ + cv_name = gen_string('alpha') + repo_name = gen_string('alpha') + package_name = 'walrus' + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + session.contentview.create({'name': cv_name}) + for filter_type in FILTER_TYPE['exclude'], FILTER_TYPE['include']: + filter_name = gen_string('alpha') + session.contentviewfilter.create( + cv_name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': filter_type, + }, + ) + assert session.contentviewfilter.search(cv_name, filter_name)[0]['Name'] == filter_name + session.contentviewfilter.add_package_rule( + cv_name, filter_name, package_name, None, ('Equal To', '0.71-1') + ) + with pytest.raises(AssertionError) as context: + session.contentviewfilter.add_package_rule( + cv_name, filter_name, package_name, None, ('Equal To', '0.71-1') + ) + assert 'This package filter rule already exists.' in str(context.value) + + +@pytest.mark.tier2 +def test_positive_remove_cv_version_from_default_env( + session, module_target_sat, module_org, target_sat +): + """Remove content view version from Library environment + + :id: 43c83c15-c883-45a7-be05-d9b26da99e3c + + :steps: + + 1. Create a content view + 2. Add a yum repo to it + 3. Publish content view + 4. remove the published version from Library environment + + :expectedresults: content view version is removed from Library + environment + + :CaseImportance: Critical + """ + cv_name = gen_string('alpha') + repo_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + # create a content view + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, repo_name) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + cvv = session.contentview.search_version(cv_name, VERSION)[0] + assert ENVIRONMENT in cvv['Environments'] + # remove the content view version from Library + session.contentview.remove_version(cv_name, VERSION, False, [ENVIRONMENT]) + cvv = session.contentview.search_version(cv_name, VERSION)[0] + assert ENVIRONMENT not in cvv['Environments'] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier2 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_remove_promoted_cv_version_from_default_env( + session, module_target_sat, module_org, target_sat +): + """Remove promoted content view version from Library environment + + :id: a8649444-b063-4fb4-b932-a3fae7d4021d + + :steps: + + 1. Create a content view + 2. Add a yum repos to the content view + 3. Publish the content view + 4. Promote the content view version from Library -> DEV + 5. remove the content view version from Library environment + + :expectedresults: + + 1. Content view version exist only in DEV and not in Library + 2. The yum repos exists in content view version + + :CaseImportance: High + """ + repo = target_sat.cli_factory.RepositoryCollection( + repositories=[ + target_sat.cli_factory.YumRepository(url=settings.repos.yum_0.url), + ] + ) + repo.setup(module_org.id) + cv, lce = repo.setup_content_view(module_org.id) + with session: + cv_values = session.contentview.read(cv['name']) + assert cv_values['details']['name'] == cv['name'] + cvv = session.contentview.read_version(cv['name'], VERSION) + assert cvv['yum_repositories']['table'][0]['Name'] + cvv = session.contentview.search_version(cv['name'], VERSION)[0] + assert ENVIRONMENT in cvv['Environments'] + # remove the content view version from Library + session.contentview.remove_version(cv['name'], VERSION, False, [ENVIRONMENT]) + cvv = session.contentview.search_version(cv['name'], VERSION)[0] + assert ENVIRONMENT not in cvv['Environments'] + # ensure that yum repos are still in content view version + cvv = session.contentview.read_version(cv['name'], VERSION) + assert cvv['yum_repositories']['table'][0]['Name'] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier2 +def test_positive_remove_qe_promoted_cv_version_from_default_env( + session, module_target_sat, module_org, target_sat +): + """Remove QE promoted content view version from Library environment + + :id: 71ad8b72-68c4-4c98-9387-077f54ef0184 + + :steps: + + 1. Create a content view + 2. Add docker repo(s) to it + 3. Publish content view + 4. Promote the content view version to multiple environments + Library -> DEV -> QE + 5. remove the content view version from Library environment + + :expectedresults: Content view version exist only in DEV, QE and not in + Library + + :CaseImportance: Low + """ + dev_lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + qe_lce = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=dev_lce + ).create() + repo = target_sat.cli_factory.RepositoryCollection( + repositories=[ + target_sat.cli_factory.DockerRepository( + url=CONTAINER_REGISTRY_HUB, upstream_name=CONTAINER_UPSTREAM_NAME + ) + ] + ) + repo.setup(module_org.id) + repo_name = repo.repos_info[0]['name'] + cv, lce = repo.setup_content_view(module_org.id, dev_lce.id) + cvv = module_target_sat.api.ContentView(id=cv['id']).read().version[0] + cvv.promote(data={'environment_ids': qe_lce.id}) + with session: + cv_values = session.contentview.read(cv['name']) + assert cv_values['docker_repositories']['resources']['assigned'][0]['Name'] == repo_name + cvv_content = session.contentview.read_version(cv['name'], VERSION) + assert cvv_content['docker_repositories']['table'][0]['Name'] == repo_name + cvv_table = session.contentview.search_version(cv['name'], VERSION) + assert all( + item in cvv_table[0]['Environments'] + for item in [ENVIRONMENT, dev_lce.name, qe_lce.name] + ) + # remove the content view version from Library + session.contentview.remove_version(cv['name'], VERSION, False, [ENVIRONMENT]) + cvv_content = session.contentview.read_version(cv['name'], VERSION) + assert cvv_content['docker_repositories']['table'][0]['Name'] == repo_name + cvv_table = session.contentview.search_version(cv['name'], VERSION) + assert all(item in cvv_table[0]['Environments'] for item in [dev_lce.name, qe_lce.name]) + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier2 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +@pytest.mark.parametrize( + 'repos_collection', + [ + { + 'distro': 'rhel7', + 'YumRepository': {'url': settings.repos.yum_0.url}, + 'DockerRepository': { + 'url': CONTAINER_REGISTRY_HUB, + 'upstream_name': CONTAINER_UPSTREAM_NAME, + }, + } + ], + indirect=True, +) +def test_positive_remove_cv_version_from_env( + session, module_target_sat, module_org, repos_collection +): + """Remove promoted content view version from environment + + :id: d1da23ee-a5db-4990-9572-1a0919a9fe1c + + :steps: + + 1. Create a content view + 2. Add a yum repo and a docker repo to the content view + 3. Publish the content view + 4. Promote the content view version to multiple environments + Library -> DEV -> QE + 5. remove the content view version from QE environment + 6. Assert: content view version exists only in Library, DEV and not in QE + 7. Promote again from DEV -> QE + + :expectedresults: Content view version exist in Library, DEV, QE + + :CaseImportance: High + """ + dev_lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + qe_lce = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=dev_lce + ).create() + repos_collection.setup(module_org.id) + yum_repo_name = [ + repo['name'] for repo in repos_collection.repos_info if repo['content-type'] == 'yum' + ][0] + docker_repo_name = [ + repo['name'] for repo in repos_collection.repos_info if repo['content-type'] == 'docker' + ][0] + cv, lce = repos_collection.setup_content_view(module_org.id, dev_lce.id) + cvv = module_target_sat.api.ContentView(id=cv['id']).read().version[0] + cvv.promote(data={'environment_ids': qe_lce.id}) + with session: + cvv = session.contentview.read_version(cv['name'], VERSION) + assert cvv['yum_repositories']['table'][0]['Name'] + assert cvv['docker_repositories']['table'][0]['Name'] + assert yum_repo_name == cvv['yum_repositories']['table'][0]['Name'] + cvv = session.contentview.search_version(cv['name'], VERSION)[0] + assert all(item in cvv['Environments'] for item in [ENVIRONMENT, dev_lce.name, qe_lce.name]) + # remove the content view version from QE Environment + session.contentview.remove_version(cv['name'], VERSION, False, [qe_lce.name]) + cvv = session.contentview.search_version(cv['name'], VERSION)[0] + assert all(item in cvv['Environments'] for item in [ENVIRONMENT, dev_lce.name]) + # promote again to QE + result = session.contentview.promote(cv['name'], VERSION, qe_lce.name) + assert f'Promoted to {qe_lce.name}' in result['Status'] + cvv = session.contentview.read_version(cv['name'], VERSION) + assert docker_repo_name in cvv['docker_repositories']['table'][0]['Name'] + assert yum_repo_name == cvv['yum_repositories']['table'][0]['Name'] + cvv = session.contentview.search_version(cv['name'], VERSION)[0] + assert all(item in cvv['Environments'] for item in [ENVIRONMENT, dev_lce.name, qe_lce.name]) + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.upgrade +@pytest.mark.tier2 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_delete_cv_promoted_to_multi_env( + session, module_target_sat, module_org, target_sat +): + """Delete published content view with version promoted to multiple + environments + + :id: f16f2db5-7f5b-4ebb-863e-6c18ff745ce4 + + :steps: + + 1. Create a content view + 2. Add a yum repo to the content view + 3. Publish the content view + 4. Promote the content view to multiple environment Library -> DEV + 5. Disassociate content view from promoted environment + 6. Delete the content view. + + :expectedresults: The content view doesn't exists. + + :CaseImportance:High + """ + repo = target_sat.cli_factory.RepositoryCollection( + repositories=[target_sat.cli_factory.YumRepository(url=settings.repos.yum_0.url)] + ) + repo.setup(module_org.id) + cv, lce = repo.setup_content_view(module_org.id) + repo_name = repo.repos_info[0]['name'] + with session: + cvv = session.contentview.read_version(cv['name'], VERSION) + assert repo_name == cvv['yum_repositories']['table'][0]['Name'] + cvv = session.contentview.search_version(cv['name'], VERSION)[0] + assert lce['name'] in cvv['Environments'] + lce_values = session.lifecycleenvironment.read(lce['name']) + assert len(lce_values['content_views']['resources']) == 1 + assert lce_values['content_views']['resources'][0]['Name'] == cv['name'] + session.contentview.remove_version(cv['name'], VERSION, False, [ENVIRONMENT, lce['name']]) + cvv = session.contentview.search_version(cv['name'], VERSION)[0] + assert lce['name'] not in cvv['Environments'] + session.contentview.delete(cv['name']) + lce_values = session.lifecycleenvironment.read(lce['name']) + assert cv not in lce_values['content_views']['resources'] + + +@pytest.mark.tier2 +@pytest.mark.upgrade +def test_positive_delete_composite_version(session, module_target_sat, module_org, target_sat): + """Delete a composite content-view version associated to 'Library' + + :id: b2d9b21d-1e0d-40f1-9bbc-3c88cddd4f5e + + :expectedresults: Deletion was performed successfully + + :BZ: 1276479 + + :CaseImportance: High + """ + cv_name = gen_string('alpha') + ccv_name = gen_string('alpha') + repo_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + # create a content view + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, repo_name) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + session.contentview.create({'name': ccv_name, 'composite_view': True}) + session.contentview.add_cv(ccv_name, cv_name) + result = session.contentview.publish(ccv_name) + assert result['Version'] == VERSION + cvv = session.contentview.search_version(ccv_name, VERSION)[0] + assert ENVIRONMENT in cvv['Environments'] + # remove composite content view version from Library + session.contentview.remove_version(ccv_name, VERSION, False, [ENVIRONMENT]) + cvv = session.contentview.search_version(ccv_name, VERSION)[0] + assert ENVIRONMENT not in cvv['Environments'] + + +@pytest.mark.tier2 +def test_positive_delete_non_default_version(session, module_target_sat, target_sat): + """Delete a content-view version associated to non-default + environment + + :id: 1c1beb36-e06b-419f-96db-43b4d85c5e25 + + :expectedresults: Deletion was performed successfully + + :CaseImportance: Critical + """ + repo_name = gen_string('alpha') + org = module_target_sat.api.Organization().create() + target_sat.api_factory.create_sync_custom_repo(org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=org, repository=[repo]).create() + lce = module_target_sat.api.LifecycleEnvironment(organization=org).create() + with session: + session.organization.select(org.name) + # Publish and promote CV to next environment + result = session.contentview.publish(cv.name) + assert result['Version'] == VERSION + result = session.contentview.promote(cv.name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + cvv = session.contentview.search_version(cv.name, VERSION)[0] + assert lce.name in cvv['Environments'] + # remove the content view version from new custom lifecycle environment + session.contentview.remove_version(cv.name, VERSION, False, [lce.name]) + cvv = session.contentview.search_version(cv.name, VERSION)[0] + assert lce.name not in cvv['Environments'] + + +@pytest.mark.upgrade +@pytest.mark.tier2 +def test_positive_delete_version_with_ak(session, module_target_sat): + """Delete a content-view version that had associated activation key to it + + :id: 0da50b26-f82b-4663-9372-4c39270d4323 + + :expectedresults: Delete operation was performed successfully + + :CaseImportance: High + """ + org = module_target_sat.api.Organization().create() + cv = module_target_sat.api.ContentView(organization=org).create() + cv.publish() + cvv = cv.read().version[0].read() + lc_env = module_target_sat.api.LifecycleEnvironment(organization=org).create() + cvv.promote(data={'environment_ids': lc_env.id}) + ak = module_target_sat.api.ActivationKey( + name=gen_string('alphanumeric'), environment=lc_env.id, organization=org, content_view=cv + ).create() + with session: + session.organization.select(org.name) + assert session.contentview.search_version(cv.name, VERSION) + # It is impossible to remove content view version from content view that + # has activation key assigned + with pytest.raises(AssertionError) as context: + session.contentview.remove_version(cv.name, VERSION) + assert 'Activation Key is assigned to content view version' in str(context.value) + # Update activation key with new name + session.activationkey.update( + ak.name, {'details.lce': {ENVIRONMENT: True}, 'details.content_view': DEFAULT_CV} + ) + # remove the content view version + session.contentview.remove_version(cv.name, VERSION) + assert session.contentview.search_version(cv.name, VERSION)[0]['Version'] != VERSION + + +@pytest.mark.tier2 +def test_positive_clone_within_same_env(session, module_target_sat, module_org, target_sat): + """attempt to create new content view based on existing + view within environment + + :id: 862c385b-d98c-4c29-8345-fd7a5900483a + + :expectedresults: Content view can be cloned + + :BZ: 1461017 + + :CaseImportance: High + """ + repo_name = gen_string('alpha') + cv_name = gen_string('alpha') + copy_cv_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + with session: + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, repo_name) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + # Copy the CV + session.contentview.copy(cv_name, copy_cv_name) + assert session.contentview.search(copy_cv_name)[0]['Name'] == copy_cv_name + copy_cv = session.contentview.read(copy_cv_name) + assert copy_cv['repositories']['resources']['assigned'][0]['Name'] == repo_name + + +@pytest.mark.tier2 +def test_positive_clone_within_diff_env(session, module_target_sat, module_org, target_sat): + """attempt to create new content view based on existing + view, inside a different environment + + :id: 09b9307f-91de-4d3d-a6af-31c526ea816f + + :expectedresults: Cloned content view can be published and promoted to different + environment than initial one + + :BZ: 1461017 + + :CaseImportance: High + """ + repo_name = gen_string('alpha') + copy_cv_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + copy_lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + with session: + # publish the content view + result = session.contentview.publish(cv.name) + assert result['Version'] == VERSION + # promote the content view + result = session.contentview.promote(cv.name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + # Copy the CV + session.contentview.copy(cv.name, copy_cv_name) + assert session.contentview.search(copy_cv_name)[0]['Name'] == copy_cv_name + copy_cv = session.contentview.read(copy_cv_name) + assert copy_cv['repositories']['resources']['assigned'][0]['Name'] == repo_name + # publish new content view + result = session.contentview.publish(copy_cv_name) + assert result['Version'] == VERSION + # promote cloned content view to different environment + result = session.contentview.promote(copy_cv_name, VERSION, copy_lce.name) + assert f'Promoted to {copy_lce.name}' in result['Status'] + assert lce.name not in result['Environments'] + + +@pytest.mark.tier2 +def test_positive_remove_filter(session, module_target_sat, module_org): + """Create empty content views filter and remove it + + :id: 6c6deae7-13f1-4638-a960-d3565d93fd64 + + :expectedresults: content views filter removed successfully + + :CaseImportance: Low + """ + filter_name = gen_string('alpha') + cv = module_target_sat.api.ContentView(organization=module_org).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + assert session.contentviewfilter.search(cv.name, filter_name)[0]['Name'] == filter_name + session.contentviewfilter.delete(cv.name, filter_name) + assert not session.contentviewfilter.search(cv.name, filter_name) + + +@pytest.mark.tier2 +def test_positive_add_package_filter(session, module_target_sat, module_org, target_sat): + """Add package to content views filter + + :id: 1cc8d921-92e5-4b51-8050-a7e775095f97 + + :expectedresults: content views filter created and selected packages can be + added for inclusion + + :CaseImportance: High + """ + packages = ( + ('cow', 'All Versions'), + ('bird', ('Equal To', '0.5')), + ('crow', ('Less Than', '0.5')), + ('bear', ('Range', '4.1', '4.6')), + ) + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + for package_name, versions in packages: + session.contentviewfilter.add_package_rule( + cv.name, filter_name, package_name, None, versions + ) + cvf = session.contentviewfilter.read(cv.name, filter_name) + expected_packages = {package_name for package_name, versions in packages} + actual_packages = {row['RPM Name'] for row in cvf['content_tabs']['rpms']['table']} + assert expected_packages == actual_packages + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +def test_positive_add_package_inclusion_filter_and_publish( + session, module_target_sat, module_org, target_sat +): + """Add package to inclusion content views filter, publish CV and verify + package was actually filtered + + :id: 58c32cb5-1392-478e-807a-9c023d5ca0ea + + :expectedresults: Package is included in content view version + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + package1_name = 'cow' + package2_name = 'bear' + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + session.contentviewfilter.add_package_rule( + cv.name, filter_name, package1_name, None, 'All Versions' + ) + result = session.contentview.publish(cv.name) + assert result['Version'] == VERSION + packages = session.contentview.search_version_package( + cv.name, VERSION, f'name = "{package1_name}"' + ) + assert len(packages) == 1 + assert packages[0]['Name'] == package1_name + packages = session.contentview.search_version_package( + cv.name, VERSION, f'name = "{package2_name}"' + ) + assert not packages[0]['Name'] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +def test_positive_add_package_exclusion_filter_and_publish( + session, module_target_sat, module_org, target_sat +): + """Add package to exclusion content views filter, publish CV and verify + package was actually filtered + + :id: 304dfb76-a222-48ab-b6de-578a2c81210c + + :expectedresults: Package is excluded from content view version + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + package1_name = 'cow' + package2_name = 'bear' + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + session.contentviewfilter.add_package_rule( + cv.name, filter_name, package1_name, None, 'All Versions' + ) + result = session.contentview.publish(cv.name) + assert result['Version'] == VERSION + packages = session.contentview.search_version_package( + cv.name, VERSION, f'name = "{package2_name}"' + ) + assert len(packages) == 1 + assert packages[0]['Name'] == package2_name + packages = session.contentview.search_version_package( + cv.name, VERSION, f'name = "{package1_name}"' + ) + assert not packages[0]['Name'] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_remove_package_from_exclusion_filter( + session, module_target_sat, module_org, target_sat +): + """Remove package from content view exclusion filter + + :id: 2f0adc16-2305-4adf-8582-82e6110fa385 + + :expectedresults: Package was successfully removed from content view + filter and is present in next published content view version + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + package_name = 'cow' + repo = target_sat.cli_factory.RepositoryCollection( + repositories=[target_sat.cli_factory.YumRepository(url=settings.repos.yum_1.url)] + ) + repo.setup(module_org.id) + cv, lce = repo.setup_content_view(module_org.id) + with session: + session.contentviewfilter.create( + cv['name'], + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + session.contentviewfilter.add_package_rule( + cv['name'], filter_name, package_name, None, ('Equal To', '2.2-3') + ) + result = session.contentview.publish(cv['name']) + assert result['Version'] == 'Version 2.0' + packages = session.contentview.search_version_package( + cv['name'], 'Version 2.0', f'name = "{package_name}"' + ) + assert not packages[0]['Name'] + session.contentviewfilter.remove_package_rule(cv['name'], filter_name, package_name) + result = session.contentview.publish(cv['name']) + assert result['Version'] == 'Version 3.0' + packages = session.contentview.search_version_package( + cv['name'], 'Version 3.0', f'name = "{package_name}"' + ) + assert len(packages) == 1 + assert packages[0]['Name'] == package_name + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +def test_positive_update_inclusive_filter_package_version( + session, module_target_sat, module_org, target_sat +): + """Update version of package inside inclusive cv package filter + + :id: 8d6801de-ab82-49d6-bdeb-0f6e5c95b906 + + :expectedresults: Version was updated, next content view version contains + package with updated version + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + package_name = 'walrus' + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + session.contentviewfilter.add_package_rule( + cv.name, filter_name, package_name, None, ('Equal To', '0.71-1') + ) + result = session.contentview.publish(cv.name) + assert result['Version'] == VERSION + packages = session.contentview.search_version_package( + cv.name, VERSION, 'name = "{}" and version = "{}"'.format(package_name, '0.71') + ) + assert len(packages) == 1 + assert packages[0]['Name'] == package_name + assert packages[0]['Version'] == '0.71' + packages = session.contentview.search_version_package( + cv.name, VERSION, 'name = "{}" and version = "{}"'.format(package_name, '5.21') + ) + assert not packages[0]['Name'] + session.contentviewfilter.update_package_rule( + cv.name, + filter_name, + package_name, + {'Version': ('Equal To', '5.21-1')}, + version='Version 0.71-1', + ) + new_version = session.contentview.publish(cv.name)['Version'] + packages = session.contentview.search_version_package( + cv.name, new_version, 'name = "{}" and version = "{}"'.format(package_name, '0.71') + ) + assert not packages[0]['Name'] + packages = session.contentview.search_version_package( + cv.name, new_version, 'name = "{}" and version = "{}"'.format(package_name, '5.21') + ) + assert len(packages) == 1 + assert packages[0]['Name'] == package_name + assert packages[0]['Version'] == '5.21' + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +def test_positive_update_exclusive_filter_package_version( + session, module_target_sat, module_org, target_sat +): + """Update version of package inside exclusive cv package filter + + :id: a8aa8864-190a-46c3-aeed-4953c8f3f601 + + :expectedresults: Version was updated, next content view version + contains package with updated version + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + package_name = 'walrus' + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + session.contentviewfilter.add_package_rule( + cv.name, filter_name, package_name, None, ('Equal To', '0.71-1') + ) + result = session.contentview.publish(cv.name) + assert result['Version'] == VERSION + packages = session.contentview.search_version_package( + cv.name, VERSION, 'name = "{}" and version = "{}"'.format(package_name, '5.21') + ) + assert len(packages) == 1 + assert packages[0]['Name'] == package_name + assert packages[0]['Version'] == '5.21' + packages = session.contentview.search_version_package( + cv.name, VERSION, 'name = "{}" and version = "{}"'.format(package_name, '0.71') + ) + assert not packages[0]['Name'] + session.contentviewfilter.update_package_rule( + cv.name, + filter_name, + package_name, + {'Version': ('Equal To', '5.21-1')}, + version='Version 0.71-1', + ) + new_version = session.contentview.publish(cv.name)['Version'] + packages = session.contentview.search_version_package( + cv.name, new_version, 'name = "{}" and version = "{}"'.format(package_name, '5.21') + ) + assert not packages[0]['Name'] + packages = session.contentview.search_version_package( + cv.name, new_version, 'name = "{}" and version = "{}"'.format(package_name, '0.71') + ) + assert len(packages) == 1 + assert packages[0]['Name'] == package_name + assert packages[0]['Version'] == '0.71' + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_add_all_security_errata_by_date_range_filter( + session, module_target_sat, module_org, target_sat +): + """Create erratum date range filter to include only security errata and + publish new content view version + + :id: c8f4453b-e654-4e8d-9156-5443bfb92f23 + + :CaseImportance: High + + :expectedresults: all security errata is present in content view + version + """ + filter_name = gen_string('alphanumeric') + start_date = datetime.date(2010, 1, 1) + end_date = datetime.date.today() + repo = target_sat.cli_factory.RepositoryCollection( + repositories=[target_sat.cli_factory.YumRepository(url=settings.repos.yum_9.url)] + ) + repo.setup(module_org.id) + cv, lce = repo.setup_content_view(module_org.id) + with session: + session.contentviewfilter.create( + cv['name'], + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['erratum by date and type'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + session.contentviewfilter.update( + cv['name'], + filter_name, + { + 'content_tabs.erratum_date_range.security': True, + 'content_tabs.erratum_date_range.enhancement': False, + 'content_tabs.erratum_date_range.bugfix': False, + 'content_tabs.erratum_date_range.date_type': 'Issued On', + 'content_tabs.erratum_date_range.start_date': start_date.strftime('%m-%d-%Y'), + 'content_tabs.erratum_date_range.end_date': end_date.strftime('%m-%d-%Y'), + }, + ) + session.contentview.publish(cv['name']) + cvv = session.contentview.read_version(cv['name'], 'Version 2.0') + assert len(cvv['errata']['table']) == FAKE_9_YUM_SECURITY_ERRATUM_COUNT + assert all( + errata['Type'] == FILTER_ERRATA_TYPE['security'] for errata in cvv['errata']['table'] + ) + + +@pytest.mark.run_in_one_thread +@pytest.mark.skip_if_not_set('fake_manifest') +@pytest.mark.tier3 +def test_positive_edit_rh_custom_spin(session, module_target_sat, target_sat): + """Edit content views for a custom rh spin. For example, modify a filter. + + :id: 05639074-ef6d-4c6b-8ff6-53033821e686 + + :expectedresults: edited content view save is successful and info is + updated + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + start_date = datetime.date(2016, 1, 1) + end_date = datetime.date(2016, 6, 1) + org = module_target_sat.api.Organization().create() + lce = module_target_sat.api.LifecycleEnvironment(organization=org).create() + repos_collection = target_sat.cli_factory.RepositoryCollection( + distro='rhel7', repositories=[target_sat.cli_factory.SatelliteToolsRepository()] + ) + repos_collection.setup_content(org.id, lce.id, upload_manifest=True) + cv = module_target_sat.api.ContentView( + id=repos_collection.setup_content_data['content_view']['id'] + ).read() + with session: + session.organization.select(org.name) + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['erratum by date and type'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + session.contentviewfilter.update( + cv.name, + filter_name, + { + 'content_tabs.erratum_date_range.security': False, + 'content_tabs.erratum_date_range.enhancement': True, + 'content_tabs.erratum_date_range.bugfix': True, + 'content_tabs.erratum_date_range.date_type': 'Issued On', + 'content_tabs.erratum_date_range.start_date': start_date.strftime('%m-%d-%Y'), + 'content_tabs.erratum_date_range.end_date': end_date.strftime('%m-%d-%Y'), + }, + ) + cvf = session.contentviewfilter.read(cv.name, filter_name) + assert not cvf['content_tabs']['erratum_date_range']['security'] + assert cvf['content_tabs']['erratum_date_range']['enhancement'] + assert cvf['content_tabs']['erratum_date_range']['bugfix'] + assert cvf['content_tabs']['erratum_date_range']['date_type'] == 'Issued On' + assert cvf['content_tabs']['erratum_date_range']['start_date'] == start_date.strftime( + '%Y-%m-%d' + ) + assert cvf['content_tabs']['erratum_date_range']['end_date'] == end_date.strftime( + '%Y-%m-%d' + ) + + +@pytest.mark.run_in_one_thread +@pytest.mark.skip_if_not_set('fake_manifest') +@pytest.mark.upgrade +@pytest.mark.tier2 +def test_positive_promote_with_rh_custom_spin(session, module_target_sat, target_sat): + """attempt to promote a content view containing a custom RH + spin - i.e., contains filters. + + :id: 7d93c81f-2815-4b0e-b72c-23a902fe34b1 + + :expectedresults: Content view can be promoted + + :CaseImportance: Critical + """ + filter_name = gen_string('alpha') + org = module_target_sat.api.Organization().create() + lce = module_target_sat.api.LifecycleEnvironment(organization=org).create() + repos_collection = target_sat.cli_factory.RepositoryCollection( + distro='rhel7', repositories=[target_sat.cli_factory.SatelliteToolsRepository()] + ) + repos_collection.setup_content(org.id, lce.id, upload_manifest=True) + cv = module_target_sat.api.ContentView( + id=repos_collection.setup_content_data['content_view']['id'] + ).read() + with session: + session.organization.select(org.name) + # add a package exclude filter + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + # assert the added filter visible + assert session.contentviewfilter.search(cv.name, filter_name)[0]['Name'] == filter_name + # exclude some package in the created filter + session.contentviewfilter.add_package_rule( + cv.name, filter_name, 'gofer', None, 'All Versions' + ) + # Publish and promote CV to next environment + result = session.contentview.publish(cv.name) + assert result['Version'] == 'Version 2.0' + result = session.contentview.promote(cv.name, 'Version 2.0', lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_add_all_security_errata_by_id_filter(session, module_target_sat, module_org): + """Create erratum filter to include only security errata and publish new + content view version + + :id: bc0be8e8-af53-4db8-937d-93c49c937dcc + + :customerscenario: true + + :BZ: 1275756 + + :CaseImportance: High + + :expectedresults: all security errata is present in content view version + """ + version = 'Version 2.0' + filter_name = gen_string('alphanumeric') + product = module_target_sat.api.Product(organization=module_org).create() + repo = module_target_sat.api.Repository(product=product, url=settings.repos.yum_9.url).create() + repo.sync() + content_view = module_target_sat.api.ContentView( + organization=module_org, repository=[repo] + ).create() + content_view.publish() + with session: + session.contentviewfilter.create( + content_view.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['erratum by id'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + session.contentviewfilter.add_errata( + content_view.name, + filter_name, + search_filters={'security': True, 'bugfix': False, 'enhancement': False}, + ) + content_view.publish() + cvv = session.contentview.read_version(content_view.name, version) + assert len(cvv['errata']['table']) == FAKE_9_YUM_SECURITY_ERRATUM_COUNT + assert all( + errata['Type'] == FILTER_ERRATA_TYPE['security'] for errata in cvv['errata']['table'] + ) + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +def test_positive_add_errata_filter(session, module_target_sat, module_org, target_sat): + """add errata to content views filter + + :id: bb9eef30-62c4-435c-9573-9f31210b8d7d + + :expectedresults: content views filter created and selected errata-id + can be added for inclusion/exclusion + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['erratum by id'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + for errata in ['RHEA-2012:0001', 'RHEA-2012:0004']: + session.contentviewfilter.add_errata(cv.name, filter_name, errata) + cv.publish() + cvv = session.contentview.read_version(cv.name, VERSION) + assert len(cvv['errata']['table']) == 2 + assert {'RHEA-2012:0001', 'RHEA-2012:0004'} == { + value['Errata ID'] for value in cvv['errata']['table'] + } + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_add_module_stream_filter(session, module_target_sat, module_org, target_sat): + """add module stream filter in a content view + + :id: 343c543e-5773-4ea4-aff4-27e0ed6be19e + + :expectedresults: content views filter created and selected module stream + can be added for inclusion/exclusion + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + target_sat.api_factory.create_sync_custom_repo( + module_org.id, repo_name=repo_name, repo_url=settings.repos.module_stream_1.url + ) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['modulemd'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + for ms_name, ms_version in [('duck', '0'), ('walrus', '5.21')]: + session.contentviewfilter.add_module_stream( + cv.name, filter_name, f'name = {ms_name} and stream = {ms_version}' + ) + cv.publish() + cvv = session.contentview.read_version(cv.name, VERSION) + assert len(cvv['module_streams']['table']) == 2 + assert {('duck', '0'), ('walrus', '5.21')} == { + (value['Name'], value['Stream']) for value in cvv['module_streams']['table'] + } + + +@pytest.mark.tier3 +def test_positive_add_package_group_filter(session, module_target_sat, module_org, target_sat): + """add package group to content views filter + + :id: 8c02a432-8b2a-4ba3-9613-7070b2dc2bcb + + :expectedresults: content views filter created and selected package + groups can be added for inclusion/exclusion + + :CaseImportance: Low + """ + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + package_group = 'mammals' + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package group'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + session.contentviewfilter.add_package_group(cv.name, filter_name, package_group) + cvf = session.contentviewfilter.read(cv.name, filter_name) + assert cvf['content_tabs']['assigned'][0]['Name'] == package_group + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_update_filter_affected_repos(session, module_target_sat, module_org, target_sat): + """Update content view package filter affected repos + + :id: 8f095b11-fd63-4a23-9586-a85d6191314f + + :expectedresults: Affected repos were updated, after new content view + version publishing only updated repos are affected by content view + filter + + :CaseImportance: High + """ + filter_name = gen_string('alpha') + repo1_name = gen_string('alpha') + repo2_name = gen_string('alpha') + repo1_package_name = 'dolphin' + repo2_package_name = 'dolphin' + target_sat.api_factory.create_sync_custom_repo( + module_org.id, repo_name=repo1_name, repo_url=settings.repos.yum_3.url + ) + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo2_name) + repo1 = module_target_sat.api.Repository(name=repo1_name).search( + query={'organization_id': module_org.id} + )[0] + repo2 = module_target_sat.api.Repository(name=repo2_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView( + organization=module_org, repository=[repo1, repo2] + ).create() + with session: + # create a filter that affects a subset of repos in the cv + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + session.contentviewfilter.add_package_rule( + cv.name, filter_name, repo1_package_name, None, ('Equal To', '4.2.8') + ) + session.contentviewfilter.update_repositories(cv.name, filter_name, [repo1_name]) + cv.publish() + # Verify filter affected repo1 + packages = session.contentview.search_version_package( + cv.name, VERSION, 'name = "{}" and version = "{}"'.format(repo1_package_name, '4.2.8') + ) + assert len(packages) == 1 + assert packages[0]['Name'] == repo1_package_name + assert packages[0]['Version'] == '4.2.8' + packages = session.contentview.search_version_package( + cv.name, VERSION, 'name = "{}" and version = "{}"'.format(repo1_package_name, '4.2.9') + ) + # checking search showing empty result + assert not packages[0]['Name'] + # Verify repo2 was not affected and repo2 packages are present + packages = session.contentview.search_version_package( + cv.name, + VERSION, + 'name = "{}" and version = "{}"'.format(repo2_package_name, '3.10.232'), + ) + assert len(packages) == 1 + assert packages[0]['Name'] == repo2_package_name + assert packages[0]['Version'] == '3.10.232' + + +@pytest.mark.tier3 +def test_positive_search_composite(session, module_target_sat): + """Search for content view by its composite property criteria + + :id: 214a721b-3993-4251-9b7c-0f6d2446c1d1 + + :customerscenario: true + + :expectedresults: Composite content view is successfully found + + :BZ: 1259374 + + :CaseImportance: Low + """ + composite_name = gen_string('alpha') + with session: + session.contentview.create({'name': composite_name, 'composite_view': True}) + assert composite_name in { + ccv['Name'] for ccv in session.contentview.search('composite = true') + } + + +@pytest.mark.tier3 +def test_positive_publish_with_repo_with_disabled_http( + session, module_target_sat, module_org, target_sat +): + """Attempt to publish content view with repository that set + 'Unprotected' to False + + :id: 36ccb083-3433-4b54-911a-856e3dc85f39 + + :customerscenario: true + + :steps: + 1. Create a repo with 'Unprotected' set to true, url set to + some upstream repo + 2. Sync the repo + 3. Create a content view + 4. Set 'Unprotected' to false + 5. Add this repo to the content view + 6. Publish the content view + + :expectedresults: Content view is published successfully + + :BZ: 1355752 + + :CaseImportance: Low + """ + repo_name = gen_string('alpha') + product_name = gen_string('alpha') + cv_name = gen_string('alpha') + # Creates a CV along with product and sync'ed repository + target_sat.api_factory.create_sync_custom_repo( + module_org.id, product_name=product_name, repo_name=repo_name, repo_unprotected=True + ) + with session: + # Create content-view + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + # Update repository publishing method + session.repository.update(product_name, repo_name, {'repo_content.unprotected': False}) + session.contentview.add_yum_repo(cv_name, repo_name) + # Publish content view + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + + +@pytest.mark.upgrade +@pytest.mark.tier2 +@pytest.mark.parametrize( + 'repos_collection', + [ + { + 'distro': 'rhel7', + 'SatelliteToolsRepository': {}, + 'YumRepository': {'url': settings.repos.yum_0.url}, + } + ], + indirect=True, +) +def test_positive_subscribe_system_with_custom_content( + session, rhel7_contenthost, target_sat, repos_collection +): + """Attempt to subscribe a host to content view with custom repository + + :id: 715db997-707b-4868-b7cc-b6977fd6ac04 + + :setup: content view with custom yum repo + + :expectedresults: Systems can be subscribed to content view(s) + + :parametrized: yes + + :CaseImportance: High + """ + org = target_sat.api.Organization().create() + lce = target_sat.api.LifecycleEnvironment(organization=org).create() + repos_collection.setup_content(org.id, lce.id, upload_manifest=True) + repos_collection.setup_virtual_machine(rhel7_contenthost) + assert rhel7_contenthost.subscribed + with session: + session.organization.select(org.name) + session.location.select(constants.DEFAULT_LOC) + # assert the vm exists in content hosts page + assert ( + session.contenthost.search(rhel7_contenthost.hostname)[0]['Name'] + == rhel7_contenthost.hostname + ) + + +@pytest.mark.tier3 +def test_positive_delete_with_kickstart_repo_and_host_group( + session, target_sat, smart_proxy_location +): + """Check that Content View associated with kickstart repository and + which is used by a host group can be removed from the system + + :id: 7b076f55-72c9-4413-a592-92a47b51cb0a + + :customerscenario: true + + :expectedresults: Deletion was performed successfully + + :BZ: 1417072 + + :CaseImportance: High + """ + hg_name = gen_string('alpha') + sat_hostname = target_sat.hostname + org = target_sat.api.Organization().create() + # Create a new Lifecycle environment + lc_env = target_sat.api.LifecycleEnvironment(organization=org).create() + # Create a Product and Kickstart Repository for OS distribution content + product = target_sat.api.Product(organization=org).create() + repo = target_sat.api.Repository(product=product, url=settings.repos.rhel7_os).create() + # Repo sync procedure + call_entity_method_with_timeout(repo.sync, timeout=3600) + # Create, Publish and promote CV + content_view = target_sat.api.ContentView(organization=org).create() + content_view.repository = [repo] + content_view = content_view.update(['repository']) + content_view.publish() + content_view = content_view.read() + content_view.version[0].promote(data={'environment_ids': lc_env.id}) + cv_name = content_view.name + # Get the Partition table ID + ptable = target_sat.api.PartitionTable().search(query={'search': f'name="{DEFAULT_PTABLE}"'})[0] + # Get the arch ID + arch = ( + target_sat.api.Architecture() + .search(query={'search': f'name="{DEFAULT_ARCHITECTURE}"'})[0] + .read() + ) + # Get the OS ID + os = target_sat.api.OperatingSystem().search( + query={'search': 'name="RedHat" AND (major="6" OR major="7")'} + )[0] + # Update the OS to associate arch and ptable + os.architecture = [arch] + os.ptable = [ptable] + os = os.update(['architecture', 'ptable']) + with session: + session.organization.select(org.name) + session.location.select(smart_proxy_location.name) + session.hostgroup.create( + { + 'host_group.name': hg_name, + 'host_group.lce': lc_env.name, + 'host_group.content_view': content_view.name, + 'host_group.content_source': sat_hostname, + 'operating_system.architecture': arch.name, + 'operating_system.operating_system': f'{os.name} {os.major}.{os.minor}', + 'operating_system.ptable': ptable.name, + 'operating_system.media_type': 'Synced Content', + 'operating_system.media_content.synced_content': repo.name, + } + ) + assert session.hostgroup.search(hg_name)[0]['Name'] == hg_name + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + with pytest.raises(AssertionError) as context: + session.contentview.delete(cv_name) + assert 'Unable to delete content view' in str(context.value) + # remove the content view version + session.contentview.remove_version(cv_name, VERSION) + assert session.contentview.search_version(cv_name, VERSION)[0]['Version'] != VERSION + session.contentview.delete(cv_name) + assert session.contentview.search(cv_name)[0]['Name'] != cv_name + + +@pytest.mark.upgrade +@pytest.mark.tier3 +def test_positive_rh_mixed_content_end_to_end( + session, module_prod, module_entitlement_manifest_org, target_sat +): + """Create a CV with docker repo as well as RH yum contents and publish and promote + them to next environment. Remove promoted version afterwards + + :id: 752f7b95-26af-4f20-a49d-7b31ae3d7a1a + + :expectedresults: CV should be published and promoted with RH OSTree and all + other contents. Then version is removed successfully. + + :customerscenario: true + + :CaseImportance: High + """ + cv_name = gen_string('alpha') + docker_repo = target_sat.api.Repository( + url=CONTAINER_REGISTRY_HUB, product=module_prod, content_type=REPO_TYPE['docker'] + ).create() + rh_st_repo = { + 'name': REPOS['rhst7']['name'], + 'product': PRDS['rhel'], + 'reposet': REPOSET['rhst7'], + 'basearch': 'x86_64', + 'releasever': None, + } + target_sat.api_factory.enable_sync_redhat_repo(rh_st_repo, module_entitlement_manifest_org.id) + docker_repo.sync() + lce = target_sat.api.LifecycleEnvironment(organization=module_entitlement_manifest_org).create() + with session: + session.organization.select(module_org.name) + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, rh_st_repo['name']) + session.contentview.add_docker_repo(cv_name, docker_repo.name) + cv = session.contentview.read(cv_name) + assert cv['repositories']['resources']['assigned'][0]['Name'] == rh_st_repo['name'] + assert cv['docker_repositories']['resources']['assigned'][0]['Name'] == docker_repo.name + # Publish and promote CV to next environment + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + result = session.contentview.promote(cv_name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + # remove the content view version + session.contentview.remove_version(cv_name, VERSION) + assert session.contentview.search_version(cv_name, VERSION)[0]['Version'] != VERSION + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_errata_inc_update_list_package(session, module_target_sat, target_sat): + """Publish incremental update with a new errata for a custom repo + + :BZ: 1489778 + + :id: fb43791c-60ee-4190-86be-34ccba411396 + + :customerscenario: true + + :expectedresults: New errata and corresponding package are present + in new content view version + + :CaseImportance: High + """ + org = module_target_sat.api.Organization().create() + product = module_target_sat.api.Product(organization=org).create() + yum_repo_name = gen_string('alpha') + # Creates custom yum repository + yum_repo = module_target_sat.api.Repository( + name=yum_repo_name, + url=settings.repos.yum_1.url, + content_type=REPO_TYPE['yum'], + product=product, + ).create() + product.sync() + # creating cv, cv filter, and publish cv + cv = module_target_sat.api.ContentView(organization=org, repository=[yum_repo]).create() + cvf = module_target_sat.api.RPMContentViewFilter( + content_view=cv, inclusion=True, name=gen_string('alphanumeric') + ).create() + module_target_sat.api.ContentViewFilterRule( + content_view_filter=cvf, + name='walrus', + version='0.71', + ).create() + cv.publish() + # Get published content-view version info + cvvs = module_target_sat.api.ContentView(id=cv.id).read().version + assert len(cvvs) == 1 + cvv = cvvs[0].read() + result = ContentView.version_incremental_update( + {'content-view-version-id': cvv.id, 'errata-ids': settings.repos.yum_1.errata[1]} + ) + result = [line.strip() for line_dict in result for line in line_dict.values()] + with session: + session.organization.select(org.name) + cvv = module_target_sat.api.ContentView(id=cv.id).read().version[1].read() + version = session.contentview.read_version(cv.name, f'Version {cvv.version}') + errata = version['errata']['table'] + assert len(errata) == 1 + assert settings.repos.yum_1.errata[1] in {row['Errata ID'] for row in errata} + packages = version['rpm_packages']['table'] + assert len(packages) == 4 + packages = {'{}-{}-{}.{}'.format(*row.values()) for row in packages} + assert set(result[4:]).issubset(packages) + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_composite_child_inc_update( + session, module_target_sat, rhel7_contenthost, target_sat +): + """Incremental update with a new errata on a child content view should + trigger incremental update of parent composite content view + + :BZ: 1304891 + + :id: 1a870ad6-c79c-49fc-b449-8c7e74dd95ff + + :customerscenario: true + + :steps: + + 1. Create a custom repo with filters that excludes the updated package + 2. Create content view with custom repo publish and + promote it + 3. Create another content view with Satellite tools in it, publish + and promote it to the same environment + 4. Create composite content view, add content views from previous + steps in it (force using the latest versions) + 5. Promote composite content view + 6. Create activation key with subscriptions to both child content + views + 7. Register a content host with activation key, install certs, + katello agent, enable repositories + 8. Install outdated package in the content host (walrus-0.71) + 9. On the WebUI, find the errata with the updated package, make sure it's applicable for + the host + 10. Install the errata to the host, agree with incremental update + + :expectedresults: + + 1. Errata installation was successful + 2. Incremental version of composite content view was published + 3. Latest version of composite content view contains the errata and + updated package + + :CaseImportance: Medium + + :parametrized: yes + """ + org = module_target_sat.api.Organization().create() + lce = module_target_sat.api.LifecycleEnvironment(organization=org).create() + product = module_target_sat.api.Product(organization=org).create() + yum_repo_name = gen_string('alpha') + # Creates custom yum repository + yum_repo = module_target_sat.api.Repository( + name=yum_repo_name, + url=settings.repos.yum_1.url, + content_type=REPO_TYPE['yum'], + product=product, + ).create() + product.sync() + # creating cv, cv filter, and publish cv + cv = module_target_sat.api.ContentView(organization=org, repository=[yum_repo]).create() + cvf = module_target_sat.api.RPMContentViewFilter( + content_view=cv, inclusion=False, name=gen_string('alphanumeric') + ).create() + module_target_sat.api.ContentViewFilterRule( + content_view_filter=cvf, + name='walrus', + version='5.21', + ).create() + cv.publish() + cvv = module_target_sat.api.ContentView(id=cv.id).read().version[0] + cvv.promote(data={'environment_ids': lce.id}) + # Setup tools repo and add it to ak + repos_collection = target_sat.cli_factory.RepositoryCollection( + distro='rhel7', + repositories=[target_sat.cli_factory.SatelliteToolsRepository()], + ) + content_data = repos_collection.setup_content(org.id, lce.id, upload_manifest=True) + # adding custom repo subscription to ak + ak_id = content_data['activation_key']['id'] + command = ( + f'hammer activation-key add-subscription --id {ak_id} ' + f'--subscription {product.name} --organization-id {org.id}' + ) + result = target_sat.execute(command) + assert result.status == 0 + # Create composite cv + composite_cv = module_target_sat.api.ContentView(composite=True, organization=org).create() + # Adds all repos to composite cv + composite_cv.component = [ + module_target_sat.api.ContentView(id=content_data['content_view']['id']).read().version[0], + cvv, + ] + composite_cv = composite_cv.update(['component']) + # Publish and promote + composite_cv.publish() + composite_cv.read().version[0].promote(data={'environment_ids': lce.id}) + # Update AK to use composite cv + module_target_sat.api.ActivationKey( + id=content_data['activation_key']['id'], content_view=composite_cv + ).update(['content_view']) + repos_collection.setup_virtual_machine(rhel7_contenthost) + result = rhel7_contenthost.run(f'yum -y install {FAKE_1_CUSTOM_PACKAGE}') + assert result.status == 0 + with session: + session.organization.select(org.name) + session.location.select('Default Location') + result = session.errata.install(settings.repos.yum_1.errata[1], rhel7_contenthost.hostname) + assert result['result'] == 'success' + expected_version = 'Version 1.1' + version = session.contentview.read_version(composite_cv.name, expected_version) + errata = version['errata']['table'] + assert len(errata) > 1 + assert settings.repos.yum_1.errata[1] in {row['Errata ID'] for row in errata} + nvra1 = parse_nvra(FAKE_2_CUSTOM_PACKAGE) + packages = session.contentview.search_version_package( + composite_cv.name, expected_version, nvra1['name'] + ) + packages_data = {'{}-{}-{}.{}'.format(*row.values()) for row in packages} + assert FAKE_2_CUSTOM_PACKAGE in packages_data + + +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_module_stream_end_to_end(session, module_target_sat, module_org, target_sat): + """Create content view with custom module_stream contents, publish and promote it + to Library +1 env. Then disassociate repository from that content view + + :id: 66955a89-14ed-414e-a15a-6ed9ede520ea + + :steps: + 1. Create yum repo with module_stream content and sync it + 2. Create content view and add created repo to it + 3. Publish that content view + 4. Promote it to next environment + + :expectedresults: Content view works properly with module_streams and + count shown should be correct + + :CaseImportance: Medium + """ + repo_name = gen_string('alpha') + env_name = gen_string('alpha') + cv_name = gen_string('alpha') + # Creates a CV along with product and sync'ed repository + target_sat.api_factory.create_sync_custom_repo( + module_org.id, repo_name=repo_name, repo_url=settings.repos.module_stream_1.url + ) + with session: + # Create Life-cycle environment + session.lifecycleenvironment.create({'name': env_name}) + # Create content-view + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + # Add repository to selected CV + session.contentview.add_yum_repo(cv_name, repo_name) + # Publish and promote CV to next environment + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + result = session.contentview.promote(cv_name, VERSION, env_name) + assert f'Promoted to {env_name}' in result['Status'] + assert '7 Module Streams' in result['Content'] + # remove the content view version + session.contentview.remove_version(cv_name, VERSION) + assert session.contentview.search_version(cv_name, VERSION)[0]['Version'] != VERSION + session.contentview.delete(cv_name) + assert session.contentview.search(cv_name)[0]['Name'] != cv_name + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_search_module_streams_in_content_view( + session, module_target_sat, module_org, target_sat +): + """Search module streams in content view version + + :id: 7f5273ff-e80f-459d-adf4-b517b6d60fdc + + :expectedresults: Searching for module streams should work inside content + view version + + :CaseImportance: Low + """ + repo_name = gen_string('alpha') + module_stream = 'walrus' + target_sat.api_factory.create_sync_custom_repo( + module_org.id, repo_name=repo_name, repo_url=settings.repos.module_stream_1.url + ) + repo = module_target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = module_target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + result = session.contentview.publish(cv.name) + assert result['Version'] == VERSION + for module_version in ['0.71', '5.21']: + module_streams = session.contentview.search_version_module_stream( + cv.name, + VERSION, + f'name = "{module_stream}" and stream = "{module_version}"', + ) + assert len(module_streams) == 1 + assert module_streams[0]['Name'] == module_stream + assert module_streams[0]['Stream'] == module_version + + +@pytest.mark.tier2 +def test_positive_non_admin_user_actions( + session, module_target_sat, module_org, test_name, target_sat +): + """Attempt to manage content views + + :id: c4d270fc-a3e6-4ae2-a338-41d864a5622a + + :steps: with global admin account: + + 1. create a user with all content views permissions + 2. create lifecycle environment + 3. create 2 content views (one to delete, the other to manage) + + :setup: create a user with all content views permissions + + :expectedresults: Custom user can Read, Modify, Delete, Publish, Promote + the content views + + :BZ: 1461017 + + :CaseImportance: Critical + """ + # note: the user to be created should not have permissions to access + # products repositories + repo_name = gen_string('alpha') + cv_name = gen_string('alpha') + cv_new_name = gen_string('alpha') + cv_copy_name = gen_string('alpha') + user_login = gen_string('alpha') + user_password = gen_string('alphanumeric') + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + # create a role with all content views permissions + role = module_target_sat.api.Role().create() + target_sat.api_factory.create_role_permissions( + role, {'Katello::ContentView': PERMISSIONS['Katello::ContentView']} + ) + target_sat.api_factory.create_role_permissions( + role, + { + 'Katello::KTEnvironment': [ + 'promote_or_remove_content_views_to_environments', + 'view_lifecycle_environments', + ] + }, + search=f'name = {ENVIRONMENT} or name = {lce.name}', + ) + # create a user and assign the above created role + module_target_sat.api.User( + default_organization=module_org, + organization=[module_org], + role=[role], + login=user_login, + password=user_password, + mail='test@test.com', + ).create() + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + # create a content view with the main admin account + with session: + session.contentview.create({'name': cv_name}) + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + session.contentview.add_yum_repo(cv_name, repo_name) + # Copy the CV + session.contentview.copy(cv_name, cv_copy_name) + assert session.contentview.search(cv_copy_name)[0]['Name'] == cv_copy_name + # login as the user created above + with target_sat.ui_session(test_name, user=user_login, password=user_password) as session: + with pytest.raises(NavigationTriesExceeded): + session.organization.create({'name': gen_string('alpha'), 'label': gen_string('alpha')}) + # assert the user can view all the content views created + # by admin user + assert session.contentview.search(cv_name)[0]['Name'] == cv_name + assert session.contentview.search(cv_copy_name)[0]['Name'] == cv_copy_name + # assert that the user can delete a content view + session.contentview.delete(cv_copy_name) + assert session.contentview.search(cv_copy_name)[0]['Name'] != cv_copy_name + session.contentview.update(cv_name, {'details.name': cv_new_name}) + assert session.contentview.search(cv_new_name)[0]['Name'] == cv_new_name + # Publish and promote CV to next environment + result = session.contentview.publish(cv_new_name) + assert result['Version'] == VERSION + result = session.contentview.promote(cv_new_name, VERSION, lce.name) + assert f'Promoted to {lce.name}' in result['Status'] + # check that cv tabs are accessible + cv = session.contentview.read(cv_new_name) + for tab_name in [ + 'details', + 'versions', + 'repositories', + 'filters', + 'docker_repositories', + ]: + assert cv.get(tab_name) is not None + + +@pytest.mark.tier2 +def test_positive_readonly_user_actions(module_org, test_name, target_sat): + """Attempt to view content views + + :id: ebdc37ed-7887-4f64-944c-f2f92c58a206 + + :setup: + + 1. create a user with the Content View read-only role + 2. create content view + 3. add a custom repository to content view + + :expectedresults: User with read-only role for content view can view + the repository in the content view + + :CaseImportance: Critical + """ + user_login = gen_string('alpha') + user_password = gen_string('alphanumeric') + # create a role with content views read only permissions + role = target_sat.api.Role().create() + target_sat.api_factory.create_role_permissions( + role, {'Katello::ContentView': ['view_content_views']} + ) + target_sat.api_factory.create_role_permissions(role, {'Katello::Product': ['view_products']}) + # create a user and assign the above created role + target_sat.api.User( + default_organization=module_org, + organization=[module_org], + role=[role], + login=user_login, + password=user_password, + ).create() + repo_id = target_sat.api_factory.create_sync_custom_repo(module_org.id) + yum_repo = target_sat.api.Repository(id=repo_id).read() + cv = target_sat.api.ContentView(organization=module_org, repository=[yum_repo]).create() + cv.publish() + # login as the user created above + with target_sat.ui_session(test_name, user=user_login, password=user_password) as session: + with pytest.raises(NavigationTriesExceeded): + session.location.create({'name': gen_string('alpha'), 'label': gen_string('alpha')}) + assert session.contentview.search(cv.name)[0]['Name'] == cv.name + cv_values = session.contentview.read(cv.name) + assert cv_values['details']['name'] == cv.name + assert cv_values['versions']['table'][0]['Version'] == VERSION + assert cv_values['repositories']['resources']['assigned'][0]['Name'] == yum_repo.name + + +@pytest.mark.tier2 +def test_negative_read_only_user_actions( + session, module_target_sat, module_org, test_name, target_sat +): + """Attempt to manage content views + + :id: aae6eede-b40e-4e06-a5f7-59d9251aa35d + + :setup: + + 1. create a user with the Content View read-only role + 2. create content view + 3. add a custom repository to content view + + :expectedresults: User with read only role for content view cannot + Modify, Delete, Publish, Promote the content views. Additionally, + users cannot create content view, create product, create host collection, + create activation key, or see repo discovery + + :BZ: 1922134 + + :CaseImportance: Critical + """ + # create a content view read only user with lifecycle environment + # permissions: view_lifecycle_environments and + # promote_or_remove_content_views_to_environments + user_login = gen_string('alpha') + user_password = gen_string('alphanumeric') + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + # create a role with content views read only permissions + role = module_target_sat.api.Role().create() + target_sat.api_factory.create_role_permissions( + role, {'Katello::ContentView': ['view_content_views']} + ) + target_sat.api_factory.create_role_permissions( + role, + { + 'Katello::KTEnvironment': [ + 'promote_or_remove_content_views_to_environments', + 'view_lifecycle_environments', + ] + }, + search=f'name = {ENVIRONMENT} or name = {lce.name}', + ) + # create a user and assign the above created role + module_target_sat.api.User( + default_organization=module_org, + organization=[module_org], + role=[role], + login=user_login, + password=user_password, + ).create() + repo_id = target_sat.api_factory.create_sync_custom_repo(module_org.id) + yum_repo = module_target_sat.api.Repository(id=repo_id).read() + repo_name = 'fakerepo01' + cv = module_target_sat.api.ContentView(organization=module_org, repository=[yum_repo]).create() + # login as the user created above + with target_sat.ui_session( + test_name, user=user_login, password=user_password + ) as custom_session: + with pytest.raises(NavigationTriesExceeded): + custom_session.location.create( + {'name': gen_string('alpha'), 'label': gen_string('alpha')} + ) + assert custom_session.contentview.search(cv.name)[0]['Name'] == cv.name + # Cannot update content view + with pytest.raises(InvalidElementStateException): + custom_session.contentview.update(cv.name, {'details.name': gen_string('alpha')}) + # Cannot publish content view + with pytest.raises(NavigationTriesExceeded) as context: + custom_session.contentview.publish(cv.name) + assert 'failed to reach [Publish]' in str(context.value) + with session: + result = session.contentview.publish(cv.name) + assert result['Version'] == VERSION + with target_sat.ui_session(test_name, user=user_login, password=user_password) as session: + # Cannot create content view + with pytest.raises(NoSuchElementException) as context: + session.contentview.create({'name': gen_string('alpha')}) + assert 'Could not find an element' in str(context.value) + # Cannot create activation key + with pytest.raises(NavigationTriesExceeded) as context: + session.activationkey.create({'name': gen_string('alpha')}) + assert 'failed to reach [All]' in str(context.value) + # Cannot create product + with pytest.raises(NavigationTriesExceeded) as context: + session.product.create({'name': gen_string('alpha')}) + assert 'failed to reach [All]' in str(context.value) + # Cannot create host collection + with pytest.raises(NavigationTriesExceeded) as context: + session.hostcollection.create({'name': gen_string('alpha')}) + assert 'failed to reach [All]' in str(context.value) + # Cannot create discovery repo + with pytest.raises(NavigationTriesExceeded) as context: + session.product.discover_repo( + { + 'repo_type': 'Yum Repositories', + 'url': settings.repos.repo_discovery.url, + 'discovered_repos.repos': repo_name, + 'create_repo.product_type': 'Existing Product', + 'create_repo.product_content.product_name': gen_string('alpha'), + } + ) + assert 'failed to reach [All]' in str(context.value) + # Cannot promote content view + with pytest.raises(NavigationTriesExceeded) as context: + session.contentview.promote(cv.name, VERSION, lce.name) + assert 'failed to reach [Promote]' in str(context.value) + # Cannot delete content view + with pytest.raises(NavigationTriesExceeded) as context: + session.contentview.delete(cv.name) + assert 'failed to reach [Delete]' in str(context.value) + + +@pytest.mark.tier2 +def test_negative_non_readonly_user_actions(module_org, test_name, target_sat): + """Attempt to view content views + + :id: 9cbc661a-dbe3-4b88-af27-4cf7b9544074 + + :setup: create a user with the Content View without the content views + read role + + :expectedresults: the user cannot access content views web resources + + :CaseImportance: High + """ + user_login = gen_string('alpha') + user_password = gen_string('alphanumeric') + # create a role with all content views permissions except + # view_content_views + lce = target_sat.api.LifecycleEnvironment(organization=module_org).create() + cv = target_sat.api.ContentView(organization=module_org).create() + role = target_sat.api.Role().create() + target_sat.api_factory.create_role_permissions( + role, + { + 'Katello::ContentView': [ + 'create_content_views', + 'edit_content_views', + 'destroy_content_views', + 'publish_content_views', + 'promote_or_remove_content_views', + ] + }, + ) + target_sat.api_factory.create_role_permissions( + role, + { + 'Katello::KTEnvironment': [ + 'promote_or_remove_content_views_to_environments', + 'view_lifecycle_environments', + ] + }, + search=f'name = {ENVIRONMENT} or name = {lce.name}', + ) + # create a user and assign the above created role + target_sat.api.User( + default_organization=module_org, + organization=[module_org], + role=[role], + login=user_login, + password=user_password, + ).create() + # login as the user created above + with target_sat.ui_session(test_name, user=user_login, password=user_password) as session: + with pytest.raises(NavigationTriesExceeded): + session.user.create( + { + 'user.login': gen_string('alpha'), + 'user.auth': 'INTERNAL', + 'user.password': gen_string('alpha'), + 'user.confirm': gen_string('alpha'), + } + ) + with pytest.raises(NavigationTriesExceeded) as context: + session.contentview.search(cv.name) + assert 'Navigation failed to reach [All]' in str(context.value) + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier2 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_conservative_solve_dependencies( + session, module_target_sat, module_org, target_sat +): + """Performing solve dependencies on a package that is required by another + package. Then performing solve dependencies on a root package with + its corresponding dependency. + + :id: bffd50f3-77e4-492f-a0ac-09dfb95b1987 + + :setup: + 1. Turn dependency solving to conservative. + 2. Create and sync custom repo. + 3. Create cv and add custom repo. + 4. Create exclusion filter and exclude a package that is required + by another package (cockateel). + 5. Publish CV + 6. Check rpm package list for that version and make sure it's in the + list. + 7. Create exclusion filter for a root package (duck) along with + package from above. + 8. Republish and check rpm package list for new version and make + sure they are NOT in the list. + + :expectedresults: In step 6, 'cockateel' should be in the list. + In step 8, 'duck' and 'cockateel' should NOT be in the list. + + :CaseImportance: High + """ + property_name = 'dependency_solving_algorithm' + param_value = 'conservative' + cv_name = gen_string('alpha') + repo_name = gen_string('alpha') + package1_name = 'duck' + package2_name = 'cockateel' + arch = 'noarch' + target_sat.api_factory.create_sync_custom_repo( + module_org.id, repo_name=repo_name, repo_url=settings.repos.yum_0.url + ) + with session: + session.settings.update(f'name = {property_name}', param_value) + session.contentview.create({'name': cv_name, 'solve_dependencies': True}) + session.contentview.add_yum_repo(cv_name, repo_name) + filter_name = gen_string('alpha') + session.contentviewfilter.create( + cv_name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + session.contentviewfilter.add_package_rule( + cv_name, filter_name, package2_name, arch, ('All Versions') + ) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + package = session.contentview.search_version_package( + cv_name, VERSION, f'name = "{package2_name}"' + ) + assert len(package) == 1 + assert package[0]['Name'] == package2_name + package = session.contentview.search_version_package( + cv_name, VERSION, f'name = "{package1_name}"' + ) + assert package[0]['Name'] == package1_name + session.contentviewfilter.add_package_rule( + cv_name, filter_name, package1_name, arch, ('All Versions') + ) + result = session.contentview.publish(cv_name) + assert result['Version'] == 'Version 2.0' + for package_names in ['duck', 'cockateel']: + package = session.contentview.search_version_package( + cv_name, 'Version 2.0', f'name = "{package_names}"' + ) + assert not package[0]['Name'] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier2 +def test_positive_conservative_dep_solving_with_multiversion_packages( + session, module_org, target_sat +): + """Performing solve dependencies on a package with multiple versions that is required + by another package. + + :id: f1fb2f2e-6d63-4705-b0cd-6697fed2b6e9 + + :setup: + 1. Turn dependency solving to conservative. + 2. Create and sync custom repo. + 3. Create cv and add custom repo. + 4. Create exclusion filter and exclude a package (walrus) that has multiple versions that + is required by another package. + 5. Publish CV + 6. Check rpm package list for that version + 7. Repeat steps 4 - 7 but exclude higher version + + :expectedresults: In step 6, the older version of the package should be filtered out while the + newest version is still in the list. In step 7, the new version is filtered out while the + old version is still in the list. + + :CaseImportance: High + """ + property_name = 'dependency_solving_algorithm' + param_value = 'conservative' + cv_name = gen_string('alpha') + repo_name = gen_string('alpha') + package_name = 'walrus' + arch = 'noarch' + target_sat.api_factory.create_sync_custom_repo( + module_org.id, repo_name=repo_name, repo_url=settings.repos.yum_0.url + ) + with session: + session.settings.update(f'name = {property_name}', param_value) + session.contentview.create({'name': cv_name, 'solve_dependencies': True}) + session.contentview.add_yum_repo(cv_name, repo_name) + filter_name = gen_string('alpha') + session.contentviewfilter.create( + cv_name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + session.contentviewfilter.add_package_rule( + cv_name, filter_name, package_name, arch, ('All Versions') + ) + result = session.contentview.publish(cv_name) + assert result['Version'] == VERSION + package = session.contentview.search_version_package( + cv_name, VERSION, f'name = "{package_name}"' + ) + assert len(package) == 1 + assert package[0]['Name'] == package_name + assert package[0]['Version'] == '5.21' + session.contentviewfilter.update_package_rule( + cv_name, filter_name, package_name, {'Version': ('Equal To', '5.21')} + ) + session.contentview.publish(cv_name) + package = session.contentview.search_version_package( + cv_name, 'Version 2.0', f'name = "{package_name}"' + ) + assert len(package) == 1 + assert package[0]['Name'] == package_name + assert package[0]['Version'] == '0.71' + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier2 +@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') +def test_positive_depsolve_with_module_errata(session, module_target_sat, module_org, target_sat): + """Allowing users to filter module streams in content views. This test case does not test + against RHEL8 repos because it is known that RHEL8 filtering with depsolving creates + inconsistent results. The custom repo used in this test case has consistent results based + on filtering and thus why it's used. + + :id: 59f9ed09-fe32-4e52-9fb9-6fa2d22eeb26 + + :setup: + 1. Create custom repo and sync + 2. Add custom repos to a CV and turn depsolving = true. + 3. Create an inclusion filter for module stream. + 4. Create an exclusion filter for packages for all packages. + 5. Publish CV + + :expectedresults: Content view result should have 4 packages, 1 errata, + and 1 Module Streams associated with the CV + + :CaseImportance: High + """ + cv_name = gen_string('alpha') + repo_name_1 = gen_string('alpha') + repo_name_2 = gen_string('alpha') + include_filter_name = gen_string('alpha') + exclude_filter_name = gen_string('alpha') + all_packages = '*' + ms_name = 'walrus' + ms_version = '0.71' + rpm_pack = ['shark', 'stork', 'walrus', 'whale'] + mod_stream = 'walrus' + target_sat.api_factory.create_sync_custom_repo( + module_org.id, repo_name=repo_name_1, repo_url=settings.repos.yum_10.url + ) + target_sat.api_factory.create_sync_custom_repo( + module_org.id, repo_name=repo_name_2, repo_url=settings.repos.yum_11.url + ) + content = '4 Packages 1 Errata ( 1 0 0 ) 1 Module Streams' + with session: + session.contentview.create({'name': cv_name, 'solve_dependencies': True}) + session.contentview.add_yum_repo(cv_name, repo_name_1) + session.contentview.add_yum_repo(cv_name, repo_name_2) + session.contentviewfilter.create( + cv_name, + { + 'name': include_filter_name, + 'content_type': FILTER_CONTENT_TYPE['modulemd'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + session.contentviewfilter.add_module_stream( + cv_name, include_filter_name, f'name = {ms_name} and stream = {ms_version}' + ) + session.contentviewfilter.create( + cv_name, + { + 'name': exclude_filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + session.contentviewfilter.add_package_rule( + cv_name, exclude_filter_name, all_packages, '', ('All Versions') + ) + result = session.contentview.publish(cv_name) + assert result['Content'] == content + result = session.contentview.read_version(cv_name, VERSION) + assert len(result['rpm_packages']['table']) == 4 + assert len(result['module_streams']['table']) == 1 + assert len(result['errata']['table']) == 1 + for items in result['rpm_packages']['table']: + assert items['Name'] in rpm_pack + assert result['module_streams']['table'][0]['Name'] == mod_stream + assert result['errata']['table'][0]['Errata ID'] == settings.repos.yum_10.errata[0] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier2 +def test_positive_filter_by_pkg_group_name(session, module_target_sat, module_org, target_sat): + """Publish a filtered version of a Content View, filtering on the package group's name. + + :id: c7021f46-0168-44f7-a863-4aa34533efdb + + :expectedresults: Published Content View's contents is filtered + based on package group. + + :CaseImportance: Medium + """ + + filter_name = gen_string('alpha') + repo_name = gen_string('alpha') + package_group = 'birds' + expected_packages = [('cockateel'), ('duck'), ('penguin'), ('stork')] + target_sat.api_factory.create_sync_custom_repo(module_org.id, repo_name=repo_name) + repo = target_sat.api.Repository(name=repo_name).search( + query={'organization_id': module_org.id} + )[0] + cv = target_sat.api.ContentView(organization=module_org, repository=[repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package group'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + session.contentviewfilter.add_package_group(cv.name, filter_name, package_group) + cvf = session.contentviewfilter.read(cv.name, filter_name) + assert cvf['content_tabs']['assigned'][0]['Name'] == package_group + # Publish CV and check filter worked + session.contentview.publish(cv.name) + result = session.contentview.read_version(cv.name, VERSION) + # Assert only the expected packages are present + assert expected_packages == [pkg['Name'] for pkg in result['rpm_packages']['table']] + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier3 +def test_positive_inc_update_should_not_fail(session, module_target_sat, module_org): + """Incremental update after removing a package should not give a 400 error code + + :BZ: 2041497 + + :id: 1d78db8f-53cc-4f00-9fea-d871c2f53d03 + + :setup: + 1. Create custom repo and sync + 2. Delete some packages from the repo (bear in this case) + 3. Create a cv, add the repo, and publish it + 4. Re-sync the repo to get hte deleted RPMs back + 5. Perform incremental update to add back the repo to the cv + + :customerscenario: true + + :expectedresults: Incremental update is successful + + :CaseImportance: High + """ + package1_name = 'bear' + product = module_target_sat.api.Product(organization=module_org).create() + yum_repo_name = gen_string('alpha') + # Creates custom yum repository + yum_repo = module_target_sat.api.Repository( + name=yum_repo_name, + url=settings.repos.yum_1.url, + content_type=REPO_TYPE['yum'], + product=product, + ).create() + yum_repo.sync() + # remove 'bear' package + package_id = yum_repo.packages()['results'][0]['id'] + yum_repo.remove_content(data={'ids': [package_id]}) + assert yum_repo.packages()['total'] == 31 + cv = module_target_sat.api.ContentView(organization=module_org, repository=[yum_repo]).create() + cv.publish() + cvvs = module_target_sat.api.ContentView(id=cv.id).read().version + assert len(cvvs) == 1 + yum_repo.sync() + assert yum_repo.packages()['total'] == 32 + cvv = cvvs[0].read() + result = ContentView.version_incremental_update( + {'content-view-version-id': cvv.id, 'errata-ids': settings.repos.yum_1.errata[0]} + ) + result = [line.strip() for line_dict in result for line in line_dict.values()] + assert result[2] == FAKE_0_CUSTOM_PACKAGE + with session: + cvv = module_target_sat.api.ContentView(id=cv.id).read().version[1].read() + assert cvv.version == '1.1' + packages = session.contentview.search_version_package( + cv.name, 'Version 1.1', f'name= "{package1_name}"' + ) + assert packages[0]['Name'] == package1_name + + +@pytest.mark.skip_if_open('BZ:2086957') +@pytest.mark.tier2 +def test_positive_no_duplicate_key_violate_unique_constraint_using_filters( + session, module_entitlement_manifest_org, target_sat +): + """Ensure that there's no duplicate key issues when filtering packages + + :BZ: 2080336 + + :id: 6e872dc4-ed8c-450b-8ce6-9f873ac490a1 + + :customerscenario: true + + :steps: + 1. Sync rhel tools 6.10 repo + 2. Create cv and add rhel repo + 3. Create include package filter for 'foreman-cli' and 'katello-agent' + 4. Publish cv + 5. Check cv has only 2 packages + 6. Amend the filter to add 'katello-host-tools' + 7. Public cv and check it has 3 packages + 8. Amend filter to remove 'foreman-cli' and 'katello-agent'. + 9. Add 'katello-host-tools-facts-plugin' + 10. Publish cv and check cv has 2 packages: katello-host-tools and + katello-host-tools-fact-plugin + 11. Add 'foreman-cli' and 'katello-agent' back + 12. Publish cv and check that all 4 packages are there + 13. Trigger orphan clean up + 14. Amend the filter and remove 'foreman-cli' and 'katello-agent' + 15. Publish cv and check cv has 2 packages: katello-host-tools and + katello-host-tools-fact-plugin + + :expectedresults: + + 1. Cv has 2 packages without errors: katello-host-tools and + katello-host-tools-fact-plugin + + :CaseImportance: Medium + """ + cv = gen_string('alpha') + filter_name = gen_string('alpha') + rh_repo = { + 'name': REPOS['rhst7_610']['name'], + 'product': PRDS['rhel'], + 'reposet': REPOSET['rhst7_610'], + 'basearch': 'x86_64', + 'releasever': None, + } + packages = [ + 'foreman-cli', + 'katello-agent', + 'katello-host-tools', + 'katello-host-tools-fact-plugin', + ] + target_sat.api_factory.enable_sync_redhat_repo(rh_repo, module_entitlement_manifest_org.id) + with session: + session.contentview.create({'name': cv}) + session.contentview.add_yum_repo(cv, rh_repo['name']) + # create filters and rule + session.contentviewfilter.create( + cv, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['include'], + }, + ) + # add rule to include only 'foreman-cli' and 'katello-agent' + session.contentviewfilter.add_package_rule(cv, filter_name, packages[0], None, None) + session.contentviewfilter.add_package_rule(cv, filter_name, packages[1], None, None) + result = session.contentview.publish(cv) + assert result['Version'] == VERSION + # check only the 2 packages are in the cv + packages_check = session.contentview.read_version(cv, result['Version']) + assert len(packages_check['rpm_packages']['table']) == 2 + for i in range(len(packages_check['rpm_packages']['table'])): + assert packages_check['rpm_packages']['table'][i]['Name'] == packages[i] + # add 3rd package - katello-host-tools + session.contentviewfilter.add_package_rule(cv, filter_name, packages[2], None, None) + result = session.contentview.publish(cv) + assert result['Version'] == 'Version 2.0' + packages_check = session.contentview.read_version(cv, result['Version']) + assert len(packages_check['rpm_packages']['table']) == 3 + for i in range(len(packages_check['rpm_packages']['table'])): + assert packages_check['rpm_packages']['table'][i]['Name'] == packages[i] + # remove the rule for the first 2 packages and add another new package rule + session.contentviewfilter.remove_package_rule(cv, filter_name, packages[0]) + session.contentviewfilter.remove_package_rule(cv, filter_name, packages[1]) + session.contentviewfilter.add_package_rule(cv, filter_name, packages[3], None, None) + result = session.contentview.publish(cv) + assert result['Version'] == 'Version 3.0' + packages_check = session.contentview.read_version(cv, result['Version']) + assert len(packages_check['rpm_packages']['table']) == 2 + assert packages_check['rpm_packages']['table'][0]['Name'] == packages[2] + assert packages_check['rpm_packages']['table'][1]['Name'] == packages[3] + session.contentviewfilter.add_package_rule(cv, filter_name, packages[0], None, None) + session.contentviewfilter.add_package_rule(cv, filter_name, packages[1], None, None) + result = session.contentview.publish(cv) + assert result['Version'] == 'Version 4.0' + packages_check = session.contentview.read_version(cv, result['Version']) + assert len(packages_check['rpm_packages']['table']) == 4 + for i in range(len(packages)): + assert packages_check['rpm_packages']['table'][i]['Name'] == packages[i] + # trigger orphan cleanup + result = target_sat.execute('foreman-rake katello:delete_orphaned_content') + assert result.status == 0 + # remove the rule for the first 2 packages again + session.contentviewfilter.remove_package_rule(cv, filter_name, packages[0]) + session.contentviewfilter.remove_package_rule(cv, filter_name, packages[1]) + result = session.contentview.publish(cv) + assert result['Version'] == 'Version 5.0' + packages_check = session.contentview.read_version(cv, result['Version']) + # finally should only see 'katello-host-tools' and 'katello-host-tools-fact-plugin' + assert len(packages_check['rpm_packages']['table']) == 2 + assert packages_check['rpm_packages']['table'][0]['Name'] == packages[2] + assert packages_check['rpm_packages']['table'][1]['Name'] == packages[3] + + +@pytest.mark.tier2 +def test_positive_inc_publish_cv(session, module_target_sat, module_org): + """Ensure that the content count gets updated when doing incremental update + + :BZ: 2032098 + + :id: 611693c5-bfa5-462a-bd78-fa624af7ff75 + + :setup: + 1. Create custom repo and sync + 2. Create a cv and add the repo + 3. Create a filter to exclude a package + 4. Publish cv + 5. Incrementally update the cv with an errata + + :customerscenario: true + + :expectedresults: Content count is updated as expected + + :CaseImportance: High + """ + package_name = 'bear' + product = module_target_sat.api.Product(organization=module_org).create() + yum_repo_name = gen_string('alpha') + filter_name = gen_string('alpha') + yum_repo = module_target_sat.api.Repository( + name=yum_repo_name, + url=settings.repos.yum_1.url, + content_type=REPO_TYPE['yum'], + product=product, + ).create() + yum_repo.sync() + cv = module_target_sat.api.ContentView(organization=module_org, repository=[yum_repo]).create() + with session: + session.contentviewfilter.create( + cv.name, + { + 'name': filter_name, + 'content_type': FILTER_CONTENT_TYPE['package'], + 'inclusion_type': FILTER_TYPE['exclude'], + }, + ) + session.contentviewfilter.add_package_rule( + cv.name, filter_name, package_name, None, ('Equal To', '4.1-1') + ) + session.contentview.publish(cv.name) + cvv = module_target_sat.api.ContentView(id=cv.id).read().version[0].read() + assert cvv.package_count == 31 + ContentView.version_incremental_update( + {'content-view-version-id': cvv.id, 'errata-ids': settings.repos.yum_1.errata[0]} + ) + cvv = module_target_sat.api.ContentView(id=cv.id).read().version[1].read() + assert cvv.package_count == 32 diff --git a/tests/foreman/ui/test_dashboard.py b/tests/foreman/ui/test_dashboard.py index 80b7ce16732..f72b8c42afc 100644 --- a/tests/foreman/ui/test_dashboard.py +++ b/tests/foreman/ui/test_dashboard.py @@ -16,8 +16,6 @@ :Upstream: No """ -from airgun.session import Session -from nailgun import entities from nailgun.entity_mixins import TaskFailedError import pytest @@ -28,7 +26,7 @@ @pytest.mark.tier2 -def test_positive_host_configuration_status(session): +def test_positive_host_configuration_status(session, target_sat): """Check if the Host Configuration Status Widget links are working :id: ffb0a6a1-2b65-4578-83c7-61492122d865 @@ -48,9 +46,9 @@ def test_positive_host_configuration_status(session): :CaseLevel: Integration """ - org = entities.Organization().create() - loc = entities.Location().create() - host = entities.Host(organization=org, location=loc).create() + org = target_sat.api.Organization().create() + loc = target_sat.api.Location().create() + host = target_sat.api.Host(organization=org, location=loc).create() criteria_list = [ 'Hosts that had performed modifications without error', 'Hosts in error state', @@ -101,7 +99,7 @@ def test_positive_host_configuration_status(session): @pytest.mark.tier2 -def test_positive_host_configuration_chart(session): +def test_positive_host_configuration_chart(session, target_sat): """Check if the Host Configuration Chart is working in the Dashboard UI :id: b03314aa-4394-44e5-86da-c341c783003d @@ -116,9 +114,9 @@ def test_positive_host_configuration_chart(session): :CaseLevel: Integration """ - org = entities.Organization().create() - loc = entities.Location().create() - entities.Host(organization=org, location=loc).create() + org = target_sat.api.Organization().create() + loc = target_sat.api.Location().create() + target_sat.api.Host(organization=org, location=loc).create() with session: session.organization.select(org_name=org.name) session.location.select(loc_name=loc.name) @@ -129,7 +127,7 @@ def test_positive_host_configuration_chart(session): @pytest.mark.upgrade @pytest.mark.run_in_one_thread @pytest.mark.tier2 -def test_positive_task_status(session): +def test_positive_task_status(session, target_sat): """Check if the Task Status is working in the Dashboard UI and filter from Tasks index page is working correctly @@ -152,9 +150,11 @@ def test_positive_task_status(session): :CaseLevel: Integration """ url = 'www.non_existent_repo_url.org' - org = entities.Organization().create() - product = entities.Product(organization=org).create() - repo = entities.Repository(url=f'http://{url}', product=product, content_type='yum').create() + org = target_sat.api.Organization().create() + product = target_sat.api.Product(organization=org).create() + repo = target_sat.api.Repository( + url=f'http://{url}', product=product, content_type='yum' + ).create() with pytest.raises(TaskFailedError): repo.sync() with session: @@ -235,9 +235,9 @@ def test_positive_user_access_with_host_filter( user_login = gen_string('alpha') user_password = gen_string('alphanumeric') org = function_entitlement_manifest_org - lce = entities.LifecycleEnvironment(organization=org).create() + lce = target_sat.api.LifecycleEnvironment(organization=org).create() # create a role with necessary permissions - role = entities.Role().create() + role = target_sat.api.Role().create() user_permissions = { 'Organization': ['view_organizations'], 'Location': ['view_locations'], @@ -246,7 +246,7 @@ def test_positive_user_access_with_host_filter( } target_sat.api_factory.create_role_permissions(role, user_permissions) # create a user and assign the above created role - entities.User( + target_sat.api.User( default_organization=org, organization=[org], default_location=module_location, @@ -255,7 +255,7 @@ def test_positive_user_access_with_host_filter( login=user_login, password=user_password, ).create() - 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: assert session.dashboard.read('HostConfigurationStatus')['total_count'] == 0 assert len(session.dashboard.read('LatestErrata')['erratas']) == 0 rhel_contenthost.add_rex_key(target_sat) @@ -279,8 +279,7 @@ def test_positive_user_access_with_host_filter( @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_sync_overview_widget(session, module_org, module_product): - +def test_positive_sync_overview_widget(session, module_product, module_target_sat): """Check if the Sync Overview widget is working in the Dashboard UI :id: 553fbe33-0f6f-46fb-8d80-5d1d9ed483cf @@ -296,7 +295,9 @@ def test_positive_sync_overview_widget(session, module_org, module_product): :CaseLevel: Integration """ - repo = entities.Repository(url=settings.repos.yum_1.url, product=module_product).create() + repo = module_target_sat.api.Repository( + url=settings.repos.yum_1.url, product=module_product + ).create() with session: session.repository.synchronize(module_product.name, repo.name) sync_params = session.dashboard.read('SyncOverview')['syncs'] diff --git a/tests/foreman/ui/test_discoveryrule.py b/tests/foreman/ui/test_discoveryrule.py index d61d5067f85..e4a08d44bf4 100644 --- a/tests/foreman/ui/test_discoveryrule.py +++ b/tests/foreman/ui/test_discoveryrule.py @@ -16,7 +16,6 @@ :Upstream: No """ -from airgun.session import Session from fauxfactory import gen_integer, gen_ipaddr, gen_string import pytest @@ -89,7 +88,9 @@ def test_positive_crud_with_non_admin_user( new_priority = str(gen_integer(101, 200)) hg = module_target_sat.api.HostGroup(organization=[module_org]).create() new_hg_name = module_target_sat.api.HostGroup(organization=[module_org]).create() - with Session(user=manager_user.login, password=manager_user.password) as session: + with module_target_sat.ui_session( + user=manager_user.login, password=manager_user.password + ) as session: session.location.select(loc_name=module_location.name) session.discoveryrule.create( { @@ -154,7 +155,9 @@ def test_negative_delete_rule_with_non_admin_user( organization=[module_org], location=[module_location], ).create() - with Session(user=reader_user.login, password=reader_user.password) as session: + with module_target_sat.ui_session( + user=reader_user.login, password=reader_user.password + ) as session: with pytest.raises(ValueError): # noqa: PT011 - TODO Adarsh determine better exception session.discoveryrule.delete(dr.name) dr_val = session.discoveryrule.read_all() diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index 3bec22806b8..ca3b4bae176 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -16,11 +16,9 @@ :Upstream: No """ -from airgun.session import Session from broker import Broker from fauxfactory import gen_string from manifester import Manifester -from nailgun import entities import pytest from robottelo.config import settings @@ -55,9 +53,9 @@ pytestmark = [pytest.mark.run_in_one_thread] -def _generate_errata_applicability(hostname): +def _generate_errata_applicability(hostname, module_target_sat): """Force host to generate errata applicability""" - host = entities.Host().search(query={'search': f'name={hostname}'})[0].read() + host = module_target_sat.api.Host().search(query={'search': f'name={hostname}'})[0].read() host.errata_applicability(synchronous=False) @@ -145,9 +143,9 @@ def erratatype_vm(module_repos_collection_with_setup, target_sat): @pytest.fixture -def errata_status_installable(): +def errata_status_installable(module_target_sat): """Fixture to allow restoring errata_status_installable setting after usage""" - errata_status_installable = entities.Setting().search( + errata_status_installable = module_target_sat.api.Setting().search( query={'search': 'name="errata_status_installable"'} )[0] original_value = errata_status_installable.value @@ -401,7 +399,7 @@ def test_positive_list(session, function_org_with_parameter, lce, target_sat): indirect=True, ) def test_positive_list_permission( - test_name, module_org_with_parameter, module_repos_collection_with_setup + test_name, module_org_with_parameter, module_repos_collection_with_setup, module_target_sat ): """Show errata only if the User has permissions to view them @@ -421,23 +419,25 @@ def test_positive_list_permission( :CaseLevel: Integration """ module_org = module_org_with_parameter - role = entities.Role().create() - entities.Filter( + role = module_target_sat.api.Role().create() + module_target_sat.api.Filter( organization=[module_org], - permission=entities.Permission().search( + permission=module_target_sat.api.Permission().search( query={'search': 'resource_type="Katello::Product"'} ), role=role, search='name = "{}"'.format(PRDS['rhel']), ).create() user_password = gen_string('alphanumeric') - user = entities.User( + user = module_target_sat.api.User( default_organization=module_org, organization=[module_org], role=[role], password=user_password, ).create() - with Session(test_name, user=user.login, password=user_password) as session: + with module_target_sat.ui_session( + test_name, user=user.login, password=user_password + ) as session: assert ( session.errata.search(RHVA_ERRATA_ID, applicable=False)[0]['Errata ID'] == RHVA_ERRATA_ID @@ -587,14 +587,16 @@ def test_positive_filter_by_environment( ) assert _install_client_package(client, FAKE_1_CUSTOM_PACKAGE, errata_applicability=True) # Promote the latest content view version to a new lifecycle environment - content_view = entities.ContentView( + content_view = target_sat.api.ContentView( id=module_repos_collection_with_setup.setup_content_data['content_view']['id'] ).read() content_view_version = content_view.version[-1].read() lce = content_view_version.environment[-1].read() - new_lce = entities.LifecycleEnvironment(organization=module_org, prior=lce).create() + new_lce = target_sat.api.LifecycleEnvironment(organization=module_org, prior=lce).create() content_view_version.promote(data={'environment_ids': new_lce.id}) - host = entities.Host().search(query={'search': f'name={clients[0].hostname}'})[0].read() + host = ( + target_sat.api.Host().search(query={'search': f'name={clients[0].hostname}'})[0].read() + ) host.content_facet_attributes = { 'content_view_id': content_view.id, 'lifecycle_environment_id': new_lce.id, @@ -635,7 +637,7 @@ def test_positive_filter_by_environment( indirect=True, ) def test_positive_content_host_previous_env( - session, module_org_with_parameter, module_repos_collection_with_setup, vm + session, module_org_with_parameter, module_repos_collection_with_setup, vm, module_target_sat ): """Check if the applicable errata are available from the content host's previous environment @@ -660,14 +662,16 @@ def test_positive_content_host_previous_env( hostname = vm.hostname assert _install_client_package(vm, FAKE_1_CUSTOM_PACKAGE, errata_applicability=True) # Promote the latest content view version to a new lifecycle environment - content_view = entities.ContentView( + content_view = module_target_sat.api.ContentView( id=module_repos_collection_with_setup.setup_content_data['content_view']['id'] ).read() content_view_version = content_view.version[-1].read() lce = content_view_version.environment[-1].read() - new_lce = entities.LifecycleEnvironment(organization=module_org, prior=lce).create() + new_lce = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce + ).create() content_view_version.promote(data={'environment_ids': new_lce.id}) - host = entities.Host().search(query={'search': f'name={hostname}'})[0].read() + host = module_target_sat.api.Host().search(query={'search': f'name={hostname}'})[0].read() host.content_facet_attributes = { 'content_view_id': content_view.id, 'lifecycle_environment_id': new_lce.id, @@ -945,7 +949,7 @@ def test_positive_filtered_errata_status_installable_param( :CaseLevel: System """ org = function_entitlement_manifest_org - lce = entities.LifecycleEnvironment(organization=org).create() + lce = target_sat.api.LifecycleEnvironment(organization=org).create() repos_collection = target_sat.cli_factory.RepositoryCollection( distro='rhel7', repositories=[ @@ -962,16 +966,16 @@ def test_positive_filtered_errata_status_installable_param( assert _install_client_package(client, FAKE_1_CUSTOM_PACKAGE, errata_applicability=True) # Adding content view filter and content view filter rule to exclude errata for the # installed package. - content_view = entities.ContentView( + content_view = target_sat.api.ContentView( id=repos_collection.setup_content_data['content_view']['id'] ).read() - cv_filter = entities.ErratumContentViewFilter( + cv_filter = target_sat.api.ErratumContentViewFilter( content_view=content_view, inclusion=False ).create() - errata = entities.Errata(content_view_version=content_view.version[-1]).search( + errata = target_sat.api.Errata(content_view_version=content_view.version[-1]).search( query=dict(search=f'errata_id="{CUSTOM_REPO_ERRATA_ID}"') )[0] - entities.ContentViewFilterRule(content_view_filter=cv_filter, errata=errata).create() + target_sat.api.ContentViewFilterRule(content_view_filter=cv_filter, errata=errata).create() content_view.publish() content_view = content_view.read() content_view_version = content_view.version[-1] diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index c4ae7a73773..d64494a0d64 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -23,7 +23,6 @@ import re from airgun.exceptions import DisabledWidgetError, NoSuchElementException -from airgun.session import Session import pytest from wait_for import wait_for import yaml @@ -504,7 +503,7 @@ def test_positive_view_hosts_with_non_admin_user( created_host = target_sat.api.Host( location=smart_proxy_location, organization=module_org ).create() - 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: host = session.host.get_details(created_host.name, widget_names='breadcrumb') assert host['breadcrumb'] == created_host.name content_host = session.contenthost.read(created_host.name, widget_names='breadcrumb') @@ -555,7 +554,7 @@ def test_positive_remove_parameter_non_admin_user( organization=module_org, host_parameters_attributes=[parameter], ).create() - with Session(test_name, user=user.login, password=user_password) as session: + with target_sat.ui_seesion(test_name, user=user.login, password=user_password) as session: values = session.host.read(host.name, 'parameters') assert values['parameters']['host_params'][0] == parameter session.host.update(host.name, {'parameters.host_params': []}) @@ -612,7 +611,7 @@ def test_negative_remove_parameter_non_admin_user( organization=module_org, host_parameters_attributes=[parameter], ).create() - 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: values = session.host.read(host.name, 'parameters') assert values['parameters']['host_params'][0] == parameter with pytest.raises(NoSuchElementException) as context: @@ -723,7 +722,7 @@ def test_positive_check_permissions_affect_create_procedure( 'other_fields_values': {'host.lce': filter_lc_env.name}, }, ] - 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: for host_field in host_fields: values = {host_field['name']: host_field['unexpected_value']} values.update(host_field.get('other_fields_values', {})) @@ -2411,7 +2410,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( { @@ -2426,3 +2425,42 @@ def test_positive_host_registration_with_non_admin_user( # Verify server.hostname and server.port from subscription-manager config assert target_sat.hostname == rhel8_contenthost.subscription_config['server']['hostname'] assert constants.CLIENT_PORT == rhel8_contenthost.subscription_config['server']['port'] + + +@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 + + :id: 42b4560c-bb57-4c58-928e-e5fd5046b93f + + :expectedresults: Successful deletion of a host through the table dropdown + + :CaseComponent:Hosts-Content + + :Team: Phoenix-subscriptions + """ + host = target_sat.api.Host(organization=function_org, location=function_location).create() + with target_sat.ui_session() as session: + session.organization.select(function_org.name) + session.location.select(function_location.name) + assert session.all_hosts.delete(host.name) + + +@pytest.mark.tier2 +def test_all_hosts_bulk_delete(target_sat, function_org, function_location, new_host_ui): + """Create several hosts, and delete them via Bulk Actions in All Hosts UI + + :id: af1b4a66-dd83-47c3-904b-e8627119cc53 + + :expectedresults: Successful deletion of multiple hosts at once through Bulk Action + + :CaseComponent:Hosts-Content + + :Team: Phoenix-subscriptions + """ + for _ in range(10): + target_sat.api.Host(organization=function_org, location=function_location).create() + with target_sat.ui_session() as session: + session.organization.select(function_org.name) + session.location.select(function_location.name) + assert session.all_hosts.bulk_delete_all() diff --git a/tests/foreman/ui/test_ldap_authentication.py b/tests/foreman/ui/test_ldap_authentication.py index b72d1bbcd8f..1491f23e9d0 100644 --- a/tests/foreman/ui/test_ldap_authentication.py +++ b/tests/foreman/ui/test_ldap_authentication.py @@ -18,9 +18,7 @@ """ import os -from airgun.session import Session from fauxfactory import gen_url -from nailgun import entities from navmazing import NavigationTriesExceeded import pyotp import pytest @@ -60,43 +58,43 @@ def set_certificate_in_satellite(server_type, target_sat, hostname=None): @pytest.fixture -def ldap_usergroup_name(): +def ldap_usergroup_name(target_sat): """Return some random usergroup name, and attempt to delete such usergroup when test finishes. """ usergroup_name = gen_string('alphanumeric') yield usergroup_name - user_groups = entities.UserGroup().search(query={'search': f'name="{usergroup_name}"'}) + user_groups = target_sat.api.UserGroup().search(query={'search': f'name="{usergroup_name}"'}) if user_groups: user_groups[0].delete() @pytest.fixture -def ldap_tear_down(): +def ldap_tear_down(target_sat): """Teardown the all ldap settings user, usergroup and ldap delete""" yield - ldap_auth_sources = entities.AuthSourceLDAP().search() + ldap_auth_sources = target_sat.api.AuthSourceLDAP().search() for ldap_auth in ldap_auth_sources: - users = entities.User(auth_source=ldap_auth).search() + users = target_sat.api.User(auth_source=ldap_auth).search() for user in users: user.delete() ldap_auth.delete() @pytest.fixture -def external_user_count(): +def external_user_count(target_sat): """return the external auth source user count""" - users = entities.User().search() + users = target_sat.api.User().search() return len([user for user in users if user.auth_source_name == 'External']) @pytest.fixture -def groups_teardown(): +def groups_teardown(target_sat): """teardown for groups created for external/remote groups""" yield # tier down groups for group_name in ('sat_users', 'sat_admins', EXTERNAL_GROUP_NAME): - user_groups = entities.UserGroup().search(query={'search': f'name="{group_name}"'}) + user_groups = target_sat.api.UserGroup().search(query={'search': f'name="{group_name}"'}) if user_groups: user_groups[0].delete() @@ -179,7 +177,7 @@ def test_positive_end_to_end(session, ldap_auth_source, ldap_tear_down): @pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True) @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_create_org_and_loc(session, ldap_auth_source, ldap_tear_down): +def test_positive_create_org_and_loc(session, ldap_auth_source, ldap_tear_down, target_sat): """Create LDAP auth_source with org and loc assigned. :id: 4f595af4-fc01-44c6-a614-a9ec827e3c3c @@ -197,8 +195,8 @@ def test_positive_create_org_and_loc(session, ldap_auth_source, ldap_tear_down): :parametrized: yes """ ldap_data, auth_source = ldap_auth_source - org = entities.Organization().create() - loc = entities.Location().create() + org = target_sat.api.Organization().create() + loc = target_sat.api.Location().create() ldap_auth_name = gen_string('alphanumeric') with session: session.ldapauthentication.create( @@ -263,7 +261,7 @@ def test_positive_add_katello_role( auth_source_name = f'LDAP-{auth_source.name}' ak_name = gen_string('alpha') user_permissions = {'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey']} - katello_role = entities.Role().create() + katello_role = target_sat.api.Role().create() target_sat.api_factory.create_role_permissions(katello_role, user_permissions) with session: session.usergroup.create( @@ -276,7 +274,9 @@ def test_positive_add_katello_role( ) assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME) - with Session(test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']) as session: + with target_sat.ui_session( + test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] + ) as session: with pytest.raises(NavigationTriesExceeded): session.architecture.search('') session.activationkey.create({'name': ak_name}) @@ -315,8 +315,8 @@ def test_positive_update_external_roles( ak_name = gen_string('alpha') auth_source_name = f'LDAP-{auth_source.name}' location_name = gen_string('alpha') - foreman_role = entities.Role().create() - katello_role = entities.Role().create() + foreman_role = target_sat.api.Role().create() + katello_role = target_sat.api.Role().create() foreman_permissions = {'Location': PERMISSIONS['Location']} katello_permissions = {'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey']} target_sat.api_factory.create_role_permissions(foreman_role, foreman_permissions) @@ -331,19 +331,23 @@ def test_positive_update_external_roles( } ) assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name - with Session( + with target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: with pytest.raises(NavigationTriesExceeded): ldapsession.architecture.search('') ldapsession.location.create({'name': location_name}) - location = entities.Location().search(query={'search': f'name="{location_name}"'})[0] + location = target_sat.api.Location().search( + query={'search': f'name="{location_name}"'} + )[0] assert location.name == location_name session.usergroup.update( ldap_usergroup_name, {'roles.resources.assigned': [katello_role.name]} ) session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME) - with Session(test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']) as session: + with target_sat.ui_session( + test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] + ) as session: session.activationkey.create({'name': ak_name}) assert session.activationkey.search(ak_name)[0]['Name'] == ak_name current_user = session.activationkey.read(ak_name, 'current_user')['current_user'] @@ -381,7 +385,7 @@ def test_positive_delete_external_roles( ldap_data, auth_source = ldap_auth_source auth_source_name = f'LDAP-{auth_source.name}' location_name = gen_string('alpha') - foreman_role = entities.Role().create() + foreman_role = target_sat.api.Role().create() foreman_permissions = {'Location': PERMISSIONS['Location']} target_sat.api_factory.create_role_permissions(foreman_role, foreman_permissions) with session: @@ -394,18 +398,20 @@ def test_positive_delete_external_roles( } ) assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name - with Session( + with target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: with pytest.raises(NavigationTriesExceeded): ldapsession.architecture.search('') ldapsession.location.create({'name': location_name}) - location = entities.Location().search(query={'search': f'name="{location_name}"'})[0] + location = target_sat.api.Location().search( + query={'search': f'name="{location_name}"'} + )[0] assert location.name == location_name session.usergroup.update( ldap_usergroup_name, {'roles.resources.unassigned': [foreman_role.name]} ) - with Session( + with target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: with pytest.raises(NavigationTriesExceeded): @@ -448,8 +454,8 @@ def test_positive_update_external_user_roles( ak_name = gen_string('alpha') auth_source_name = f'LDAP-{auth_source.name}' location_name = gen_string('alpha') - foreman_role = entities.Role().create() - katello_role = entities.Role().create() + foreman_role = target_sat.api.Role().create() + katello_role = target_sat.api.Role().create() foreman_permissions = {'Location': PERMISSIONS['Location']} katello_permissions = {'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey']} target_sat.api_factory.create_role_permissions(foreman_role, foreman_permissions) @@ -464,17 +470,21 @@ def test_positive_update_external_user_roles( } ) assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name - with Session( + with target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: ldapsession.location.create({'name': location_name}) - location = entities.Location().search(query={'search': f'name="{location_name}"'})[0] + location = target_sat.api.Location().search( + query={'search': f'name="{location_name}"'} + )[0] assert location.name == location_name session.location.select(ANY_CONTEXT['location']) session.user.update( ldap_data['ldap_user_name'], {'roles.resources.assigned': [katello_role.name]} ) - with Session(test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']) as session: + with target_sat.ui_session( + test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] + ) as session: with pytest.raises(NavigationTriesExceeded): ldapsession.architecture.search('') session.activationkey.create({'name': ak_name}) @@ -492,6 +502,7 @@ def test_positive_add_admin_role_with_org_loc( module_org, ldap_tear_down, ldap_auth_source, + target_sat, ): """Associate Admin role to User Group with org and loc set. [belonging to external User Group.] @@ -528,7 +539,9 @@ def test_positive_add_admin_role_with_org_loc( } ) assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name - with Session(test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']) as session: + with target_sat.ui_session( + test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] + ) as session: session.location.create({'name': location_name}) assert session.location.search(location_name)[0]['Name'] == location_name location = session.location.read(location_name, ['current_user', 'primary']) @@ -583,7 +596,7 @@ def test_positive_add_foreman_role_with_org_loc( 'Location': ['assign_locations'], 'Organization': ['assign_organizations'], } - foreman_role = entities.Role().create() + foreman_role = module_target_sat.api.Role().create() module_target_sat.api_factory.create_role_permissions(foreman_role, user_permissions) with session: session.usergroup.create( @@ -596,7 +609,7 @@ def test_positive_add_foreman_role_with_org_loc( ) assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME) - with Session( + with module_target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: with pytest.raises(NavigationTriesExceeded): @@ -648,9 +661,9 @@ def test_positive_add_katello_role_with_org( 'Location': ['assign_locations'], 'Organization': ['assign_organizations'], } - katello_role = entities.Role().create() + katello_role = target_sat.api.Role().create() target_sat.api_factory.create_role_permissions(katello_role, user_permissions) - different_org = entities.Organization().create() + different_org = target_sat.api.Organization().create() with session: session.usergroup.create( { @@ -662,7 +675,7 @@ def test_positive_add_katello_role_with_org( ) assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME) - with Session( + with target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: with pytest.raises(NavigationTriesExceeded): @@ -673,7 +686,7 @@ def test_positive_add_katello_role_with_org( session.organization.select(different_org.name) assert not session.activationkey.search(ak_name)[0]['Name'] == ak_name ak = ( - entities.ActivationKey(organization=module_org) + target_sat.api.ActivationKey(organization=module_org) .search(query={'search': f'name={ak_name}'})[0] .read() ) @@ -706,7 +719,7 @@ def test_positive_create_user_in_ldap_mode(session, ldap_auth_source, ldap_tear_ @pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA'], indirect=True) @pytest.mark.tier2 -def test_positive_login_user_no_roles(test_name, ldap_tear_down, ldap_auth_source): +def test_positive_login_user_no_roles(test_name, ldap_tear_down, ldap_auth_source, target_sat): """Login with LDAP Auth for user with no roles/rights :id: 7dc8d9a7-ff08-4d8e-a842-d370ffd69741 @@ -723,7 +736,7 @@ def test_positive_login_user_no_roles(test_name, ldap_tear_down, ldap_auth_sourc :parametrized: yes """ ldap_data, auth_source = ldap_auth_source - with Session( + with target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: ldapsession.task.read_all() @@ -750,17 +763,17 @@ def test_positive_login_user_basic_roles( """ ldap_data, auth_source = ldap_auth_source name = gen_string('alpha') - role = entities.Role().create() + role = target_sat.api.Role().create() permissions = {'Architecture': PERMISSIONS['Architecture']} target_sat.api_factory.create_role_permissions(role, permissions) - with Session( + with target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: with pytest.raises(NavigationTriesExceeded): ldapsession.usergroup.search('') with session: session.user.update(ldap_data['ldap_user_name'], {'roles.resources.assigned': [role.name]}) - with Session( + with target_sat.ui_session( test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd'] ) as ldapsession: ldapsession.architecture.create({'name': name}) @@ -770,7 +783,7 @@ def test_positive_login_user_basic_roles( @pytest.mark.upgrade @pytest.mark.tier2 def test_positive_login_user_password_otp( - auth_source_ipa, default_ipa_host, test_name, ldap_tear_down + auth_source_ipa, default_ipa_host, test_name, ldap_tear_down, target_sat ): """Login with password with time based OTP @@ -788,16 +801,20 @@ def test_positive_login_user_password_otp( otp_pass = ( f"{default_ipa_host.ldap_user_passwd}{generate_otp(default_ipa_host.time_based_secret)}" ) - with Session(test_name, default_ipa_host.ipa_otp_username, otp_pass) as ldapsession: + with target_sat.ui_session( + test_name, default_ipa_host.ipa_otp_username, otp_pass + ) as ldapsession: with pytest.raises(NavigationTriesExceeded): ldapsession.user.search('') - users = entities.User().search(query={'search': f'login="{default_ipa_host.ipa_otp_username}"'}) + users = target_sat.api.User().search( + query={'search': f'login="{default_ipa_host.ipa_otp_username}"'} + ) assert users[0].login == default_ipa_host.ipa_otp_username @pytest.mark.tier2 def test_negative_login_user_with_invalid_password_otp( - auth_source_ipa, default_ipa_host, test_name, ldap_tear_down + auth_source_ipa, default_ipa_host, test_name, ldap_tear_down, target_sat ): """Login with password with time based OTP @@ -815,7 +832,9 @@ def test_negative_login_user_with_invalid_password_otp( password_with_otp = ( f"{default_ipa_host.ldap_user_passwd}{gen_string(str_type='numeric', length=6)}" ) - with Session(test_name, default_ipa_host.ipa_otp_username, password_with_otp) as ldapsession: + with target_sat.ui_session( + test_name, default_ipa_host.ipa_otp_username, password_with_otp + ) as ldapsession: with pytest.raises(NavigationTriesExceeded) as error: ldapsession.user.search('') assert error.typename == 'NavigationTriesExceeded' @@ -843,7 +862,7 @@ def test_positive_test_connection_functionality(session, ldap_auth_source): @pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True) @pytest.mark.tier2 -def test_negative_login_with_incorrect_password(test_name, ldap_auth_source): +def test_negative_login_with_incorrect_password(test_name, ldap_auth_source, target_sat): """Attempt to login in Satellite an user with the wrong password :id: 3f09de90-a656-11ea-aa43-4ceb42ab8dbc @@ -860,7 +879,7 @@ def test_negative_login_with_incorrect_password(test_name, ldap_auth_source): """ ldap_data, auth_source = ldap_auth_source incorrect_password = gen_string('alphanumeric') - with Session( + with target_sat.ui_session( test_name, user=ldap_data['ldap_user_name'], password=incorrect_password ) as ldapsession: with pytest.raises(NavigationTriesExceeded) as error: @@ -869,7 +888,9 @@ def test_negative_login_with_incorrect_password(test_name, ldap_auth_source): @pytest.mark.tier2 -def test_negative_login_with_disable_user(default_ipa_host, auth_source_ipa, ldap_tear_down): +def test_negative_login_with_disable_user( + default_ipa_host, auth_source_ipa, ldap_tear_down, target_sat +): """Disabled IDM user cannot login :id: 49f28006-aa1f-11ea-90d3-4ceb42ab8dbc @@ -880,7 +901,7 @@ def test_negative_login_with_disable_user(default_ipa_host, auth_source_ipa, lda :expectedresults: Login fails """ - with Session( + with target_sat.ui_session( user=default_ipa_host.disabled_user_ipa, password=default_ipa_host.ldap_user_passwd ) as ldapsession: with pytest.raises(NavigationTriesExceeded) as error: @@ -890,7 +911,7 @@ def test_negative_login_with_disable_user(default_ipa_host, auth_source_ipa, lda @pytest.mark.tier2 def test_email_of_the_user_should_be_copied( - session, default_ipa_host, auth_source_ipa, ldap_tear_down + session, default_ipa_host, auth_source_ipa, ldap_tear_down, target_sat ): """Email of the user created in idm server ( set as external authorization source ) should be copied to the satellite. @@ -911,7 +932,7 @@ def test_email_of_the_user_should_be_copied( if 'Email' in line: _, result = line.split(': ', 2) break - with Session( + with target_sat.ui_session( user=default_ipa_host.ldap_user_name, password=default_ipa_host.ldap_user_passwd ) as ldapsession: ldapsession.bookmark.search('controller = hosts') @@ -938,10 +959,10 @@ def test_deleted_idm_user_should_not_be_able_to_login( """ test_user = gen_string('alpha') default_ipa_host.create_user(test_user) - with Session(user=test_user, password=settings.ipa.password) as ldapsession: + with target_sat.ui_session(user=test_user, password=settings.ipa.password) as ldapsession: ldapsession.bookmark.search('controller = hosts') default_ipa_host.delete_user(test_user) - with Session(user=test_user, password=settings.ipa.password) as ldapsession: + with target_sat.ui_session(user=test_user, password=settings.ipa.password) as ldapsession: with pytest.raises(NavigationTriesExceeded) as error: ldapsession.user.search('') assert error.typename == 'NavigationTriesExceeded' @@ -949,7 +970,7 @@ def test_deleted_idm_user_should_not_be_able_to_login( @pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True) @pytest.mark.tier2 -def test_onthefly_functionality(session, ldap_auth_source, ldap_tear_down): +def test_onthefly_functionality(session, ldap_auth_source, ldap_tear_down, target_sat): """User will not be created automatically in Satellite if onthefly is disabled @@ -984,7 +1005,7 @@ def test_onthefly_functionality(session, ldap_auth_source, ldap_tear_down): 'attribute_mappings.mail': LDAP_ATTR['mail'], } ) - with Session( + with target_sat.ui_session( user=ldap_data['ldap_user_name'], password=ldap_data['ldap_user_passwd'] ) as ldapsession: with pytest.raises(NavigationTriesExceeded) as error: @@ -1035,7 +1056,9 @@ def test_timeout_and_cac_card_ejection(): @pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True) @pytest.mark.tier2 @pytest.mark.skip_if_open('BZ:1670397') -def test_verify_attribute_of_users_are_updated(session, ldap_auth_source, ldap_tear_down): +def test_verify_attribute_of_users_are_updated( + session, ldap_auth_source, ldap_tear_down, target_sat +): """Verify if attributes of LDAP user are updated upon first login when onthefly is disabled @@ -1083,7 +1106,7 @@ def test_verify_attribute_of_users_are_updated(session, ldap_auth_source, ldap_t 'roles.admin': True, } ) - with Session( + with target_sat.ui_session( user=ldap_data['ldap_user_name'], password=ldap_data['ldap_user_passwd'] ) as ldapsession: with pytest.raises(NavigationTriesExceeded) as error: @@ -1100,7 +1123,7 @@ def test_verify_attribute_of_users_are_updated(session, ldap_auth_source, ldap_t @pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True) @pytest.mark.tier2 def test_login_failure_if_internal_user_exist( - session, test_name, ldap_auth_source, module_org, module_location, ldap_tear_down + session, test_name, ldap_auth_source, module_org, module_location, ldap_tear_down, target_sat ): """Verify the failure of login for the AD/IPA user in case same username internal user exists @@ -1122,19 +1145,21 @@ def test_login_failure_if_internal_user_exist( try: internal_username = ldap_data['ldap_user_name'] internal_password = gen_string('alphanumeric') - user = entities.User( + user = target_sat.api.User( admin=True, default_organization=module_org, default_location=module_location, login=internal_username, password=internal_password, ).create() - with Session(test_name, internal_username, ldap_data['ldap_user_passwd']) as ldapsession: + with target_sat.ui_session( + test_name, internal_username, ldap_data['ldap_user_passwd'] + ) as ldapsession: with pytest.raises(NavigationTriesExceeded) as error: ldapsession.user.search('') assert error.typename == 'NavigationTriesExceeded' finally: - entities.User(id=user.id).delete() + target_sat.api.User(id=user.id).delete() @pytest.mark.skip_if_open("BZ:1812688") @@ -1172,7 +1197,7 @@ def test_userlist_with_external_admin( auth_source_name = f'LDAP-{auth_source_ipa.name}' user_permissions = {'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey']} - katello_role = entities.Role().create() + katello_role = target_sat.api.Role().create() target_sat.api_factory.create_role_permissions(katello_role, user_permissions) with session: session.usergroup.create( @@ -1191,12 +1216,14 @@ def test_userlist_with_external_admin( 'external_groups.auth_source': auth_source_name, } ) - with Session(user=idm_user, password=settings.server.ssh_password) as ldapsession: + with target_sat.ui_session(user=idm_user, password=settings.server.ssh_password) as ldapsession: assert idm_user in ldapsession.task.read_all()['current_user'] # verify the users count with local admin and remote/external admin - with Session(user=idm_admin, password=settings.server.ssh_password) as remote_admin_session: - with Session( + with target_sat.ui_session( + user=idm_admin, password=settings.server.ssh_password + ) as remote_admin_session: + with target_sat.ui_session( user=settings.server.admin_username, password=settings.server.admin_password ) as local_admin_session: assert local_admin_session.user.search(idm_user)[0]['Username'] == idm_user @@ -1231,7 +1258,7 @@ def test_positive_group_sync_open_ldap_authsource( ak_name = gen_string('alpha') auth_source_name = f'LDAP-{auth_source_open_ldap.name}' user_permissions = {'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey']} - katello_role = entities.Role().create() + katello_role = target_sat.api.Role().create() target_sat.api_factory.create_role_permissions(katello_role, user_permissions) with session: session.usergroup.create( @@ -1245,7 +1272,7 @@ def test_positive_group_sync_open_ldap_authsource( assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME) user_name = open_ldap_data.open_ldap_user - with Session(test_name, user_name, open_ldap_data.password) as session: + with target_sat.ui_session(test_name, user_name, open_ldap_data.password) as session: with pytest.raises(NavigationTriesExceeded): session.architecture.search('') session.activationkey.create({'name': ak_name}) @@ -1281,7 +1308,7 @@ def test_verify_group_permissions( idm_users = settings.ipa.group_users auth_source_name = f'LDAP-{auth_source_ipa.name}' user_permissions = {None: ['access_dashboard']} - katello_role = entities.Role().create() + katello_role = target_sat.api.Role().create() target_sat.api_factory.create_role_permissions(katello_role, user_permissions) with session: session.usergroup.create( @@ -1301,15 +1328,17 @@ def test_verify_group_permissions( } ) location_name = gen_string('alpha') - with Session(user=idm_users[1], password=settings.server.ssh_password) as ldapsession: + with target_sat.ui_session( + user=idm_users[1], password=settings.server.ssh_password + ) as ldapsession: ldapsession.location.create({'name': location_name}) - location = entities.Location().search(query={'search': f'name="{location_name}"'})[0] + location = target_sat.api.Location().search(query={'search': f'name="{location_name}"'})[0] assert location.name == location_name @pytest.mark.tier2 def test_verify_ldap_filters_ipa( - session, ipa_add_user, auth_source_ipa, default_ipa_host, ldap_tear_down + session, ipa_add_user, auth_source_ipa, default_ipa_host, ldap_tear_down, target_sat ): """Verifying ldap filters in authsource to restrict access @@ -1326,7 +1355,9 @@ def test_verify_ldap_filters_ipa( # 'test_user' able to login before the filter is applied. test_user = ipa_add_user - with Session(user=test_user, password=default_ipa_host.ldap_user_passwd) as ldapsession: + with target_sat.ui_session( + user=test_user, password=default_ipa_host.ldap_user_passwd + ) as ldapsession: ldapsession.task.read_all() # updating the authsource with filter @@ -1335,7 +1366,9 @@ def test_verify_ldap_filters_ipa( session.ldapauthentication.update(auth_source_ipa.name, {'account.ldap_filter': ldap_data}) # 'test_user' not able login as it gets filtered out - with Session(user=test_user, password=default_ipa_host.ldap_user_passwd) as ldapsession: + with target_sat.ui_session( + user=test_user, password=default_ipa_host.ldap_user_passwd + ) as ldapsession: with pytest.raises(NavigationTriesExceeded) as error: ldapsession.user.search('') assert error.typename == 'NavigationTriesExceeded' diff --git a/tests/foreman/ui/test_lifecycleenvironment.py b/tests/foreman/ui/test_lifecycleenvironment.py index 5ff44751f6e..4f49f867c95 100644 --- a/tests/foreman/ui/test_lifecycleenvironment.py +++ b/tests/foreman/ui/test_lifecycleenvironment.py @@ -16,7 +16,6 @@ :Upstream: No """ -from airgun.session import Session from navmazing import NavigationTriesExceeded import pytest @@ -315,7 +314,7 @@ def test_positive_custom_user_view_lce(session, test_name, target_sat): lce_values = session.lifecycleenvironment.read_all() assert lce_name in lce_values['lce'] # ensure the created user also can find the created lifecycle environment link - with Session(test_name, user_login, user_password) as non_admin_session: + with target_sat.ui_session(test_name, user_login, user_password) as non_admin_session: # to ensure that the created user has only the assigned # permissions, check that hosts menu tab does not exist with pytest.raises(NavigationTriesExceeded): diff --git a/tests/foreman/ui/test_repository.py b/tests/foreman/ui/test_repository.py index 8395d096967..60ee23aa93b 100644 --- a/tests/foreman/ui/test_repository.py +++ b/tests/foreman/ui/test_repository.py @@ -19,8 +19,6 @@ from datetime import datetime, timedelta from random import randint, shuffle -from airgun.session import Session -from nailgun import entities from navmazing import NavigationTriesExceeded import pytest @@ -46,19 +44,19 @@ @pytest.fixture(scope='module') -def module_org(): - return entities.Organization().create() +def module_org(module_target_sat): + return module_target_sat.api.Organization().create() @pytest.fixture(scope='module') -def module_prod(module_org): - return entities.Product(organization=module_org).create() +def module_prod(module_org, module_target_sat): + return module_target_sat.api.Product(organization=module_org).create() @pytest.mark.tier2 @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_create_in_different_orgs(session, module_org): +def test_positive_create_in_different_orgs(session, module_org, module_target_sat): """Create repository in two different orgs with same name :id: 019c2242-8802-4bae-82c5-accf8f793dbc @@ -69,9 +67,9 @@ def test_positive_create_in_different_orgs(session, module_org): :CaseLevel: Integration """ repo_name = gen_string('alpha') - org2 = entities.Organization().create() - prod1 = entities.Product(organization=module_org).create() - prod2 = entities.Product(organization=org2).create() + org2 = module_target_sat.api.Organization().create() + prod1 = module_target_sat.api.Product(organization=module_org).create() + prod2 = module_target_sat.api.Product(organization=org2).create() with session: for org, prod in [[module_org, prod1], [org2, prod2]]: session.organization.select(org_name=org.name) @@ -116,9 +114,9 @@ def test_positive_create_as_non_admin_user(module_org, test_name, target_sat): 'sync_products', ], } - role = entities.Role().create() + role = target_sat.api.Role().create() target_sat.api_factory.create_role_permissions(role, user_permissions) - entities.User( + target_sat.api.User( login=user_login, password=user_password, role=[role], @@ -126,8 +124,8 @@ def test_positive_create_as_non_admin_user(module_org, test_name, target_sat): default_organization=module_org, organization=[module_org], ).create() - product = entities.Product(organization=module_org).create() - with Session(test_name, user=user_login, password=user_password) as session: + product = target_sat.api.Product(organization=module_org).create() + with target_sat.ui_session(test_name, user=user_login, password=user_password) as session: # ensure that the created user is not a global admin user # check administer->organizations page with pytest.raises(NavigationTriesExceeded): @@ -146,7 +144,7 @@ def test_positive_create_as_non_admin_user(module_org, test_name, target_sat): @pytest.mark.tier2 @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_create_yum_repo_same_url_different_orgs(session, module_prod): +def test_positive_create_yum_repo_same_url_different_orgs(session, module_prod, module_target_sat): """Create two repos with the same URL in two different organizations. :id: f4cb00ed-6faf-4c79-9f66-76cd333299cb @@ -156,12 +154,16 @@ def test_positive_create_yum_repo_same_url_different_orgs(session, module_prod): :CaseLevel: Integration """ # Create first repository - repo = entities.Repository(product=module_prod, url=settings.repos.yum_0.url).create() + repo = module_target_sat.api.Repository( + product=module_prod, url=settings.repos.yum_0.url + ).create() repo.sync() # Create second repository - org = entities.Organization().create() - product = entities.Product(organization=org).create() - new_repo = entities.Repository(product=product, url=settings.repos.yum_0.url).create() + org = module_target_sat.api.Organization().create() + product = module_target_sat.api.Product(organization=org).create() + new_repo = module_target_sat.api.Repository( + product=product, url=settings.repos.yum_0.url + ).create() new_repo.sync() with session: # Check packages number in first repository @@ -207,9 +209,9 @@ def test_positive_create_as_non_admin_user_with_cv_published(module_org, test_na 'sync_products', ], } - role = entities.Role().create() + role = target_sat.api.Role().create() target_sat.api_factory.create_role_permissions(role, user_permissions) - entities.User( + target_sat.api.User( login=user_login, password=user_password, role=[role], @@ -217,14 +219,14 @@ def test_positive_create_as_non_admin_user_with_cv_published(module_org, test_na default_organization=module_org, organization=[module_org], ).create() - prod = entities.Product(organization=module_org).create() - repo = entities.Repository(product=prod, url=settings.repos.yum_2.url).create() + prod = target_sat.api.Product(organization=module_org).create() + repo = target_sat.api.Repository(product=prod, url=settings.repos.yum_2.url).create() repo.sync() - content_view = entities.ContentView(organization=module_org).create() + content_view = target_sat.api.ContentView(organization=module_org).create() content_view.repository = [repo] content_view = content_view.update(['repository']) content_view.publish() - with Session(test_name, user_login, user_password) as session: + with target_sat.ui_session(test_name, user_login, user_password) as session: # ensure that the created user is not a global admin user # check administer->users page pswd = gen_string('alphanumeric') @@ -256,7 +258,7 @@ def test_positive_create_as_non_admin_user_with_cv_published(module_org, test_na @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') @pytest.mark.usefixtures('allow_repo_discovery') -def test_positive_discover_repo_via_existing_product(session, module_org): +def test_positive_discover_repo_via_existing_product(session, module_org, module_target_sat): """Create repository via repo-discovery under existing product :id: 9181950c-a756-456f-a46a-059e7a2add3c @@ -266,7 +268,7 @@ def test_positive_discover_repo_via_existing_product(session, module_org): :CaseLevel: Integration """ repo_name = 'fakerepo01' - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() with session: session.organization.select(org_name=module_org.name) session.product.discover_repo( @@ -314,7 +316,9 @@ def test_positive_discover_repo_via_new_product(session, module_org): @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') @pytest.mark.usefixtures('allow_repo_discovery') -def test_positive_discover_module_stream_repo_via_existing_product(session, module_org): +def test_positive_discover_module_stream_repo_via_existing_product( + session, module_org, module_target_sat +): """Create repository with module streams via repo-discovery under an existing product. :id: e7b9e2c4-7ecd-4cde-8f74-961fbac8919c @@ -334,7 +338,7 @@ def test_positive_discover_module_stream_repo_via_existing_product(session, modu """ repo_name = gen_string('alpha') repo_label = gen_string('alpha') - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() with session: session.organization.select(org_name=module_org.name) session.product.discover_repo( @@ -355,7 +359,7 @@ def test_positive_discover_module_stream_repo_via_existing_product(session, modu @pytest.mark.tier2 @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_sync_custom_repo_yum(session, module_org): +def test_positive_sync_custom_repo_yum(session, module_org, module_target_sat): """Create Custom yum repos and sync it via the repos page. :id: afa218f4-e97a-4240-a82a-e69538d837a1 @@ -364,8 +368,8 @@ def test_positive_sync_custom_repo_yum(session, module_org): :CaseLevel: Integration """ - product = entities.Product(organization=module_org).create() - repo = entities.Repository(url=settings.repos.yum_1.url, product=product).create() + product = module_target_sat.api.Product(organization=module_org).create() + repo = module_target_sat.api.Repository(url=settings.repos.yum_1.url, product=product).create() with session: result = session.repository.synchronize(product.name, repo.name) assert result['result'] == 'success' @@ -378,7 +382,7 @@ def test_positive_sync_custom_repo_yum(session, module_org): @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_sync_custom_repo_docker(session, module_org): +def test_positive_sync_custom_repo_docker(session, module_org, module_target_sat): """Create Custom docker repos and sync it via the repos page. :id: 942e0b4f-3524-4f00-812d-bdad306f81de @@ -388,8 +392,8 @@ def test_positive_sync_custom_repo_docker(session, module_org): :CaseLevel: Integration """ - product = entities.Product(organization=module_org).create() - repo = entities.Repository( + product = module_target_sat.api.Product(organization=module_org).create() + repo = module_target_sat.api.Repository( url=CONTAINER_REGISTRY_HUB, product=product, content_type=REPO_TYPE['docker'] ).create() with session: @@ -399,7 +403,7 @@ def test_positive_sync_custom_repo_docker(session, module_org): @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_resync_custom_repo_after_invalid_update(session, module_org): +def test_positive_resync_custom_repo_after_invalid_update(session, module_org, module_target_sat): """Create Custom yum repo and sync it via the repos page. Then try to change repo url to invalid one and re-sync that repository @@ -414,8 +418,8 @@ def test_positive_resync_custom_repo_after_invalid_update(session, module_org): :CaseLevel: Integration """ - product = entities.Product(organization=module_org).create() - repo = entities.Repository(url=settings.repos.yum_1.url, product=product).create() + product = module_target_sat.api.Product(organization=module_org).create() + repo = module_target_sat.api.Repository(url=settings.repos.yum_1.url, product=product).create() with session: result = session.repository.synchronize(product.name, repo.name) assert result['result'] == 'success' @@ -433,7 +437,7 @@ def test_positive_resync_custom_repo_after_invalid_update(session, module_org): @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_resynchronize_rpm_repo(session, module_prod): +def test_positive_resynchronize_rpm_repo(session, module_prod, module_target_sat): """Check that repository content is resynced after packages were removed from repository @@ -445,7 +449,7 @@ def test_positive_resynchronize_rpm_repo(session, module_prod): :BZ: 1318004 """ - repo = entities.Repository( + repo = module_target_sat.api.Repository( url=settings.repos.yum_1.url, content_type=REPO_TYPE['yum'], product=module_prod ).create() with session: @@ -469,7 +473,7 @@ def test_positive_resynchronize_rpm_repo(session, module_prod): @pytest.mark.tier2 @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_end_to_end_custom_yum_crud(session, module_org, module_prod): +def test_positive_end_to_end_custom_yum_crud(session, module_org, module_prod, module_target_sat): """Perform end to end testing for custom yum repository :id: 8baf11c9-019e-4625-a549-ec4cd9312f75 @@ -484,11 +488,11 @@ def test_positive_end_to_end_custom_yum_crud(session, module_org, module_prod): checksum_type = 'sha256' new_repo_name = gen_string('alphanumeric') new_checksum_type = 'sha1' - gpg_key = entities.GPGKey( + gpg_key = module_target_sat.api.GPGKey( content=DataFile.VALID_GPG_KEY_FILE.read_bytes(), organization=module_org, ).create() - new_gpg_key = entities.GPGKey( + new_gpg_key = module_target_sat.api.GPGKey( content=DataFile.VALID_GPG_KEY_BETA_FILE.read_bytes(), organization=module_org, ).create() @@ -801,7 +805,7 @@ def test_positive_reposet_disable_after_manifest_deleted( :CaseLevel: Integration """ org = function_entitlement_manifest_org - sub = entities.Subscription(organization=org) + sub = target_sat.api.Subscription(organization=org) sat_tools_repo = target_sat.cli_factory.SatelliteToolsRepository(distro='rhel7', cdn=True) repository_name = sat_tools_repo.data['repository'] repository_name_orphaned = f'{repository_name} (Orphaned)' @@ -841,7 +845,7 @@ def test_positive_reposet_disable_after_manifest_deleted( @pytest.mark.tier2 -def test_positive_delete_random_docker_repo(session, module_org): +def test_positive_delete_random_docker_repo(session, module_org, module_target_sat): """Create Docker-type repositories on multiple products and delete a random repository from a random product. @@ -853,9 +857,12 @@ def test_positive_delete_random_docker_repo(session, module_org): :CaseLevel: Integration """ entities_list = [] - products = [entities.Product(organization=module_org).create() for _ in range(randint(2, 5))] + products = [ + module_target_sat.api.Product(organization=module_org).create() + for _ in range(randint(2, 5)) + ] for product in products: - repo = entities.Repository( + repo = module_target_sat.api.Repository( url=CONTAINER_REGISTRY_HUB, product=product, content_type=REPO_TYPE['docker'] ).create() entities_list.append((product.name, repo.name)) @@ -1227,7 +1234,7 @@ def test_positive_select_org_in_any_context(): @pytest.mark.tier2 @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_sync_repo_and_verify_checksum(session, module_org): +def test_positive_sync_repo_and_verify_checksum(session, module_org, module_target_sat): """Tests that Verify Content Checksum succeeds when executing from the products page :id: 577be1f8-7510-49d2-8b33-600db60bd960 @@ -1243,7 +1250,7 @@ def test_positive_sync_repo_and_verify_checksum(session, module_org): :expectedresults: Verify Content Checksum task succeeds """ repo_name = gen_string('alpha') - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() with session: session.repository.create( product.name, @@ -1259,7 +1266,7 @@ def test_positive_sync_repo_and_verify_checksum(session, module_org): @pytest.mark.tier2 -def test_positive_sync_sha_repo(session, module_org): +def test_positive_sync_sha_repo(session, module_org, module_target_sat): """Sync 'sha' repo successfully :id: 6172035f-96c4-41e4-a79b-acfaa78ad734 @@ -1271,7 +1278,7 @@ def test_positive_sync_sha_repo(session, module_org): :SubComponent: Candlepin """ repo_name = gen_string('alpha') - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() with session: session.repository.create( product.name, @@ -1286,7 +1293,7 @@ def test_positive_sync_sha_repo(session, module_org): @pytest.mark.tier2 -def test_positive_sync_third_party_repo(session, module_org): +def test_positive_sync_third_party_repo(session, module_org, module_target_sat): """Sync third part repo successfully :id: 655161e0-aa90-4c7c-9a0d-cb5b9f56eac3 @@ -1298,7 +1305,7 @@ def test_positive_sync_third_party_repo(session, module_org): :SubComponent: Pulp """ repo_name = gen_string('alpha') - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() with session: session.repository.create( product.name, diff --git a/tests/foreman/ui/test_role.py b/tests/foreman/ui/test_role.py index 86b93fd7baa..9a3b1ef9708 100644 --- a/tests/foreman/ui/test_role.py +++ b/tests/foreman/ui/test_role.py @@ -18,8 +18,6 @@ """ import random -from airgun.session import Session -from nailgun import entities from navmazing import NavigationTriesExceeded import pytest @@ -30,7 +28,7 @@ @pytest.mark.e2e @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_end_to_end(session, module_org, module_location): +def test_positive_end_to_end(session, module_org, module_location, module_target_sat): """Perform end to end testing for role component :id: 3284016a-e2df-4a0e-aa24-c95ab132eec1 @@ -52,8 +50,8 @@ def test_positive_end_to_end(session, module_org, module_location): cloned_role_name = gen_string('alpha') new_role_name = gen_string('alpha') new_role_description = gen_string('alpha') - new_org = entities.Organization().create() - new_loc = entities.Location(organization=[new_org]).create() + new_org = module_target_sat.api.Organization().create() + new_loc = module_target_sat.api.Location(organization=[new_org]).create() with session: session.role.create( { @@ -163,7 +161,9 @@ def test_positive_delete_cloned_builtin(session): @pytest.mark.tier2 -def test_positive_create_filter_without_override(session, module_org, module_location, test_name): +def test_positive_create_filter_without_override( + session, module_org, module_location, test_name, module_target_sat +): """Create filter in role w/o overriding it :id: a7f76f6e-6c13-4b34-b38c-19501b65786f @@ -185,7 +185,7 @@ def test_positive_create_filter_without_override(session, module_org, module_loc role_name = gen_string('alpha') username = gen_string('alpha') password = gen_string('alpha') - subnet = entities.Subnet() + subnet = module_target_sat.api.Subnet() subnet.create_missing() subnet_name = subnet.name with session: @@ -229,7 +229,7 @@ def test_positive_create_filter_without_override(session, module_org, module_loc 'locations.resources.assigned': [module_location.name], } ) - with Session(test_name, user=username, password=password) as session: + with module_target_sat.ui_session(test_name, user=username, password=password) as session: session.subnet.create( { 'subnet.name': subnet_name, @@ -246,7 +246,9 @@ def test_positive_create_filter_without_override(session, module_org, module_loc @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_create_non_overridable_filter(session, module_org, module_location, test_name): +def test_positive_create_non_overridable_filter( + session, module_org, module_location, test_name, module_target_sat +): """Create non overridden filter in role :id: 5ee281cf-28fa-439d-888d-b1f9aacc6d57 @@ -269,9 +271,9 @@ def test_positive_create_non_overridable_filter(session, module_org, module_loca username = gen_string('alpha') password = gen_string('alpha') new_name = gen_string('alpha') - user_org = entities.Organization().create() - user_loc = entities.Location().create() - arch = entities.Architecture().create() + user_org = module_target_sat.api.Organization().create() + user_loc = module_target_sat.api.Location().create() + arch = module_target_sat.api.Architecture().create() with session: session.role.create( { @@ -300,7 +302,7 @@ def test_positive_create_non_overridable_filter(session, module_org, module_loca 'locations.resources.assigned': [user_loc.name], } ) - with Session(test_name, user=username, password=password) as session: + with module_target_sat.ui_session(test_name, user=username, password=password) as session: session.architecture.update(arch.name, {'name': new_name}) assert session.architecture.search(new_name)[0]['Name'] == new_name with pytest.raises(NavigationTriesExceeded): @@ -309,7 +311,9 @@ def test_positive_create_non_overridable_filter(session, module_org, module_loca @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_create_overridable_filter(session, module_org, module_location, test_name): +def test_positive_create_overridable_filter( + session, module_org, module_location, test_name, module_target_sat +): """Create overridden filter in role :id: 325e7e3e-60fc-4182-9585-0449d9660e8d @@ -334,9 +338,9 @@ def test_positive_create_overridable_filter(session, module_org, module_location role_name = gen_string('alpha') username = gen_string('alpha') password = gen_string('alpha') - role_org = entities.Organization().create() - role_loc = entities.Location().create() - subnet = entities.Subnet() + role_org = module_target_sat.api.Organization().create() + role_loc = module_target_sat.api.Location().create() + subnet = module_target_sat.api.Subnet() subnet.create_missing() subnet_name = subnet.name new_subnet_name = gen_string('alpha') @@ -385,7 +389,7 @@ def test_positive_create_overridable_filter(session, module_org, module_location 'locations.resources.assigned': [role_loc.name, module_location.name], } ) - with Session(test_name, user=username, password=password) as session: + with module_target_sat.ui_session(test_name, user=username, password=password) as session: session.organization.select(org_name=module_org.name) session.location.select(loc_name=module_location.name) session.subnet.create( @@ -492,7 +496,7 @@ def test_positive_create_with_sc_parameter_permission(session_puppet_enabled_sat @pytest.mark.tier2 -def test_positive_create_filter_admin_user_with_locs(test_name): +def test_positive_create_filter_admin_user_with_locs(test_name, module_target_sat): """Attempt to create a role filter by admin user, who has 6+ locations assigned. :id: 688ecb7d-1d49-494c-97cc-0d5e715f3bb1 @@ -508,10 +512,10 @@ def test_positive_create_filter_admin_user_with_locs(test_name): role_name = gen_string('alpha') resource_type = 'Architecture' permissions = ['view_architectures', 'edit_architectures'] - org = entities.Organization().create() - locations = [entities.Location(organization=[org]).create() for _ in range(6)] + org = module_target_sat.api.Organization().create() + locations = [module_target_sat.api.Location(organization=[org]).create() for _ in range(6)] password = gen_string('alphanumeric') - user = entities.User( + user = module_target_sat.api.User( admin=True, organization=[org], location=locations, @@ -519,7 +523,7 @@ def test_positive_create_filter_admin_user_with_locs(test_name): default_location=locations[0], password=password, ).create() - with Session(test_name, user=user.login, password=password) as session: + with module_target_sat.ui_session(test_name, user=user.login, password=password) as session: session.role.create({'name': role_name}) assert session.role.search(role_name)[0]['Name'] == role_name session.filter.create( @@ -530,7 +534,7 @@ def test_positive_create_filter_admin_user_with_locs(test_name): @pytest.mark.tier2 -def test_positive_create_filter_admin_user_with_orgs(test_name): +def test_positive_create_filter_admin_user_with_orgs(test_name, module_target_sat): """Attempt to create a role filter by admin user, who has 10 organizations assigned. :id: 04208e17-34b5-46b1-84dd-b8a973521d30 @@ -547,9 +551,9 @@ def test_positive_create_filter_admin_user_with_orgs(test_name): resource_type = 'Architecture' permissions = ['view_architectures', 'edit_architectures'] password = gen_string('alphanumeric') - organizations = [entities.Organization().create() for _ in range(10)] - loc = entities.Location(organization=[organizations[0]]).create() - user = entities.User( + organizations = [module_target_sat.api.Organization().create() for _ in range(10)] + loc = module_target_sat.api.Location(organization=[organizations[0]]).create() + user = module_target_sat.api.User( admin=True, organization=organizations, location=[loc], @@ -557,7 +561,7 @@ def test_positive_create_filter_admin_user_with_orgs(test_name): default_location=loc, password=password, ).create() - with Session(test_name, user=user.login, password=password) as session: + with module_target_sat.ui_session(test_name, user=user.login, password=password) as session: session.role.create({'name': role_name}) assert session.role.search(role_name)[0]['Name'] == role_name session.filter.create( diff --git a/tests/foreman/ui/test_settings.py b/tests/foreman/ui/test_settings.py index 43111a7aadc..ce884b4ae4c 100644 --- a/tests/foreman/ui/test_settings.py +++ b/tests/foreman/ui/test_settings.py @@ -18,9 +18,7 @@ """ import math -from airgun.session import Session from fauxfactory import gen_url -from nailgun import entities import pytest from robottelo.config import settings @@ -33,14 +31,14 @@ def invalid_settings_values(): return [' ', '-1', 'text', '0'] -def add_content_views_to_composite(composite_cv, org, repo): +def add_content_views_to_composite(composite_cv, org, repo, module_target_sat): """Add necessary number of content views to the composite one :param composite_cv: Composite content view object :param org: Organisation of satellite :param repo: repository need to added in content view """ - content_view = entities.ContentView(organization=org).create() + content_view = module_target_sat.api.ContentView(organization=org).create() content_view.repository = [repo] content_view.update(['repository']) content_view.publish() @@ -52,7 +50,9 @@ def add_content_views_to_composite(composite_cv, org, repo): @pytest.mark.run_in_one_thread @pytest.mark.tier3 @pytest.mark.parametrize('setting_update', ['restrict_composite_view'], indirect=True) -def test_positive_update_restrict_composite_view(session, setting_update, repo_setup): +def test_positive_update_restrict_composite_view( + session, setting_update, repo_setup, module_target_sat +): """Update settings parameter restrict_composite_view to Yes/True and ensure a composite content view may not be published or promoted, unless the component content view versions that it includes exist in the target environment. @@ -68,9 +68,11 @@ def test_positive_update_restrict_composite_view(session, setting_update, repo_s :CaseLevel: Acceptance """ property_name = setting_update.name - composite_cv = entities.ContentView(composite=True, organization=repo_setup['org']).create() + composite_cv = module_target_sat.api.ContentView( + composite=True, organization=repo_setup['org'] + ).create() content_view = add_content_views_to_composite( - composite_cv, repo_setup['org'], repo_setup['repo'] + composite_cv, repo_setup['org'], repo_setup['repo'], module_target_sat ) composite_cv.publish() with session: @@ -272,9 +274,9 @@ def test_negative_settings_access_to_non_admin(module_target_sat): """ login = gen_string('alpha') password = gen_string('alpha') - entities.User(admin=False, login=login, password=password).create() + module_target_sat.api.User(admin=False, login=login, password=password).create() try: - with Session(user=login, password=password) as session: + with module_target_sat.ui_session(user=login, password=password) as session: result = session.settings.permission_denied() assert ( result == 'Permission denied You are not authorized to perform this action. ' @@ -393,7 +395,7 @@ def test_positive_update_email_delivery_method_sendmail(session, target_sat): "send_welcome_email": "", } mail_config_default_param = { - content: entities.Setting().search(query={'search': f'name={content}'})[0] + content: target_sat.api.Setting().search(query={'search': f'name={content}'})[0] for content in mail_config_default_param } mail_config_new_params = { diff --git a/tests/foreman/ui/test_subscription.py b/tests/foreman/ui/test_subscription.py index c1fdd1f3c5c..2dd36b03a9f 100644 --- a/tests/foreman/ui/test_subscription.py +++ b/tests/foreman/ui/test_subscription.py @@ -19,9 +19,7 @@ from tempfile import mkstemp import time -from airgun.session import Session from fauxfactory import gen_string -from nailgun import entities import pytest from robottelo.config import settings @@ -49,18 +47,18 @@ def golden_ticket_host_setup(function_entitlement_manifest_org, module_target_sa reposet=REPOSET['rhst7'], releasever=None, ) - rh_repo = entities.Repository(id=rh_repo_id).read() + rh_repo = module_target_sat.api.Repository(id=rh_repo_id).read() rh_repo.sync() - custom_product = entities.Product(organization=org).create() - custom_repo = entities.Repository( + custom_product = module_target_sat.api.Product(organization=org).create() + custom_repo = module_target_sat.api.Repository( name=gen_string('alphanumeric').upper(), product=custom_product ).create() custom_repo.sync() - ak = entities.ActivationKey( + ak = module_target_sat.api.ActivationKey( content_view=org.default_content_view, max_hosts=100, organization=org, - environment=entities.LifecycleEnvironment(id=org.library.id), + environment=module_target_sat.api.LifecycleEnvironment(id=org.library.id), auto_attach=True, ).create() return org, ak @@ -98,7 +96,7 @@ def test_positive_end_to_end(session, target_sat): 'Note: Deleting a subscription manifest is STRONGLY discouraged.', 'This action should only be taken for debugging purposes.', ] - org = entities.Organization().create() + org = target_sat.api.Organization().create() _, temporary_local_manifest_path = mkstemp(prefix='manifest-', suffix='.zip') with clone() as manifest: with open(temporary_local_manifest_path, 'wb') as file_handler: @@ -154,8 +152,8 @@ def test_positive_access_with_non_admin_user_without_manifest(test_name, target_ :CaseImportance: Critical """ - org = entities.Organization().create() - role = entities.Role(organization=[org]).create() + org = target_sat.api.Organization().create() + role = target_sat.api.Role(organization=[org]).create() target_sat.api_factory.create_role_permissions( role, { @@ -169,14 +167,14 @@ def test_positive_access_with_non_admin_user_without_manifest(test_name, target_ }, ) user_password = gen_string('alphanumeric') - user = entities.User( + user = target_sat.api.User( admin=False, role=[role], password=user_password, organization=[org], default_organization=org, ).create() - 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: assert not session.subscription.has_manifest @@ -202,20 +200,20 @@ def test_positive_access_with_non_admin_user_with_manifest( :CaseImportance: Critical """ org = function_entitlement_manifest_org - role = entities.Role(organization=[org]).create() + role = target_sat.api.Role(organization=[org]).create() target_sat.api_factory.create_role_permissions( role, {'Katello::Subscription': ['view_subscriptions'], 'Organization': ['view_organizations']}, ) user_password = gen_string('alphanumeric') - user = entities.User( + user = target_sat.api.User( admin=False, role=[role], password=user_password, organization=[org], default_organization=org, ).create() - 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: assert ( session.subscription.search(f'name = "{DEFAULT_SUBSCRIPTION_NAME}"')[0]['Name'] == DEFAULT_SUBSCRIPTION_NAME @@ -241,23 +239,23 @@ def test_positive_access_manifest_as_another_admin_user( :CaseImportance: High """ - org = entities.Organization().create() + org = target_sat.api.Organization().create() user1_password = gen_string('alphanumeric') - user1 = entities.User( + user1 = target_sat.api.User( admin=True, password=user1_password, organization=[org], default_organization=org ).create() user2_password = gen_string('alphanumeric') - user2 = entities.User( + user2 = target_sat.api.User( admin=True, password=user2_password, organization=[org], default_organization=org ).create() # use the first admin to upload a manifest - with Session(test_name, user=user1.login, password=user1_password) as session: + with target_sat.ui_session(test_name, user=user1.login, password=user1_password) as session: target_sat.upload_manifest(org.id, function_entitlement_manifest.content) assert session.subscription.has_manifest # store subscriptions that have "Red Hat" in the name for later rh_subs = session.subscription.search("Red Hat") # try to view and delete the manifest with another admin - with Session(test_name, user=user2.login, password=user2_password) as session: + with target_sat.ui_session(test_name, user=user2.login, password=user2_password) as session: assert session.subscription.has_manifest assert rh_subs == session.subscription.search("Red Hat") session.subscription.delete_manifest( @@ -303,7 +301,7 @@ def test_positive_view_vdc_subscription_products( :CaseLevel: System """ org = function_entitlement_manifest_org - lce = entities.LifecycleEnvironment(organization=org).create() + lce = target_sat.api.LifecycleEnvironment(organization=org).create() repos_collection = target_sat.cli_factory.RepositoryCollection( distro='rhel7', repositories=[target_sat.cli_factory.RHELAnsibleEngineRepository(cdn=True)], @@ -364,7 +362,7 @@ def test_positive_view_vdc_guest_subscription_products( :CaseLevel: System """ org = function_entitlement_manifest_org - lce = entities.LifecycleEnvironment(organization=org).create() + lce = target_sat.api.LifecycleEnvironment(organization=org).create() provisioning_server = settings.libvirt.libvirt_hostname rh_product_repository = target_sat.cli_factory.RHELAnsibleEngineRepository(cdn=True) product_name = rh_product_repository.data['product'] @@ -527,13 +525,15 @@ def test_positive_candlepin_events_processed_by_STOMP( :CaseImportance: High """ org = function_entitlement_manifest_org - repo = entities.Repository(product=entities.Product(organization=org).create()).create() + repo = target_sat.api.Repository( + product=target_sat.api.Product(organization=org).create() + ).create() repo.sync() - ak = entities.ActivationKey( + ak = target_sat.api.ActivationKey( content_view=org.default_content_view, max_hosts=100, organization=org, - environment=entities.LifecycleEnvironment(id=org.library.id), + environment=target_sat.api.LifecycleEnvironment(id=org.library.id), ).create() rhel7_contenthost.install_katello_ca(target_sat) rhel7_contenthost.register_contenthost(org.name, ak.name) @@ -549,6 +549,6 @@ def test_positive_candlepin_events_processed_by_STOMP( rhel7_contenthost.hostname, widget_names='details' )['details']['subscription_status'] assert 'Fully entitled' in updated_sub_status - response = entities.Ping().search_json()['services']['candlepin_events'] + response = target_sat.api.Ping().search_json()['services']['candlepin_events'] assert response['status'] == 'ok' assert '0 Failed' in response['message'] diff --git a/tests/foreman/ui/test_user.py b/tests/foreman/ui/test_user.py index 892024ffc8d..5f88d5bda1c 100644 --- a/tests/foreman/ui/test_user.py +++ b/tests/foreman/ui/test_user.py @@ -18,7 +18,6 @@ """ import random -from airgun.session import Session from fauxfactory import gen_email, gen_string import pytest @@ -90,7 +89,7 @@ def test_positive_end_to_end(session, target_sat, test_name, module_org, module_ assert session.user.search(new_name)[0]['Username'] == new_name assert not session.user.search(name) # Login into application using new user - with Session(test_name, new_name, password) as newsession: + with target_sat.ui_session(test_name, new_name, password) as newsession: newsession.organization.select(module_org.name) newsession.location.select(module_location.name) newsession.activationkey.create({'name': ak_name}) @@ -98,7 +97,7 @@ def test_positive_end_to_end(session, target_sat, test_name, module_org, module_ current_user = newsession.activationkey.read(ak_name, 'current_user')['current_user'] assert current_user == f'{firstname} {lastname}' # Delete user - with Session('deletehostsession') as deletehostsession: + with target_sat.ui_session('deletehostsession') as deletehostsession: deletehostsession.user.delete(new_name) assert not deletehostsession.user.search(new_name) @@ -321,7 +320,7 @@ def test_positive_create_product_with_limited_user_permission( password=password, mail='test@test.com', ).create() - with Session(test_name, username, password) as newsession: + with target_sat.ui_session(test_name, username, password) as newsession: newsession.product.create( {'name': product_name, 'label': product_label, 'description': product_description} ) diff --git a/tests/foreman/virtwho/conftest.py b/tests/foreman/virtwho/conftest.py index 8e422b22940..2ef011f5bb4 100644 --- a/tests/foreman/virtwho/conftest.py +++ b/tests/foreman/virtwho/conftest.py @@ -1,4 +1,3 @@ -from airgun.session import Session from fauxfactory import gen_string import pytest from requests.exceptions import HTTPError @@ -37,7 +36,7 @@ def module_user(request, module_target_sat, default_org, default_location): @pytest.fixture -def session(test_name, module_user): +def session(test_name, module_user, module_target_sat): """Session fixture which automatically initializes (but does not start!) airgun UI session and correctly passes current test name to it. Uses shared module user credentials to log in. @@ -51,7 +50,7 @@ def test_foo(session): session.architecture.create({'name': 'bar'}) """ - return Session(test_name, module_user.login, module_user.password) + return module_target_sat.ui_session(test_name, module_user.login, module_user.password) @pytest.fixture(scope='module') @@ -85,7 +84,7 @@ def module_user_sca(request, module_target_sat, module_org, module_location): @pytest.fixture -def session_sca(test_name, module_user_sca): +def session_sca(test_name, module_user_sca, module_target_sat): """Session fixture which automatically initializes (but does not start!) airgun UI session and correctly passes current test name to it. Uses shared module user credentials to log in. @@ -99,4 +98,4 @@ def test_foo(session): session.architecture.create({'name': 'bar'}) """ - return Session(test_name, module_user_sca.login, module_user_sca.password) + return module_target_sat.ui_session(test_name, module_user_sca.login, module_user_sca.password) diff --git a/tests/foreman/virtwho/ui/test_esx.py b/tests/foreman/virtwho/ui/test_esx.py index 7c669a62022..1083c9ebc4e 100644 --- a/tests/foreman/virtwho/ui/test_esx.py +++ b/tests/foreman/virtwho/ui/test_esx.py @@ -18,7 +18,6 @@ """ from datetime import datetime -from airgun.session import Session from fauxfactory import gen_string import pytest @@ -390,7 +389,7 @@ def test_positive_delete_configure(self, default_org, org_session, form_data_ui) @pytest.mark.tier2 def test_positive_virtwho_reporter_role( - self, default_org, org_session, test_name, form_data_ui + self, default_org, org_session, test_name, form_data_ui, target_sat ): """Verify the virt-who reporter role can TRULY work. @@ -439,13 +438,15 @@ def test_positive_virtwho_reporter_role( assert user['roles']['resources']['assigned'] == ['Virt-who Reporter'] restart_virtwho_service() assert get_virtwho_status() == 'running' - with Session(test_name, username, password) as newsession: + with target_sat.ui_session(test_name, username, password) as newsession: assert not newsession.virtwho_configure.check_create_permission()['can_view'] org_session.user.delete(username) assert not org_session.user.search(username) @pytest.mark.tier2 - def test_positive_virtwho_viewer_role(self, default_org, org_session, test_name, form_data_ui): + def test_positive_virtwho_viewer_role( + self, default_org, org_session, test_name, form_data_ui, target_sat + ): """Verify the virt-who viewer role can TRULY work. :id: bf3be2e4-3853-41cc-9b3e-c8677f0b8c5f @@ -490,7 +491,7 @@ def test_positive_virtwho_viewer_role(self, default_org, org_session, test_name, add_configure_option('rhsm_password', password, config_file) restart_virtwho_service() assert get_virtwho_status() == 'logerror' - with Session(test_name, username, password) as newsession: + with target_sat.ui_session(test_name, username, password) as newsession: create_permission = newsession.virtwho_configure.check_create_permission() update_permission = newsession.virtwho_configure.check_update_permission( config_name @@ -505,7 +506,9 @@ def test_positive_virtwho_viewer_role(self, default_org, org_session, test_name, assert not org_session.user.search(username) @pytest.mark.tier2 - def test_positive_virtwho_manager_role(self, default_org, org_session, test_name, form_data_ui): + def test_positive_virtwho_manager_role( + self, default_org, org_session, test_name, form_data_ui, target_sat + ): """Verify the virt-who manager role can TRULY work. :id: a72023fb-7b23-4582-9adc-c5227dc7859c @@ -541,7 +544,7 @@ def test_positive_virtwho_manager_role(self, default_org, org_session, test_name org_session.user.update(username, {'roles.resources.assigned': ['Virt-who Manager']}) user = org_session.user.read(username) assert user['roles']['resources']['assigned'] == ['Virt-who Manager'] - with Session(test_name, username, password) as newsession: + with target_sat.ui_session(test_name, username, password) as newsession: # create_virt_who_config new_virt_who_name = gen_string('alpha') form_data_ui['name'] = new_virt_who_name