From eadb6f73ce27539072a147c589544352b1d46c0b Mon Sep 17 00:00:00 2001 From: omkarkhatavkar Date: Wed, 18 Oct 2023 16:14:10 +0530 Subject: [PATCH] removing the import entities from nailgun and moving target_sat --- tests/foreman/api/test_activationkey.py | 108 +++++---- tests/foreman/api/test_architecture.py | 17 +- tests/foreman/api/test_audit.py | 89 +++---- tests/foreman/api/test_bookmarks.py | 65 +++-- tests/foreman/api/test_capsulecontent.py | 99 +++++--- tests/foreman/api/test_computeprofile.py | 31 ++- tests/foreman/api/test_contentcredentials.py | 49 ++-- tests/foreman/api/test_contentview.py | 197 ++++++++------- tests/foreman/api/test_contentviewfilter.py | 226 ++++++++++-------- tests/foreman/api/test_contentviewversion.py | 209 +++++++++------- tests/foreman/api/test_discoveryrule.py | 16 +- tests/foreman/api/test_errata.py | 71 +++--- tests/foreman/api/test_filter.py | 19 +- tests/foreman/api/test_foremantask.py | 9 +- tests/foreman/api/test_hostcollection.py | 115 +++++---- tests/foreman/api/test_hostgroup.py | 76 +++--- tests/foreman/api/test_http_proxy.py | 23 +- tests/foreman/api/test_ldapauthsource.py | 7 +- .../foreman/api/test_lifecycleenvironment.py | 43 ++-- tests/foreman/api/test_media.py | 61 ++--- tests/foreman/api/test_organization.py | 58 ++--- .../foreman/api/test_oscap_tailoringfiles.py | 21 +- tests/foreman/api/test_oscappolicy.py | 19 +- tests/foreman/api/test_product.py | 97 ++++---- tests/foreman/api/test_reporttemplates.py | 85 ++++--- tests/foreman/api/test_repositories.py | 3 +- tests/foreman/api/test_repository_set.py | 9 +- tests/foreman/api/test_settings.py | 9 +- tests/foreman/api/test_subnet.py | 75 +++--- tests/foreman/api/test_subscription.py | 80 ++++--- tests/foreman/api/test_syncplan.py | 130 +++++----- tests/foreman/api/test_templatesync.py | 131 +++++----- tests/foreman/api/test_usergroup.py | 89 ++++--- tests/foreman/api/test_webhook.py | 29 ++- tests/foreman/ui/test_host.py | 19 +- 35 files changed, 1280 insertions(+), 1104 deletions(-) diff --git a/tests/foreman/api/test_activationkey.py b/tests/foreman/api/test_activationkey.py index 96da8a8f4c8..8c6f9ea194d 100644 --- a/tests/foreman/api/test_activationkey.py +++ b/tests/foreman/api/test_activationkey.py @@ -19,7 +19,7 @@ import http from fauxfactory import gen_integer, gen_string -from nailgun import client, entities +from nailgun import client import pytest from requests.exceptions import HTTPError @@ -46,7 +46,7 @@ def _bad_max_hosts(): @pytest.mark.tier1 -def test_positive_create_unlimited_hosts(): +def test_positive_create_unlimited_hosts(target_sat): """Create a plain vanilla activation key. :id: 1d73b8cc-a754-4637-8bae-d9d2aaf89003 @@ -56,12 +56,12 @@ def test_positive_create_unlimited_hosts(): :CaseImportance: Critical """ - assert entities.ActivationKey().create().unlimited_hosts is True + assert target_sat.api.ActivationKey().create().unlimited_hosts is True @pytest.mark.tier1 @pytest.mark.parametrize('max_host', **parametrized(_good_max_hosts())) -def test_positive_create_limited_hosts(max_host): +def test_positive_create_limited_hosts(max_host, target_sat): """Create an activation key with limited hosts. :id: 9bbba620-fd98-4139-a44b-af8ce330c7a4 @@ -73,14 +73,14 @@ def test_positive_create_limited_hosts(max_host): :parametrized: yes """ - act_key = entities.ActivationKey(max_hosts=max_host, unlimited_hosts=False).create() + act_key = target_sat.api.ActivationKey(max_hosts=max_host, unlimited_hosts=False).create() assert act_key.max_hosts == max_host assert act_key.unlimited_hosts is False @pytest.mark.tier1 @pytest.mark.parametrize('key_name', **parametrized(valid_data_list())) -def test_positive_create_with_name(key_name): +def test_positive_create_with_name(key_name, target_sat): """Create an activation key providing the initial name. :id: 749e0d28-640e-41e5-89d6-b92411ce73a3 @@ -91,13 +91,13 @@ def test_positive_create_with_name(key_name): :parametrized: yes """ - act_key = entities.ActivationKey(name=key_name).create() + act_key = target_sat.api.ActivationKey(name=key_name).create() assert key_name == act_key.name @pytest.mark.tier2 @pytest.mark.parametrize('desc', **parametrized(valid_data_list())) -def test_positive_create_with_description(desc): +def test_positive_create_with_description(desc, target_sat): """Create an activation key and provide a description. :id: 64d93726-6f96-4a2e-ab29-eb5bfa2ff8ff @@ -106,12 +106,12 @@ def test_positive_create_with_description(desc): :parametrized: yes """ - act_key = entities.ActivationKey(description=desc).create() + act_key = target_sat.api.ActivationKey(description=desc).create() assert desc == act_key.description @pytest.mark.tier2 -def test_negative_create_with_no_host_limit(): +def test_negative_create_with_no_host_limit(target_sat): """Create activation key without providing limitation for hosts number :id: a9e756e1-886d-4f0d-b685-36ce4247517d @@ -121,12 +121,12 @@ def test_negative_create_with_no_host_limit(): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.ActivationKey(unlimited_hosts=False).create() + target_sat.api.ActivationKey(unlimited_hosts=False).create() @pytest.mark.tier3 @pytest.mark.parametrize('max_host', **parametrized(_bad_max_hosts())) -def test_negative_create_with_invalid_host_limit(max_host): +def test_negative_create_with_invalid_host_limit(max_host, target_sat): """Create activation key with invalid limit values for hosts number. :id: c018b177-2074-4f1a-a7e0-9f38d6c9a1a6 @@ -138,12 +138,12 @@ def test_negative_create_with_invalid_host_limit(max_host): :parametrized: yes """ with pytest.raises(HTTPError): - entities.ActivationKey(max_hosts=max_host, unlimited_hosts=False).create() + target_sat.api.ActivationKey(max_hosts=max_host, unlimited_hosts=False).create() @pytest.mark.tier3 @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) -def test_negative_create_with_invalid_name(name): +def test_negative_create_with_invalid_name(name, target_sat): """Create activation key providing an invalid name. :id: 5f7051be-0320-4d37-9085-6904025ad909 @@ -155,12 +155,12 @@ def test_negative_create_with_invalid_name(name): :parametrized: yes """ with pytest.raises(HTTPError): - entities.ActivationKey(name=name).create() + target_sat.api.ActivationKey(name=name).create() @pytest.mark.tier2 @pytest.mark.parametrize('max_host', **parametrized(_good_max_hosts())) -def test_positive_update_limited_host(max_host): +def test_positive_update_limited_host(max_host, target_sat): """Create activation key then update it to limited hosts. :id: 34ca8303-8135-4694-9cf7-b20f8b4b0a1e @@ -170,7 +170,7 @@ def test_positive_update_limited_host(max_host): :parametrized: yes """ # unlimited_hosts defaults to True. - act_key = entities.ActivationKey().create() + act_key = target_sat.api.ActivationKey().create() want = {'max_hosts': max_host, 'unlimited_hosts': False} for key, value in want.items(): setattr(act_key, key, value) @@ -181,7 +181,7 @@ def test_positive_update_limited_host(max_host): @pytest.mark.tier2 @pytest.mark.parametrize('new_name', **parametrized(valid_data_list())) -def test_positive_update_name(new_name): +def test_positive_update_name(new_name, target_sat): """Create activation key providing the initial name, then update its name to another valid name. @@ -192,14 +192,14 @@ def test_positive_update_name(new_name): :parametrized: yes """ - act_key = entities.ActivationKey().create() - updated = entities.ActivationKey(id=act_key.id, name=new_name).update(['name']) + act_key = target_sat.api.ActivationKey().create() + updated = target_sat.api.ActivationKey(id=act_key.id, name=new_name).update(['name']) assert new_name == updated.name @pytest.mark.tier3 @pytest.mark.parametrize('max_host', **parametrized(_bad_max_hosts())) -def test_negative_update_limit(max_host): +def test_negative_update_limit(max_host, target_sat): """Create activation key then update its limit to invalid value. :id: 0f857d2f-81ed-4b8b-b26e-34b4f294edbc @@ -214,7 +214,7 @@ def test_negative_update_limit(max_host): :parametrized: yes """ - act_key = entities.ActivationKey().create() + act_key = target_sat.api.ActivationKey().create() want = {'max_hosts': act_key.max_hosts, 'unlimited_hosts': act_key.unlimited_hosts} act_key.max_hosts = max_host act_key.unlimited_hosts = False @@ -227,7 +227,7 @@ def test_negative_update_limit(max_host): @pytest.mark.tier3 @pytest.mark.parametrize('new_name', **parametrized(invalid_names_list())) -def test_negative_update_name(new_name): +def test_negative_update_name(new_name, target_sat): """Create activation key then update its name to an invalid name. :id: da85a32c-942b-4ab8-a133-36b028208c4d @@ -239,16 +239,16 @@ def test_negative_update_name(new_name): :parametrized: yes """ - act_key = entities.ActivationKey().create() + act_key = target_sat.api.ActivationKey().create() with pytest.raises(HTTPError): - entities.ActivationKey(id=act_key.id, name=new_name).update(['name']) - new_key = entities.ActivationKey(id=act_key.id).read() + target_sat.api.ActivationKey(id=act_key.id, name=new_name).update(['name']) + new_key = target_sat.api.ActivationKey(id=act_key.id).read() assert new_key.name != new_name assert new_key.name == act_key.name @pytest.mark.tier3 -def test_negative_update_max_hosts(): +def test_negative_update_max_hosts(target_sat): """Create an activation key with ``max_hosts == 1``, then update that field with a string value. @@ -258,14 +258,14 @@ def test_negative_update_max_hosts(): :CaseImportance: Low """ - act_key = entities.ActivationKey(max_hosts=1).create() + act_key = target_sat.api.ActivationKey(max_hosts=1).create() with pytest.raises(HTTPError): - entities.ActivationKey(id=act_key.id, max_hosts='foo').update(['max_hosts']) + target_sat.api.ActivationKey(id=act_key.id, max_hosts='foo').update(['max_hosts']) assert act_key.read().max_hosts == 1 @pytest.mark.tier2 -def test_positive_get_releases_status_code(): +def test_positive_get_releases_status_code(target_sat): """Get an activation key's releases. Check response format. :id: e1ea4797-8d92-4bec-ae6b-7a26599825ab @@ -275,7 +275,7 @@ def test_positive_get_releases_status_code(): :CaseLevel: Integration """ - act_key = entities.ActivationKey().create() + act_key = target_sat.api.ActivationKey().create() path = act_key.path('releases') response = client.get(path, auth=get_credentials(), verify=False) status_code = http.client.OK @@ -284,7 +284,7 @@ def test_positive_get_releases_status_code(): @pytest.mark.tier2 -def test_positive_get_releases_content(): +def test_positive_get_releases_content(target_sat): """Get an activation key's releases. Check response contents. :id: 2fec3d71-33e9-40e5-b934-90b03afc26a1 @@ -293,14 +293,14 @@ def test_positive_get_releases_content(): :CaseLevel: Integration """ - act_key = entities.ActivationKey().create() + act_key = target_sat.api.ActivationKey().create() response = client.get(act_key.path('releases'), auth=get_credentials(), verify=False).json() assert 'results' in response.keys() assert type(response['results']) == list @pytest.mark.tier2 -def test_positive_add_host_collections(module_org): +def test_positive_add_host_collections(module_org, module_target_sat): """Associate an activation key with several host collections. :id: 1538808c-621e-4cf9-9b9b-840c5dd54644 @@ -318,23 +318,27 @@ def test_positive_add_host_collections(module_org): :CaseImportance: Critical """ # An activation key has no host collections by default. - act_key = entities.ActivationKey(organization=module_org).create() + act_key = module_target_sat.api.ActivationKey(organization=module_org).create() assert len(act_key.host_collection) == 0 # Give activation key one host collection. - act_key.host_collection.append(entities.HostCollection(organization=module_org).create()) + act_key.host_collection.append( + module_target_sat.api.HostCollection(organization=module_org).create() + ) act_key = act_key.update(['host_collection']) assert len(act_key.host_collection) == 1 # Give activation key second host collection. - act_key.host_collection.append(entities.HostCollection(organization=module_org).create()) + act_key.host_collection.append( + module_target_sat.api.HostCollection(organization=module_org).create() + ) act_key = act_key.update(['host_collection']) assert len(act_key.host_collection) == 2 @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_remove_host_collection(module_org): +def test_positive_remove_host_collection(module_org, module_target_sat): """Disassociate host collection from the activation key :id: 31992ac4-fe55-45bb-bd17-a191928ec2ab @@ -353,10 +357,10 @@ def test_positive_remove_host_collection(module_org): :CaseImportance: Critical """ # An activation key has no host collections by default. - act_key = entities.ActivationKey(organization=module_org).create() + act_key = module_target_sat.api.ActivationKey(organization=module_org).create() assert len(act_key.host_collection) == 0 - host_collection = entities.HostCollection(organization=module_org).create() + host_collection = module_target_sat.api.HostCollection(organization=module_org).create() # Associate host collection with activation key. act_key.add_host_collection(data={'host_collection_ids': [host_collection.id]}) @@ -368,7 +372,7 @@ def test_positive_remove_host_collection(module_org): @pytest.mark.tier1 -def test_positive_update_auto_attach(): +def test_positive_update_auto_attach(target_sat): """Create an activation key, then update the auto_attach field with the inverse boolean value. @@ -378,17 +382,17 @@ def test_positive_update_auto_attach(): :CaseImportance: Critical """ - act_key = entities.ActivationKey().create() - act_key_2 = entities.ActivationKey(id=act_key.id, auto_attach=(not act_key.auto_attach)).update( - ['auto_attach'] - ) + act_key = target_sat.api.ActivationKey().create() + act_key_2 = target_sat.api.ActivationKey( + id=act_key.id, auto_attach=(not act_key.auto_attach) + ).update(['auto_attach']) assert act_key.auto_attach != act_key_2.auto_attach @pytest.mark.tier1 @pytest.mark.upgrade @pytest.mark.parametrize('name', **parametrized(valid_data_list())) -def test_positive_delete(name): +def test_positive_delete(name, target_sat): """Create activation key and then delete it. :id: aa28d8fb-e07d-45fa-b43a-fc90c706d633 @@ -399,10 +403,10 @@ def test_positive_delete(name): :parametrized: yes """ - act_key = entities.ActivationKey(name=name).create() + act_key = target_sat.api.ActivationKey(name=name).create() act_key.delete() with pytest.raises(HTTPError): - entities.ActivationKey(id=act_key.id).read() + target_sat.api.ActivationKey(id=act_key.id).read() @pytest.mark.tier2 @@ -503,7 +507,7 @@ def test_positive_add_future_subscription(): @pytest.mark.tier1 -def test_positive_search_by_org(): +def test_positive_search_by_org(target_sat): """Search for all activation keys in an organization. :id: aedba598-2e47-44a8-826c-4dc304ba00be @@ -513,8 +517,8 @@ def test_positive_search_by_org(): :CaseImportance: Critical """ - org = entities.Organization().create() - act_key = entities.ActivationKey(organization=org).create() - keys = entities.ActivationKey(organization=org).search() + org = target_sat.api.Organization().create() + act_key = target_sat.api.ActivationKey(organization=org).create() + keys = target_sat.api.ActivationKey(organization=org).search() assert len(keys) == 1 assert act_key.id == keys[0].id diff --git a/tests/foreman/api/test_architecture.py b/tests/foreman/api/test_architecture.py index f88c8adba18..f0b7c428b0f 100644 --- a/tests/foreman/api/test_architecture.py +++ b/tests/foreman/api/test_architecture.py @@ -17,7 +17,6 @@ :Upstream: No """ from fauxfactory import gen_choice -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -29,7 +28,7 @@ @pytest.mark.tier1 -def test_positive_CRUD(default_os): +def test_positive_CRUD(default_os, target_sat): """Create a new Architecture with several attributes, update the name and delete the Architecture itself. @@ -43,13 +42,13 @@ def test_positive_CRUD(default_os): # Create name = gen_choice(list(valid_data_list().values())) - arch = entities.Architecture(name=name, operatingsystem=[default_os]).create() + arch = target_sat.api.Architecture(name=name, operatingsystem=[default_os]).create() assert {default_os.id} == {os.id for os in arch.operatingsystem} assert name == arch.name # Update name = gen_choice(list(valid_data_list().values())) - arch = entities.Architecture(id=arch.id, name=name).update(['name']) + arch = target_sat.api.Architecture(id=arch.id, name=name).update(['name']) assert name == arch.name # Delete @@ -60,7 +59,7 @@ def test_positive_CRUD(default_os): @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) -def test_negative_create_with_invalid_name(name): +def test_negative_create_with_invalid_name(name, target_sat): """Create architecture providing an invalid initial name. :id: 0fa6377d-063a-4e24-b606-b342e0d9108b @@ -74,12 +73,12 @@ def test_negative_create_with_invalid_name(name): :BZ: 1401519 """ with pytest.raises(HTTPError): - entities.Architecture(name=name).create() + target_sat.api.Architecture(name=name).create() @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) -def test_negative_update_with_invalid_name(name, module_architecture): +def test_negative_update_with_invalid_name(name, module_architecture, module_target_sat): """Update architecture's name to an invalid name. :id: cb27b69b-14e0-42d0-9e44-e09d68324803 @@ -91,6 +90,6 @@ def test_negative_update_with_invalid_name(name, module_architecture): :CaseImportance: Medium """ with pytest.raises(HTTPError): - entities.Architecture(id=module_architecture.id, name=name).update(['name']) - arch = entities.Architecture(id=module_architecture.id).read() + module_target_sat.api.Architecture(id=module_architecture.id, name=name).update(['name']) + arch = module_target_sat.api.Architecture(id=module_architecture.id).read() assert arch.name != name diff --git a/tests/foreman/api/test_audit.py b/tests/foreman/api/test_audit.py index 59b19d0806c..1aa9c28cc41 100644 --- a/tests/foreman/api/test_audit.py +++ b/tests/foreman/api/test_audit.py @@ -16,7 +16,6 @@ :Upstream: No """ -from nailgun import entities import pytest from robottelo.utils.datafactory import gen_string @@ -24,7 +23,7 @@ @pytest.mark.e2e @pytest.mark.tier1 -def test_positive_create_by_type(): +def test_positive_create_by_type(target_sat): """Create entities of different types and check audit logs for these events using entity type as search criteria @@ -40,45 +39,49 @@ def test_positive_create_by_type(): :CaseImportance: Medium """ for entity_item in [ - {'entity': entities.Architecture()}, + {'entity': target_sat.api.Architecture()}, { - 'entity': entities.AuthSourceLDAP(), + 'entity': target_sat.api.AuthSourceLDAP(), 'entity_type': 'auth_source', 'value_template': 'LDAP-{entity.name}', }, - {'entity': entities.ComputeProfile(), 'entity_type': 'compute_profile'}, + {'entity': target_sat.api.ComputeProfile(), 'entity_type': 'compute_profile'}, { - 'entity': entities.LibvirtComputeResource(), + 'entity': target_sat.api.LibvirtComputeResource(), 'entity_type': 'compute_resource', 'value_template': '{entity.name} (Libvirt)', }, - {'entity': entities.Domain()}, - {'entity': entities.Host()}, - {'entity': entities.HostGroup()}, - {'entity': entities.Image(compute_resource=entities.LibvirtComputeResource().create())}, - {'entity': entities.Location()}, - {'entity': entities.Media(), 'entity_type': 'medium'}, + {'entity': target_sat.api.Domain()}, + {'entity': target_sat.api.Host()}, + {'entity': target_sat.api.HostGroup()}, { - 'entity': entities.OperatingSystem(), + 'entity': target_sat.api.Image( + compute_resource=target_sat.api.LibvirtComputeResource().create() + ) + }, + {'entity': target_sat.api.Location()}, + {'entity': target_sat.api.Media(), 'entity_type': 'medium'}, + { + 'entity': target_sat.api.OperatingSystem(), 'entity_type': 'os', 'value_template': '{entity.name} {entity.major}', }, - {'entity': entities.PartitionTable(), 'entity_type': 'ptable'}, - {'entity': entities.Role()}, + {'entity': target_sat.api.PartitionTable(), 'entity_type': 'ptable'}, + {'entity': target_sat.api.Role()}, { - 'entity': entities.Subnet(), + 'entity': target_sat.api.Subnet(), 'value_template': '{entity.name} ({entity.network}/{entity.cidr})', }, - {'entity': entities.ProvisioningTemplate(), 'entity_type': 'provisioning_template'}, - {'entity': entities.User(), 'value_template': '{entity.login}'}, - {'entity': entities.UserGroup()}, - {'entity': entities.ContentView(), 'entity_type': 'katello/content_view'}, - {'entity': entities.LifecycleEnvironment(), 'entity_type': 'katello/kt_environment'}, - {'entity': entities.ActivationKey(), 'entity_type': 'katello/activation_key'}, - {'entity': entities.HostCollection(), 'entity_type': 'katello/host_collection'}, - {'entity': entities.Product(), 'entity_type': 'katello/product'}, + {'entity': target_sat.api.ProvisioningTemplate(), 'entity_type': 'provisioning_template'}, + {'entity': target_sat.api.User(), 'value_template': '{entity.login}'}, + {'entity': target_sat.api.UserGroup()}, + {'entity': target_sat.api.ContentView(), 'entity_type': 'katello/content_view'}, + {'entity': target_sat.api.LifecycleEnvironment(), 'entity_type': 'katello/kt_environment'}, + {'entity': target_sat.api.ActivationKey(), 'entity_type': 'katello/activation_key'}, + {'entity': target_sat.api.HostCollection(), 'entity_type': 'katello/host_collection'}, + {'entity': target_sat.api.Product(), 'entity_type': 'katello/product'}, { - 'entity': entities.SyncPlan(organization=entities.Organization(id=1)), + 'entity': target_sat.api.SyncPlan(organization=target_sat.api.Organization(id=1)), 'entity_type': 'katello/sync_plan', }, ]: @@ -86,7 +89,7 @@ def test_positive_create_by_type(): entity_type = entity_item.get('entity_type', created_entity.__class__.__name__.lower()) value_template = entity_item.get('value_template', '{entity.name}') entity_value = value_template.format(entity=created_entity) - audits = entities.Audit().search(query={'search': f'type={entity_type}'}) + audits = target_sat.api.Audit().search(query={'search': f'type={entity_type}'}) entity_audits = [entry for entry in audits if entry.auditable_name == entity_value] assert entity_audits, ( f'audit not found by name "{entity_value}" for entity: ' @@ -99,7 +102,7 @@ def test_positive_create_by_type(): @pytest.mark.tier1 -def test_positive_update_by_type(): +def test_positive_update_by_type(target_sat): """Update some entities of different types and check audit logs for these events using entity type as search criteria @@ -111,19 +114,19 @@ def test_positive_update_by_type(): :CaseImportance: Medium """ for entity in [ - entities.Architecture(), - entities.Domain(), - entities.HostGroup(), - entities.Location(), - entities.Role(), - entities.UserGroup(), + target_sat.api.Architecture(), + target_sat.api.Domain(), + target_sat.api.HostGroup(), + target_sat.api.Location(), + target_sat.api.Role(), + target_sat.api.UserGroup(), ]: created_entity = entity.create() name = created_entity.name new_name = gen_string('alpha') created_entity.name = new_name created_entity = created_entity.update(['name']) - audits = entities.Audit().search( + audits = target_sat.api.Audit().search( query={'search': f'type={created_entity.__class__.__name__.lower()}'} ) entity_audits = [entry for entry in audits if entry.auditable_name == name] @@ -136,7 +139,7 @@ def test_positive_update_by_type(): @pytest.mark.tier1 -def test_positive_delete_by_type(): +def test_positive_delete_by_type(target_sat): """Delete some entities of different types and check audit logs for these events using entity type as search criteria @@ -148,17 +151,17 @@ def test_positive_delete_by_type(): :CaseImportance: Medium """ for entity in [ - entities.Architecture(), - entities.Domain(), - entities.Host(), - entities.HostGroup(), - entities.Location(), - entities.Role(), - entities.UserGroup(), + target_sat.api.Architecture(), + target_sat.api.Domain(), + target_sat.api.Host(), + target_sat.api.HostGroup(), + target_sat.api.Location(), + target_sat.api.Role(), + target_sat.api.UserGroup(), ]: created_entity = entity.create() created_entity.delete() - audits = entities.Audit().search( + audits = target_sat.api.Audit().search( query={'search': f'type={created_entity.__class__.__name__.lower()}'} ) entity_audits = [entry for entry in audits if entry.auditable_name == created_entity.name] diff --git a/tests/foreman/api/test_bookmarks.py b/tests/foreman/api/test_bookmarks.py index 71ae30391ab..6ae674f7699 100644 --- a/tests/foreman/api/test_bookmarks.py +++ b/tests/foreman/api/test_bookmarks.py @@ -19,7 +19,6 @@ import random from fauxfactory import gen_string -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -32,7 +31,7 @@ @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_positive_create_with_name(controller): +def test_positive_create_with_name(controller, target_sat): """Create a bookmark :id: aeef0944-379a-4a27-902d-aa5969dbd441 @@ -51,14 +50,14 @@ def test_positive_create_with_name(controller): :CaseImportance: Critical """ name = random.choice(list(valid_data_list().values())) - bm = entities.Bookmark(controller=controller, name=name, public=False).create() + bm = target_sat.api.Bookmark(controller=controller, name=name, public=False).create() assert bm.controller == controller assert bm.name == name @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_positive_create_with_query(controller): +def test_positive_create_with_query(controller, target_sat): """Create a bookmark :id: 9fb6d485-92b5-43ea-b776-012c13734100 @@ -77,7 +76,7 @@ def test_positive_create_with_query(controller): :CaseImportance: Critical """ query = random.choice(list(valid_data_list().values())) - bm = entities.Bookmark(controller=controller, query=query).create() + bm = target_sat.api.Bookmark(controller=controller, query=query).create() assert bm.controller == controller assert bm.query == query @@ -85,7 +84,7 @@ def test_positive_create_with_query(controller): @pytest.mark.tier1 @pytest.mark.parametrize('public', (True, False)) @pytest.mark.parametrize('controller', CONTROLLERS) -def test_positive_create_public(controller, public): +def test_positive_create_public(controller, public, target_sat): """Create a public bookmark :id: 511b9bcf-0661-4e44-b1bc-475a1c207aa9 @@ -103,14 +102,14 @@ def test_positive_create_public(controller, public): :CaseImportance: Critical """ - bm = entities.Bookmark(controller=controller, public=public).create() + bm = target_sat.api.Bookmark(controller=controller, public=public).create() assert bm.controller == controller assert bm.public == public @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_negative_create_with_invalid_name(controller): +def test_negative_create_with_invalid_name(controller, target_sat): """Create a bookmark with invalid name :id: 9a79c561-8225-43fc-8ec7-b6858e9665e2 @@ -131,14 +130,14 @@ def test_negative_create_with_invalid_name(controller): """ name = random.choice(invalid_values_list()) with pytest.raises(HTTPError): - entities.Bookmark(controller=controller, name=name, public=False).create() - result = entities.Bookmark().search(query={'search': f'name="{name}"'}) + target_sat.api.Bookmark(controller=controller, name=name, public=False).create() + result = target_sat.api.Bookmark().search(query={'search': f'name="{name}"'}) assert len(result) == 0 @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_negative_create_empty_query(controller): +def test_negative_create_empty_query(controller, target_sat): """Create a bookmark with empty query :id: 674d569f-6f86-43ba-b9cc-f43e05e8ab1c @@ -159,14 +158,14 @@ def test_negative_create_empty_query(controller): """ name = gen_string('alpha') with pytest.raises(HTTPError): - entities.Bookmark(controller=controller, name=name, query='').create() - result = entities.Bookmark().search(query={'search': f'name="{name}"'}) + target_sat.api.Bookmark(controller=controller, name=name, query='').create() + result = target_sat.api.Bookmark().search(query={'search': f'name="{name}"'}) assert len(result) == 0 @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_negative_create_same_name(controller): +def test_negative_create_same_name(controller, target_sat): """Create bookmarks with the same names :id: f78f6e97-da77-4a61-95c2-622c439d325d @@ -187,16 +186,16 @@ def test_negative_create_same_name(controller): :CaseImportance: Critical """ name = gen_string('alphanumeric') - entities.Bookmark(controller=controller, name=name).create() + target_sat.api.Bookmark(controller=controller, name=name).create() with pytest.raises(HTTPError): - entities.Bookmark(controller=controller, name=name).create() - result = entities.Bookmark().search(query={'search': f'name="{name}"'}) + target_sat.api.Bookmark(controller=controller, name=name).create() + result = target_sat.api.Bookmark().search(query={'search': f'name="{name}"'}) assert len(result) == 1 @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_negative_create_null_public(controller): +def test_negative_create_null_public(controller, target_sat): """Create a bookmark omitting the public parameter :id: 0a4cb5ea-912b-445e-a874-b345e43d3eac @@ -220,14 +219,14 @@ def test_negative_create_null_public(controller): """ name = gen_string('alphanumeric') with pytest.raises(HTTPError): - entities.Bookmark(controller=controller, name=name, public=None).create() - result = entities.Bookmark().search(query={'search': f'name="{name}"'}) + target_sat.api.Bookmark(controller=controller, name=name, public=None).create() + result = target_sat.api.Bookmark().search(query={'search': f'name="{name}"'}) assert len(result) == 0 @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_positive_update_name(controller): +def test_positive_update_name(controller, target_sat): """Update a bookmark :id: 1cde270a-26fb-4cff-bdff-89fef17a7624 @@ -246,7 +245,7 @@ def test_positive_update_name(controller): :CaseImportance: Critical """ new_name = random.choice(list(valid_data_list().values())) - bm = entities.Bookmark(controller=controller, public=False).create() + bm = target_sat.api.Bookmark(controller=controller, public=False).create() bm.name = new_name bm = bm.update(['name']) assert bm.name == new_name @@ -254,7 +253,7 @@ def test_positive_update_name(controller): @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_negative_update_same_name(controller): +def test_negative_update_same_name(controller, target_sat): """Update a bookmark with name already taken :id: 6becf121-2bea-4f7e-98f4-338bd88b8f4b @@ -274,8 +273,8 @@ def test_negative_update_same_name(controller): :CaseImportance: Critical """ name = gen_string('alphanumeric') - entities.Bookmark(controller=controller, name=name).create() - bm = entities.Bookmark(controller=controller).create() + target_sat.api.Bookmark(controller=controller, name=name).create() + bm = target_sat.api.Bookmark(controller=controller).create() bm.name = name with pytest.raises(HTTPError): bm.update(['name']) @@ -285,7 +284,7 @@ def test_negative_update_same_name(controller): @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_negative_update_invalid_name(controller): +def test_negative_update_invalid_name(controller, target_sat): """Update a bookmark with an invalid name :id: 479795bb-aeed-45b3-a7e3-d3449c808087 @@ -304,7 +303,7 @@ def test_negative_update_invalid_name(controller): :CaseImportance: Critical """ new_name = random.choice(invalid_values_list()) - bm = entities.Bookmark(controller=controller, public=False).create() + bm = target_sat.api.Bookmark(controller=controller, public=False).create() bm.name = new_name with pytest.raises(HTTPError): bm.update(['name']) @@ -314,7 +313,7 @@ def test_negative_update_invalid_name(controller): @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_positive_update_query(controller): +def test_positive_update_query(controller, target_sat): """Update a bookmark query :id: 92a31de2-bebf-4396-94f5-adf59f8d66a5 @@ -333,7 +332,7 @@ def test_positive_update_query(controller): :CaseImportance: Critical """ new_query = random.choice(list(valid_data_list().values())) - bm = entities.Bookmark(controller=controller).create() + bm = target_sat.api.Bookmark(controller=controller).create() bm.query = new_query bm = bm.update(['query']) assert bm.query == new_query @@ -341,7 +340,7 @@ def test_positive_update_query(controller): @pytest.mark.tier1 @pytest.mark.parametrize('controller', CONTROLLERS) -def test_negative_update_empty_query(controller): +def test_negative_update_empty_query(controller, target_sat): """Update a bookmark with an empty query :id: 948602d3-532a-47fe-b313-91e3fab809bf @@ -359,7 +358,7 @@ def test_negative_update_empty_query(controller): :CaseImportance: Critical """ - bm = entities.Bookmark(controller=controller).create() + bm = target_sat.api.Bookmark(controller=controller).create() bm.query = '' with pytest.raises(HTTPError): bm.update(['query']) @@ -370,7 +369,7 @@ def test_negative_update_empty_query(controller): @pytest.mark.tier1 @pytest.mark.parametrize('public', (True, False)) @pytest.mark.parametrize('controller', CONTROLLERS) -def test_positive_update_public(controller, public): +def test_positive_update_public(controller, public, target_sat): """Update a bookmark public state to private and vice versa :id: 2717360d-37c4-4bb9-bce1-b1edabdf11b3 @@ -389,7 +388,7 @@ def test_positive_update_public(controller, public): :CaseImportance: Critical """ - bm = entities.Bookmark(controller=controller, public=not public).create() + bm = target_sat.api.Bookmark(controller=controller, public=not public).create() assert bm.public != public bm.public = public bm = bm.update(['public']) diff --git a/tests/foreman/api/test_capsulecontent.py b/tests/foreman/api/test_capsulecontent.py index cdc388fd149..641e1390167 100644 --- a/tests/foreman/api/test_capsulecontent.py +++ b/tests/foreman/api/test_capsulecontent.py @@ -21,7 +21,7 @@ import re from time import sleep -from nailgun import client, entities +from nailgun import client from nailgun.entity_mixins import call_entity_method_with_timeout import pytest @@ -43,9 +43,13 @@ class TestCapsuleContentManagement: interactions and use capsule. """ - def update_capsule_download_policy(self, module_capsule_configured, download_policy): + def update_capsule_download_policy( + self, module_capsule_configured, download_policy, module_target_sat + ): """Updates capsule's download policy to desired value""" - proxy = entities.SmartProxy(id=module_capsule_configured.nailgun_capsule.id).read() + proxy = module_target_sat.api.SmartProxy( + id=module_capsule_configured.nailgun_capsule.id + ).read() proxy.download_policy = download_policy proxy.update(['download_policy']) @@ -78,7 +82,12 @@ def test_positive_insights_puppet_package_availability(self, module_capsule_conf @pytest.mark.tier4 @pytest.mark.skip_if_not_set('capsule', 'clients', 'fake_manifest') def test_positive_uploaded_content_library_sync( - self, module_capsule_configured, function_org, function_product, function_lce_library + self, + module_capsule_configured, + function_org, + function_product, + function_lce_library, + target_sat, ): """Ensure custom repo with no upstream url and manually uploaded content after publishing to Library is synchronized to capsule @@ -92,7 +101,7 @@ def test_positive_uploaded_content_library_sync( :expectedresults: custom content is present on external capsule """ - repo = entities.Repository(product=function_product, url=None).create() + repo = target_sat.api.Repository(product=function_product, url=None).create() # Associate the lifecycle environment with the capsule module_capsule_configured.nailgun_capsule.content_add_lifecycle_environment( data={'environment_id': function_lce_library.id} @@ -103,7 +112,7 @@ def test_positive_uploaded_content_library_sync( assert function_lce_library.id in [capsule_lce['id'] for capsule_lce in result['results']] # Create a content view with the repository - cv = entities.ContentView(organization=function_org, repository=[repo]).create() + cv = target_sat.api.ContentView(organization=function_org, repository=[repo]).create() # Upload custom content into the repo with open(DataFile.RPM_TO_UPLOAD, 'rb') as handle: @@ -134,7 +143,7 @@ def test_positive_uploaded_content_library_sync( @pytest.mark.tier4 @pytest.mark.skip_if_not_set('capsule', 'clients', 'fake_manifest') def test_positive_checksum_sync( - self, module_capsule_configured, function_org, function_product, function_lce + self, module_capsule_configured, function_org, function_product, function_lce, target_sat ): """Synchronize repository to capsule, update repository's checksum type, trigger capsule sync and make sure checksum type was updated on @@ -152,7 +161,7 @@ def test_positive_checksum_sync( :CaseImportance: Critical """ # Create repository with sha256 checksum type - repo = entities.Repository( + repo = target_sat.api.Repository( product=function_product, checksum_type='sha256', mirroring_policy='additive', @@ -168,7 +177,7 @@ def test_positive_checksum_sync( assert function_lce.id in [capsule_lce['id'] for capsule_lce in result['results']] # Sync, publish and promote a repo - cv = entities.ContentView(organization=function_org, repository=[repo]).create() + cv = target_sat.api.ContentView(organization=function_org, repository=[repo]).create() repo.sync() repo = repo.read() cv.publish() @@ -228,7 +237,12 @@ def test_positive_checksum_sync( @pytest.mark.tier4 @pytest.mark.skip_if_not_set('capsule') def test_positive_sync_updated_repo( - self, target_sat, module_capsule_configured, function_org, function_product, function_lce + self, + target_sat, + module_capsule_configured, + function_org, + function_product, + function_lce, ): """Sync a custom repo with no upstream url but uploaded content to the Capsule via promoted CV, update content of the repo, publish and promote the CV again, resync @@ -256,7 +270,7 @@ def test_positive_sync_updated_repo( :BZ: 2025494 """ - repo = entities.Repository(url=None, product=function_product).create() + repo = target_sat.api.Repository(url=None, product=function_product).create() # Associate the lifecycle environment with the capsule module_capsule_configured.nailgun_capsule.content_add_lifecycle_environment( @@ -274,7 +288,7 @@ def test_positive_sync_updated_repo( assert repo.read().content_counts['rpm'] == 1 # Create, publish and promote CV with the repository to the Capsule's LCE - cv = entities.ContentView(organization=function_org, repository=[repo]).create() + cv = target_sat.api.ContentView(organization=function_org, repository=[repo]).create() cv.publish() cv = cv.read() assert len(cv.version) == 1 @@ -329,7 +343,12 @@ def test_positive_sync_updated_repo( @pytest.mark.tier4 @pytest.mark.skip_if_not_set('capsule', 'clients', 'fake_manifest') def test_positive_capsule_sync( - self, target_sat, module_capsule_configured, function_org, function_product, function_lce + self, + target_sat, + module_capsule_configured, + function_org, + function_product, + function_lce, ): """Create repository, add it to lifecycle environment, assign lifecycle environment with a capsule, sync repository, sync it once again, update @@ -353,7 +372,7 @@ def test_positive_capsule_sync( capsule """ repo_url = settings.repos.yum_1.url - repo = entities.Repository(product=function_product, url=repo_url).create() + repo = target_sat.api.Repository(product=function_product, url=repo_url).create() # Associate the lifecycle environment with the capsule module_capsule_configured.nailgun_capsule.content_add_lifecycle_environment( data={'environment_id': function_lce.id} @@ -364,7 +383,7 @@ def test_positive_capsule_sync( assert function_lce.id in [capsule_lce['id'] for capsule_lce in result['results']] # Create a content view with the repository - cv = entities.ContentView(organization=function_org, repository=[repo]).create() + cv = target_sat.api.ContentView(organization=function_org, repository=[repo]).create() # Sync repository repo.sync() repo = repo.read() @@ -491,12 +510,12 @@ def test_positive_iso_library_sync( reposet=constants.REPOSET['rhsc7_iso'], releasever=None, ) - rh_repo = entities.Repository(id=rh_repo_id).read() + rh_repo = module_target_sat.api.Repository(id=rh_repo_id).read() call_entity_method_with_timeout(rh_repo.sync, timeout=2500) # Find "Library" lifecycle env for specific organization - lce = entities.LifecycleEnvironment(organization=module_entitlement_manifest_org).search( - query={'search': f'name={constants.ENVIRONMENT}'} - )[0] + lce = module_target_sat.api.LifecycleEnvironment( + organization=module_entitlement_manifest_org + ).search(query={'search': f'name={constants.ENVIRONMENT}'})[0] # Associate the lifecycle environment with the capsule module_capsule_configured.nailgun_capsule.content_add_lifecycle_environment( @@ -508,7 +527,7 @@ def test_positive_iso_library_sync( assert lce.id in [capsule_lce['id'] for capsule_lce in result['results']] # Create a content view with the repository - cv = entities.ContentView( + cv = module_target_sat.api.ContentView( organization=module_entitlement_manifest_org, repository=[rh_repo] ).create() # Publish new version of the content view @@ -536,7 +555,12 @@ def test_positive_iso_library_sync( @pytest.mark.tier4 @pytest.mark.skip_if_not_set('capsule', 'clients', 'fake_manifest') def test_positive_on_demand_sync( - self, target_sat, module_capsule_configured, function_org, function_product, function_lce + self, + target_sat, + module_capsule_configured, + function_org, + function_product, + function_lce, ): """Create a repository with 'on_demand' policy, add it to a CV, promote to an 'on_demand' Capsule's LCE, download a published package, @@ -555,7 +579,7 @@ def test_positive_on_demand_sync( repo_url = settings.repos.yum_3.url packages_count = constants.FAKE_3_YUM_REPOS_COUNT package = constants.FAKE_3_YUM_REPO_RPMS[0] - repo = entities.Repository( + repo = target_sat.api.Repository( download_policy='on_demand', mirroring_policy='mirror_complete', product=function_product, @@ -574,7 +598,7 @@ def test_positive_on_demand_sync( self.update_capsule_download_policy(module_capsule_configured, 'on_demand') # Create a content view with the repository - cv = entities.ContentView(organization=function_org, repository=[repo]).create() + cv = target_sat.api.ContentView(organization=function_org, repository=[repo]).create() # Sync repository repo.sync() repo = repo.read() @@ -616,7 +640,12 @@ def test_positive_on_demand_sync( @pytest.mark.tier4 @pytest.mark.skip_if_not_set('capsule', 'clients', 'fake_manifest') def test_positive_update_with_immediate_sync( - self, target_sat, module_capsule_configured, function_org, function_product, function_lce + self, + target_sat, + module_capsule_configured, + function_org, + function_product, + function_lce, ): """Create a repository with on_demand download policy, associate it with capsule, sync repo, update download policy to immediate, sync once @@ -633,7 +662,7 @@ def test_positive_update_with_immediate_sync( """ repo_url = settings.repos.yum_1.url packages_count = constants.FAKE_1_YUM_REPOS_COUNT - repo = entities.Repository( + repo = target_sat.api.Repository( download_policy='on_demand', mirroring_policy='mirror_complete', product=function_product, @@ -651,7 +680,7 @@ def test_positive_update_with_immediate_sync( assert function_lce.id in [capsule_lce['id'] for capsule_lce in result['results']] # Create a content view with the repository - cv = entities.ContentView(organization=function_org, repository=[repo]).create() + cv = target_sat.api.ContentView(organization=function_org, repository=[repo]).create() # Sync repository repo.sync() repo = repo.read() @@ -765,8 +794,10 @@ def test_positive_sync_kickstart_repo( repo=constants.REPOS['kickstart'][distro]['name'], releasever=constants.REPOS['kickstart'][distro]['version'], ) - repo = entities.Repository(id=repo_id).read() - lce = entities.LifecycleEnvironment(organization=function_entitlement_manifest_org).create() + repo = target_sat.api.Repository(id=repo_id).read() + lce = target_sat.api.LifecycleEnvironment( + organization=function_entitlement_manifest_org + ).create() # Associate the lifecycle environment with the capsule module_capsule_configured.nailgun_capsule.content_add_lifecycle_environment( data={'environment_id': lce.id} @@ -780,7 +811,7 @@ def test_positive_sync_kickstart_repo( self.update_capsule_download_policy(module_capsule_configured, 'on_demand') # Create a content view with the repository - cv = entities.ContentView( + cv = target_sat.api.ContentView( organization=function_entitlement_manifest_org, repository=[repo] ).create() # Sync repository @@ -868,7 +899,7 @@ def test_positive_sync_container_repo_end_to_end( repos = [] for ups_name in upstream_names: - repo = entities.Repository( + repo = target_sat.api.Repository( content_type='docker', docker_upstream_name=ups_name, product=function_product, @@ -886,7 +917,7 @@ def test_positive_sync_container_repo_end_to_end( assert function_lce.id in [capsule_lce['id'] for capsule_lce in result['results']] # Create and publish a content view with all repositories - cv = entities.ContentView(organization=function_org, repository=repos).create() + cv = target_sat.api.ContentView(organization=function_org, repository=repos).create() cv.publish() cv = cv.read() assert len(cv.version) == 1 @@ -995,7 +1026,7 @@ def test_positive_sync_collection_repo( - name: theforeman.operations version: "0.1.0" ''' - repo = entities.Repository( + repo = target_sat.api.Repository( content_type='ansible_collection', ansible_collection_requirements=requirements, product=function_product, @@ -1066,7 +1097,7 @@ def test_positive_sync_file_repo( :BZ: 1985122 """ - repo = entities.Repository( + repo = target_sat.api.Repository( content_type='file', product=function_product, url=constants.FAKE_FILE_LARGE_URL, @@ -1086,7 +1117,7 @@ def test_positive_sync_file_repo( assert function_lce.id in [capsule_lce['id'] for capsule_lce in result['results']] # Create and publish a content view with all repositories - cv = entities.ContentView(organization=function_org, repository=[repo]).create() + cv = target_sat.api.ContentView(organization=function_org, repository=[repo]).create() cv.publish() cv = cv.read() assert len(cv.version) == 1 diff --git a/tests/foreman/api/test_computeprofile.py b/tests/foreman/api/test_computeprofile.py index d0ee003c7a3..dffe47620b4 100644 --- a/tests/foreman/api/test_computeprofile.py +++ b/tests/foreman/api/test_computeprofile.py @@ -16,7 +16,6 @@ :Upstream: No """ -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -29,7 +28,7 @@ @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_create_with_name(name): +def test_positive_create_with_name(name, target_sat): """Create new Compute Profile using different names :id: 97d04911-9368-4674-92c7-1e3ff114bc18 @@ -42,13 +41,13 @@ def test_positive_create_with_name(name): :parametrized: yes """ - profile = entities.ComputeProfile(name=name).create() + profile = target_sat.api.ComputeProfile(name=name).create() assert name == profile.name @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_create(name): +def test_negative_create(name, target_sat): """Attempt to create Compute Profile using invalid names only :id: 2d34a1fd-70a5-4e59-b2e2-86fbfe8e31ab @@ -62,12 +61,12 @@ def test_negative_create(name): :parametrized: yes """ with pytest.raises(HTTPError): - entities.ComputeProfile(name=name).create() + target_sat.api.ComputeProfile(name=name).create() @pytest.mark.parametrize('new_name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_update_name(new_name): +def test_positive_update_name(new_name, target_sat): """Update selected Compute Profile entity using proper names :id: c79193d7-2e0f-4ed9-b947-05feeddabfda @@ -80,15 +79,15 @@ def test_positive_update_name(new_name): :parametrized: yes """ - profile = entities.ComputeProfile().create() - entities.ComputeProfile(id=profile.id, name=new_name).update(['name']) - updated_profile = entities.ComputeProfile(id=profile.id).read() + profile = target_sat.api.ComputeProfile().create() + target_sat.api.ComputeProfile(id=profile.id, name=new_name).update(['name']) + updated_profile = target_sat.api.ComputeProfile(id=profile.id).read() assert new_name == updated_profile.name @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_update_name(new_name): +def test_negative_update_name(new_name, target_sat): """Attempt to update Compute Profile entity using invalid names only :id: 042b40d5-a78b-4e65-b5cb-5b270b800b37 @@ -101,16 +100,16 @@ def test_negative_update_name(new_name): :parametrized: yes """ - profile = entities.ComputeProfile().create() + profile = target_sat.api.ComputeProfile().create() with pytest.raises(HTTPError): - entities.ComputeProfile(id=profile.id, name=new_name).update(['name']) - updated_profile = entities.ComputeProfile(id=profile.id).read() + target_sat.api.ComputeProfile(id=profile.id, name=new_name).update(['name']) + updated_profile = target_sat.api.ComputeProfile(id=profile.id).read() assert new_name != updated_profile.name @pytest.mark.parametrize('new_name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_delete(new_name): +def test_positive_delete(new_name, target_sat): """Delete Compute Profile entity :id: 0a620e23-7ba6-4178-af7a-fd1e332f478f @@ -123,7 +122,7 @@ def test_positive_delete(new_name): :parametrized: yes """ - profile = entities.ComputeProfile(name=new_name).create() + profile = target_sat.api.ComputeProfile(name=new_name).create() profile.delete() with pytest.raises(HTTPError): - entities.ComputeProfile(id=profile.id).read() + target_sat.api.ComputeProfile(id=profile.id).read() diff --git a/tests/foreman/api/test_contentcredentials.py b/tests/foreman/api/test_contentcredentials.py index 81602c953e4..aaad0322976 100644 --- a/tests/foreman/api/test_contentcredentials.py +++ b/tests/foreman/api/test_contentcredentials.py @@ -19,7 +19,6 @@ from copy import copy from fauxfactory import gen_string -from nailgun import entities import pytest from requests import HTTPError @@ -35,7 +34,7 @@ @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_create_with_name(module_org, name): +def test_positive_create_with_name(module_org, name, module_target_sat): """Create a GPG key with valid name. :id: 741d969b-28ef-481f-bcf7-ed4cd920b030 @@ -46,12 +45,12 @@ def test_positive_create_with_name(module_org, name): :CaseImportance: Critical """ - gpg_key = entities.GPGKey(organization=module_org, name=name).create() + gpg_key = module_target_sat.api.GPGKey(organization=module_org, name=name).create() assert name == gpg_key.name @pytest.mark.tier1 -def test_positive_create_with_content(module_org): +def test_positive_create_with_content(module_org, module_target_sat): """Create a GPG key with valid name and valid gpg key text. :id: cfa6690e-fed7-49cf-94f9-fd2deed941c0 @@ -60,13 +59,13 @@ def test_positive_create_with_content(module_org): :CaseImportance: Critical """ - gpg_key = entities.GPGKey(organization=module_org, content=key_content).create() + gpg_key = module_target_sat.api.GPGKey(organization=module_org, content=key_content).create() assert key_content == gpg_key.content @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_create_name(module_org, name): +def test_negative_create_name(module_org, name, module_target_sat): """Attempt to create GPG key with invalid names only. :id: 904a3ed0-7d50-495e-a700-b4f1ae913599 @@ -78,13 +77,13 @@ def test_negative_create_name(module_org, name): :CaseImportance: Critical """ with pytest.raises(HTTPError) as error: - entities.GPGKey(organization=module_org, name=name).create() + module_target_sat.api.GPGKey(organization=module_org, name=name).create() assert error.value.response.status_code == 422 assert 'Validation failed:' in error.value.response.text @pytest.mark.tier1 -def test_negative_create_with_same_name(module_org): +def test_negative_create_with_same_name(module_org, module_target_sat): """Attempt to create a GPG key providing a name of already existent entity @@ -95,15 +94,15 @@ def test_negative_create_with_same_name(module_org): :CaseImportance: Critical """ name = gen_string('alphanumeric') - entities.GPGKey(organization=module_org, name=name).create() + module_target_sat.api.GPGKey(organization=module_org, name=name).create() with pytest.raises(HTTPError) as error: - entities.GPGKey(organization=module_org, name=name).create() + module_target_sat.api.GPGKey(organization=module_org, name=name).create() assert error.value.response.status_code == 422 assert 'Validation failed:' in error.value.response.text @pytest.mark.tier1 -def test_negative_create_with_content(module_org): +def test_negative_create_with_content(module_org, module_target_sat): """Attempt to create GPG key with empty content. :id: fc79c840-6bcb-4d97-9145-c0008d5b028d @@ -113,14 +112,14 @@ def test_negative_create_with_content(module_org): :CaseImportance: Critical """ with pytest.raises(HTTPError) as error: - entities.GPGKey(organization=module_org, content='').create() + module_target_sat.api.GPGKey(organization=module_org, content='').create() assert error.value.response.status_code == 422 assert 'Validation failed:' in error.value.response.text @pytest.mark.parametrize('new_name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_update_name(module_org, new_name): +def test_positive_update_name(module_org, new_name, module_target_sat): """Update GPG key name to another valid name. :id: 9868025d-5346-42c9-b850-916ce37a9541 @@ -131,14 +130,14 @@ def test_positive_update_name(module_org, new_name): :CaseImportance: Critical """ - gpg_key = entities.GPGKey(organization=module_org).create() + gpg_key = module_target_sat.api.GPGKey(organization=module_org).create() gpg_key.name = new_name gpg_key = gpg_key.update(['name']) assert new_name == gpg_key.name @pytest.mark.tier1 -def test_positive_update_content(module_org): +def test_positive_update_content(module_org, module_target_sat): """Update GPG key content text to another valid one. :id: 62fdaf55-c931-4be6-9857-68cc816046ad @@ -147,7 +146,7 @@ def test_positive_update_content(module_org): :CaseImportance: Critical """ - gpg_key = entities.GPGKey( + gpg_key = module_target_sat.api.GPGKey( organization=module_org, content=DataFile.VALID_GPG_KEY_BETA_FILE.read_text(), ).create() @@ -158,7 +157,7 @@ def test_positive_update_content(module_org): @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_update_name(module_org, new_name): +def test_negative_update_name(module_org, new_name, module_target_sat): """Attempt to update GPG key name to invalid one :id: 1a43f610-8969-4f08-967f-fb6af0fca31b @@ -169,7 +168,7 @@ def test_negative_update_name(module_org, new_name): :CaseImportance: Critical """ - gpg_key = entities.GPGKey(organization=module_org).create() + gpg_key = module_target_sat.api.GPGKey(organization=module_org).create() gpg_key.name = new_name with pytest.raises(HTTPError) as error: gpg_key.update(['name']) @@ -178,7 +177,7 @@ def test_negative_update_name(module_org, new_name): @pytest.mark.tier1 -def test_negative_update_same_name(module_org): +def test_negative_update_same_name(module_org, module_target_sat): """Attempt to update GPG key name to the name of existing GPG key entity @@ -189,8 +188,8 @@ def test_negative_update_same_name(module_org): :CaseImportance: Critical """ name = gen_string('alpha') - entities.GPGKey(organization=module_org, name=name).create() - new_gpg_key = entities.GPGKey(organization=module_org).create() + module_target_sat.api.GPGKey(organization=module_org, name=name).create() + new_gpg_key = module_target_sat.api.GPGKey(organization=module_org).create() new_gpg_key.name = name with pytest.raises(HTTPError) as error: new_gpg_key.update(['name']) @@ -199,7 +198,7 @@ def test_negative_update_same_name(module_org): @pytest.mark.tier1 -def test_negative_update_content(module_org): +def test_negative_update_content(module_org, module_target_sat): """Attempt to update GPG key content to invalid one :id: fee30ef8-370a-4fdd-9e45-e7ab95dade8b @@ -208,7 +207,7 @@ def test_negative_update_content(module_org): :CaseImportance: Critical """ - gpg_key = entities.GPGKey(organization=module_org, content=key_content).create() + gpg_key = module_target_sat.api.GPGKey(organization=module_org, content=key_content).create() gpg_key.content = '' with pytest.raises(HTTPError) as error: gpg_key.update(['content']) @@ -218,7 +217,7 @@ def test_negative_update_content(module_org): @pytest.mark.tier1 -def test_positive_delete(module_org): +def test_positive_delete(module_org, module_target_sat): """Create a GPG key with different names and then delete it. :id: b06d211f-2827-40f7-b627-8b1fbaee2eb4 @@ -227,7 +226,7 @@ def test_positive_delete(module_org): :CaseImportance: Critical """ - gpg_key = entities.GPGKey(organization=module_org).create() + gpg_key = module_target_sat.api.GPGKey(organization=module_org).create() gpg_key.delete() with pytest.raises(HTTPError): gpg_key.read() diff --git a/tests/foreman/api/test_contentview.py b/tests/foreman/api/test_contentview.py index 0e1e94c88d4..d060ed58a19 100644 --- a/tests/foreman/api/test_contentview.py +++ b/tests/foreman/api/test_contentview.py @@ -19,7 +19,6 @@ import random from fauxfactory import gen_integer, gen_string, gen_utf8 -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -48,8 +47,8 @@ @pytest.fixture(scope='class') -def class_cv(module_org): - return entities.ContentView(organization=module_org).create() +def class_cv(module_org, module_target_sat): + return module_target_sat.api.ContentView(organization=module_org).create() @pytest.fixture(scope='class') @@ -65,22 +64,22 @@ def class_promoted_cv(class_published_cv, module_lce): @pytest.fixture(scope='class') -def class_cloned_cv(class_cv): - copied_cv_id = entities.ContentView(id=class_cv.id).copy( +def class_cloned_cv(class_cv, target_sat): + copied_cv_id = target_sat.api.ContentView(id=class_cv.id).copy( data={'name': gen_string('alpha', gen_integer(3, 30))} )['id'] - return entities.ContentView(id=copied_cv_id).read() + return target_sat.api.ContentView(id=copied_cv_id).read() @pytest.fixture(scope='class') -def class_published_cloned_cv(class_cloned_cv): +def class_published_cloned_cv(class_cloned_cv, target_sat): class_cloned_cv.publish() - return entities.ContentView(id=class_cloned_cv.id).read() + return target_sat.api.ContentView(id=class_cloned_cv.id).read() @pytest.fixture -def content_view(module_org): - return entities.ContentView(organization=module_org).create() +def content_view(module_org, module_target_sat): + return module_target_sat.api.ContentView(organization=module_org).create() def apply_package_filter(content_view, repo, package, target_sat, inclusion=True): @@ -93,7 +92,7 @@ def apply_package_filter(content_view, repo, package, target_sat, inclusion=True :return list : list of content view versions """ - cv_filter = entities.RPMContentViewFilter( + cv_filter = target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=inclusion, repository=[repo] ).create() cv_filter_rule = target_sat.api.ContentViewFilterRule( @@ -109,7 +108,9 @@ def apply_package_filter(content_view, repo, package, target_sat, inclusion=True class TestContentView: @pytest.mark.upgrade @pytest.mark.tier3 - def test_positive_subscribe_host(self, class_cv, class_promoted_cv, module_lce, module_org): + def test_positive_subscribe_host( + self, class_cv, class_promoted_cv, module_lce, module_org, module_target_sat + ): """Subscribe a host to a content view :id: b5a08369-bf92-48ab-b9aa-10f5b9774b79 @@ -130,7 +131,7 @@ def test_positive_subscribe_host(self, class_cv, class_promoted_cv, module_lce, # Check that no host associated to just created content view assert class_cv.content_host_count == 0 assert len(class_promoted_cv.version) == 1 - host = entities.Host( + host = module_target_sat.api.Host( content_facet_attributes={ 'content_view_id': class_cv.id, 'lifecycle_environment_id': module_lce.id, @@ -160,7 +161,9 @@ def test_positive_clone_within_same_env(self, class_published_cloned_cv, module_ @pytest.mark.upgrade @pytest.mark.tier2 - def test_positive_clone_with_diff_env(self, module_org, class_published_cloned_cv): + def test_positive_clone_with_diff_env( + self, module_org, class_published_cloned_cv, module_target_sat + ): """attempt to create, publish and promote new content view based on existing view but promoted to a different environment @@ -174,11 +177,11 @@ def test_positive_clone_with_diff_env(self, module_org, class_published_cloned_c :CaseImportance: Medium """ - le_clone = entities.LifecycleEnvironment(organization=module_org).create() + le_clone = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() class_published_cloned_cv.read().version[0].promote(data={'environment_ids': le_clone.id}) @pytest.mark.tier2 - def test_positive_add_custom_content(self, module_product, module_org): + def test_positive_add_custom_content(self, module_product, module_org, module_target_sat): """Associate custom content in a view :id: db452e0c-0c17-40f2-bab4-8467e7a875f1 @@ -189,9 +192,9 @@ def test_positive_add_custom_content(self, module_product, module_org): :CaseImportance: Critical """ - yum_repo = entities.Repository(product=module_product).create() + yum_repo = module_target_sat.api.Repository(product=module_product).create() yum_repo.sync() - content_view = entities.ContentView(organization=module_org.id).create() + content_view = module_target_sat.api.ContentView(organization=module_org.id).create() assert len(content_view.repository) == 0 content_view.repository = [yum_repo] content_view = content_view.update(['repository']) @@ -202,7 +205,9 @@ def test_positive_add_custom_content(self, module_product, module_org): @pytest.mark.skipif( (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) - def test_positive_add_custom_module_streams(self, content_view, module_product, module_org): + def test_positive_add_custom_module_streams( + self, content_view, module_product, module_org, module_target_sat + ): """Associate custom content (module streams) in a view :id: 9e4821cb-293a-4d84-bd1f-bb9fff36b143 @@ -213,7 +218,7 @@ def test_positive_add_custom_module_streams(self, content_view, module_product, :CaseImportance: High """ - yum_repo = entities.Repository( + yum_repo = module_target_sat.api.Repository( product=module_product, url=settings.repos.module_stream_1.url ).create() yum_repo.sync() @@ -226,7 +231,9 @@ def test_positive_add_custom_module_streams(self, content_view, module_product, assert repo.content_counts['module_stream'] == 7 @pytest.mark.tier2 - def test_negative_add_dupe_repos(self, content_view, module_product, module_org): + def test_negative_add_dupe_repos( + self, content_view, module_product, module_org, module_target_sat + ): """Attempt to associate the same repo multiple times within a content view @@ -238,7 +245,7 @@ def test_negative_add_dupe_repos(self, content_view, module_product, module_org) :CaseImportance: Low """ - yum_repo = entities.Repository(product=module_product).create() + yum_repo = module_target_sat.api.Repository(product=module_product).create() yum_repo.sync() assert len(content_view.repository) == 0 with pytest.raises(HTTPError): @@ -251,7 +258,7 @@ def test_negative_add_dupe_repos(self, content_view, module_product, module_org) @pytest.mark.skipif( (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) - def test_positive_add_sha512_rpm(self, content_view, module_org): + def test_positive_add_sha512_rpm(self, content_view, module_org, module_target_sat): """Associate sha512 RPM content in a view :id: 1f473b02-5e2b-41ff-a706-c0635abc2476 @@ -270,8 +277,10 @@ def test_positive_add_sha512_rpm(self, content_view, module_org): :BZ: 1639406 """ - product = entities.Product(organization=module_org).create() - yum_sha512_repo = entities.Repository(product=product, url=CUSTOM_RPM_SHA_512).create() + product = module_target_sat.api.Product(organization=module_org).create() + yum_sha512_repo = module_target_sat.api.Repository( + product=product, url=CUSTOM_RPM_SHA_512 + ).create() yum_sha512_repo.sync() repo_content = yum_sha512_repo.read() # Assert that the repository content was properly synced @@ -295,7 +304,7 @@ class TestContentViewCreate: @pytest.mark.parametrize('composite', [True, False]) @pytest.mark.tier1 - def test_positive_create_composite(self, composite): + def test_positive_create_composite(self, composite, target_sat): """Create composite and non-composite content views. :id: 4a3b616d-53ab-4396-9a50-916d6c42a401 @@ -307,11 +316,11 @@ def test_positive_create_composite(self, composite): :CaseImportance: Critical """ - assert entities.ContentView(composite=composite).create().composite == composite + assert target_sat.api.ContentView(composite=composite).create().composite == composite @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 - def test_positive_create_with_name(self, name): + def test_positive_create_with_name(self, name, target_sat): """Create empty content-view with random names. :id: 80d36498-2e71-4aa9-b696-f0a45e86267f @@ -322,11 +331,11 @@ def test_positive_create_with_name(self, name): :CaseImportance: Critical """ - assert entities.ContentView(name=name).create().name == name + assert target_sat.api.ContentView(name=name).create().name == name @pytest.mark.parametrize('desc', **parametrized(valid_data_list())) @pytest.mark.tier1 - def test_positive_create_with_description(self, desc): + def test_positive_create_with_description(self, desc, target_sat): """Create empty content view with random description. :id: 068e3e7c-34ac-47cb-a1bb-904d12c74cc7 @@ -337,10 +346,10 @@ def test_positive_create_with_description(self, desc): :CaseImportance: High """ - assert entities.ContentView(description=desc).create().description == desc + assert target_sat.api.ContentView(description=desc).create().description == desc @pytest.mark.tier1 - def test_positive_clone(self, content_view, module_org): + def test_positive_clone(self, content_view, module_org, module_target_sat): """Create a content view by copying an existing one :id: ee03dc63-e2b0-4a89-a828-2910405279ff @@ -349,7 +358,7 @@ def test_positive_clone(self, content_view, module_org): :CaseImportance: Critical """ - cloned_cv = entities.ContentView( + cloned_cv = module_target_sat.api.ContentView( id=content_view.copy(data={'name': gen_string('alpha', gen_integer(3, 30))})['id'] ).read_json() cv_origin = content_view.read_json() @@ -361,7 +370,7 @@ def test_positive_clone(self, content_view, module_org): @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) @pytest.mark.tier1 - def test_negative_create_with_invalid_name(self, name): + def test_negative_create_with_invalid_name(self, name, target_sat): """Create content view providing an invalid name. :id: 261376ca-7d12-41b6-9c36-5f284865243e @@ -373,7 +382,7 @@ def test_negative_create_with_invalid_name(self, name): :CaseImportance: High """ with pytest.raises(HTTPError): - entities.ContentView(name=name).create() + target_sat.api.ContentView(name=name).create() class TestContentViewPublishPromote: @@ -383,16 +392,18 @@ class TestContentViewPublishPromote: (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) @pytest.fixture(scope='class', autouse=True) - def class_setup(self, request, module_product): + def class_setup(self, request, module_product, module_target_sat): """Set up organization, product and repositories for tests.""" - request.cls.yum_repo = entities.Repository(product=module_product).create() + request.cls.yum_repo = module_target_sat.api.Repository(product=module_product).create() self.yum_repo.sync() - request.cls.swid_repo = entities.Repository( + request.cls.swid_repo = module_target_sat.api.Repository( product=module_product, url=settings.repos.swid_tag.url ).create() self.swid_repo.sync() - def add_content_views_to_composite(self, composite_cv, module_org, cv_amount=1): + def add_content_views_to_composite( + self, module_target_sat, composite_cv, module_org, cv_amount=1 + ): """Add necessary number of content views to the composite one :param composite_cv: Composite content view object @@ -400,7 +411,7 @@ def add_content_views_to_composite(self, composite_cv, module_org, cv_amount=1): """ cv_versions = [] for _ in range(cv_amount): - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() content_view.publish() cv_versions.append(content_view.read().version[0]) composite_cv.component = cv_versions @@ -435,7 +446,7 @@ def test_positive_publish_with_content_multiple(self, content_view, module_org): assert cvv.read_json()['package_count'] > 0 @pytest.mark.tier2 - def test_positive_publish_composite_multiple_content_once(self, module_org): + def test_positive_publish_composite_multiple_content_once(self, module_org, module_target_sat): """Create empty composite view and assign random number of normal content views to it. After that publish that composite content view once. @@ -449,16 +460,20 @@ def test_positive_publish_composite_multiple_content_once(self, module_org): :CaseImportance: Critical """ - composite_cv = entities.ContentView( + composite_cv = module_target_sat.api.ContentView( composite=True, organization=module_org, ).create() - self.add_content_views_to_composite(composite_cv, module_org, random.randint(2, 3)) + self.add_content_views_to_composite( + module_target_sat, composite_cv, module_org, random.randint(2, 3) + ) composite_cv.publish() assert len(composite_cv.read().version) == 1 @pytest.mark.tier2 - def test_positive_publish_composite_multiple_content_multiple(self, module_org): + def test_positive_publish_composite_multiple_content_multiple( + self, module_org, module_target_sat + ): """Create empty composite view and assign random number of normal content views to it. After that publish that composite content view several times. @@ -472,7 +487,7 @@ def test_positive_publish_composite_multiple_content_multiple(self, module_org): :CaseImportance: High """ - composite_cv = entities.ContentView( + composite_cv = module_target_sat.api.ContentView( composite=True, organization=module_org, ).create() @@ -483,7 +498,7 @@ def test_positive_publish_composite_multiple_content_multiple(self, module_org): assert len(composite_cv.read().version) == i + 1 @pytest.mark.tier2 - def test_positive_promote_with_yum_multiple(self, content_view, module_org): + def test_positive_promote_with_yum_multiple(self, content_view, module_org, module_target_sat): """Give a content view a yum repo, publish it once and promote the content view version ``REPEAT + 1`` times. @@ -504,7 +519,7 @@ def test_positive_promote_with_yum_multiple(self, content_view, module_org): # Promote the content view version. for _ in range(REPEAT): - lce = entities.LifecycleEnvironment(organization=module_org).create() + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() content_view.version[0].promote(data={'environment_ids': lce.id}) # Everything's done - check some content view attributes... @@ -518,7 +533,7 @@ def test_positive_promote_with_yum_multiple(self, content_view, module_org): assert cvv_attrs['package_count'] > 0 @pytest.mark.tier2 - def test_positive_add_to_composite(self, content_view, module_org): + def test_positive_add_to_composite(self, content_view, module_org, module_target_sat): """Create normal content view, publish and add it to a new composite content view @@ -536,7 +551,7 @@ def test_positive_add_to_composite(self, content_view, module_org): content_view.publish() content_view = content_view.read() - composite_cv = entities.ContentView( + composite_cv = module_target_sat.api.ContentView( composite=True, organization=module_org, ).create() @@ -549,7 +564,9 @@ def test_positive_add_to_composite(self, content_view, module_org): assert composite_cv.component[0].read().content_view.id == content_view.id @pytest.mark.tier2 - def test_negative_add_components_to_composite(self, content_view, module_org): + def test_negative_add_components_to_composite( + self, content_view, module_org, module_target_sat + ): """Attempt to associate components in a non-composite content view @@ -565,7 +582,7 @@ def test_negative_add_components_to_composite(self, content_view, module_org): content_view.update(['repository']) content_view.publish() content_view = content_view.read() - non_composite_cv = entities.ContentView( + non_composite_cv = module_target_sat.api.ContentView( composite=False, organization=module_org, ).create() @@ -576,7 +593,9 @@ def test_negative_add_components_to_composite(self, content_view, module_org): @pytest.mark.upgrade @pytest.mark.tier2 - def test_positive_promote_composite_multiple_content_once(self, module_lce, module_org): + def test_positive_promote_composite_multiple_content_once( + self, module_lce, module_org, module_target_sat + ): """Create empty composite view and assign random number of normal content views to it. After that promote that composite content view once. @@ -590,7 +609,7 @@ def test_positive_promote_composite_multiple_content_once(self, module_lce, modu :CaseImportance: High """ - composite_cv = entities.ContentView( + composite_cv = module_target_sat.api.ContentView( composite=True, organization=module_org, ).create() @@ -603,7 +622,9 @@ def test_positive_promote_composite_multiple_content_once(self, module_lce, modu @pytest.mark.upgrade @pytest.mark.tier2 - def test_positive_promote_composite_multiple_content_multiple(self, module_org): + def test_positive_promote_composite_multiple_content_multiple( + self, module_org, module_target_sat + ): """Create empty composite view and assign random number of normal content views to it. After that promote that composite content view ``Library + random`` times. @@ -617,7 +638,7 @@ def test_positive_promote_composite_multiple_content_multiple(self, module_org): :CaseImportance: High """ - composite_cv = entities.ContentView( + composite_cv = module_target_sat.api.ContentView( composite=True, organization=module_org, ).create() @@ -627,7 +648,7 @@ def test_positive_promote_composite_multiple_content_multiple(self, module_org): envs_amount = random.randint(2, 3) for _ in range(envs_amount): - lce = entities.LifecycleEnvironment(organization=module_org).create() + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() composite_cv.version[0].promote(data={'environment_ids': lce.id}) composite_cv = composite_cv.read() assert len(composite_cv.version) == 1 @@ -671,7 +692,7 @@ def test_positive_promote_out_of_sequence(self, content_view, module_org): @pytest.mark.tier3 @pytest.mark.pit_server - def test_positive_publish_multiple_repos(self, content_view, module_org): + def test_positive_publish_multiple_repos(self, content_view, module_org, module_target_sat): """Attempt to publish a content view with multiple YUM repos. :id: 5557a33b-7a6f-45f5-9fe4-23a704ed9e21 @@ -690,9 +711,9 @@ def test_positive_publish_multiple_repos(self, content_view, module_org): :BZ: 1651930 """ - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() for _ in range(10): - repo = entities.Repository(product=product).create() + repo = module_target_sat.api.Repository(product=product).create() repo.sync() content_view.repository.append(repo) content_view = content_view.update(['repository']) @@ -721,13 +742,13 @@ def test_composite_content_view_with_same_repos(self, module_org, target_sat): :CaseImportance: Medium """ - product = entities.Product(organization=module_org).create() - repo = entities.Repository( + product = target_sat.api.Product(organization=module_org).create() + repo = target_sat.api.Repository( content_type='yum', product=product, url=settings.repos.module_stream_1.url ).create() repo.sync() - content_view_1 = entities.ContentView(organization=module_org).create() - content_view_2 = entities.ContentView(organization=module_org).create() + content_view_1 = target_sat.api.ContentView(organization=module_org).create() + content_view_2 = target_sat.api.ContentView(organization=module_org).create() # create content views with same repo and different filter for content_view, package in [(content_view_1, 'camel'), (content_view_2, 'cow')]: @@ -737,7 +758,7 @@ def test_composite_content_view_with_same_repos(self, module_org, target_sat): assert content_view_info.package_count == 35 # create composite content view with these two published content views - comp_content_view = entities.ContentView( + comp_content_view = target_sat.api.ContentView( composite=True, organization=module_org, ).create() @@ -877,7 +898,7 @@ def test_positive_update_attributes(self, module_cv, key, value): @pytest.mark.parametrize('new_name', **parametrized(valid_data_list())) @pytest.mark.tier1 - def test_positive_update_name(self, module_cv, new_name): + def test_positive_update_name(self, module_cv, new_name, module_target_sat): """Create content view providing the initial name, then update its name to another valid name. @@ -891,12 +912,12 @@ def test_positive_update_name(self, module_cv, new_name): """ module_cv.name = new_name module_cv.update(['name']) - updated = entities.ContentView(id=module_cv.id).read() + updated = module_target_sat.api.ContentView(id=module_cv.id).read() assert new_name == updated.name @pytest.mark.parametrize('new_name', **parametrized(invalid_names_list())) @pytest.mark.tier1 - def test_negative_update_name(self, module_cv, new_name): + def test_negative_update_name(self, module_cv, new_name, module_target_sat): """Create content view then update its name to an invalid name. @@ -920,7 +941,7 @@ class TestContentViewDelete: @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 - def test_positive_delete(self, content_view, name): + def test_positive_delete(self, content_view, name, target_sat): """Create content view and then delete it. :id: d582f1b3-8118-4e78-a639-237c6f9d27c6 @@ -933,7 +954,7 @@ def test_positive_delete(self, content_view, name): """ content_view.delete() with pytest.raises(HTTPError): - entities.ContentView(id=content_view.id).read() + target_sat.api.ContentView(id=content_view.id).read() @pytest.mark.run_in_one_thread @@ -954,7 +975,7 @@ def initiate_testclass( reposet=REPOSET['rhst7'], releasever=None, ) - request.cls.repo = entities.Repository(id=repo_id) + request.cls.repo = module_target_sat.api.Repository(id=repo_id) self.repo.sync() module_cv.repository = [self.repo] module_cv.update(['repository']) @@ -976,7 +997,7 @@ def test_positive_add_rh(self): assert self.yumcv.repository[0].read().name == REPOS['rhst7']['name'] @pytest.mark.tier2 - def test_positive_add_rh_custom_spin(self): + def test_positive_add_rh_custom_spin(self, target_sat): """Associate Red Hat content in a view and filter it using rule :id: 30c3103d-9503-4501-8117-1f2d25353215 @@ -989,7 +1010,7 @@ def test_positive_add_rh_custom_spin(self): :CaseImportance: High """ # content_view ← cv_filter - cv_filter = entities.RPMContentViewFilter( + cv_filter = target_sat.api.RPMContentViewFilter( content_view=self.yumcv, inclusion='true', name=gen_string('alphanumeric'), @@ -997,13 +1018,13 @@ def test_positive_add_rh_custom_spin(self): assert self.yumcv.id == cv_filter.content_view.id # content_view ← cv_filter ← cv_filter_rule - cv_filter_rule = entities.ContentViewFilterRule( + cv_filter_rule = target_sat.api.ContentViewFilterRule( content_view_filter=cv_filter, name=gen_string('alphanumeric'), version='1.0' ).create() assert cv_filter.id == cv_filter_rule.content_view_filter.id @pytest.mark.tier2 - def test_positive_update_rh_custom_spin(self): + def test_positive_update_rh_custom_spin(self, target_sat): """Edit content views for a custom rh spin. For example, modify a filter @@ -1016,12 +1037,12 @@ def test_positive_update_rh_custom_spin(self): :CaseImportance: High """ - cvf = entities.ErratumContentViewFilter( + cvf = target_sat.api.ErratumContentViewFilter( content_view=self.yumcv, ).create() assert self.yumcv.id == cvf.content_view.id - cv_filter_rule = entities.ContentViewFilterRule( + cv_filter_rule = target_sat.api.ContentViewFilterRule( content_view_filter=cvf, types=[FILTER_ERRATA_TYPE['enhancement']] ).create() assert cv_filter_rule.types == [FILTER_ERRATA_TYPE['enhancement']] @@ -1048,7 +1069,7 @@ def test_positive_publish_rh(self, module_org, content_view): assert len(content_view.read().version) == 1 @pytest.mark.tier2 - def test_positive_publish_rh_custom_spin(self, module_org, content_view): + def test_positive_publish_rh_custom_spin(self, module_org, content_view, module_target_sat): """Attempt to publish a content view containing Red Hat spin - i.e., contains filters. @@ -1062,7 +1083,7 @@ def test_positive_publish_rh_custom_spin(self, module_org, content_view): """ content_view.repository = [self.repo] content_view = content_view.update(['repository']) - entities.RPMContentViewFilter( + module_target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion='true', name=gen_string('alphanumeric') ).create() content_view.publish() @@ -1093,7 +1114,7 @@ def test_positive_promote_rh(self, module_org, content_view, module_lce): @pytest.mark.upgrade @pytest.mark.tier2 - def test_positive_promote_rh_custom_spin(self, content_view, module_lce): + def test_positive_promote_rh_custom_spin(self, content_view, module_lce, module_target_sat): """Attempt to promote a content view containing Red Hat spin - i.e., contains filters. @@ -1107,7 +1128,7 @@ def test_positive_promote_rh_custom_spin(self, content_view, module_lce): """ content_view.repository = [self.repo] content_view = content_view.update(['repository']) - entities.RPMContentViewFilter( + module_target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion='true', name=gen_string('alphanumeric') ).create() content_view.publish() @@ -1357,7 +1378,7 @@ def test_negative_readonly_user_actions( # create a role with content views read only permissions target_sat.api.Filter( organization=[module_org], - permission=entities.Permission().search( + permission=target_sat.api.Permission().search( filters={'name': 'view_content_views'}, query={'search': 'resource_type="Katello::ContentView"'}, ), @@ -1366,7 +1387,7 @@ def test_negative_readonly_user_actions( # create environment permissions and assign it to our role target_sat.api.Filter( organization=[module_org], - permission=entities.Permission().search( + permission=target_sat.api.Permission().search( query={'search': 'resource_type="Katello::KTEnvironment"'} ), role=function_role, @@ -1471,9 +1492,9 @@ class TestOstreeContentView: (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) @pytest.fixture(scope='class', autouse=True) - def initiate_testclass(self, request, module_product): + def initiate_testclass(self, request, module_product, module_target_sat): """Set up organization, product and repositories for tests.""" - request.cls.ostree_repo = entities.Repository( + request.cls.ostree_repo = module_target_sat.api.Repository( product=module_product, content_type='ostree', url=FEDORA_OSTREE_REPO, @@ -1481,13 +1502,13 @@ def initiate_testclass(self, request, module_product): ).create() self.ostree_repo.sync() # Create new yum repository - request.cls.yum_repo = entities.Repository( + request.cls.yum_repo = module_target_sat.api.Repository( url=settings.repos.yum_1.url, product=module_product, ).create() self.yum_repo.sync() # Create new docker repository - request.cls.docker_repo = entities.Repository( + request.cls.docker_repo = module_target_sat.api.Repository( content_type='docker', docker_upstream_name='busybox', product=module_product, @@ -1595,7 +1616,7 @@ def initiate_testclass(self, request, module_entitlement_manifest_org, class_tar reposet=REPOSET['rhaht'], releasever=None, ) - request.cls.repo = entities.Repository(id=repo_id) + request.cls.repo = class_target_sat.api.Repository(id=repo_id) self.repo.sync() @pytest.mark.tier2 @@ -1681,7 +1702,7 @@ def test_positive_publish_promote_with_RH_ostree_and_other( releasever=None, ) # Sync repository - rpm_repo = entities.Repository(id=repo_id) + rpm_repo = module_target_sat.api.Repository(id=repo_id) rpm_repo.sync() content_view.repository = [self.repo, rpm_repo] content_view = content_view.update(['repository']) diff --git a/tests/foreman/api/test_contentviewfilter.py b/tests/foreman/api/test_contentviewfilter.py index 5c1e175ed4c..dd07d57dd27 100644 --- a/tests/foreman/api/test_contentviewfilter.py +++ b/tests/foreman/api/test_contentviewfilter.py @@ -24,7 +24,7 @@ from random import randint from fauxfactory import gen_integer, gen_string -from nailgun import client, entities +from nailgun import client import pytest from requests.exceptions import HTTPError @@ -38,15 +38,15 @@ @pytest.fixture(scope='module') -def sync_repo(module_product): - repo = entities.Repository(product=module_product).create() +def sync_repo(module_product, module_target_sat): + repo = module_target_sat.api.Repository(product=module_product).create() repo.sync() return repo @pytest.fixture(scope='module') -def sync_repo_module_stream(module_product): - repo = entities.Repository( +def sync_repo_module_stream(module_product, module_target_sat): + repo = module_target_sat.api.Repository( content_type='yum', product=module_product, url=settings.repos.module_stream_1.url ).create() repo.sync() @@ -54,13 +54,15 @@ def sync_repo_module_stream(module_product): @pytest.fixture -def content_view(module_org, sync_repo): - return entities.ContentView(organization=module_org, repository=[sync_repo]).create() +def content_view(module_org, sync_repo, module_target_sat): + return module_target_sat.api.ContentView( + organization=module_org, repository=[sync_repo] + ).create() @pytest.fixture -def content_view_module_stream(module_org, sync_repo_module_stream): - return entities.ContentView( +def content_view_module_stream(module_org, sync_repo_module_stream, module_target_sat): + return module_target_sat.api.ContentView( organization=module_org, repository=[sync_repo_module_stream] ).create() @@ -69,7 +71,7 @@ class TestContentViewFilter: """Tests for content view filters.""" @pytest.mark.tier2 - def test_negative_get_with_no_args(self): + def test_negative_get_with_no_args(self, target_sat): """Issue an HTTP GET to the base content view filters path. :id: da29fd90-cd96-49f9-b94e-71d4e3a35a57 @@ -82,14 +84,14 @@ def test_negative_get_with_no_args(self): :CaseImportance: Low """ response = client.get( - entities.AbstractContentViewFilter().path(), + target_sat.api.AbstractContentViewFilter().path(), auth=get_credentials(), verify=False, ) assert response.status_code == http.client.OK @pytest.mark.tier2 - def test_negative_get_with_bad_args(self): + def test_negative_get_with_bad_args(self, target_sat): """Issue an HTTP GET to the base content view filters path. :id: e6fea726-930b-4b74-b784-41528811994f @@ -102,7 +104,7 @@ def test_negative_get_with_bad_args(self): :CaseImportance: Low """ response = client.get( - entities.AbstractContentViewFilter().path(), + target_sat.api.AbstractContentViewFilter().path(), auth=get_credentials(), verify=False, data={'foo': 'bar'}, @@ -111,7 +113,7 @@ def test_negative_get_with_bad_args(self): @pytest.mark.tier2 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) - def test_positive_create_erratum_with_name(self, name, content_view): + def test_positive_create_erratum_with_name(self, name, content_view, target_sat): """Create new erratum content filter using different inputs as a name :id: f78a133f-441f-4fcc-b292-b9eed228d755 @@ -123,13 +125,13 @@ def test_positive_create_erratum_with_name(self, name, content_view): :CaseLevel: Integration """ - cvf = entities.ErratumContentViewFilter(content_view=content_view, name=name).create() + cvf = target_sat.api.ErratumContentViewFilter(content_view=content_view, name=name).create() assert cvf.name == name assert cvf.type == 'erratum' @pytest.mark.tier2 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) - def test_positive_create_pkg_group_with_name(self, name, content_view): + def test_positive_create_pkg_group_with_name(self, name, content_view, target_sat): """Create new package group content filter using different inputs as a name :id: f9bfb6bf-a879-4f1a-970d-8f4df533cd59 @@ -143,7 +145,7 @@ def test_positive_create_pkg_group_with_name(self, name, content_view): :CaseImportance: Medium """ - cvf = entities.PackageGroupContentViewFilter( + cvf = target_sat.api.PackageGroupContentViewFilter( content_view=content_view, name=name, ).create() @@ -152,7 +154,7 @@ def test_positive_create_pkg_group_with_name(self, name, content_view): @pytest.mark.tier2 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) - def test_positive_create_rpm_with_name(self, name, content_view): + def test_positive_create_rpm_with_name(self, name, content_view, target_sat): """Create new RPM content filter using different inputs as a name :id: f1c88e72-7993-47ac-8fbc-c749d32bc768 @@ -166,13 +168,13 @@ def test_positive_create_rpm_with_name(self, name, content_view): :CaseImportance: Medium """ - cvf = entities.RPMContentViewFilter(content_view=content_view, name=name).create() + cvf = target_sat.api.RPMContentViewFilter(content_view=content_view, name=name).create() assert cvf.name == name assert cvf.type == 'rpm' @pytest.mark.tier2 @pytest.mark.parametrize('inclusion', [True, False]) - def test_positive_create_with_inclusion(self, inclusion, content_view): + def test_positive_create_with_inclusion(self, inclusion, content_view, target_sat): """Create new content view filter with different inclusion values :id: 81130dc9-ae33-48bc-96a7-d54d3e99448e @@ -184,12 +186,14 @@ def test_positive_create_with_inclusion(self, inclusion, content_view): :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter(content_view=content_view, inclusion=inclusion).create() + cvf = target_sat.api.RPMContentViewFilter( + content_view=content_view, inclusion=inclusion + ).create() assert cvf.inclusion == inclusion @pytest.mark.tier2 @pytest.mark.parametrize('description', **parametrized(valid_data_list())) - def test_positive_create_with_description(self, description, content_view): + def test_positive_create_with_description(self, description, content_view, target_sat): """Create new content filter using different inputs as a description :id: e057083f-e69d-46e7-b336-45faaf67fa52 @@ -203,14 +207,14 @@ def test_positive_create_with_description(self, description, content_view): :CaseImportance: Low """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, description=description, ).create() assert cvf.description == description @pytest.mark.tier2 - def test_positive_create_with_repo(self, content_view, sync_repo): + def test_positive_create_with_repo(self, content_view, sync_repo, target_sat): """Create new content filter with repository assigned :id: 7207d4cf-3ccf-4d63-a50a-1373b16062e2 @@ -220,7 +224,7 @@ def test_positive_create_with_repo(self, content_view, sync_repo): :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=True, repository=[sync_repo], @@ -230,7 +234,7 @@ def test_positive_create_with_repo(self, content_view, sync_repo): @pytest.mark.tier2 @pytest.mark.parametrize('original_packages', [True, False]) def test_positive_create_with_original_packages( - self, original_packages, content_view, sync_repo + self, original_packages, content_view, sync_repo, target_sat ): """Create new content view filter with different 'original packages' option values @@ -246,7 +250,7 @@ def test_positive_create_with_original_packages( :CaseImportance: Medium """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=True, repository=[sync_repo], @@ -255,7 +259,9 @@ def test_positive_create_with_original_packages( assert cvf.original_packages == original_packages @pytest.mark.tier2 - def test_positive_create_with_docker_repos(self, module_product, sync_repo, content_view): + def test_positive_create_with_docker_repos( + self, module_product, sync_repo, content_view, module_target_sat + ): """Create new docker repository and add to content view that has yum repo already assigned to it. Create new content view filter and assign it to the content view. @@ -267,7 +273,7 @@ def test_positive_create_with_docker_repos(self, module_product, sync_repo, cont :CaseLevel: Integration """ - docker_repository = entities.Repository( + docker_repository = module_target_sat.api.Repository( content_type='docker', docker_upstream_name='busybox', product=module_product.id, @@ -276,7 +282,7 @@ def test_positive_create_with_docker_repos(self, module_product, sync_repo, cont content_view.repository = [sync_repo, docker_repository] content_view.update(['repository']) - cvf = entities.RPMContentViewFilter( + cvf = module_target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=True, repository=[sync_repo, docker_repository], @@ -290,7 +296,7 @@ def test_positive_create_with_docker_repos(self, module_product, sync_repo, cont (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) def test_positive_create_with_module_streams( - self, module_product, sync_repo, sync_repo_module_stream, content_view + self, module_product, sync_repo, sync_repo_module_stream, content_view, target_sat ): """Verify Include and Exclude Filters creation for modulemd (module streams) @@ -304,7 +310,7 @@ def test_positive_create_with_module_streams( content_view.repository += [sync_repo_module_stream] content_view.update(['repository']) for inclusion in (True, False): - cvf = entities.ModuleStreamContentViewFilter( + cvf = target_sat.api.ModuleStreamContentViewFilter( content_view=content_view, inclusion=inclusion, repository=[sync_repo, sync_repo_module_stream], @@ -316,7 +322,7 @@ def test_positive_create_with_module_streams( @pytest.mark.tier2 @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) - def test_negative_create_with_invalid_name(self, name, content_view): + def test_negative_create_with_invalid_name(self, name, content_view, target_sat): """Try to create content view filter using invalid names only :id: 8cf4227b-75c4-4d6f-b94f-88e4eb586435 @@ -330,10 +336,10 @@ def test_negative_create_with_invalid_name(self, name, content_view): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.RPMContentViewFilter(content_view=content_view, name=name).create() + target_sat.api.RPMContentViewFilter(content_view=content_view, name=name).create() @pytest.mark.tier2 - def test_negative_create_with_same_name(self, content_view): + def test_negative_create_with_same_name(self, content_view, target_sat): """Try to create content view filter using same name twice :id: 73a64ca7-07a3-49ee-8921-0474a16a23ff @@ -345,12 +351,12 @@ def test_negative_create_with_same_name(self, content_view): :CaseImportance: Low """ kwargs = {'content_view': content_view, 'name': gen_string('alpha')} - entities.RPMContentViewFilter(**kwargs).create() + target_sat.api.RPMContentViewFilter(**kwargs).create() with pytest.raises(HTTPError): - entities.RPMContentViewFilter(**kwargs).create() + target_sat.api.RPMContentViewFilter(**kwargs).create() @pytest.mark.tier2 - def test_negative_create_without_cv(self): + def test_negative_create_without_cv(self, target_sat): """Try to create content view filter without providing content view @@ -363,10 +369,10 @@ def test_negative_create_without_cv(self): :CaseImportance: Low """ with pytest.raises(HTTPError): - entities.RPMContentViewFilter(content_view=None).create() + target_sat.api.RPMContentViewFilter(content_view=None).create() @pytest.mark.tier2 - def test_negative_create_with_invalid_repo_id(self, content_view): + def test_negative_create_with_invalid_repo_id(self, content_view, target_sat): """Try to create content view filter using incorrect repository id @@ -379,13 +385,13 @@ def test_negative_create_with_invalid_repo_id(self, content_view): :CaseImportance: Low """ with pytest.raises(HTTPError): - entities.RPMContentViewFilter( + target_sat.api.RPMContentViewFilter( content_view=content_view, repository=[gen_integer(10000, 99999)], ).create() @pytest.mark.tier2 - def test_positive_delete_by_id(self, content_view): + def test_positive_delete_by_id(self, content_view, target_sat): """Delete content view filter :id: 07caeb9d-419d-43f8-996b-456b0cc0f70d @@ -396,14 +402,14 @@ def test_positive_delete_by_id(self, content_view): :CaseImportance: Critical """ - cvf = entities.RPMContentViewFilter(content_view=content_view).create() + cvf = target_sat.api.RPMContentViewFilter(content_view=content_view).create() cvf.delete() with pytest.raises(HTTPError): cvf.read() @pytest.mark.tier2 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) - def test_positive_update_name(self, name, content_view): + def test_positive_update_name(self, name, content_view, target_sat): """Update content view filter with new name :id: f310c161-00d2-4281-9721-6e45cbc5e4ec @@ -415,13 +421,13 @@ def test_positive_update_name(self, name, content_view): :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter(content_view=content_view).create() + cvf = target_sat.api.RPMContentViewFilter(content_view=content_view).create() cvf.name = name assert cvf.update(['name']).name == name @pytest.mark.tier2 @pytest.mark.parametrize('description', **parametrized(valid_data_list())) - def test_positive_update_description(self, description, content_view): + def test_positive_update_description(self, description, content_view, target_sat): """Update content view filter with new description :id: f2c5db28-0163-4cf3-929a-16ba1cb98c34 @@ -435,14 +441,14 @@ def test_positive_update_description(self, description, content_view): :CaseImportance: Low """ - cvf = entities.RPMContentViewFilter(content_view=content_view).create() + cvf = target_sat.api.RPMContentViewFilter(content_view=content_view).create() cvf.description = description cvf = cvf.update(['description']) assert cvf.description == description @pytest.mark.tier2 @pytest.mark.parametrize('inclusion', [True, False]) - def test_positive_update_inclusion(self, inclusion, content_view): + def test_positive_update_inclusion(self, inclusion, content_view, target_sat): """Update content view filter with new inclusion value :id: 0aedd2d6-d020-4a90-adcd-01694b47c0b0 @@ -454,13 +460,13 @@ def test_positive_update_inclusion(self, inclusion, content_view): :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter(content_view=content_view).create() + cvf = target_sat.api.RPMContentViewFilter(content_view=content_view).create() cvf.inclusion = inclusion cvf = cvf.update(['inclusion']) assert cvf.inclusion == inclusion @pytest.mark.tier2 - def test_positive_update_repo(self, module_product, sync_repo, content_view): + def test_positive_update_repo(self, module_product, sync_repo, content_view, target_sat): """Update content view filter with new repository :id: 329ef155-c2d0-4aa2-bac3-79087ae49bdf @@ -470,12 +476,12 @@ def test_positive_update_repo(self, module_product, sync_repo, content_view): :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=True, repository=[sync_repo], ).create() - new_repo = entities.Repository(product=module_product).create() + new_repo = target_sat.api.Repository(product=module_product).create() new_repo.sync() content_view.repository = [new_repo] content_view.update(['repository']) @@ -485,7 +491,7 @@ def test_positive_update_repo(self, module_product, sync_repo, content_view): assert cvf.repository[0].id == new_repo.id @pytest.mark.tier2 - def test_positive_update_repos(self, module_product, sync_repo, content_view): + def test_positive_update_repos(self, module_product, sync_repo, content_view, target_sat): """Update content view filter with multiple repositories :id: 478fbb1c-fa1d-4fcd-93d6-3a7f47092ed3 @@ -497,12 +503,14 @@ def test_positive_update_repos(self, module_product, sync_repo, content_view): :CaseImportance: Low """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=True, repository=[sync_repo], ).create() - repos = [entities.Repository(product=module_product).create() for _ in range(randint(3, 5))] + repos = [ + target_sat.api.Repository(product=module_product).create() for _ in range(randint(3, 5)) + ] for repo in repos: repo.sync() content_view.repository = repos @@ -513,7 +521,9 @@ def test_positive_update_repos(self, module_product, sync_repo, content_view): @pytest.mark.tier2 @pytest.mark.parametrize('original_packages', [True, False]) - def test_positive_update_original_packages(self, original_packages, sync_repo, content_view): + def test_positive_update_original_packages( + self, original_packages, sync_repo, content_view, target_sat + ): """Update content view filter with new 'original packages' option value :id: 0c41e57a-afa3-479e-83ba-01f09f0fd2b6 @@ -525,7 +535,7 @@ def test_positive_update_original_packages(self, original_packages, sync_repo, c :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=True, repository=[sync_repo], @@ -535,7 +545,9 @@ def test_positive_update_original_packages(self, original_packages, sync_repo, c assert cvf.original_packages == original_packages @pytest.mark.tier2 - def test_positive_update_repo_with_docker(self, module_product, sync_repo, content_view): + def test_positive_update_repo_with_docker( + self, module_product, sync_repo, content_view, target_sat + ): """Update existing content view filter which has yum repository assigned with new docker repository @@ -546,12 +558,12 @@ def test_positive_update_repo_with_docker(self, module_product, sync_repo, conte :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=True, repository=[sync_repo], ).create() - docker_repository = entities.Repository( + docker_repository = target_sat.api.Repository( content_type='docker', docker_upstream_name='busybox', product=module_product.id, @@ -567,7 +579,7 @@ def test_positive_update_repo_with_docker(self, module_product, sync_repo, conte @pytest.mark.tier2 @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) - def test_negative_update_name(self, name, content_view): + def test_negative_update_name(self, name, content_view, target_sat): """Try to update content view filter using invalid names only :id: 9799648a-3900-4186-8271-6b2dedb547ab @@ -580,13 +592,13 @@ def test_negative_update_name(self, name, content_view): :CaseImportance: Low """ - cvf = entities.RPMContentViewFilter(content_view=content_view).create() + cvf = target_sat.api.RPMContentViewFilter(content_view=content_view).create() cvf.name = name with pytest.raises(HTTPError): cvf.update(['name']) @pytest.mark.tier2 - def test_negative_update_same_name(self, content_view): + def test_negative_update_same_name(self, content_view, target_sat): """Try to update content view filter's name to already used one :id: b68569f1-9f7b-4a95-9e2a-a5da348abff7 @@ -598,14 +610,14 @@ def test_negative_update_same_name(self, content_view): :CaseImportance: Low """ name = gen_string('alpha', 8) - entities.RPMContentViewFilter(content_view=content_view, name=name).create() - cvf = entities.RPMContentViewFilter(content_view=content_view).create() + target_sat.api.RPMContentViewFilter(content_view=content_view, name=name).create() + cvf = target_sat.api.RPMContentViewFilter(content_view=content_view).create() cvf.name = name with pytest.raises(HTTPError): cvf.update(['name']) @pytest.mark.tier2 - def test_negative_update_cv_by_id(self, content_view): + def test_negative_update_cv_by_id(self, content_view, target_sat): """Try to update content view filter using incorrect content view ID @@ -615,13 +627,13 @@ def test_negative_update_cv_by_id(self, content_view): :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter(content_view=content_view).create() + cvf = target_sat.api.RPMContentViewFilter(content_view=content_view).create() cvf.content_view.id = gen_integer(10000, 99999) with pytest.raises(HTTPError): cvf.update(['content_view']) @pytest.mark.tier2 - def test_negative_update_repo_by_id(self, sync_repo, content_view): + def test_negative_update_repo_by_id(self, sync_repo, content_view, target_sat): """Try to update content view filter using incorrect repository ID @@ -631,7 +643,7 @@ def test_negative_update_repo_by_id(self, sync_repo, content_view): :CaseLevel: Integration """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, repository=[sync_repo], ).create() @@ -640,7 +652,7 @@ def test_negative_update_repo_by_id(self, sync_repo, content_view): cvf.update(['repository']) @pytest.mark.tier2 - def test_negative_update_repo(self, module_product, sync_repo, content_view): + def test_negative_update_repo(self, module_product, sync_repo, content_view, target_sat): """Try to update content view filter with new repository which doesn't belong to filter's content view @@ -652,12 +664,12 @@ def test_negative_update_repo(self, module_product, sync_repo, content_view): :CaseImportance: Low """ - cvf = entities.RPMContentViewFilter( + cvf = target_sat.api.RPMContentViewFilter( content_view=content_view, inclusion=True, repository=[sync_repo], ).create() - new_repo = entities.Repository(product=module_product).create() + new_repo = target_sat.api.Repository(product=module_product).create() new_repo.sync() cvf.repository = [new_repo] with pytest.raises(HTTPError): @@ -714,7 +726,7 @@ class TestContentViewFilterSearch: """Tests that search through content view filters.""" @pytest.mark.tier1 - def test_positive_search_erratum(self, content_view): + def test_positive_search_erratum(self, content_view, target_sat): """Search for an erratum content view filter's rules. :id: 6a86060f-6b4f-4688-8ea9-c198e0aeb3f6 @@ -725,11 +737,11 @@ def test_positive_search_erratum(self, content_view): :BZ: 1242534 """ - cv_filter = entities.ErratumContentViewFilter(content_view=content_view).create() - entities.ContentViewFilterRule(content_view_filter=cv_filter).search() + cv_filter = target_sat.api.ErratumContentViewFilter(content_view=content_view).create() + target_sat.api.ContentViewFilterRule(content_view_filter=cv_filter).search() @pytest.mark.tier1 - def test_positive_search_package_group(self, content_view): + def test_positive_search_package_group(self, content_view, target_sat): """Search for an package group content view filter's rules. :id: 832c50cc-c2c8-48c9-9a23-80956baf5f3c @@ -738,11 +750,11 @@ def test_positive_search_package_group(self, content_view): :CaseImportance: Critical """ - cv_filter = entities.PackageGroupContentViewFilter(content_view=content_view).create() - entities.ContentViewFilterRule(content_view_filter=cv_filter).search() + cv_filter = target_sat.api.PackageGroupContentViewFilter(content_view=content_view).create() + target_sat.api.ContentViewFilterRule(content_view_filter=cv_filter).search() @pytest.mark.tier1 - def test_positive_search_rpm(self, content_view): + def test_positive_search_rpm(self, content_view, target_sat): """Search for an rpm content view filter's rules. :id: 1c9058f1-35c4-46f2-9b21-155ef988564a @@ -751,8 +763,8 @@ def test_positive_search_rpm(self, content_view): :CaseImportance: Critical """ - cv_filter = entities.RPMContentViewFilter(content_view=content_view).create() - entities.ContentViewFilterRule(content_view_filter=cv_filter).search() + cv_filter = target_sat.api.RPMContentViewFilter(content_view=content_view).create() + target_sat.api.ContentViewFilterRule(content_view_filter=cv_filter).search() class TestContentViewFilterRule: @@ -762,7 +774,9 @@ class TestContentViewFilterRule: (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) @pytest.mark.tier2 - def test_positive_promote_module_stream_filter(self, module_org, content_view_module_stream): + def test_positive_promote_module_stream_filter( + self, module_org, content_view_module_stream, target_sat + ): """Verify Module Stream, Errata Count after Promote, Publish for Content View with Module Stream Exclude Filter @@ -775,14 +789,14 @@ def test_positive_promote_module_stream_filter(self, module_org, content_view_mo """ # Exclude module stream filter content_view = content_view_module_stream - cv_filter = entities.ModuleStreamContentViewFilter( + cv_filter = target_sat.api.ModuleStreamContentViewFilter( content_view=content_view, inclusion=False, ).create() - module_streams = entities.ModuleStream().search( + module_streams = target_sat.api.ModuleStream().search( query={'search': 'name="{}"'.format('duck')} ) - entities.ContentViewFilterRule( + target_sat.api.ContentViewFilterRule( content_view_filter=cv_filter, module_stream=module_streams ).create() content_view.publish() @@ -796,7 +810,7 @@ def test_positive_promote_module_stream_filter(self, module_org, content_view_mo assert content_view_version_info.errata_counts['total'] == 3 # Promote Content View - lce = entities.LifecycleEnvironment(organization=module_org).create() + lce = target_sat.api.LifecycleEnvironment(organization=module_org).create() content_view.version[0].promote(data={'environment_ids': lce.id, 'force': False}) content_view = content_view.read() content_view_version_info = content_view.version[0].read() @@ -809,7 +823,9 @@ def test_positive_promote_module_stream_filter(self, module_org, content_view_mo (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) @pytest.mark.tier2 - def test_positive_include_exclude_module_stream_filter(self, content_view_module_stream): + def test_positive_include_exclude_module_stream_filter( + self, content_view_module_stream, target_sat + ): """Verify Include and Exclude Errata filter(modular errata) automatically force the copy of the module streams associated to it. @@ -828,14 +844,14 @@ def test_positive_include_exclude_module_stream_filter(self, content_view_module :CaseLevel: Integration """ content_view = content_view_module_stream - cv_filter = entities.ErratumContentViewFilter( + cv_filter = target_sat.api.ErratumContentViewFilter( content_view=content_view, inclusion=True, ).create() - errata = entities.Errata().search( + errata = target_sat.api.Errata().search( query={'search': f'errata_id="{settings.repos.module_stream_0.errata[2]}"'} )[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() @@ -847,14 +863,14 @@ def test_positive_include_exclude_module_stream_filter(self, content_view_module # delete the previous content_view_filter cv_filter.delete() - cv_filter = entities.ErratumContentViewFilter( + cv_filter = target_sat.api.ErratumContentViewFilter( content_view=content_view, inclusion=False, ).create() - errata = entities.Errata().search( + errata = target_sat.api.Errata().search( query={'search': f'errata_id="{settings.repos.module_stream_0.errata[2]}"'} )[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_version_info = content_view.read().version[1].read() @@ -867,7 +883,7 @@ def test_positive_include_exclude_module_stream_filter(self, content_view_module (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) @pytest.mark.tier2 - def test_positive_multi_level_filters(self, content_view_module_stream): + def test_positive_multi_level_filters(self, content_view_module_stream, target_sat): """Verify promotion of Content View and Verify count after applying multi_filters (errata and module stream) @@ -879,24 +895,24 @@ def test_positive_multi_level_filters(self, content_view_module_stream): """ content_view = content_view_module_stream # apply include errata filter - cv_filter = entities.ErratumContentViewFilter( + cv_filter = target_sat.api.ErratumContentViewFilter( content_view=content_view, inclusion=True, ).create() - errata = entities.Errata().search( + errata = target_sat.api.Errata().search( query={'search': f'errata_id="{settings.repos.module_stream_0.errata[2]}"'} )[0] - entities.ContentViewFilterRule(content_view_filter=cv_filter, errata=errata).create() + target_sat.api.ContentViewFilterRule(content_view_filter=cv_filter, errata=errata).create() # apply exclude module filter - cv_filter = entities.ModuleStreamContentViewFilter( + cv_filter = target_sat.api.ModuleStreamContentViewFilter( content_view=content_view, inclusion=False, ).create() - module_streams = entities.ModuleStream().search( + module_streams = target_sat.api.ModuleStream().search( query={'search': 'name="{}"'.format('walrus')} ) - entities.ContentViewFilterRule( + target_sat.api.ContentViewFilterRule( content_view_filter=cv_filter, module_stream=module_streams ).create() content_view.publish() @@ -910,7 +926,9 @@ def test_positive_multi_level_filters(self, content_view_module_stream): (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) @pytest.mark.tier2 - def test_positive_dependency_solving_module_stream_filter(self, content_view_module_stream): + def test_positive_dependency_solving_module_stream_filter( + self, content_view_module_stream, target_sat + ): """Verify Module Stream Content View Filter's with Dependency Solve 'Yes'. If dependency solving enabled then module streams with deps will not get fetched over even if the exclude filter has been applied. @@ -928,14 +946,14 @@ def test_positive_dependency_solving_module_stream_filter(self, content_view_mod content_view = content_view_module_stream content_view.solve_dependencies = True content_view = content_view.update(['solve_dependencies']) - cv_filter = entities.ModuleStreamContentViewFilter( + cv_filter = target_sat.api.ModuleStreamContentViewFilter( content_view=content_view, inclusion=False, ).create() - module_streams = entities.ModuleStream().search( + module_streams = target_sat.api.ModuleStream().search( query={'search': 'name="{}" and version="{}'.format('duck', '20180704244205')} ) - entities.ContentViewFilterRule( + target_sat.api.ContentViewFilterRule( content_view_filter=cv_filter, module_stream=module_streams ).create() content_view.publish() diff --git a/tests/foreman/api/test_contentviewversion.py b/tests/foreman/api/test_contentviewversion.py index ca0e5e7cf36..5953edeed42 100644 --- a/tests/foreman/api/test_contentviewversion.py +++ b/tests/foreman/api/test_contentviewversion.py @@ -17,7 +17,6 @@ :Upstream: No """ from fauxfactory import gen_string -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -31,11 +30,13 @@ @pytest.fixture(scope='module') -def module_lce_cv(module_org): +def module_lce_cv(module_org, module_target_sat): """Create some entities for all tests.""" - lce1 = entities.LifecycleEnvironment(organization=module_org).create() - lce2 = entities.LifecycleEnvironment(organization=module_org, prior=lce1).create() - default_cv = entities.ContentView(organization=module_org, name=DEFAULT_CV).search() + lce1 = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + lce2 = module_target_sat.api.LifecycleEnvironment(organization=module_org, prior=lce1).create() + default_cv = module_target_sat.api.ContentView( + organization=module_org, name=DEFAULT_CV + ).search() default_cvv = default_cv[0].version[0] return lce1, lce2, default_cvv @@ -68,7 +69,7 @@ def test_positive_create(module_cv): @pytest.mark.tier2 -def test_negative_create(module_org): +def test_negative_create(module_org, module_target_sat): """Attempt to create content view version using the 'Default Content View'. :id: 0afd49c6-f3a4-403e-9929-849f51ffa922 @@ -80,7 +81,7 @@ def test_negative_create(module_org): :CaseImportance: Critical """ # The default content view cannot be published - cv = entities.ContentView(organization=module_org.id, name=DEFAULT_CV).search() + cv = module_target_sat.api.ContentView(organization=module_org.id, name=DEFAULT_CV).search() # There should be only 1 record returned assert len(cv) == 1 with pytest.raises(HTTPError): @@ -91,8 +92,8 @@ def test_negative_create(module_org): @pytest.mark.tier2 -def test_positive_promote_valid_environment(module_lce_cv, module_org): - """Promote a content view version to 'next in sequence lifecycle environment. +def test_positive_promote_valid_environment(module_lce_cv, module_org, module_target_sat): + """Promote a content view version to next in sequence lifecycle environment. :id: f205ca06-8ab5-4546-83bd-deac4363d487 @@ -103,7 +104,7 @@ def test_positive_promote_valid_environment(module_lce_cv, module_org): :CaseImportance: Critical """ # Create a new content view... - cv = entities.ContentView(organization=module_org).create() + cv = module_target_sat.api.ContentView(organization=module_org).create() # ... and promote it. cv.publish() # Refresh the entity @@ -123,7 +124,7 @@ def test_positive_promote_valid_environment(module_lce_cv, module_org): @pytest.mark.tier2 -def test_positive_promote_out_of_sequence_environment(module_org, module_lce_cv): +def test_positive_promote_out_of_sequence_environment(module_org, module_lce_cv, module_target_sat): """Promote a content view version to a lifecycle environment that is 'out of sequence'. @@ -134,7 +135,7 @@ def test_positive_promote_out_of_sequence_environment(module_org, module_lce_cv) :CaseLevel: Integration """ # Create a new content view... - cv = entities.ContentView(organization=module_org).create() + cv = module_target_sat.api.ContentView(organization=module_org).create() # ... and publish it. cv.publish() # Refresh the entity @@ -168,7 +169,7 @@ def test_negative_promote_valid_environment(module_lce_cv): @pytest.mark.tier2 -def test_negative_promote_out_of_sequence_environment(module_lce_cv, module_org): +def test_negative_promote_out_of_sequence_environment(module_lce_cv, module_org, module_target_sat): """Attempt to promote a content view version to a Lifecycle environment that is 'out of sequence'. @@ -179,7 +180,7 @@ def test_negative_promote_out_of_sequence_environment(module_lce_cv, module_org) :CaseLevel: Integration """ # Create a new content view... - cv = entities.ContentView(organization=module_org).create() + cv = module_target_sat.api.ContentView(organization=module_org).create() # ... and publish it. cv.publish() # Refresh the entity @@ -197,7 +198,7 @@ def test_negative_promote_out_of_sequence_environment(module_lce_cv, module_org) @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_delete(module_org, module_product): +def test_positive_delete(module_org, module_product, module_target_sat): """Create content view and publish it. After that try to disassociate content view from 'Library' environment through 'delete_from_environment' command and delete content view version from @@ -213,15 +214,15 @@ def test_positive_delete(module_org, module_product): :CaseImportance: Critical """ key_content = DataFile.ZOO_CUSTOM_GPG_KEY.read_text() - gpgkey = entities.GPGKey(content=key_content, organization=module_org).create() + gpgkey = module_target_sat.api.GPGKey(content=key_content, organization=module_org).create() # Creates new repository with GPGKey - repo = entities.Repository( + repo = module_target_sat.api.Repository( gpg_key=gpgkey, product=module_product, url=settings.repos.yum_1.url ).create() # sync repository repo.sync() # Create content view - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() # Associate repository to new content view content_view.repository = [repo] content_view = content_view.update(['repository']) @@ -242,7 +243,7 @@ def test_positive_delete(module_org, module_product): @pytest.mark.upgrade @pytest.mark.tier2 -def test_positive_delete_non_default(module_org): +def test_positive_delete_non_default(module_org, module_target_sat): """Create content view and publish and promote it to new environment. After that try to disassociate content view from 'Library' and one more non-default environment through 'delete_from_environment' @@ -256,13 +257,13 @@ def test_positive_delete_non_default(module_org): :CaseImportance: Critical """ - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() # Publish content view content_view.publish() content_view = content_view.read() assert len(content_view.version) == 1 assert len(content_view.version[0].read().environment) == 1 - lce = entities.LifecycleEnvironment(organization=module_org).create() + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() content_view.version[0].promote(data={'environment_ids': lce.id, 'force': False}) cvv = content_view.version[0].read() assert len(cvv.environment) == 2 @@ -277,7 +278,7 @@ def test_positive_delete_non_default(module_org): @pytest.mark.upgrade @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_delete_composite_version(module_org): +def test_positive_delete_composite_version(module_org, module_target_sat): """Create composite content view and publish it. After that try to disassociate content view from 'Library' environment through 'delete_from_environment' command and delete content view version from @@ -293,14 +294,16 @@ def test_positive_delete_composite_version(module_org): :BZ: 1276479 """ # Create product with repository and publish it - product = entities.Product(organization=module_org).create() - repo = entities.Repository(product=product, url=settings.repos.yum_1.url).create() + product = module_target_sat.api.Product(organization=module_org).create() + repo = module_target_sat.api.Repository(product=product, url=settings.repos.yum_1.url).create() repo.sync() # Create and publish content views - content_view = entities.ContentView(organization=module_org, repository=[repo]).create() + content_view = module_target_sat.api.ContentView( + organization=module_org, repository=[repo] + ).create() content_view.publish() # Create and publish composite content view - composite_cv = entities.ContentView( + composite_cv = module_target_sat.api.ContentView( organization=module_org, composite=True, component=[content_view.read().version[0]] ).create() composite_cv.publish() @@ -318,7 +321,7 @@ def test_positive_delete_composite_version(module_org): @pytest.mark.tier2 -def test_negative_delete(module_org): +def test_negative_delete(module_org, module_target_sat): """Create content view and publish it. Try to delete content view version while content view is still associated with lifecycle environment @@ -331,7 +334,7 @@ def test_negative_delete(module_org): :CaseImportance: Critical """ - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() # Publish content view content_view.publish() content_view = content_view.read() @@ -344,7 +347,7 @@ def test_negative_delete(module_org): @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_remove_renamed_cv_version_from_default_env(module_org): +def test_positive_remove_renamed_cv_version_from_default_env(module_org, module_target_sat): """Remove version of renamed content view from Library environment :id: 7d5961d0-6a9a-4610-979e-cbc4ddbc50ca @@ -364,11 +367,13 @@ def test_positive_remove_renamed_cv_version_from_default_env(module_org): """ new_name = gen_string('alpha') # create yum product and repo - product = entities.Product(organization=module_org).create() - yum_repo = entities.Repository(url=settings.repos.yum_1.url, product=product).create() + product = module_target_sat.api.Product(organization=module_org).create() + yum_repo = module_target_sat.api.Repository( + url=settings.repos.yum_1.url, product=product + ).create() yum_repo.sync() # create a content view and add the yum repo to it - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() content_view.repository = [yum_repo] content_view = content_view.update(['repository']) # publish the content view @@ -377,7 +382,9 @@ def test_positive_remove_renamed_cv_version_from_default_env(module_org): assert len(content_view.version) == 1 content_view_version = content_view.version[0].read() assert len(content_view_version.environment) == 1 - lce_library = entities.LifecycleEnvironment(id=content_view_version.environment[0].id).read() + lce_library = module_target_sat.api.LifecycleEnvironment( + id=content_view_version.environment[0].id + ).read() # ensure that the content view version is promoted to the Library # lifecycle environment assert lce_library.name == ENVIRONMENT @@ -393,7 +400,7 @@ def test_positive_remove_renamed_cv_version_from_default_env(module_org): @pytest.mark.tier2 -def test_positive_remove_qe_promoted_cv_version_from_default_env(module_org): +def test_positive_remove_qe_promoted_cv_version_from_default_env(module_org, module_target_sat): """Remove QE promoted content view version from Library environment :id: c7795762-93bd-419c-ac49-d10dc26b842b @@ -412,10 +419,12 @@ def test_positive_remove_qe_promoted_cv_version_from_default_env(module_org): :CaseLevel: Integration """ - lce_dev = entities.LifecycleEnvironment(organization=module_org).create() - lce_qe = entities.LifecycleEnvironment(organization=module_org, prior=lce_dev).create() - product = entities.Product(organization=module_org).create() - docker_repo = entities.Repository( + lce_dev = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + lce_qe = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_dev + ).create() + product = module_target_sat.api.Product(organization=module_org).create() + docker_repo = module_target_sat.api.Repository( content_type='docker', docker_upstream_name='busybox', product=product, @@ -423,7 +432,7 @@ def test_positive_remove_qe_promoted_cv_version_from_default_env(module_org): ).create() docker_repo.sync() # create a content view and add to it the docker repo - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() content_view.repository = [docker_repo] content_view = content_view.update(['repository']) # publish the content view @@ -432,7 +441,9 @@ def test_positive_remove_qe_promoted_cv_version_from_default_env(module_org): assert len(content_view.version) == 1 content_view_version = content_view.version[0].read() assert len(content_view_version.environment) == 1 - lce_library = entities.LifecycleEnvironment(id=content_view_version.environment[0].id).read() + lce_library = module_target_sat.api.LifecycleEnvironment( + id=content_view_version.environment[0].id + ).read() assert lce_library.name == ENVIRONMENT # promote content view version to DEV and QE lifecycle environments for lce in [lce_dev, lce_qe]: @@ -449,7 +460,7 @@ def test_positive_remove_qe_promoted_cv_version_from_default_env(module_org): @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_remove_prod_promoted_cv_version_from_default_env(module_org): +def test_positive_remove_prod_promoted_cv_version_from_default_env(module_org, module_target_sat): """Remove PROD promoted content view version from Library environment :id: 24911876-7c2a-4a12-a3aa-98051dfda29d @@ -468,13 +479,19 @@ def test_positive_remove_prod_promoted_cv_version_from_default_env(module_org): :CaseLevel: Integration """ - lce_dev = entities.LifecycleEnvironment(organization=module_org).create() - lce_qe = entities.LifecycleEnvironment(organization=module_org, prior=lce_dev).create() - lce_prod = entities.LifecycleEnvironment(organization=module_org, prior=lce_qe).create() - product = entities.Product(organization=module_org).create() - yum_repo = entities.Repository(url=settings.repos.yum_1.url, product=product).create() + lce_dev = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + lce_qe = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_dev + ).create() + lce_prod = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_qe + ).create() + product = module_target_sat.api.Product(organization=module_org).create() + yum_repo = module_target_sat.api.Repository( + url=settings.repos.yum_1.url, product=product + ).create() yum_repo.sync() - docker_repo = entities.Repository( + docker_repo = module_target_sat.api.Repository( content_type='docker', docker_upstream_name='busybox', product=product, @@ -482,7 +499,7 @@ def test_positive_remove_prod_promoted_cv_version_from_default_env(module_org): ).create() docker_repo.sync() # create a content view and add to it the yum and docker repos - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() content_view.repository = [yum_repo, docker_repo] content_view = content_view.update(['repository']) # publish the content view @@ -491,7 +508,9 @@ def test_positive_remove_prod_promoted_cv_version_from_default_env(module_org): assert len(content_view.version) == 1 content_view_version = content_view.version[0].read() assert len(content_view_version.environment) == 1 - lce_library = entities.LifecycleEnvironment(id=content_view_version.environment[0].id).read() + lce_library = module_target_sat.api.LifecycleEnvironment( + id=content_view_version.environment[0].id + ).read() assert lce_library.name == ENVIRONMENT # promote content view version to DEV QE PROD lifecycle environments for lce in [lce_dev, lce_qe, lce_prod]: @@ -510,7 +529,7 @@ def test_positive_remove_prod_promoted_cv_version_from_default_env(module_org): @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_remove_cv_version_from_env(module_org): +def test_positive_remove_cv_version_from_env(module_org, module_target_sat): """Remove promoted content view version from environment :id: 17cf18bf-09d5-4641-b0e0-c50e628fa6c8 @@ -532,15 +551,23 @@ def test_positive_remove_cv_version_from_env(module_org): :CaseLevel: Integration """ - lce_dev = entities.LifecycleEnvironment(organization=module_org).create() - lce_qe = entities.LifecycleEnvironment(organization=module_org, prior=lce_dev).create() - lce_stage = entities.LifecycleEnvironment(organization=module_org, prior=lce_qe).create() - lce_prod = entities.LifecycleEnvironment(organization=module_org, prior=lce_stage).create() - product = entities.Product(organization=module_org).create() - yum_repo = entities.Repository(url=settings.repos.yum_1.url, product=product).create() + lce_dev = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + lce_qe = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_dev + ).create() + lce_stage = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_qe + ).create() + lce_prod = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_stage + ).create() + product = module_target_sat.api.Product(organization=module_org).create() + yum_repo = module_target_sat.api.Repository( + url=settings.repos.yum_1.url, product=product + ).create() yum_repo.sync() # docker repo - docker_repo = entities.Repository( + docker_repo = module_target_sat.api.Repository( content_type='docker', docker_upstream_name='busybox', product=product, @@ -548,7 +575,7 @@ def test_positive_remove_cv_version_from_env(module_org): ).create() docker_repo.sync() # create a content view and add the yum and docker repo to it - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() content_view.repository = [yum_repo, docker_repo] content_view = content_view.update(['repository']) # publish the content view @@ -557,7 +584,9 @@ def test_positive_remove_cv_version_from_env(module_org): assert len(content_view.version) == 1 content_view_version = content_view.version[0].read() assert len(content_view_version.environment) == 1 - lce_library = entities.LifecycleEnvironment(id=content_view_version.environment[0].id).read() + lce_library = module_target_sat.api.LifecycleEnvironment( + id=content_view_version.environment[0].id + ).read() assert lce_library.name == ENVIRONMENT # promote content view version to DEV QE STAGE PROD lifecycle # environments @@ -582,7 +611,7 @@ def test_positive_remove_cv_version_from_env(module_org): @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_remove_cv_version_from_multi_env(module_org): +def test_positive_remove_cv_version_from_multi_env(module_org, module_target_sat): """Remove promoted content view version from multiple environments :id: 18b86a68-8e6a-43ea-b95e-188fba125a26 @@ -602,14 +631,22 @@ def test_positive_remove_cv_version_from_multi_env(module_org): :CaseImportance: Low """ - lce_dev = entities.LifecycleEnvironment(organization=module_org).create() - lce_qe = entities.LifecycleEnvironment(organization=module_org, prior=lce_dev).create() - lce_stage = entities.LifecycleEnvironment(organization=module_org, prior=lce_qe).create() - lce_prod = entities.LifecycleEnvironment(organization=module_org, prior=lce_stage).create() - product = entities.Product(organization=module_org).create() - yum_repo = entities.Repository(url=settings.repos.yum_1.url, product=product).create() + lce_dev = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + lce_qe = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_dev + ).create() + lce_stage = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_qe + ).create() + lce_prod = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_stage + ).create() + product = module_target_sat.api.Product(organization=module_org).create() + yum_repo = module_target_sat.api.Repository( + url=settings.repos.yum_1.url, product=product + ).create() yum_repo.sync() - docker_repo = entities.Repository( + docker_repo = module_target_sat.api.Repository( content_type='docker', docker_upstream_name='busybox', product=product, @@ -617,7 +654,7 @@ def test_positive_remove_cv_version_from_multi_env(module_org): ).create() docker_repo.sync() # create a content view and add the yum repo to it - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() content_view.repository = [yum_repo, docker_repo] content_view = content_view.update(['repository']) # publish the content view @@ -626,7 +663,9 @@ def test_positive_remove_cv_version_from_multi_env(module_org): assert len(content_view.version) == 1 content_view_version = content_view.version[0].read() assert len(content_view_version.environment) == 1 - lce_library = entities.LifecycleEnvironment(id=content_view_version.environment[0].id).read() + lce_library = module_target_sat.api.LifecycleEnvironment( + id=content_view_version.environment[0].id + ).read() assert lce_library.name == ENVIRONMENT # promote content view version to DEV QE STAGE PROD lifecycle # environments @@ -648,7 +687,7 @@ def test_positive_remove_cv_version_from_multi_env(module_org): @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(module_org): +def test_positive_delete_cv_promoted_to_multi_env(module_org, module_target_sat): """Delete published content view with version promoted to multiple environments @@ -664,20 +703,28 @@ def test_positive_delete_cv_promoted_to_multi_env(module_org): 5. Delete the content view, this should delete the content with all it's published/promoted versions from all environments - :expectedresults: The content view doesn't exists + :expectedresults: The content view doesn't exist :CaseLevel: Integration :CaseImportance: Critical """ - lce_dev = entities.LifecycleEnvironment(organization=module_org).create() - lce_qe = entities.LifecycleEnvironment(organization=module_org, prior=lce_dev).create() - lce_stage = entities.LifecycleEnvironment(organization=module_org, prior=lce_qe).create() - lce_prod = entities.LifecycleEnvironment(organization=module_org, prior=lce_stage).create() - product = entities.Product(organization=module_org).create() - yum_repo = entities.Repository(url=settings.repos.yum_1.url, product=product).create() + lce_dev = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + lce_qe = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_dev + ).create() + lce_stage = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_qe + ).create() + lce_prod = module_target_sat.api.LifecycleEnvironment( + organization=module_org, prior=lce_stage + ).create() + product = module_target_sat.api.Product(organization=module_org).create() + yum_repo = module_target_sat.api.Repository( + url=settings.repos.yum_1.url, product=product + ).create() yum_repo.sync() - docker_repo = entities.Repository( + docker_repo = module_target_sat.api.Repository( content_type='docker', docker_upstream_name='busybox', product=product, @@ -685,7 +732,7 @@ def test_positive_delete_cv_promoted_to_multi_env(module_org): ).create() docker_repo.sync() # create a content view and add the yum repo to it - content_view = entities.ContentView(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() content_view.repository = [yum_repo, docker_repo] content_view = content_view.update(['repository']) # publish the content view @@ -694,7 +741,9 @@ def test_positive_delete_cv_promoted_to_multi_env(module_org): assert len(content_view.version) == 1 content_view_version = content_view.version[0].read() assert len(content_view_version.environment) == 1 - lce_library = entities.LifecycleEnvironment(id=content_view_version.environment[0].id).read() + lce_library = module_target_sat.api.LifecycleEnvironment( + id=content_view_version.environment[0].id + ).read() assert lce_library.name == ENVIRONMENT # promote content view version to DEV QE STAGE PROD lifecycle # environments diff --git a/tests/foreman/api/test_discoveryrule.py b/tests/foreman/api/test_discoveryrule.py index f55a287d675..06b11a151bc 100644 --- a/tests/foreman/api/test_discoveryrule.py +++ b/tests/foreman/api/test_discoveryrule.py @@ -17,7 +17,6 @@ :Upstream: No """ from fauxfactory import gen_choice, gen_integer, gen_string -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -25,8 +24,8 @@ @pytest.fixture(scope="module") -def module_hostgroup(module_org): - module_hostgroup = entities.HostGroup(organization=[module_org]).create() +def module_hostgroup(module_org, module_target_sat): + module_hostgroup = module_target_sat.api.HostGroup(organization=[module_org]).create() yield module_hostgroup module_hostgroup.delete() @@ -45,7 +44,7 @@ def module_org(module_org): @pytest.mark.tier1 @pytest.mark.e2e -def test_positive_end_to_end_crud(module_org, module_location, module_hostgroup): +def test_positive_end_to_end_crud(module_org, module_location, module_hostgroup, module_target_sat): """Create a new discovery rule with several attributes, update them and delete the rule itself. @@ -67,7 +66,7 @@ def test_positive_end_to_end_crud(module_org, module_location, module_hostgroup) name = gen_choice(list(valid_data_list().values())) search = gen_choice(searches) hostname = 'myhost-<%= rand(99999) %>' - discovery_rule = entities.DiscoveryRule( + discovery_rule = module_target_sat.api.DiscoveryRule( name=name, search_=search, hostname=hostname, @@ -104,7 +103,7 @@ def test_positive_end_to_end_crud(module_org, module_location, module_hostgroup) @pytest.mark.tier1 -def test_negative_create_with_invalid_host_limit_and_priority(): +def test_negative_create_with_invalid_host_limit_and_priority(module_target_sat): """Create a discovery rule with invalid host limit and priority :id: e3c7acb1-ac56-496b-ac04-2a83f66ec290 @@ -112,9 +111,9 @@ def test_negative_create_with_invalid_host_limit_and_priority(): :expectedresults: Validation error should be raised """ with pytest.raises(HTTPError): - entities.DiscoveryRule(max_count=gen_string('alpha')).create() + module_target_sat.api.DiscoveryRule(max_count=gen_string('alpha')).create() with pytest.raises(HTTPError): - entities.DiscoveryRule(priority=gen_string('alpha')).create() + module_target_sat.api.DiscoveryRule(priority=gen_string('alpha')).create() @pytest.mark.stubbed @@ -150,7 +149,6 @@ def test_positive_multi_provision_with_rule_limit(): and the rule should already be skipped for the 3rd one. :CaseAutomation: NotAutomated - :CaseImportance: High """ diff --git a/tests/foreman/api/test_errata.py b/tests/foreman/api/test_errata.py index 8c6383a4c7a..90319dea15f 100644 --- a/tests/foreman/api/test_errata.py +++ b/tests/foreman/api/test_errata.py @@ -19,7 +19,6 @@ # For ease of use hc refers to host-collection throughout this document from time import sleep -from nailgun import entities import pytest from robottelo import constants @@ -40,8 +39,8 @@ @pytest.fixture(scope='module') -def activation_key(module_org, module_lce): - activation_key = entities.ActivationKey( +def activation_key(module_org, module_lce, module_target_sat): + activation_key = module_target_sat.api.ActivationKey( environment=module_lce, organization=module_org ).create() return activation_key @@ -302,7 +301,7 @@ def test_positive_sorted_issue_date_and_filter_by_cve(module_org, custom_repo, t :CaseLevel: System """ # Errata is sorted by issued date. - erratum_list = entities.Errata(repository=custom_repo['repository-id']).search( + erratum_list = target_sat.api.Errata(repository=custom_repo['repository-id']).search( query={'order': 'issued ASC', 'per_page': '1000'} ) issued = [errata.issued for errata in erratum_list] @@ -337,28 +336,28 @@ def setup_content_rhel6(module_entitlement_manifest_org, module_target_sat): reposet=constants.REPOSET['rhva6'], releasever=constants.DEFAULT_RELEASE_VERSION, ) - rh_repo = entities.Repository(id=rh_repo_id_rhva).read() + rh_repo = module_target_sat.api.Repository(id=rh_repo_id_rhva).read() rh_repo.sync() - host_tools_product = entities.Product(organization=org).create() - host_tools_repo = entities.Repository( + host_tools_product = module_target_sat.api.Product(organization=org).create() + host_tools_repo = module_target_sat.api.Repository( product=host_tools_product, ).create() host_tools_repo.url = settings.repos.SATCLIENT_REPO.RHEL6 host_tools_repo = host_tools_repo.update(['url']) host_tools_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( product=custom_product, ).create() custom_repo.url = CUSTOM_REPO_URL custom_repo = custom_repo.update(['url']) custom_repo.sync() - lce = entities.LifecycleEnvironment(organization=org).create() + lce = module_target_sat.api.LifecycleEnvironment(organization=org).create() - cv = entities.ContentView( + cv = module_target_sat.api.ContentView( organization=org, repository=[rh_repo_id_rhva, host_tools_repo.id, custom_repo.id], ).create() @@ -366,11 +365,13 @@ def setup_content_rhel6(module_entitlement_manifest_org, module_target_sat): cvv = cv.read().version[0].read() cvv.promote(data={'environment_ids': lce.id, 'force': False}) - ak = entities.ActivationKey(content_view=cv, organization=org, environment=lce).create() + ak = module_target_sat.api.ActivationKey( + content_view=cv, organization=org, environment=lce + ).create() sub_list = [DEFAULT_SUBSCRIPTION_NAME, host_tools_product.name, custom_product.name] for sub_name in sub_list: - subscription = entities.Subscription(organization=org).search( + subscription = module_target_sat.api.Subscription(organization=org).search( query={'search': f'name="{sub_name}"'} )[0] ak.add_subscriptions(data={'subscription_id': subscription.id}) @@ -467,7 +468,7 @@ def test_positive_get_applicable_for_host(setup_content_rhel6, rhel6_contenthost @pytest.mark.tier3 -def test_positive_get_diff_for_cv_envs(): +def test_positive_get_diff_for_cv_envs(target_sat): """Generate a difference in errata between a set of environments for a content view @@ -485,10 +486,10 @@ def test_positive_get_diff_for_cv_envs(): :CaseLevel: System """ - org = entities.Organization().create() - env = entities.LifecycleEnvironment(organization=org).create() - content_view = entities.ContentView(organization=org).create() - activation_key = entities.ActivationKey(environment=env, organization=org).create() + org = target_sat.api.Organization().create() + env = target_sat.api.LifecycleEnvironment(organization=org).create() + content_view = target_sat.api.ContentView(organization=org).create() + activation_key = target_sat.api.ActivationKey(environment=env, organization=org).create() for repo_url in [settings.repos.yum_9.url, CUSTOM_REPO_URL]: setup_org_for_a_custom_repo( { @@ -499,10 +500,10 @@ def test_positive_get_diff_for_cv_envs(): 'activationkey-id': activation_key.id, } ) - new_env = entities.LifecycleEnvironment(organization=org, prior=env).create() + new_env = target_sat.api.LifecycleEnvironment(organization=org, prior=env).create() cvvs = content_view.read().version[-2:] cvvs[-1].promote(data={'environment_ids': new_env.id, 'force': False}) - result = entities.Errata().compare( + result = target_sat.api.Errata().compare( data={'content_view_version_ids': [cvv.id for cvv in cvvs], 'per_page': '9999'} ) cvv2_only_errata = next( @@ -567,7 +568,7 @@ def test_positive_incremental_update_required( # install package to create demand for an Erratum assert rhel7_contenthost.run(f'yum install -y {constants.FAKE_1_CUSTOM_PACKAGE}').status == 0 # Call nailgun to make the API POST to see if any incremental updates are required - response = entities.Host().bulk_available_incremental_updates( + response = target_sat.api.Host().bulk_available_incremental_updates( data={ 'organization_id': module_org.id, 'included': {'ids': [host.id]}, @@ -577,7 +578,7 @@ def test_positive_incremental_update_required( assert not response, 'Incremental update should not be required at this point' # Add filter of type include but do not include anything # this will hide all RPMs from selected erratum before publishing - entities.RPMContentViewFilter( + target_sat.api.RPMContentViewFilter( content_view=module_cv, inclusion=True, name='Include Nothing' ).create() module_cv.publish() @@ -587,7 +588,7 @@ def test_positive_incremental_update_required( CV1V.promote(data={'environment_ids': module_lce.id, 'force': False}) module_cv = module_cv.read() # Call nailgun to make the API POST to ensure an incremental update is required - response = entities.Host().bulk_available_incremental_updates( + response = target_sat.api.Host().bulk_available_incremental_updates( data={ 'organization_id': module_org.id, 'included': {'ids': [host.id]}, @@ -729,7 +730,7 @@ def rh_repo_module_manifest(module_entitlement_manifest_org, module_target_sat): releasever='None', ) # Sync step because repo is not synced by default - rh_repo = entities.Repository(id=rh_repo_id).read() + rh_repo = module_target_sat.api.Repository(id=rh_repo_id).read() rh_repo.sync() return rh_repo @@ -747,11 +748,17 @@ def rhel8_custom_repo_cv(module_entitlement_manifest_org): @pytest.fixture(scope='module') def rhel8_module_ak( - module_entitlement_manifest_org, default_lce, rh_repo_module_manifest, rhel8_custom_repo_cv + module_entitlement_manifest_org, + default_lce, + rh_repo_module_manifest, + rhel8_custom_repo_cv, + module_target_sat, ): - rhel8_module_ak = entities.ActivationKey( + rhel8_module_ak = module_target_sat.api.ActivationKey( content_view=module_entitlement_manifest_org.default_content_view, - environment=entities.LifecycleEnvironment(id=module_entitlement_manifest_org.library.id), + environment=module_target_sat.api.LifecycleEnvironment( + id=module_entitlement_manifest_org.library.id + ), organization=module_entitlement_manifest_org, ).create() # Ensure tools repo is enabled in the activation key @@ -761,19 +768,19 @@ def rhel8_module_ak( } ) # Fetch available subscriptions - subs = entities.Subscription(organization=module_entitlement_manifest_org).search( + subs = module_target_sat.api.Subscription(organization=module_entitlement_manifest_org).search( query={'search': f'{constants.DEFAULT_SUBSCRIPTION_NAME}'} ) assert subs # Add default subscription to activation key rhel8_module_ak.add_subscriptions(data={'subscription_id': subs[0].id}) # Add custom subscription to activation key - product = entities.Product(organization=module_entitlement_manifest_org).search( + product = module_target_sat.api.Product(organization=module_entitlement_manifest_org).search( query={'search': "redhat=false"} ) - custom_sub = entities.Subscription(organization=module_entitlement_manifest_org).search( - query={'search': f"name={product[0].name}"} - ) + custom_sub = module_target_sat.api.Subscription( + organization=module_entitlement_manifest_org + ).search(query={'search': f"name={product[0].name}"}) rhel8_module_ak.add_subscriptions(data={'subscription_id': custom_sub[0].id}) return rhel8_module_ak diff --git a/tests/foreman/api/test_filter.py b/tests/foreman/api/test_filter.py index 75d42707e4a..c4f2e2d12c7 100644 --- a/tests/foreman/api/test_filter.py +++ b/tests/foreman/api/test_filter.py @@ -20,22 +20,21 @@ :Upstream: No """ -from nailgun import entities import pytest from requests.exceptions import HTTPError @pytest.fixture(scope='module') -def module_perms(): +def module_perms(module_target_sat): """Search for provisioning template permissions. Set ``cls.ct_perms``.""" - ct_perms = entities.Permission().search( + ct_perms = module_target_sat.api.Permission().search( query={'search': 'resource_type="ProvisioningTemplate"'} ) return ct_perms @pytest.mark.tier1 -def test_positive_create_with_permission(module_perms): +def test_positive_create_with_permission(module_perms, module_target_sat): """Create a filter and assign it some permissions. :id: b8631d0a-a71a-41aa-9f9a-d12d62adc496 @@ -45,14 +44,14 @@ def test_positive_create_with_permission(module_perms): :CaseImportance: Critical """ # Create a filter and assign all ProvisioningTemplate permissions to it - filter_ = entities.Filter(permission=module_perms).create() + filter_ = module_target_sat.api.Filter(permission=module_perms).create() filter_perms = [perm.id for perm in filter_.permission] perms = [perm.id for perm in module_perms] assert filter_perms == perms @pytest.mark.tier1 -def test_positive_delete(module_perms): +def test_positive_delete(module_perms, module_target_sat): """Create a filter and delete it afterwards. :id: f0c56fd8-c91d-48c3-ad21-f538313b17eb @@ -61,14 +60,14 @@ def test_positive_delete(module_perms): :CaseImportance: Critical """ - filter_ = entities.Filter(permission=module_perms).create() + filter_ = module_target_sat.api.Filter(permission=module_perms).create() filter_.delete() with pytest.raises(HTTPError): filter_.read() @pytest.mark.tier1 -def test_positive_delete_role(module_perms): +def test_positive_delete_role(module_perms, module_target_sat): """Create a filter and delete the role it points at. :id: b129642d-926d-486a-84d9-5952b44ac446 @@ -77,8 +76,8 @@ def test_positive_delete_role(module_perms): :CaseImportance: Critical """ - role = entities.Role().create() - filter_ = entities.Filter(permission=module_perms, role=role).create() + role = module_target_sat.api.Role().create() + filter_ = module_target_sat.api.Filter(permission=module_perms, role=role).create() # A filter depends on a role. Deleting a role implicitly deletes the # filter pointing at it. diff --git a/tests/foreman/api/test_foremantask.py b/tests/foreman/api/test_foremantask.py index f7e8377e82f..61e95bfd14f 100644 --- a/tests/foreman/api/test_foremantask.py +++ b/tests/foreman/api/test_foremantask.py @@ -16,13 +16,12 @@ :Upstream: No """ -from nailgun import entities import pytest from requests.exceptions import HTTPError @pytest.mark.tier1 -def test_negative_fetch_non_existent_task(): +def test_negative_fetch_non_existent_task(target_sat): """Fetch a non-existent task. :id: a2a81ca2-63c4-47f5-9314-5852f5e2617f @@ -32,13 +31,13 @@ def test_negative_fetch_non_existent_task(): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.ForemanTask(id='abc123').read() + target_sat.api.ForemanTask(id='abc123').read() @pytest.mark.tier1 @pytest.mark.upgrade @pytest.mark.e2e -def test_positive_get_summary(): +def test_positive_get_summary(target_sat): """Get a summary of foreman tasks. :id: bdcab413-a25d-4fe1-9db4-b50b5c31ebce @@ -47,7 +46,7 @@ def test_positive_get_summary(): :CaseImportance: Critical """ - summary = entities.ForemanTask().summary() + summary = target_sat.api.ForemanTask().summary() assert type(summary) is list for item in summary: assert type(item) is dict diff --git a/tests/foreman/api/test_hostcollection.py b/tests/foreman/api/test_hostcollection.py index 0b5c0147ead..8935779101c 100644 --- a/tests/foreman/api/test_hostcollection.py +++ b/tests/foreman/api/test_hostcollection.py @@ -19,7 +19,6 @@ from random import choice, randint from broker import Broker -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -32,15 +31,15 @@ @pytest.fixture(scope='module') -def fake_hosts(module_org): +def fake_hosts(module_org, module_target_sat): """Create content hosts that can be shared by tests.""" - hosts = [entities.Host(organization=module_org).create() for _ in range(2)] + hosts = [module_target_sat.api.Host(organization=module_org).create() for _ in range(2)] return hosts @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_create_with_name(module_org, name): +def test_positive_create_with_name(module_org, name, module_target_sat): """Create host collections with different names. :id: 8f2b9223-f5be-4cb1-8316-01ea747cae14 @@ -52,12 +51,14 @@ def test_positive_create_with_name(module_org, name): :CaseImportance: Critical """ - host_collection = entities.HostCollection(name=name, organization=module_org).create() + host_collection = module_target_sat.api.HostCollection( + name=name, organization=module_org + ).create() assert host_collection.name == name @pytest.mark.tier1 -def test_positive_list(module_org): +def test_positive_list(module_org, module_target_sat): """Create new host collection and then retrieve list of all existing host collections @@ -72,13 +73,13 @@ def test_positive_list(module_org): :CaseImportance: Critical """ - entities.HostCollection(organization=module_org).create() - hc_list = entities.HostCollection().search() + module_target_sat.api.HostCollection(organization=module_org).create() + hc_list = module_target_sat.api.HostCollection().search() assert len(hc_list) >= 1 @pytest.mark.tier1 -def test_positive_list_for_organization(): +def test_positive_list_for_organization(target_sat): """Create host collection for specific organization. Retrieve list of host collections for that organization @@ -89,16 +90,16 @@ def test_positive_list_for_organization(): :CaseImportance: Critical """ - org = entities.Organization().create() - hc = entities.HostCollection(organization=org).create() - hc_list = entities.HostCollection(organization=org).search() + org = target_sat.api.Organization().create() + hc = target_sat.api.HostCollection(organization=org).create() + hc_list = target_sat.api.HostCollection(organization=org).search() assert len(hc_list) == 1 assert hc_list[0].id == hc.id @pytest.mark.parametrize('desc', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_create_with_description(module_org, desc): +def test_positive_create_with_description(module_org, desc, module_target_sat): """Create host collections with different descriptions. :id: 9d13392f-8d9d-4ff1-8909-4233e4691055 @@ -110,12 +111,14 @@ def test_positive_create_with_description(module_org, desc): :CaseImportance: Critical """ - host_collection = entities.HostCollection(description=desc, organization=module_org).create() + host_collection = module_target_sat.api.HostCollection( + description=desc, organization=module_org + ).create() assert host_collection.description == desc @pytest.mark.tier1 -def test_positive_create_with_limit(module_org): +def test_positive_create_with_limit(module_org, module_target_sat): """Create host collections with different limits. :id: 86d9387b-7036-4794-96fd-5a3472dd9160 @@ -127,13 +130,15 @@ def test_positive_create_with_limit(module_org): """ for _ in range(5): limit = randint(1, 30) - host_collection = entities.HostCollection(max_hosts=limit, organization=module_org).create() + host_collection = module_target_sat.api.HostCollection( + max_hosts=limit, organization=module_org + ).create() assert host_collection.max_hosts == limit @pytest.mark.parametrize("unlimited", [False, True]) @pytest.mark.tier1 -def test_positive_create_with_unlimited_hosts(module_org, unlimited): +def test_positive_create_with_unlimited_hosts(module_org, unlimited, module_target_sat): """Create host collection with different values of 'unlimited hosts' parameter. @@ -146,7 +151,7 @@ def test_positive_create_with_unlimited_hosts(module_org, unlimited): :CaseImportance: Critical """ - host_collection = entities.HostCollection( + host_collection = module_target_sat.api.HostCollection( max_hosts=None if unlimited else 1, organization=module_org, unlimited_hosts=unlimited, @@ -155,7 +160,7 @@ def test_positive_create_with_unlimited_hosts(module_org, unlimited): @pytest.mark.tier1 -def test_positive_create_with_host(module_org, fake_hosts): +def test_positive_create_with_host(module_org, fake_hosts, module_target_sat): """Create a host collection that contains a host. :id: 9dc0ad72-58c2-4079-b1ca-2c4373472f0f @@ -167,14 +172,14 @@ def test_positive_create_with_host(module_org, fake_hosts): :BZ: 1325989 """ - host_collection = entities.HostCollection( + host_collection = module_target_sat.api.HostCollection( host=[fake_hosts[0]], organization=module_org ).create() assert len(host_collection.host) == 1 @pytest.mark.tier1 -def test_positive_create_with_hosts(module_org, fake_hosts): +def test_positive_create_with_hosts(module_org, fake_hosts, module_target_sat): """Create a host collection that contains hosts. :id: bb8d2b42-9a8b-4c4f-ba0c-c56ae5a7eb1d @@ -186,12 +191,14 @@ def test_positive_create_with_hosts(module_org, fake_hosts): :BZ: 1325989 """ - host_collection = entities.HostCollection(host=fake_hosts, organization=module_org).create() + host_collection = module_target_sat.api.HostCollection( + host=fake_hosts, organization=module_org + ).create() assert len(host_collection.host) == len(fake_hosts) @pytest.mark.tier2 -def test_positive_add_host(module_org, fake_hosts): +def test_positive_add_host(module_org, fake_hosts, module_target_sat): """Add a host to host collection. :id: da8bc901-7ac8-4029-bb62-af21aa4d3a88 @@ -202,7 +209,7 @@ def test_positive_add_host(module_org, fake_hosts): :BZ:1325989 """ - host_collection = entities.HostCollection(organization=module_org).create() + host_collection = module_target_sat.api.HostCollection(organization=module_org).create() host_collection.host_ids = [fake_hosts[0].id] host_collection = host_collection.update(['host_ids']) assert len(host_collection.host) == 1 @@ -210,7 +217,7 @@ def test_positive_add_host(module_org, fake_hosts): @pytest.mark.upgrade @pytest.mark.tier2 -def test_positive_add_hosts(module_org, fake_hosts): +def test_positive_add_hosts(module_org, fake_hosts, module_target_sat): """Add hosts to host collection. :id: f76b4db1-ccd5-47ab-be15-8c7d91d03b22 @@ -221,7 +228,7 @@ def test_positive_add_hosts(module_org, fake_hosts): :BZ: 1325989 """ - host_collection = entities.HostCollection(organization=module_org).create() + host_collection = module_target_sat.api.HostCollection(organization=module_org).create() host_ids = [str(host.id) for host in fake_hosts] host_collection.host_ids = host_ids host_collection = host_collection.update(['host_ids']) @@ -229,7 +236,7 @@ def test_positive_add_hosts(module_org, fake_hosts): @pytest.mark.tier1 -def test_positive_read_host_ids(module_org, fake_hosts): +def test_positive_read_host_ids(module_org, fake_hosts, module_target_sat): """Read a host collection and look at the ``host_ids`` field. :id: 444a1528-64c8-41b6-ba2b-6c49799d5980 @@ -241,7 +248,9 @@ def test_positive_read_host_ids(module_org, fake_hosts): :BZ:1325989 """ - host_collection = entities.HostCollection(host=fake_hosts, organization=module_org).create() + host_collection = module_target_sat.api.HostCollection( + host=fake_hosts, organization=module_org + ).create() assert frozenset(host.id for host in host_collection.host) == frozenset( host.id for host in fake_hosts ) @@ -249,7 +258,7 @@ def test_positive_read_host_ids(module_org, fake_hosts): @pytest.mark.parametrize('new_name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_update_name(module_org, new_name): +def test_positive_update_name(module_org, new_name, module_target_sat): """Check if host collection name can be updated :id: b2dedb99-6dd7-41be-8aaa-74065c820ac6 @@ -260,14 +269,14 @@ def test_positive_update_name(module_org, new_name): :CaseImportance: Critical """ - host_collection = entities.HostCollection(organization=module_org).create() + host_collection = module_target_sat.api.HostCollection(organization=module_org).create() host_collection.name = new_name assert host_collection.update().name == new_name @pytest.mark.parametrize('new_desc', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_update_description(module_org, new_desc): +def test_positive_update_description(module_org, new_desc, module_target_sat): """Check if host collection description can be updated :id: f8e9bd1c-1525-4b5f-a07c-eb6b6e7aa628 @@ -278,13 +287,13 @@ def test_positive_update_description(module_org, new_desc): :CaseImportance: Critical """ - host_collection = entities.HostCollection(organization=module_org).create() + host_collection = module_target_sat.api.HostCollection(organization=module_org).create() host_collection.description = new_desc assert host_collection.update().description == new_desc @pytest.mark.tier1 -def test_positive_update_limit(module_org): +def test_positive_update_limit(module_org, module_target_sat): """Check if host collection limit can be updated :id: 4eda7796-cd81-453b-9b72-4ef84b2c1d8c @@ -293,7 +302,7 @@ def test_positive_update_limit(module_org): :CaseImportance: Critical """ - host_collection = entities.HostCollection( + host_collection = module_target_sat.api.HostCollection( max_hosts=1, organization=module_org, unlimited_hosts=False ).create() for limit in (1, 3, 5, 10, 20): @@ -302,7 +311,7 @@ def test_positive_update_limit(module_org): @pytest.mark.tier1 -def test_positive_update_unlimited_hosts(module_org): +def test_positive_update_unlimited_hosts(module_org, module_target_sat): """Check if host collection 'unlimited hosts' parameter can be updated :id: 09a3973d-9832-4255-87bf-f9eaeab4aee8 @@ -313,7 +322,7 @@ def test_positive_update_unlimited_hosts(module_org): :CaseImportance: Critical """ random_unlimited = choice([True, False]) - host_collection = entities.HostCollection( + host_collection = module_target_sat.api.HostCollection( max_hosts=1 if not random_unlimited else None, organization=module_org, unlimited_hosts=random_unlimited, @@ -326,7 +335,7 @@ def test_positive_update_unlimited_hosts(module_org): @pytest.mark.tier1 -def test_positive_update_host(module_org, fake_hosts): +def test_positive_update_host(module_org, fake_hosts, module_target_sat): """Update host collection's host. :id: 23082854-abcf-4085-be9c-a5d155446acb @@ -335,7 +344,7 @@ def test_positive_update_host(module_org, fake_hosts): :CaseImportance: Critical """ - host_collection = entities.HostCollection( + host_collection = module_target_sat.api.HostCollection( host=[fake_hosts[0]], organization=module_org ).create() host_collection.host_ids = [fake_hosts[1].id] @@ -345,7 +354,7 @@ def test_positive_update_host(module_org, fake_hosts): @pytest.mark.upgrade @pytest.mark.tier1 -def test_positive_update_hosts(module_org, fake_hosts): +def test_positive_update_hosts(module_org, fake_hosts, module_target_sat): """Update host collection's hosts. :id: 0433b37d-ae16-456f-a51d-c7b800334861 @@ -354,8 +363,10 @@ def test_positive_update_hosts(module_org, fake_hosts): :CaseImportance: Critical """ - host_collection = entities.HostCollection(host=fake_hosts, organization=module_org).create() - new_hosts = [entities.Host(organization=module_org).create() for _ in range(2)] + host_collection = module_target_sat.api.HostCollection( + host=fake_hosts, organization=module_org + ).create() + new_hosts = [module_target_sat.api.Host(organization=module_org).create() for _ in range(2)] host_ids = [str(host.id) for host in new_hosts] host_collection.host_ids = host_ids host_collection = host_collection.update(['host_ids']) @@ -364,7 +375,7 @@ def test_positive_update_hosts(module_org, fake_hosts): @pytest.mark.upgrade @pytest.mark.tier1 -def test_positive_delete(module_org): +def test_positive_delete(module_org, module_target_sat): """Check if host collection can be deleted :id: 13a16cd2-16ce-4966-8c03-5d821edf963b @@ -373,7 +384,7 @@ def test_positive_delete(module_org): :CaseImportance: Critical """ - host_collection = entities.HostCollection(organization=module_org).create() + host_collection = module_target_sat.api.HostCollection(organization=module_org).create() host_collection.delete() with pytest.raises(HTTPError): host_collection.read() @@ -381,7 +392,7 @@ def test_positive_delete(module_org): @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_create_with_invalid_name(module_org, name): +def test_negative_create_with_invalid_name(module_org, name, module_target_sat): """Try to create host collections with different invalid names :id: 38f67d04-a19d-4eab-a577-21b8d62c7389 @@ -393,7 +404,7 @@ def test_negative_create_with_invalid_name(module_org, name): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.HostCollection(name=name, organization=module_org).create() + module_target_sat.api.HostCollection(name=name, organization=module_org).create() @pytest.mark.tier1 @@ -418,14 +429,14 @@ def test_positive_add_remove_subscription(module_org, module_ak_cv_lce, target_s """ # this command creates a host collection and "appends", makes available, to the AK module_ak_cv_lce.host_collection.append( - entities.HostCollection(organization=module_org).create() + target_sat.api.HostCollection(organization=module_org).create() ) # Move HC from Add tab to List tab on AK view module_ak_cv_lce = module_ak_cv_lce.update(['host_collection']) # Create a product so we have a subscription to use - product = entities.Product(organization=module_org).create() + product = target_sat.api.Product(organization=module_org).create() prod_name = product.name - product_subscription = entities.Subscription(organization=module_org).search( + product_subscription = target_sat.api.Subscription(organization=module_org).search( query={'search': f'name={prod_name}'} )[0] # Create and register VMs as members of Host Collection @@ -438,7 +449,7 @@ def test_positive_add_remove_subscription(module_org, module_ak_cv_lce, target_s host_ids = [host.id for host in host_collection.host] # Add subscription # Call nailgun to make the API PUT to members of Host Collection - entities.Host().bulk_add_subscriptions( + target_sat.api.Host().bulk_add_subscriptions( data={ "organization_id": module_org.id, "included": {"ids": host_ids}, @@ -447,13 +458,13 @@ def test_positive_add_remove_subscription(module_org, module_ak_cv_lce, target_s ) # GET the subscriptions from hosts and assert they are there for host_id in host_ids: - req = entities.HostSubscription(host=host_id).subscriptions() + req = target_sat.api.HostSubscription(host=host_id).subscriptions() assert ( prod_name in req['results'][0]['product_name'] ), 'Subscription not applied to HC members' # Remove the subscription # Call nailgun to make the API PUT to members of Host Collection - entities.Host().bulk_remove_subscriptions( + target_sat.api.Host().bulk_remove_subscriptions( data={ "organization_id": module_org.id, "included": {"ids": host_ids}, @@ -462,5 +473,5 @@ def test_positive_add_remove_subscription(module_org, module_ak_cv_lce, target_s ) # GET the subscriptions from hosts and assert they are gone for host_id in host_ids: - req = entities.HostSubscription(host=host_id).subscriptions() + req = target_sat.api.HostSubscription(host=host_id).subscriptions() assert not req['results'], 'Subscription not removed from HC members' diff --git a/tests/foreman/api/test_hostgroup.py b/tests/foreman/api/test_hostgroup.py index 9e3c3aa0c21..784b404e5dd 100644 --- a/tests/foreman/api/test_hostgroup.py +++ b/tests/foreman/api/test_hostgroup.py @@ -19,7 +19,7 @@ from random import randint from fauxfactory import gen_string -from nailgun import client, entities, entity_fields +from nailgun import client, entity_fields import pytest from requests.exceptions import HTTPError @@ -32,8 +32,10 @@ @pytest.fixture -def hostgroup(module_org, module_location): - return entities.HostGroup(location=[module_location], organization=[module_org]).create() +def hostgroup(module_org, module_location, module_target_sat): + return module_target_sat.api.HostGroup( + location=[module_location], organization=[module_org] + ).create() @pytest.fixture @@ -158,7 +160,7 @@ def test_inherit_puppetclass(self, session_puppet_enabled_sat): @pytest.mark.upgrade @pytest.mark.tier3 - def test_rebuild_config(self, module_org, module_location, hostgroup): + def test_rebuild_config(self, module_org, module_location, hostgroup, module_target_sat): """'Rebuild orchestration config' of an existing host group :id: 58bf7015-18fc-4d25-9b64-7f2dd6dde425 @@ -169,12 +171,12 @@ def test_rebuild_config(self, module_org, module_location, hostgroup): :CaseLevel: System """ - lce = entities.LifecycleEnvironment(organization=module_org).create() - content_view = entities.ContentView(organization=module_org).create() + lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() + content_view = module_target_sat.api.ContentView(organization=module_org).create() content_view.publish() content_view = content_view.read() content_view.version[0].promote(data={'environment_ids': lce.id, 'force': False}) - entities.Host( + module_target_sat.api.Host( hostgroup=hostgroup, location=module_location, organization=module_org, @@ -193,7 +195,7 @@ def test_rebuild_config(self, module_org, module_location, hostgroup): @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(valid_hostgroups_list())) - def test_positive_create_with_name(self, name, module_org, module_location): + def test_positive_create_with_name(self, name, module_org, module_location, module_target_sat): """Create a hostgroup with different names :id: fd5d353c-fd0c-4752-8a83-8f399b4c3416 @@ -204,13 +206,13 @@ def test_positive_create_with_name(self, name, module_org, module_location): :CaseImportance: Critical """ - hostgroup = entities.HostGroup( + hostgroup = module_target_sat.api.HostGroup( location=[module_location], name=name, organization=[module_org] ).create() assert name == hostgroup.name @pytest.mark.tier1 - def test_positive_clone(self, hostgroup): + def test_positive_clone(self, hostgroup, target_sat): """Create a hostgroup by cloning an existing one :id: 44ac8b3b-9cb0-4a9e-ad9b-2c67b2411922 @@ -220,7 +222,7 @@ def test_positive_clone(self, hostgroup): :CaseImportance: Critical """ hostgroup_cloned_name = gen_string('alpha') - hostgroup_cloned = entities.HostGroup(id=hostgroup.id).clone( + hostgroup_cloned = target_sat.api.HostGroup(id=hostgroup.id).clone( data={'name': hostgroup_cloned_name} ) hostgroup_origin = hostgroup.read_json() @@ -402,20 +404,20 @@ def test_positive_create_with_realm(self, module_org, module_location, target_sa :CaseLevel: Integration """ - realm = entities.Realm( + realm = target_sat.api.Realm( location=[module_location], organization=[module_org], - realm_proxy=entities.SmartProxy().search( + realm_proxy=target_sat.api.SmartProxy().search( query={'search': f'url = {target_sat.url}:9090'} )[0], ).create() - hostgroup = entities.HostGroup( + hostgroup = target_sat.api.HostGroup( location=[module_location], organization=[module_org], realm=realm ).create() assert hostgroup.realm.read().name == realm.name @pytest.mark.tier2 - def test_positive_create_with_locs(self, module_org): + def test_positive_create_with_locs(self, module_org, module_target_sat): """Create a hostgroup with multiple locations specified :id: 0c2ee2ff-9e7a-4931-8cea-f4eecbd8c4c0 @@ -427,12 +429,17 @@ def test_positive_create_with_locs(self, module_org): :CaseLevel: Integration """ - locs = [entities.Location(organization=[module_org]).create() for _ in range(randint(3, 5))] - hostgroup = entities.HostGroup(location=locs, organization=[module_org]).create() + locs = [ + module_target_sat.api.Location(organization=[module_org]).create() + for _ in range(randint(3, 5)) + ] + hostgroup = module_target_sat.api.HostGroup( + location=locs, organization=[module_org] + ).create() assert {loc.name for loc in locs} == {loc.read().name for loc in hostgroup.location} @pytest.mark.tier2 - def test_positive_create_with_orgs(self): + def test_positive_create_with_orgs(self, target_sat): """Create a hostgroup with multiple organizations specified :id: 09642238-cf0d-469a-a0b5-c167b1b8edf5 @@ -444,8 +451,8 @@ def test_positive_create_with_orgs(self): :CaseLevel: Integration """ - orgs = [entities.Organization().create() for _ in range(randint(3, 5))] - hostgroup = entities.HostGroup(organization=orgs).create() + orgs = [target_sat.api.Organization().create() for _ in range(randint(3, 5))] + hostgroup = target_sat.api.HostGroup(organization=orgs).create() assert {org.name for org in orgs}, {org.read().name for org in hostgroup.organization} @pytest.mark.tier1 @@ -497,20 +504,20 @@ def test_positive_update_realm(self, module_org, module_location, target_sat): :CaseLevel: Integration """ - realm = entities.Realm( + realm = target_sat.api.Realm( location=[module_location], organization=[module_org], - realm_proxy=entities.SmartProxy().search( + realm_proxy=target_sat.api.SmartProxy().search( query={'search': f'url = {target_sat.url}:9090'} )[0], ).create() - hostgroup = entities.HostGroup( + hostgroup = target_sat.api.HostGroup( location=[module_location], organization=[module_org], realm=realm ).create() - new_realm = entities.Realm( + new_realm = target_sat.api.Realm( location=[module_location], organization=[module_org], - realm_proxy=entities.SmartProxy().search( + realm_proxy=target_sat.api.SmartProxy().search( query={'search': f'url = {target_sat.url}:9090'} )[0], ).create() @@ -549,7 +556,7 @@ def test_positive_update_content_source(self, hostgroup, target_sat): :CaseLevel: Integration """ - new_content_source = entities.SmartProxy().search( + new_content_source = target_sat.api.SmartProxy().search( query={'search': f'url = {target_sat.url}:9090'} )[0] hostgroup.content_source = new_content_source @@ -557,7 +564,7 @@ def test_positive_update_content_source(self, hostgroup, target_sat): assert hostgroup.content_source.read().name == new_content_source.name @pytest.mark.tier2 - def test_positive_update_locs(self, module_org, hostgroup): + def test_positive_update_locs(self, module_org, hostgroup, module_target_sat): """Update a hostgroup with new multiple locations :id: b045f7e8-d7c0-428b-a29c-8d54e53742e2 @@ -569,14 +576,15 @@ def test_positive_update_locs(self, module_org, hostgroup): :CaseLevel: Integration """ new_locs = [ - entities.Location(organization=[module_org]).create() for _ in range(randint(3, 5)) + module_target_sat.api.Location(organization=[module_org]).create() + for _ in range(randint(3, 5)) ] hostgroup.location = new_locs hostgroup = hostgroup.update(['location']) assert {loc.name for loc in new_locs}, {loc.read().name for loc in hostgroup.location} @pytest.mark.tier2 - def test_positive_update_orgs(self, hostgroup): + def test_positive_update_orgs(self, hostgroup, target_sat): """Update a hostgroup with new multiple organizations :id: 5f6bd4f9-4bd6-4d7e-9a91-de824299020e @@ -587,14 +595,14 @@ def test_positive_update_orgs(self, hostgroup): :CaseLevel: Integration """ - new_orgs = [entities.Organization().create() for _ in range(randint(3, 5))] + new_orgs = [target_sat.api.Organization().create() for _ in range(randint(3, 5))] hostgroup.organization = new_orgs hostgroup = hostgroup.update(['organization']) assert {org.name for org in new_orgs} == {org.read().name for org in hostgroup.organization} @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) - def test_negative_create_with_name(self, name, module_org, module_location): + def test_negative_create_with_name(self, name, module_org, module_location, module_target_sat): """Attempt to create a hostgroup with invalid names :id: 3f5aa17a-8db9-4fe9-b309-b8ec5e739da1 @@ -606,7 +614,7 @@ def test_negative_create_with_name(self, name, module_org, module_location): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.HostGroup( + module_target_sat.api.HostGroup( location=[module_location], name=name, organization=[module_org] ).create() @@ -630,7 +638,7 @@ def test_negative_update_name(self, new_name, hostgroup): assert hostgroup.read().name == original_name @pytest.mark.tier2 - def test_positive_create_with_group_parameters(self, module_org): + def test_positive_create_with_group_parameters(self, module_org, module_target_sat): """Create a hostgroup with 'group parameters' specified :id: 0959e2a2-d635-482b-9b2e-d33990d6f0dc @@ -646,7 +654,7 @@ def test_positive_create_with_group_parameters(self, module_org): :BZ: 1710853 """ group_params = {'name': gen_string('alpha'), 'value': gen_string('alpha')} - hostgroup = entities.HostGroup( + hostgroup = module_target_sat.api.HostGroup( organization=[module_org], group_parameters_attributes=[group_params] ).create() assert group_params['name'] == hostgroup.group_parameters_attributes[0]['name'] diff --git a/tests/foreman/api/test_http_proxy.py b/tests/foreman/api/test_http_proxy.py index f9c3023c77e..ed713078b4f 100644 --- a/tests/foreman/api/test_http_proxy.py +++ b/tests/foreman/api/test_http_proxy.py @@ -17,7 +17,6 @@ :Upstream: No """ from fauxfactory import gen_string -from nailgun import entities import pytest from robottelo import constants @@ -206,7 +205,7 @@ def test_positive_auto_attach_with_http_proxy( @pytest.mark.e2e @pytest.mark.tier2 -def test_positive_assign_http_proxy_to_products(): +def test_positive_assign_http_proxy_to_products(target_sat): """Assign http_proxy to Products and check whether http-proxy is used during sync. @@ -219,15 +218,15 @@ def test_positive_assign_http_proxy_to_products(): :CaseImportance: Critical """ - org = entities.Organization().create() + org = target_sat.api.Organization().create() # create HTTP proxies - http_proxy_a = entities.HTTPProxy( + http_proxy_a = target_sat.api.HTTPProxy( name=gen_string('alpha', 15), url=settings.http_proxy.un_auth_proxy_url, organization=[org], ).create() - http_proxy_b = entities.HTTPProxy( + http_proxy_b = target_sat.api.HTTPProxy( name=gen_string('alpha', 15), url=settings.http_proxy.auth_proxy_url, username=settings.http_proxy.username, @@ -236,20 +235,20 @@ def test_positive_assign_http_proxy_to_products(): ).create() # Create products and repositories - product_a = entities.Product(organization=org).create() - product_b = entities.Product(organization=org).create() - repo_a1 = entities.Repository(product=product_a, http_proxy_policy='none').create() - repo_a2 = entities.Repository( + product_a = target_sat.api.Product(organization=org).create() + product_b = target_sat.api.Product(organization=org).create() + repo_a1 = target_sat.api.Repository(product=product_a, http_proxy_policy='none').create() + repo_a2 = target_sat.api.Repository( product=product_a, http_proxy_policy='use_selected_http_proxy', http_proxy_id=http_proxy_a.id, ).create() - repo_b1 = entities.Repository(product=product_b, http_proxy_policy='none').create() - repo_b2 = entities.Repository( + repo_b1 = target_sat.api.Repository(product=product_b, http_proxy_policy='none').create() + repo_b2 = target_sat.api.Repository( product=product_b, http_proxy_policy='global_default_http_proxy' ).create() # Add http_proxy to products - entities.ProductBulkAction().http_proxy( + target_sat.api.ProductBulkAction().http_proxy( data={ "ids": [product_a.id, product_b.id], "http_proxy_policy": "use_selected_http_proxy", diff --git a/tests/foreman/api/test_ldapauthsource.py b/tests/foreman/api/test_ldapauthsource.py index 10b9851b3d6..2139e7c947f 100644 --- a/tests/foreman/api/test_ldapauthsource.py +++ b/tests/foreman/api/test_ldapauthsource.py @@ -16,7 +16,6 @@ :Upstream: No """ -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -27,7 +26,9 @@ @pytest.mark.tier3 @pytest.mark.upgrade @pytest.mark.parametrize('auth_source_type', ['AD', 'IPA']) -def test_positive_endtoend(auth_source_type, module_org, module_location, ad_data, ipa_data): +def test_positive_endtoend( + auth_source_type, module_org, module_location, ad_data, ipa_data, module_target_sat +): """Create/update/delete LDAP authentication with AD using names of different types :id: e3607c97-7c48-4cf6-b119-2bfd895d9325 @@ -46,7 +47,7 @@ def test_positive_endtoend(auth_source_type, module_org, module_location, ad_dat auth_source_data = ipa_data auth_source_data['ldap_user_name'] = auth_source_data['ldap_user_cn'] auth_type_attr = LDAP_ATTR['login'] - authsource = entities.AuthSourceLDAP( + authsource = module_target_sat.api.AuthSourceLDAP( onthefly_register=True, account=auth_source_data['ldap_user_cn'], account_password=auth_source_data['ldap_user_passwd'], diff --git a/tests/foreman/api/test_lifecycleenvironment.py b/tests/foreman/api/test_lifecycleenvironment.py index b8e7b3ef347..79cece7c76f 100644 --- a/tests/foreman/api/test_lifecycleenvironment.py +++ b/tests/foreman/api/test_lifecycleenvironment.py @@ -21,7 +21,6 @@ :Upstream: No """ from fauxfactory import gen_string -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -34,20 +33,20 @@ @pytest.fixture(scope='module') -def module_lce(module_org): - return entities.LifecycleEnvironment( +def module_lce(module_org, module_target_sat): + return module_target_sat.api.LifecycleEnvironment( organization=module_org, description=gen_string('alpha') ).create() @pytest.fixture -def lce(module_org): - return entities.LifecycleEnvironment(organization=module_org).create() +def lce(module_org, module_target_sat): + return module_target_sat.api.LifecycleEnvironment(organization=module_org).create() @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_create_with_name(name): +def test_positive_create_with_name(name, target_sat): """Create lifecycle environment with valid name only :id: ec1d985a-6a39-4de6-b635-c803ecedd832 @@ -58,12 +57,12 @@ def test_positive_create_with_name(name): :parametrized: yes """ - assert entities.LifecycleEnvironment(name=name).create().name == name + assert target_sat.api.LifecycleEnvironment(name=name).create().name == name @pytest.mark.parametrize('desc', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_create_with_description(desc): +def test_positive_create_with_description(desc, target_sat): """Create lifecycle environment with valid description :id: 0bc05510-afc7-4087-ab75-1065ab5ba1d3 @@ -75,11 +74,11 @@ def test_positive_create_with_description(desc): :parametrized: yes """ - assert entities.LifecycleEnvironment(description=desc).create().description == desc + assert target_sat.api.LifecycleEnvironment(description=desc).create().description == desc @pytest.mark.tier1 -def test_positive_create_prior(module_org): +def test_positive_create_prior(module_org, module_target_sat): """Create a lifecycle environment with valid name with Library as prior @@ -90,13 +89,13 @@ def test_positive_create_prior(module_org): :CaseImportance: Critical """ - lc_env = entities.LifecycleEnvironment(organization=module_org).create() + lc_env = module_target_sat.api.LifecycleEnvironment(organization=module_org).create() assert lc_env.prior.read().name == ENVIRONMENT @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) @pytest.mark.tier3 -def test_negative_create_with_invalid_name(name): +def test_negative_create_with_invalid_name(name, target_sat): """Create lifecycle environment providing an invalid name :id: 7e8ea2e6-5927-4e86-8ea8-04c3feb524a6 @@ -108,12 +107,12 @@ def test_negative_create_with_invalid_name(name): :parametrized: yes """ with pytest.raises(HTTPError): - entities.LifecycleEnvironment(name=name).create() + target_sat.api.LifecycleEnvironment(name=name).create() @pytest.mark.parametrize('new_name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_update_name(module_lce, new_name): +def test_positive_update_name(module_lce, new_name, module_target_sat): """Create lifecycle environment providing the initial name, then update its name to another valid name. @@ -125,13 +124,13 @@ def test_positive_update_name(module_lce, new_name): """ module_lce.name = new_name module_lce.update(['name']) - updated = entities.LifecycleEnvironment(id=module_lce.id).read() + updated = module_target_sat.api.LifecycleEnvironment(id=module_lce.id).read() assert new_name == updated.name @pytest.mark.parametrize('new_desc', **parametrized(valid_data_list())) @pytest.mark.tier2 -def test_positive_update_description(module_lce, new_desc): +def test_positive_update_description(module_lce, new_desc, module_target_sat): """Create lifecycle environment providing the initial description, then update its description to another one. @@ -147,7 +146,7 @@ def test_positive_update_description(module_lce, new_desc): """ module_lce.description = new_desc module_lce.update(['description']) - updated = entities.LifecycleEnvironment(id=module_lce.id).read() + updated = module_target_sat.api.LifecycleEnvironment(id=module_lce.id).read() assert new_desc == updated.description @@ -175,7 +174,7 @@ def test_negative_update_name(module_lce, new_name): @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 @pytest.mark.upgrade -def test_positive_delete(lce, name): +def test_positive_delete(lce, name, target_sat): """Create lifecycle environment and then delete it. :id: cd5a97ca-c1e8-41c7-8d6b-f908916b24e1 @@ -188,12 +187,12 @@ def test_positive_delete(lce, name): """ lce.delete() with pytest.raises(HTTPError): - entities.LifecycleEnvironment(id=lce.id).read() + target_sat.api.LifecycleEnvironment(id=lce.id).read() @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier2 -def test_positive_search_in_org(name): +def test_positive_search_in_org(name, target_sat): """Search for a lifecycle environment and specify an org ID. :id: 110e4777-c374-4365-b676-b1db4552fe51 @@ -211,8 +210,8 @@ def test_positive_search_in_org(name): :parametrized: yes """ - new_org = entities.Organization().create() - lc_env = entities.LifecycleEnvironment(organization=new_org).create() + new_org = target_sat.api.Organization().create() + lc_env = target_sat.api.LifecycleEnvironment(organization=new_org).create() lc_envs = lc_env.search({'organization'}) assert len(lc_envs) == 2 assert {lc_env_.name for lc_env_ in lc_envs}, {'Library', lc_env.name} diff --git a/tests/foreman/api/test_media.py b/tests/foreman/api/test_media.py index e5524d914fd..3169dfb0177 100644 --- a/tests/foreman/api/test_media.py +++ b/tests/foreman/api/test_media.py @@ -19,7 +19,6 @@ import random from fauxfactory import gen_string, gen_url -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -35,8 +34,8 @@ class TestMedia: """Tests for ``api/v2/media``.""" @pytest.fixture(scope='class') - def class_media(self, module_org): - return entities.Media(organization=[module_org]).create() + def class_media(self, module_org, module_target_sat): + return module_target_sat.api.Media(organization=[module_org]).create() @pytest.mark.tier1 @pytest.mark.upgrade @@ -44,7 +43,7 @@ def class_media(self, module_org): 'name, new_name', **parametrized(list(zip(valid_data_list().values(), valid_data_list().values()))) ) - def test_positive_crud_with_name(self, module_org, name, new_name): + def test_positive_crud_with_name(self, module_org, name, new_name, module_target_sat): """Create, update, delete media with valid name only :id: b07a4549-7dd5-4b36-a1b4-9f8d48ddfcb5 @@ -55,9 +54,9 @@ def test_positive_crud_with_name(self, module_org, name, new_name): :CaseImportance: Critical """ - media = entities.Media(organization=[module_org], name=name).create() + media = module_target_sat.api.Media(organization=[module_org], name=name).create() assert media.name == name - media = entities.Media(id=media.id, name=new_name).update(['name']) + media = module_target_sat.api.Media(id=media.id, name=new_name).update(['name']) assert media.name == new_name media.delete() with pytest.raises(HTTPError): @@ -65,7 +64,7 @@ def test_positive_crud_with_name(self, module_org, name, new_name): @pytest.mark.tier1 @pytest.mark.parametrize('os_family', **parametrized(OPERATING_SYSTEMS)) - def test_positive_create_update_with_os_family(self, module_org, os_family): + def test_positive_create_update_with_os_family(self, module_org, os_family, module_target_sat): """Create and update media with every OS family possible :id: d02404f0-b2ad-412c-b1cd-0548254f7c88 @@ -75,14 +74,14 @@ def test_positive_create_update_with_os_family(self, module_org, os_family): :expectedresults: Media entity is created and has proper OS family assigned """ - media = entities.Media(organization=[module_org], os_family=os_family).create() + media = module_target_sat.api.Media(organization=[module_org], os_family=os_family).create() assert media.os_family == os_family new_os_family = new_os_family = random.choice(OPERATING_SYSTEMS) media.os_family = new_os_family assert media.update(['os_family']).os_family == new_os_family @pytest.mark.tier2 - def test_positive_create_with_location(self, module_org, module_location): + def test_positive_create_with_location(self, module_org, module_location, module_target_sat): """Create media entity assigned to non-default location :id: 1c4fa736-c145-46ca-9feb-c4046fc778c6 @@ -91,11 +90,13 @@ def test_positive_create_with_location(self, module_org, module_location): :CaseLevel: Integration """ - media = entities.Media(organization=[module_org], location=[module_location]).create() + media = module_target_sat.api.Media( + organization=[module_org], location=[module_location] + ).create() assert media.location[0].read().name == module_location.name @pytest.mark.tier2 - def test_positive_create_with_os(self, module_org): + def test_positive_create_with_os(self, module_org, module_target_sat): """Create media entity assigned to operation system entity :id: dec22198-ed07-480c-9306-fa5458baec0b @@ -104,12 +105,14 @@ def test_positive_create_with_os(self, module_org): :CaseLevel: Integration """ - os = entities.OperatingSystem().create() - media = entities.Media(organization=[module_org], operatingsystem=[os]).create() + os = module_target_sat.api.OperatingSystem().create() + media = module_target_sat.api.Media( + organization=[module_org], operatingsystem=[os] + ).create() assert os.read().medium[0].read().name == media.name @pytest.mark.tier2 - def test_positive_create_update_url(self, module_org): + def test_positive_create_update_url(self, module_org, module_target_sat): """Create media entity providing the initial url path, then update that url to another valid one. @@ -120,15 +123,15 @@ def test_positive_create_update_url(self, module_org): :CaseImportance: Medium """ url = gen_url(subdomain=gen_string('alpha')) - media = entities.Media(organization=[module_org], path_=url).create() + media = module_target_sat.api.Media(organization=[module_org], path_=url).create() assert media.path_ == url new_url = gen_url(subdomain=gen_string('alpha')) - media = entities.Media(id=media.id, path_=new_url).update(['path_']) + media = module_target_sat.api.Media(id=media.id, path_=new_url).update(['path_']) assert media.path_ == new_url @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) - def test_negative_create_with_invalid_name(self, name): + def test_negative_create_with_invalid_name(self, name, target_sat): """Try to create media entity providing an invalid name :id: 0934f4dc-f674-40fe-a639-035761139c83 @@ -140,10 +143,10 @@ def test_negative_create_with_invalid_name(self, name): :CaseImportance: Medium """ with pytest.raises(HTTPError): - entities.Media(name=name).create() + target_sat.api.Media(name=name).create() @pytest.mark.tier1 - def test_negative_create_with_invalid_url(self): + def test_negative_create_with_invalid_url(self, target_sat): """Try to create media entity providing an invalid URL :id: ae00b6bb-37ed-459e-b9f7-acc92ed0b262 @@ -153,10 +156,10 @@ def test_negative_create_with_invalid_url(self): :CaseImportance: Medium """ with pytest.raises(HTTPError): - entities.Media(path_='NON_EXISTENT_URL').create() + target_sat.api.Media(path_='NON_EXISTENT_URL').create() @pytest.mark.tier1 - def test_negative_create_with_invalid_os_family(self): + def test_negative_create_with_invalid_os_family(self, target_sat): """Try to create media entity providing an invalid OS family :id: 368b7eac-8c52-4071-89c0-1946d7101291 @@ -166,11 +169,11 @@ def test_negative_create_with_invalid_os_family(self): :CaseImportance: Medium """ with pytest.raises(HTTPError): - entities.Media(os_family='NON_EXISTENT_OS').create() + target_sat.api.Media(os_family='NON_EXISTENT_OS').create() @pytest.mark.tier1 @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list())) - def test_negative_update_name(self, module_org, class_media, new_name): + def test_negative_update_name(self, class_media, new_name, target_sat): """Create media entity providing the initial name, then try to update its name to invalid one. @@ -183,10 +186,10 @@ def test_negative_update_name(self, module_org, class_media, new_name): :CaseImportance: Medium """ with pytest.raises(HTTPError): - entities.Media(id=class_media.id, name=new_name).update(['name']) + target_sat.api.Media(id=class_media.id, name=new_name).update(['name']) @pytest.mark.tier1 - def test_negative_update_url(self, module_org, class_media): + def test_negative_update_url(self, class_media, target_sat): """Try to update media with invalid url. :id: 6832f178-4adc-4bb1-957d-0d8d4fd8d9cd @@ -196,10 +199,10 @@ def test_negative_update_url(self, module_org, class_media): :CaseImportance: Medium """ with pytest.raises(HTTPError): - entities.Media(id=class_media.id, path_='NON_EXISTENT_URL').update(['path_']) + target_sat.api.Media(id=class_media.id, path_='NON_EXISTENT_URL').update(['path_']) @pytest.mark.tier1 - def test_negative_update_os_family(self, module_org, class_media): + def test_negative_update_os_family(self, class_media, target_sat): """Try to update media with invalid operation system. :id: f4c5438d-5f98-40b1-9bc7-c0741e81303a @@ -209,4 +212,6 @@ def test_negative_update_os_family(self, module_org, class_media): :CaseImportance: Medium """ with pytest.raises(HTTPError): - entities.Media(id=class_media.id, os_family='NON_EXISTENT_OS').update(['os_family']) + target_sat.api.Media(id=class_media.id, os_family='NON_EXISTENT_OS').update( + ['os_family'] + ) diff --git a/tests/foreman/api/test_organization.py b/tests/foreman/api/test_organization.py index 692504faf79..6e9b75b38e6 100644 --- a/tests/foreman/api/test_organization.py +++ b/tests/foreman/api/test_organization.py @@ -24,7 +24,7 @@ from random import randint from fauxfactory import gen_string -from nailgun import client, entities +from nailgun import client import pytest from requests.exceptions import HTTPError @@ -44,7 +44,7 @@ def valid_org_data_list(): Note: The maximum allowed length of org name is 242 only. This is an intended behavior (Also note that 255 is the standard across other - entities.) + target_sat.api.) """ return dict( alpha=gen_string('alpha', randint(1, 242)), @@ -61,7 +61,7 @@ class TestOrganization: """Tests for the ``organizations`` path.""" @pytest.mark.tier1 - def test_positive_create(self): + def test_positive_create(self, target_sat): """Create an organization using a 'text/plain' content-type. :id: 6f67a3f0-0c1d-498c-9a35-28207b0faec2 @@ -70,7 +70,7 @@ def test_positive_create(self): :CaseImportance: Critical """ - organization = entities.Organization() + organization = target_sat.api.Organization() organization.create_missing() response = client.post( organization.path(), @@ -87,7 +87,7 @@ def test_positive_create(self): @pytest.mark.tier1 @pytest.mark.build_sanity @pytest.mark.parametrize('name', **parametrized(valid_org_data_list())) - def test_positive_create_with_name_and_description(self, name): + def test_positive_create_with_name_and_description(self, name, target_sat): """Create an organization and provide a name and description. :id: afeea84b-61ca-40bf-bb16-476432919115 @@ -99,7 +99,7 @@ def test_positive_create_with_name_and_description(self, name): :parametrized: yes """ - org = entities.Organization(name=name, description=name).create() + org = target_sat.api.Organization(name=name, description=name).create() assert org.name == name assert org.description == name @@ -110,7 +110,7 @@ def test_positive_create_with_name_and_description(self, name): @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) - def test_negative_create_with_invalid_name(self, name): + def test_negative_create_with_invalid_name(self, name, target_sat): """Create an org with an incorrect name. :id: 9c6a4b45-a98a-4d76-9865-92d992fa1a22 @@ -120,10 +120,10 @@ def test_negative_create_with_invalid_name(self, name): :parametrized: yes """ with pytest.raises(HTTPError): - entities.Organization(name=name).create() + target_sat.api.Organization(name=name).create() @pytest.mark.tier1 - def test_negative_create_with_same_name(self): + def test_negative_create_with_same_name(self, target_sat): """Create two organizations with identical names. :id: a0f5333c-cc83-403c-9bf7-08fb372909dc @@ -132,9 +132,9 @@ def test_negative_create_with_same_name(self): :CaseImportance: Critical """ - name = entities.Organization().create().name + name = target_sat.api.Organization().create().name with pytest.raises(HTTPError): - entities.Organization(name=name).create() + target_sat.api.Organization(name=name).create() @pytest.mark.tier1 def test_negative_check_org_endpoint(self, module_entitlement_manifest_org): @@ -155,7 +155,7 @@ def test_negative_check_org_endpoint(self, module_entitlement_manifest_org): assert 'BEGIN RSA PRIVATE KEY' not in orgstring @pytest.mark.tier1 - def test_positive_search(self): + def test_positive_search(self, target_sat): """Create an organization, then search for it by name. :id: f6f1d839-21f2-4676-8683-9f899cbdec4c @@ -164,14 +164,14 @@ def test_positive_search(self): :CaseImportance: High """ - org = entities.Organization().create() - orgs = entities.Organization().search(query={'search': f'name="{org.name}"'}) + org = target_sat.api.Organization().create() + orgs = target_sat.api.Organization().search(query={'search': f'name="{org.name}"'}) assert len(orgs) == 1 assert orgs[0].id == org.id assert orgs[0].name == org.name @pytest.mark.tier1 - def test_negative_create_with_wrong_path(self): + def test_negative_create_with_wrong_path(self, target_sat): """Attempt to create an organization using foreman API path (``api/v2/organizations``) @@ -184,7 +184,7 @@ def test_negative_create_with_wrong_path(self): :CaseImportance: Critical """ - org = entities.Organization() + org = target_sat.api.Organization() org._meta['api_path'] = 'api/v2/organizations' with pytest.raises(HTTPError) as err: org.create() @@ -192,7 +192,7 @@ def test_negative_create_with_wrong_path(self): assert 'Route overriden by Katello' in err.value.response.text @pytest.mark.tier2 - def test_default_org_id_check(self): + def test_default_org_id_check(self, target_sat): """test to check the default_organization id :id: df066396-a069-4e9e-b3c1-c6d34a755ec0 @@ -204,7 +204,7 @@ def test_default_org_id_check(self): :CaseImportance: Low """ default_org_id = ( - entities.Organization().search(query={'search': f'name="{DEFAULT_ORG}"'})[0].id + target_sat.api.Organization().search(query={'search': f'name="{DEFAULT_ORG}"'})[0].id ) assert default_org_id == 1 @@ -213,9 +213,9 @@ class TestOrganizationUpdate: """Tests for the ``organizations`` path.""" @pytest.fixture - def module_org(self): + def module_org(self, target_sat): """Create an organization.""" - return entities.Organization().create() + return target_sat.api.Organization().create() @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(valid_org_data_list())) @@ -252,7 +252,7 @@ def test_positive_update_description(self, module_org, desc): assert module_org.description == desc @pytest.mark.tier2 - def test_positive_update_user(self, module_org): + def test_positive_update_user(self, module_org, target_sat): """Update an organization, associate user with it. :id: 2c0c0061-5b4e-4007-9f54-b61d6e65ef58 @@ -261,14 +261,14 @@ def test_positive_update_user(self, module_org): :CaseLevel: Integration """ - user = entities.User().create() + user = target_sat.api.User().create() module_org.user = [user] module_org = module_org.update(['user']) assert len(module_org.user) == 1 assert module_org.user[0].id == user.id @pytest.mark.tier2 - def test_positive_update_subnet(self, module_org): + def test_positive_update_subnet(self, module_org, target_sat): """Update an organization, associate subnet with it. :id: 3aa0b9cb-37f7-4e7e-a6ec-c1b407225e54 @@ -277,14 +277,14 @@ def test_positive_update_subnet(self, module_org): :CaseLevel: Integration """ - subnet = entities.Subnet().create() + subnet = target_sat.api.Subnet().create() module_org.subnet = [subnet] module_org = module_org.update(['subnet']) assert len(module_org.subnet) == 1 assert module_org.subnet[0].id == subnet.id @pytest.mark.tier2 - def test_positive_add_and_remove_hostgroup(self): + def test_positive_add_and_remove_hostgroup(self, target_sat): """Add a hostgroup to an organization and then remove it :id: 7eb1aca7-fd7b-404f-ab18-21be5052a11f @@ -297,8 +297,8 @@ def test_positive_add_and_remove_hostgroup(self): :CaseImportance: Medium """ - org = entities.Organization().create() - hostgroup = entities.HostGroup().create() + org = target_sat.api.Organization().create() + hostgroup = target_sat.api.HostGroup().create() org.hostgroup = [hostgroup] org = org.update(['hostgroup']) assert len(org.hostgroup) == 1 @@ -348,7 +348,7 @@ def test_positive_add_and_remove_smart_proxy(self, target_sat): @pytest.mark.tier1 @pytest.mark.parametrize('update_field', ['name', 'label']) - def test_negative_update(self, module_org, update_field): + def test_negative_update(self, module_org, update_field, target_sat): """Update an organization's attributes with invalid values. :id: b7152d0b-5ab0-4d68-bfdf-f3eabcb5fbc6 @@ -367,4 +367,4 @@ def test_negative_update(self, module_org, update_field): update_field: gen_string(str_type='utf8', length=256 if update_field == 'name' else 10) } with pytest.raises(HTTPError): - entities.Organization(id=module_org.id, **update_dict).update([update_field]) + target_sat.api.Organization(id=module_org.id, **update_dict).update([update_field]) diff --git a/tests/foreman/api/test_oscap_tailoringfiles.py b/tests/foreman/api/test_oscap_tailoringfiles.py index d29eed1ca95..fb6b78750f0 100644 --- a/tests/foreman/api/test_oscap_tailoringfiles.py +++ b/tests/foreman/api/test_oscap_tailoringfiles.py @@ -16,7 +16,6 @@ :Upstream: No """ -from nailgun import entities import pytest from robottelo.utils.datafactory import gen_string @@ -27,7 +26,9 @@ class TestTailoringFile: @pytest.mark.tier1 @pytest.mark.e2e - def test_positive_crud_tailoringfile(self, default_org, default_location, tailoring_file_path): + def test_positive_crud_tailoringfile( + self, default_org, default_location, tailoring_file_path, target_sat + ): """Perform end to end testing for oscap tailoring files component :id: 2441988f-2054-49f7-885e-3675336f712f @@ -39,23 +40,23 @@ def test_positive_crud_tailoringfile(self, default_org, default_location, tailor name = gen_string('alpha') new_name = gen_string('alpha') original_filename = gen_string('alpha') - scap = entities.TailoringFile( + scap = target_sat.api.TailoringFile( name=name, scap_file=tailoring_file_path['local'], organization=[default_org], location=[default_location], ).create() - assert entities.TailoringFile().search(query={'search': f'name={name}'}) - result = entities.TailoringFile(id=scap.id).read() + assert target_sat.api.TailoringFile().search(query={'search': f'name={name}'}) + result = target_sat.api.TailoringFile(id=scap.id).read() assert result.name == name assert result.location[0].id == default_location.id assert result.organization[0].id == default_org.id - scap = entities.TailoringFile( + scap = target_sat.api.TailoringFile( id=scap.id, name=new_name, original_filename=f'{original_filename}' ).update() - result = entities.TailoringFile(id=scap.id).read() + result = target_sat.api.TailoringFile(id=scap.id).read() assert result.name == new_name assert result.original_filename == original_filename - assert entities.TailoringFile().search(query={'search': f'name={new_name}'}) - entities.TailoringFile(id=scap.id).delete() - assert not entities.TailoringFile().search(query={'search': f'name={new_name}'}) + assert target_sat.api.TailoringFile().search(query={'search': f'name={new_name}'}) + target_sat.api.TailoringFile(id=scap.id).delete() + assert not target_sat.api.TailoringFile().search(query={'search': f'name={new_name}'}) diff --git a/tests/foreman/api/test_oscappolicy.py b/tests/foreman/api/test_oscappolicy.py index 1efdd3e3779..c9500c465d1 100644 --- a/tests/foreman/api/test_oscappolicy.py +++ b/tests/foreman/api/test_oscappolicy.py @@ -17,7 +17,6 @@ :Upstream: No """ from fauxfactory import gen_string -from nailgun import entities import pytest @@ -27,7 +26,7 @@ class TestOscapPolicy: @pytest.mark.tier1 @pytest.mark.e2e def test_positive_crud_scap_policy( - self, default_org, default_location, scap_content, tailoring_file + self, default_org, default_location, scap_content, tailoring_file, target_sat ): """Perform end to end testing for oscap policy component @@ -42,11 +41,11 @@ def test_positive_crud_scap_policy( name = gen_string('alpha') new_name = gen_string('alpha') description = gen_string('alpha') - hostgroup = entities.HostGroup( + hostgroup = target_sat.api.HostGroup( location=[default_location], organization=[default_org] ).create() # Create new oscap policy with assigned content and tailoring file - policy = entities.CompliancePolicies( + policy = target_sat.api.CompliancePolicies( name=name, deploy_by='ansible', description=description, @@ -60,7 +59,7 @@ def test_positive_crud_scap_policy( location=[default_location], organization=[default_org], ).create() - assert entities.CompliancePolicies().search(query={'search': f'name="{name}"'}) + assert target_sat.api.CompliancePolicies().search(query={'search': f'name="{name}"'}) # Check that created entity has expected values assert policy.deploy_by == 'ansible' assert policy.name == name @@ -74,9 +73,11 @@ def test_positive_crud_scap_policy( assert str(policy.organization[0].id) == str(default_org.id) assert str(policy.location[0].id) == str(default_location.id) # Update oscap policy with new name - policy = entities.CompliancePolicies(id=policy.id, name=new_name).update() + policy = target_sat.api.CompliancePolicies(id=policy.id, name=new_name).update() assert policy.name == new_name - assert not entities.CompliancePolicies().search(query={'search': f'name="{name}"'}) + assert not target_sat.api.CompliancePolicies().search(query={'search': f'name="{name}"'}) # Delete oscap policy entity - entities.CompliancePolicies(id=policy.id).delete() - assert not entities.CompliancePolicies().search(query={'search': f'name="{new_name}"'}) + target_sat.api.CompliancePolicies(id=policy.id).delete() + assert not target_sat.api.CompliancePolicies().search( + query={'search': f'name="{new_name}"'} + ) diff --git a/tests/foreman/api/test_product.py b/tests/foreman/api/test_product.py index 84b6d78f866..dfa9f59f705 100644 --- a/tests/foreman/api/test_product.py +++ b/tests/foreman/api/test_product.py @@ -20,7 +20,6 @@ :Upstream: No """ from fauxfactory import gen_string -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -40,7 +39,7 @@ @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) -def test_positive_create_with_name(request, name, module_org): +def test_positive_create_with_name(request, name, module_org, module_target_sat): """Create a product providing different valid names :id: 3d873b73-6919-4fda-84df-0e26bdf0c1dc @@ -51,12 +50,12 @@ def test_positive_create_with_name(request, name, module_org): :CaseImportance: Critical """ - product = entities.Product(name=name, organization=module_org).create() + product = module_target_sat.api.Product(name=name, organization=module_org).create() assert product.name == name @pytest.mark.tier1 -def test_positive_create_with_label(module_org): +def test_positive_create_with_label(module_org, module_target_sat): """Create a product providing label which is different from its name :id: 95cf8e05-fd09-422e-bf6f-8b1dde762976 @@ -66,14 +65,14 @@ def test_positive_create_with_label(module_org): :CaseImportance: Critical """ label = gen_string('alphanumeric') - product = entities.Product(label=label, organization=module_org).create() + product = module_target_sat.api.Product(label=label, organization=module_org).create() assert product.label == label assert product.name != label @pytest.mark.tier1 @pytest.mark.parametrize('description', **parametrized(valid_data_list())) -def test_positive_create_with_description(description, module_org): +def test_positive_create_with_description(description, module_org, module_target_sat): """Create a product providing different descriptions :id: f3e2df77-6711-440b-800a-9cebbbec36c5 @@ -84,12 +83,14 @@ def test_positive_create_with_description(description, module_org): :CaseImportance: Critical """ - product = entities.Product(description=description, organization=module_org).create() + product = module_target_sat.api.Product( + description=description, organization=module_org + ).create() assert product.description == description @pytest.mark.tier2 -def test_positive_create_with_gpg(module_org): +def test_positive_create_with_gpg(module_org, module_target_sat): """Create a product and provide a GPG key. :id: 57331c1f-15dd-4c9f-b8fc-3010847b2975 @@ -98,17 +99,17 @@ def test_positive_create_with_gpg(module_org): :CaseLevel: Integration """ - gpg_key = entities.GPGKey( + gpg_key = module_target_sat.api.GPGKey( content=DataFile.VALID_GPG_KEY_FILE.read_text(), organization=module_org, ).create() - product = entities.Product(gpg_key=gpg_key, organization=module_org).create() + product = module_target_sat.api.Product(gpg_key=gpg_key, organization=module_org).create() assert product.gpg_key.id == gpg_key.id @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) -def test_negative_create_with_name(name, module_org): +def test_negative_create_with_name(name, module_org, module_target_sat): """Create a product providing invalid names only :id: 76531f53-09ff-4ee9-89b9-09a697526fb1 @@ -120,11 +121,11 @@ def test_negative_create_with_name(name, module_org): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.Product(name=name, organization=module_org).create() + module_target_sat.api.Product(name=name, organization=module_org).create() @pytest.mark.tier1 -def test_negative_create_with_same_name(module_org): +def test_negative_create_with_same_name(module_org, module_target_sat): """Create a product providing a name of already existent entity :id: 039269c5-607a-4b70-91dd-b8fed8e50cc6 @@ -134,13 +135,13 @@ def test_negative_create_with_same_name(module_org): :CaseImportance: Critical """ name = gen_string('alphanumeric') - entities.Product(name=name, organization=module_org).create() + module_target_sat.api.Product(name=name, organization=module_org).create() with pytest.raises(HTTPError): - entities.Product(name=name, organization=module_org).create() + module_target_sat.api.Product(name=name, organization=module_org).create() @pytest.mark.tier1 -def test_negative_create_with_label(module_org): +def test_negative_create_with_label(module_org, module_target_sat): """Create a product providing invalid label :id: 30b1a737-07f1-4786-b68a-734e57c33a62 @@ -150,12 +151,12 @@ def test_negative_create_with_label(module_org): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.Product(label=gen_string('utf8'), organization=module_org).create() + module_target_sat.api.Product(label=gen_string('utf8'), organization=module_org).create() @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) -def test_positive_update_name(name, module_org): +def test_positive_update_name(name, module_org, module_target_sat): """Update product name to another valid name. :id: 1a9f6e0d-43fb-42e2-9dbd-e880f03b0297 @@ -166,7 +167,7 @@ def test_positive_update_name(name, module_org): :CaseImportance: Critical """ - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() product.name = name product = product.update(['name']) assert product.name == name @@ -174,7 +175,7 @@ def test_positive_update_name(name, module_org): @pytest.mark.tier1 @pytest.mark.parametrize('description', **parametrized(valid_data_list())) -def test_positive_update_description(description, module_org): +def test_positive_update_description(description, module_org, module_target_sat): """Update product description to another valid one. :id: c960c326-2e9f-4ee7-bdec-35a705305067 @@ -185,14 +186,14 @@ def test_positive_update_description(description, module_org): :CaseImportance: Critical """ - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() product.description = description product = product.update(['description']) assert product.description == description @pytest.mark.tier1 -def test_positive_update_name_to_original(module_org): +def test_positive_update_name_to_original(module_org, module_target_sat): """Rename Product back to original name :id: 3075f17f-4475-4b64-9fbd-1e41ced9142d @@ -201,7 +202,7 @@ def test_positive_update_name_to_original(module_org): :CaseImportance: Critical """ - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() old_name = product.name # Update product name @@ -218,7 +219,7 @@ def test_positive_update_name_to_original(module_org): @pytest.mark.upgrade @pytest.mark.tier2 -def test_positive_update_gpg(module_org): +def test_positive_update_gpg(module_org, module_target_sat): """Create a product and update its GPGKey :id: 3b08f155-a0d6-4987-b281-dc02e8d5a03e @@ -228,14 +229,14 @@ def test_positive_update_gpg(module_org): :CaseLevel: Integration """ # Create a product and make it point to a GPG key. - gpg_key_1 = entities.GPGKey( + gpg_key_1 = module_target_sat.api.GPGKey( content=DataFile.VALID_GPG_KEY_FILE.read_text(), organization=module_org, ).create() - product = entities.Product(gpg_key=gpg_key_1, organization=module_org).create() + product = module_target_sat.api.Product(gpg_key=gpg_key_1, organization=module_org).create() # Update the product and make it point to a new GPG key. - gpg_key_2 = entities.GPGKey( + gpg_key_2 = module_target_sat.api.GPGKey( content=DataFile.VALID_GPG_KEY_BETA_FILE.read_text(), organization=module_org, ).create() @@ -246,7 +247,7 @@ def test_positive_update_gpg(module_org): @pytest.mark.skip_if_open("BZ:1310422") @pytest.mark.tier2 -def test_positive_update_organization(module_org): +def test_positive_update_organization(module_org, module_target_sat): """Create a product and update its organization :id: b298957a-2cdb-4f17-a934-098612f3b659 @@ -257,9 +258,9 @@ def test_positive_update_organization(module_org): :BZ: 1310422 """ - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() # Update the product and make it point to a new organization. - new_org = entities.Organization().create() + new_org = module_target_sat.api.Organization().create() product.organization = new_org product = product.update() assert product.organization.id == new_org.id @@ -267,7 +268,7 @@ def test_positive_update_organization(module_org): @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) -def test_negative_update_name(name, module_org): +def test_negative_update_name(name, module_org, module_target_sat): """Attempt to update product name to invalid one :id: 3eb61fa8-3524-4872-8f1b-4e88004f66f5 @@ -278,13 +279,13 @@ def test_negative_update_name(name, module_org): :CaseImportance: Critical """ - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() with pytest.raises(HTTPError): - entities.Product(id=product.id, name=name).update(['name']) + module_target_sat.api.Product(id=product.id, name=name).update(['name']) @pytest.mark.tier1 -def test_negative_update_label(module_org): +def test_negative_update_label(module_org, module_target_sat): """Attempt to update product label to another one. :id: 065cd673-8d10-46c7-800c-b731b06a5359 @@ -293,7 +294,7 @@ def test_negative_update_label(module_org): :CaseImportance: Critical """ - product = entities.Product(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() product.label = gen_string('alpha') with pytest.raises(HTTPError): product.update(['label']) @@ -301,7 +302,7 @@ def test_negative_update_label(module_org): @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) -def test_positive_delete(name, module_org): +def test_positive_delete(name, module_org, module_target_sat): """Create product and then delete it. :id: 30df95f5-0a4e-41ee-a99f-b418c5c5f2f3 @@ -312,7 +313,7 @@ def test_positive_delete(name, module_org): :CaseImportance: Critical """ - product = entities.Product(name=name, organization=module_org).create() + product = module_target_sat.api.Product(name=name, organization=module_org).create() product.delete() with pytest.raises(HTTPError): product.read() @@ -320,7 +321,7 @@ def test_positive_delete(name, module_org): @pytest.mark.tier1 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_sync(module_org): +def test_positive_sync(module_org, module_target_sat): """Sync product (repository within a product) :id: 860e00a1-c370-4bd0-8987-449338071d56 @@ -329,8 +330,8 @@ def test_positive_sync(module_org): :CaseImportance: Critical """ - 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( product=product, content_type='yum', url=settings.repos.yum_1.url ).create() assert repo.read().content_counts['rpm'] == 0 @@ -341,7 +342,7 @@ def test_positive_sync(module_org): @pytest.mark.tier2 @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') -def test_positive_sync_several_repos(module_org): +def test_positive_sync_several_repos(module_org, module_target_sat): """Sync product (all repositories within a product) :id: 07918442-b72f-4db5-96b6-975564f3663a @@ -353,11 +354,11 @@ def test_positive_sync_several_repos(module_org): :BZ: 1389543 """ - product = entities.Product(organization=module_org).create() - rpm_repo = entities.Repository( + product = module_target_sat.api.Product(organization=module_org).create() + rpm_repo = module_target_sat.api.Repository( product=product, content_type='yum', url=settings.repos.yum_1.url ).create() - docker_repo = entities.Repository( + docker_repo = module_target_sat.api.Repository( content_type=REPO_TYPE['docker'], docker_upstream_name=CONTAINER_UPSTREAM_NAME, product=product, @@ -372,7 +373,7 @@ def test_positive_sync_several_repos(module_org): @pytest.mark.tier2 -def test_positive_filter_product_list(module_entitlement_manifest_org): +def test_positive_filter_product_list(module_entitlement_manifest_org, module_target_sat): """Filter products based on param 'custom/redhat_only' :id: e61fb63a-4552-4915-b13d-23ab80138249 @@ -384,9 +385,9 @@ def test_positive_filter_product_list(module_entitlement_manifest_org): :BZ: 1667129 """ org = module_entitlement_manifest_org - product = entities.Product(organization=org).create() - custom_products = entities.Product(organization=org).search(query={'custom': True}) - rh_products = entities.Product(organization=org).search( + product = module_target_sat.api.Product(organization=org).create() + custom_products = module_target_sat.api.Product(organization=org).search(query={'custom': True}) + rh_products = module_target_sat.api.Product(organization=org).search( query={'redhat_only': True, 'per_page': 1000} ) diff --git a/tests/foreman/api/test_reporttemplates.py b/tests/foreman/api/test_reporttemplates.py index 5047a9a616c..7d6bf4d2e1d 100644 --- a/tests/foreman/api/test_reporttemplates.py +++ b/tests/foreman/api/test_reporttemplates.py @@ -18,7 +18,6 @@ """ from broker import Broker from fauxfactory import gen_string -from nailgun import entities import pytest from requests import HTTPError from wait_for import wait_for @@ -49,24 +48,24 @@ def setup_content(module_entitlement_manifest_org, module_target_sat): 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_repo = entities.Repository( - product=entities.Product(organization=org).create(), + custom_repo = module_target_sat.api.Repository( + product=module_target_sat.api.Product(organization=org).create(), ).create() custom_repo.sync() - lce = entities.LifecycleEnvironment(organization=org).create() - cv = entities.ContentView( + lce = module_target_sat.api.LifecycleEnvironment(organization=org).create() + cv = module_target_sat.api.ContentView( organization=org, repository=[rh_repo_id, custom_repo.id], ).create() cv.publish() cvv = cv.read().version[0].read() cvv.promote(data={'environment_ids': lce.id, 'force': False}) - ak = entities.ActivationKey( + ak = module_target_sat.api.ActivationKey( content_view=cv, max_hosts=100, organization=org, environment=lce, auto_attach=True ).create() - subscription = entities.Subscription(organization=org).search( + subscription = module_target_sat.api.Subscription(organization=org).search( query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'} )[0] ak.add_subscriptions(data={'quantity': 1, 'subscription_id': subscription.id}) @@ -78,7 +77,7 @@ def setup_content(module_entitlement_manifest_org, module_target_sat): @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) -def test_positive_CRUDL(name): +def test_positive_CRUDL(name, target_sat): """Create, Read, Update, Delete, List :id: a2a577db-144e-4761-a42e-e83885464786 @@ -101,27 +100,27 @@ def test_positive_CRUDL(name): """ # Create template1 = gen_string('alpha') - rt = entities.ReportTemplate(name=name, template=template1).create() + rt = target_sat.api.ReportTemplate(name=name, template=template1).create() # List - res = entities.ReportTemplate().search(query={'search': f'name="{name}"'}) + res = target_sat.api.ReportTemplate().search(query={'search': f'name="{name}"'}) assert name in list(map(lambda x: x.name, res)) # Read - rt = entities.ReportTemplate(id=rt.id).read() + rt = target_sat.api.ReportTemplate(id=rt.id).read() assert name == rt.name assert template1 == rt.template # Update template2 = gen_string('alpha') - entities.ReportTemplate(id=rt.id, template=template2).update(['template']) - rt = entities.ReportTemplate(id=rt.id).read() + target_sat.api.ReportTemplate(id=rt.id, template=template2).update(['template']) + rt = target_sat.api.ReportTemplate(id=rt.id).read() assert template2 == rt.template # Delete - entities.ReportTemplate(id=rt.id).delete() + target_sat.api.ReportTemplate(id=rt.id).delete() with pytest.raises(HTTPError): - rt = entities.ReportTemplate(id=rt.id).read() + rt = target_sat.api.ReportTemplate(id=rt.id).read() @pytest.mark.tier1 -def test_positive_generate_report_nofilter(): +def test_positive_generate_report_nofilter(target_sat): """Generate Host - Statuses report :id: a4b687db-144e-4761-a42e-e93887464986 @@ -137,8 +136,10 @@ def test_positive_generate_report_nofilter(): :CaseImportance: Critical """ host_name = gen_string('alpha').lower() - entities.Host(name=host_name).create() - rt = entities.ReportTemplate().search(query={'search': 'name="Host - Statuses"'})[0].read() + target_sat.api.Host(name=host_name).create() + rt = ( + target_sat.api.ReportTemplate().search(query={'search': 'name="Host - Statuses"'})[0].read() + ) res = rt.generate() for column_name in [ 'Name', @@ -164,7 +165,7 @@ def test_positive_generate_report_nofilter(): @pytest.mark.tier2 -def test_positive_generate_report_filter(): +def test_positive_generate_report_filter(target_sat): """Generate Host - Statuses report :id: a4b677cb-144e-4761-a42e-e93887464986 @@ -181,9 +182,11 @@ def test_positive_generate_report_filter(): """ host1_name = gen_string('alpha').lower() host2_name = gen_string('alpha').lower() - entities.Host(name=host1_name).create() - entities.Host(name=host2_name).create() - rt = entities.ReportTemplate().search(query={'search': 'name="Host - Statuses"'})[0].read() + target_sat.api.Host(name=host1_name).create() + target_sat.api.Host(name=host2_name).create() + rt = ( + target_sat.api.ReportTemplate().search(query={'search': 'name="Host - Statuses"'})[0].read() + ) res = rt.generate(data={"input_values": {"hosts": host2_name}}) for column_name in [ 'Name', @@ -210,7 +213,7 @@ def test_positive_generate_report_filter(): @pytest.mark.tier2 -def test_positive_report_add_userinput(): +def test_positive_report_add_userinput(target_sat): """Add user input to template, use it in template, generate template :id: a4a577db-144e-4761-a42e-e86887464986 @@ -230,21 +233,21 @@ def test_positive_report_add_userinput(): input_value = gen_string('alpha').lower() template_name = gen_string('alpha').lower() template = f'<%= "value=\\"" %><%= input(\'{input_name}\') %><%= "\\"" %>' - entities.Host(name=host_name).create() - rt = entities.ReportTemplate(name=template_name, template=template).create() - entities.TemplateInput( + target_sat.api.Host(name=host_name).create() + rt = target_sat.api.ReportTemplate(name=template_name, template=template).create() + target_sat.api.TemplateInput( name=input_name, input_type="user", template=rt.id, ).create() - ti = entities.TemplateInput(template=rt.id).search()[0].read() + ti = target_sat.api.TemplateInput(template=rt.id).search()[0].read() assert input_name == ti.name res = rt.generate(data={"input_values": {input_name: input_value}}) assert f'value="{input_value}"' in res @pytest.mark.tier2 -def test_positive_lock_clone_nodelete_unlock_report(): +def test_positive_lock_clone_nodelete_unlock_report(target_sat): """Lock report template. Check it can be cloned and can't be deleted or edited. Unlock. Check it can be deleted and edited. @@ -274,15 +277,15 @@ def test_positive_lock_clone_nodelete_unlock_report(): template_clone_name = gen_string('alpha').lower() template1 = gen_string('alpha') template2 = gen_string('alpha') - rt = entities.ReportTemplate(name=template_name, template=template1).create() + rt = target_sat.api.ReportTemplate(name=template_name, template=template1).create() # 2. Lock template - entities.ReportTemplate(id=rt.id, locked=True).update(["locked"]) + target_sat.api.ReportTemplate(id=rt.id, locked=True).update(["locked"]) rt = rt.read() assert rt.locked is True # 3. Clone template, check cloned data rt.clone(data={'name': template_clone_name}) cloned_rt = ( - entities.ReportTemplate() + target_sat.api.ReportTemplate() .search(query={'search': f'name="{template_clone_name}"'})[0] .read() ) @@ -294,24 +297,28 @@ def test_positive_lock_clone_nodelete_unlock_report(): rt.delete() # In BZ1680458, exception is thrown but template is deleted anyway assert ( - len(entities.ReportTemplate().search(query={'search': f'name="{template_name}"'})) != 0 + len(target_sat.api.ReportTemplate().search(query={'search': f'name="{template_name}"'})) + != 0 ) # 5. Try to edit template with pytest.raises(HTTPError): - entities.ReportTemplate(id=rt.id, template=template2).update(["template"]) + target_sat.api.ReportTemplate(id=rt.id, template=template2).update(["template"]) rt = rt.read() assert template1 == rt.template # 6. Unlock template - entities.ReportTemplate(id=rt.id, locked=False).update(["locked"]) + target_sat.api.ReportTemplate(id=rt.id, locked=False).update(["locked"]) rt = rt.read() assert rt.locked is False # 7. Edit template - entities.ReportTemplate(id=rt.id, template=template2).update(["template"]) + target_sat.api.ReportTemplate(id=rt.id, template=template2).update(["template"]) rt = rt.read() assert template2 == rt.template # 8. Delete template rt.delete() - assert len(entities.ReportTemplate().search(query={'search': f'name="{template_name}"'})) == 0 + assert ( + len(target_sat.api.ReportTemplate().search(query={'search': f'name="{template_name}"'})) + == 0 + ) @pytest.mark.tier2 @@ -593,7 +600,7 @@ def test_positive_generate_entitlements_report(setup_content, target_sat): vm.register_contenthost(org.label, ak.name) assert vm.subscribed rt = ( - entities.ReportTemplate() + target_sat.api.ReportTemplate() .search(query={'search': 'name="Subscription - Entitlement Report"'})[0] .read() ) @@ -632,7 +639,7 @@ def test_positive_schedule_entitlements_report(setup_content, target_sat): vm.register_contenthost(org.label, ak.name) assert vm.subscribed rt = ( - entities.ReportTemplate() + target_sat.api.ReportTemplate() .search(query={'search': 'name="Subscription - Entitlement Report"'})[0] .read() ) diff --git a/tests/foreman/api/test_repositories.py b/tests/foreman/api/test_repositories.py index 58cbd9792b2..b2df979ba5d 100644 --- a/tests/foreman/api/test_repositories.py +++ b/tests/foreman/api/test_repositories.py @@ -17,7 +17,6 @@ :Upstream: No """ from manifester import Manifester -from nailgun import entities from nailgun.entity_mixins import call_entity_method_with_timeout import pytest from requests.exceptions import HTTPError @@ -179,7 +178,7 @@ def test_positive_sync_kickstart_repo(module_entitlement_manifest_org, target_sa repo=constants.REPOS['kickstart'][distro]['name'], releasever=constants.REPOS['kickstart'][distro]['version'], ) - rh_repo = entities.Repository(id=rh_repo_id).read() + rh_repo = target_sat.api.Repository(id=rh_repo_id).read() rh_repo.sync() rh_repo.download_policy = 'immediate' rh_repo = rh_repo.update(['download_policy']) diff --git a/tests/foreman/api/test_repository_set.py b/tests/foreman/api/test_repository_set.py index 449bb1be33c..e4766585824 100644 --- a/tests/foreman/api/test_repository_set.py +++ b/tests/foreman/api/test_repository_set.py @@ -19,7 +19,6 @@ :Upstream: No """ -from nailgun import entities import pytest from robottelo.constants import PRDS, REPOSET @@ -33,17 +32,17 @@ @pytest.fixture -def product(function_entitlement_manifest_org): +def product(function_entitlement_manifest_org, module_target_sat): """Find and return the product matching PRODUCT_NAME.""" - return entities.Product( + return module_target_sat.api.Product( name=PRODUCT_NAME, organization=function_entitlement_manifest_org ).search()[0] @pytest.fixture -def reposet(product): +def reposet(product, module_target_sat): """Find and return the repository set matching REPOSET_NAME and product.""" - return entities.RepositorySet(name=REPOSET_NAME, product=product).search()[0] + return module_target_sat.api.RepositorySet(name=REPOSET_NAME, product=product).search()[0] @pytest.fixture diff --git a/tests/foreman/api/test_settings.py b/tests/foreman/api/test_settings.py index b5d0542d35d..b4fe49c23c1 100644 --- a/tests/foreman/api/test_settings.py +++ b/tests/foreman/api/test_settings.py @@ -18,7 +18,6 @@ """ import random -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -188,7 +187,7 @@ def test_negative_discover_host_with_invalid_prefix(): @pytest.mark.tier2 @pytest.mark.parametrize('download_policy', ["immediate", "on_demand"]) @pytest.mark.parametrize('setting_update', ['default_download_policy'], indirect=True) -def test_positive_custom_repo_download_policy(setting_update, download_policy): +def test_positive_custom_repo_download_policy(setting_update, download_policy, target_sat): """Check the set custom repository download policy for newly created custom repository. :id: d5150cce-ba85-4ea0-a8d1-6a54d0d29571 @@ -209,11 +208,11 @@ def test_positive_custom_repo_download_policy(setting_update, download_policy): :CaseLevel: Acceptance """ - org = entities.Organization().create() - prod = entities.Product(organization=org).create() + org = target_sat.api.Organization().create() + prod = target_sat.api.Product(organization=org).create() setting_update.value = download_policy setting_update.update({'value'}) - repo = entities.Repository(product=prod, content_type='yum', organization=org).create() + repo = target_sat.api.Repository(product=prod, content_type='yum', organization=org).create() assert repo.download_policy == download_policy repo.delete() prod.delete() diff --git a/tests/foreman/api/test_subnet.py b/tests/foreman/api/test_subnet.py index c5188d12808..75d7bff0b9e 100644 --- a/tests/foreman/api/test_subnet.py +++ b/tests/foreman/api/test_subnet.py @@ -23,7 +23,6 @@ """ import re -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -36,7 +35,7 @@ @pytest.mark.tier1 -def test_positive_create_with_parameter(): +def test_positive_create_with_parameter(target_sat): """Subnet can be created along with parameters :id: ec581cb5-8c48-4b9c-b536-302c0b7ec30f @@ -47,14 +46,14 @@ def test_positive_create_with_parameter(): :expectedresults: The Subnet is created with parameter """ parameter = [{'name': gen_string('alpha'), 'value': gen_string('alpha')}] - subnet = entities.Subnet(subnet_parameters_attributes=parameter).create() + subnet = target_sat.api.Subnet(subnet_parameters_attributes=parameter).create() assert subnet.subnet_parameters_attributes[0]['name'] == parameter[0]['name'] assert subnet.subnet_parameters_attributes[0]['value'] == parameter[0]['value'] @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(generate_strings_list())) -def test_positive_add_parameter(name): +def test_positive_add_parameter(name, target_sat): """Parameters can be created in subnet :id: c1dae6f4-45b1-45db-8529-d7918e41a99b @@ -70,15 +69,15 @@ def test_positive_add_parameter(name): :CaseImportance: Medium """ - subnet = entities.Subnet().create() + subnet = target_sat.api.Subnet().create() value = gen_string('utf8') - subnet_param = entities.Parameter(subnet=subnet.id, name=name, value=value).create() + subnet_param = target_sat.api.Parameter(subnet=subnet.id, name=name, value=value).create() assert subnet_param.name == name assert subnet_param.value == value @pytest.mark.tier1 -def test_positive_add_parameter_with_values_and_separator(): +def test_positive_add_parameter_with_values_and_separator(target_sat): """Subnet parameters can be created with values separated by comma :id: b3de6f96-7c39-4c44-b91c-a6d141f5dd6a @@ -94,10 +93,10 @@ def test_positive_add_parameter_with_values_and_separator(): :CaseImportance: Low """ - subnet = entities.Subnet().create() + subnet = target_sat.api.Subnet().create() name = gen_string('alpha') values = ', '.join(generate_strings_list()) - subnet_param = entities.Parameter(name=name, subnet=subnet.id, value=values).create() + subnet_param = target_sat.api.Parameter(name=name, subnet=subnet.id, value=values).create() assert subnet_param.name == name assert subnet_param.value == values @@ -106,7 +105,7 @@ def test_positive_add_parameter_with_values_and_separator(): @pytest.mark.parametrize( 'separator', **parametrized({'comma': ',', 'slash': '/', 'dash': '-', 'pipe': '|'}) ) -def test_positive_create_with_parameter_and_valid_separator(separator): +def test_positive_create_with_parameter_and_valid_separator(separator, target_sat): """Subnet parameters can be created with name with valid separators :id: d1e2d75a-a1e8-4767-93f1-0bb1b75e10a0 @@ -124,16 +123,16 @@ def test_positive_create_with_parameter_and_valid_separator(separator): :CaseImportance: Low """ name = f'{separator}'.join(generate_strings_list()) - subnet = entities.Subnet().create() + subnet = target_sat.api.Subnet().create() value = gen_string('utf8') - subnet_param = entities.Parameter(name=name, subnet=subnet.id, value=value).create() + subnet_param = target_sat.api.Parameter(name=name, subnet=subnet.id, value=value).create() assert subnet_param.name == name assert subnet_param.value == value @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_values_list() + ['name with space'])) -def test_negative_create_with_parameter_and_invalid_separator(name): +def test_negative_create_with_parameter_and_invalid_separator(name, target_sat): """Subnet parameters can not be created with name with invalid separators @@ -155,13 +154,13 @@ def test_negative_create_with_parameter_and_invalid_separator(name): :CaseImportance: Low """ - subnet = entities.Subnet().create() + subnet = target_sat.api.Subnet().create() with pytest.raises(HTTPError): - entities.Parameter(name=name, subnet=subnet.id).create() + target_sat.api.Parameter(name=name, subnet=subnet.id).create() @pytest.mark.tier1 -def test_negative_create_with_duplicated_parameters(): +def test_negative_create_with_duplicated_parameters(target_sat): """Attempt to create multiple parameters with same key name for the same subnet @@ -180,10 +179,10 @@ def test_negative_create_with_duplicated_parameters(): :CaseImportance: Low """ - subnet = entities.Subnet().create() - entities.Parameter(name='duplicateParameter', subnet=subnet.id).create() + subnet = target_sat.api.Subnet().create() + target_sat.api.Parameter(name='duplicateParameter', subnet=subnet.id).create() with pytest.raises(HTTPError) as context: - entities.Parameter(name='duplicateParameter', subnet=subnet.id).create() + target_sat.api.Parameter(name='duplicateParameter', subnet=subnet.id).create() assert re.search("Name has already been taken", context.value.response.text) @@ -244,7 +243,7 @@ def test_positive_subnet_parameters_override_from_host(): @pytest.mark.tier3 -def test_positive_subnet_parameters_override_impact_on_subnet(): +def test_positive_subnet_parameters_override_impact_on_subnet(target_sat): """Override subnet parameter from host impact on subnet parameter :id: 6fe963ed-93a3-496e-bfd9-599bf91a61f3 @@ -266,15 +265,15 @@ def test_positive_subnet_parameters_override_impact_on_subnet(): # Create subnet with valid parameters parameter = [{'name': gen_string('alpha'), 'value': gen_string('alpha')}] - org = entities.Organization().create() - loc = entities.Location(organization=[org]).create() - org_subnet = entities.Subnet( + org = target_sat.api.Organization().create() + loc = target_sat.api.Location(organization=[org]).create() + org_subnet = target_sat.api.Subnet( location=[loc], organization=[org], subnet_parameters_attributes=parameter ).create() assert org_subnet.subnet_parameters_attributes[0]['name'] == parameter[0]['name'] assert org_subnet.subnet_parameters_attributes[0]['value'] == parameter[0]['value'] # Create host with above subnet - host = entities.Host(location=loc, organization=org, subnet=org_subnet).create() + host = target_sat.api.Host(location=loc, organization=org, subnet=org_subnet).create() assert host.subnet.read().name == org_subnet.name parameter_new_value = [ { @@ -293,7 +292,7 @@ def test_positive_subnet_parameters_override_impact_on_subnet(): @pytest.mark.tier1 -def test_positive_update_parameter(): +def test_positive_update_parameter(target_sat): """Subnet parameter can be updated :id: 8c389c3f-60ef-4856-b8fc-c5b066c67a2f @@ -309,7 +308,7 @@ def test_positive_update_parameter(): :CaseImportance: Medium """ parameter = [{'name': gen_string('alpha'), 'value': gen_string('alpha')}] - subnet = entities.Subnet(subnet_parameters_attributes=parameter).create() + subnet = target_sat.api.Subnet(subnet_parameters_attributes=parameter).create() update_parameter = [{'name': gen_string('utf8'), 'value': gen_string('utf8')}] subnet.subnet_parameters_attributes = update_parameter up_subnet = subnet.update(['subnet_parameters_attributes']) @@ -319,7 +318,7 @@ def test_positive_update_parameter(): @pytest.mark.tier1 @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list() + ['name with space'])) -def test_negative_update_parameter(new_name): +def test_negative_update_parameter(new_name, target_sat): """Subnet parameter can not be updated with invalid names :id: fcdbad13-ad96-4152-8e20-e023d61a2853 @@ -339,8 +338,8 @@ def test_negative_update_parameter(new_name): :CaseImportance: Medium """ - subnet = entities.Subnet().create() - sub_param = entities.Parameter( + subnet = target_sat.api.Subnet().create() + sub_param = target_sat.api.Parameter( name=gen_string('utf8'), subnet=subnet.id, value=gen_string('utf8') ).create() with pytest.raises(HTTPError): @@ -377,7 +376,7 @@ def test_positive_update_subnet_parameter_host_impact(): @pytest.mark.tier1 @pytest.mark.upgrade -def test_positive_delete_subnet_parameter(): +def test_positive_delete_subnet_parameter(target_sat): """Subnet parameter can be deleted :id: 972b66ec-d506-4fcb-9786-c62f2f79ac1a @@ -389,8 +388,8 @@ def test_positive_delete_subnet_parameter(): :expectedresults: The parameter should be deleted from subnet """ - subnet = entities.Subnet().create() - sub_param = entities.Parameter(subnet=subnet.id).create() + subnet = target_sat.api.Subnet().create() + sub_param = target_sat.api.Parameter(subnet=subnet.id).create() sub_param.delete() with pytest.raises(HTTPError): sub_param.read() @@ -452,7 +451,7 @@ def test_positive_delete_subnet_overridden_parameter_host_impact(): @pytest.mark.tier1 -def test_positive_list_parameters(): +def test_positive_list_parameters(target_sat): """Satellite lists all the subnet parameters :id: ce86d531-bf6b-45a9-81e3-67e1b3398f76 @@ -467,9 +466,9 @@ def test_positive_list_parameters(): parameters """ parameter = {'name': gen_string('alpha'), 'value': gen_string('alpha')} - org = entities.Organization().create() - loc = entities.Location(organization=[org]).create() - org_subnet = entities.Subnet( + org = target_sat.api.Organization().create() + loc = target_sat.api.Location(organization=[org]).create() + org_subnet = target_sat.api.Subnet( location=[loc], organization=[org], ipam='DHCP', @@ -478,10 +477,10 @@ def test_positive_list_parameters(): ).create() assert org_subnet.subnet_parameters_attributes[0]['name'] == parameter['name'] assert org_subnet.subnet_parameters_attributes[0]['value'] == parameter['value'] - sub_param = entities.Parameter( + sub_param = target_sat.api.Parameter( name=gen_string('alpha'), subnet=org_subnet.id, value=gen_string('alpha') ).create() - org_subnet = entities.Subnet(id=org_subnet.id).read() + org_subnet = target_sat.api.Subnet(id=org_subnet.id).read() params_list = { param['name']: param['value'] for param in org_subnet.subnet_parameters_attributes diff --git a/tests/foreman/api/test_subscription.py b/tests/foreman/api/test_subscription.py index 377d43555dd..b27488cd5f7 100644 --- a/tests/foreman/api/test_subscription.py +++ b/tests/foreman/api/test_subscription.py @@ -21,7 +21,6 @@ :Upstream: No """ from fauxfactory import gen_string -from nailgun import entities from nailgun.config import ServerConfig from nailgun.entity_mixins import TaskFailedError import pytest @@ -44,28 +43,30 @@ def rh_repo(module_sca_manifest_org, module_target_sat): 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() return rh_repo @pytest.fixture(scope='module') -def custom_repo(rh_repo, module_sca_manifest_org): - custom_repo = entities.Repository( - product=entities.Product(organization=module_sca_manifest_org).create(), +def custom_repo(rh_repo, module_sca_manifest_org, module_target_sat): + custom_repo = module_target_sat.api.Repository( + product=module_target_sat.api.Product(organization=module_sca_manifest_org).create(), ).create() custom_repo.sync() return custom_repo @pytest.fixture(scope='module') -def module_ak(module_sca_manifest_org, rh_repo, custom_repo): +def module_ak(module_sca_manifest_org, rh_repo, custom_repo, module_target_sat): """rh_repo and custom_repo are included here to ensure their execution before the AK""" - module_ak = entities.ActivationKey( + module_ak = module_target_sat.api.ActivationKey( content_view=module_sca_manifest_org.default_content_view, max_hosts=100, organization=module_sca_manifest_org, - environment=entities.LifecycleEnvironment(id=module_sca_manifest_org.library.id), + environment=module_target_sat.api.LifecycleEnvironment( + id=module_sca_manifest_org.library.id + ), auto_attach=True, ).create() return module_ak @@ -82,12 +83,12 @@ def test_positive_create(module_entitlement_manifest, module_target_sat): :CaseImportance: Critical """ - org = entities.Organization().create() + org = module_target_sat.api.Organization().create() module_target_sat.upload_manifest(org.id, module_entitlement_manifest.content) @pytest.mark.tier1 -def test_positive_refresh(function_entitlement_manifest_org, request): +def test_positive_refresh(function_entitlement_manifest_org, request, target_sat): """Upload a manifest and refresh it afterwards. :id: cd195db6-e81b-42cb-a28d-ec0eb8a53341 @@ -97,7 +98,7 @@ def test_positive_refresh(function_entitlement_manifest_org, request): :CaseImportance: Critical """ org = function_entitlement_manifest_org - sub = entities.Subscription(organization=org) + sub = target_sat.api.Subscription(organization=org) request.addfinalizer(lambda: sub.delete_manifest(data={'organization_id': org.id})) sub.refresh_manifest(data={'organization_id': org.id}) assert sub.search() @@ -120,9 +121,9 @@ def test_positive_create_after_refresh( :CaseImportance: Critical """ - org_sub = entities.Subscription(organization=function_entitlement_manifest_org) - new_org = entities.Organization().create() - new_org_sub = entities.Subscription(organization=new_org) + org_sub = target_sat.api.Subscription(organization=function_entitlement_manifest_org) + new_org = target_sat.api.Organization().create() + new_org_sub = target_sat.api.Subscription(organization=new_org) try: org_sub.refresh_manifest(data={'organization_id': function_entitlement_manifest_org.id}) assert org_sub.search() @@ -133,7 +134,7 @@ def test_positive_create_after_refresh( @pytest.mark.tier1 -def test_positive_delete(function_entitlement_manifest_org): +def test_positive_delete(function_entitlement_manifest_org, target_sat): """Delete an Uploaded manifest. :id: 4c21c7c9-2b26-4a65-a304-b978d5ba34fc @@ -142,7 +143,7 @@ def test_positive_delete(function_entitlement_manifest_org): :CaseImportance: Critical """ - sub = entities.Subscription(organization=function_entitlement_manifest_org) + sub = target_sat.api.Subscription(organization=function_entitlement_manifest_org) assert sub.search() sub.delete_manifest(data={'organization_id': function_entitlement_manifest_org.id}) assert len(sub.search()) == 0 @@ -157,12 +158,12 @@ def test_negative_upload(function_entitlement_manifest, target_sat): :expectedresults: The manifest is not uploaded to the second organization. """ - orgs = [entities.Organization().create() for _ in range(2)] + orgs = [target_sat.api.Organization().create() for _ in range(2)] with function_entitlement_manifest as manifest: target_sat.upload_manifest(orgs[0].id, manifest.content) with pytest.raises(TaskFailedError): target_sat.upload_manifest(orgs[1].id, manifest.content) - assert len(entities.Subscription(organization=orgs[1]).search()) == 0 + assert len(target_sat.api.Subscription(organization=orgs[1]).search()) == 0 @pytest.mark.tier2 @@ -208,11 +209,11 @@ def test_positive_delete_manifest_as_another_user( ) # use the first admin to upload a manifest with function_entitlement_manifest as manifest: - entities.Subscription(sc1, organization=function_org).upload( + target_sat.api.Subscription(sc1, organization=function_org).upload( data={'organization_id': function_org.id}, files={'content': manifest.content} ) # try to search and delete the manifest with another admin - entities.Subscription(sc2, organization=function_org).delete_manifest( + target_sat.api.Subscription(sc2, organization=function_org).delete_manifest( data={'organization_id': function_org.id} ) assert len(Subscription.list({'organization-id': function_org.id})) == 0 @@ -238,7 +239,7 @@ def test_positive_subscription_status_disabled( rhel_contenthost.install_katello_ca(target_sat) rhel_contenthost.register_contenthost(module_sca_manifest_org.label, module_ak.name) assert rhel_contenthost.subscribed - host_content = entities.Host(id=rhel_contenthost.nailgun_host.id).read_raw().content + host_content = target_sat.api.Host(id=rhel_contenthost.nailgun_host.id).read_raw().content assert 'Simple Content Access' in str(host_content) @@ -266,9 +267,12 @@ def test_sca_end_to_end( rhel7_contenthost.register_contenthost(module_sca_manifest_org.label, module_ak.name) assert rhel7_contenthost.subscribed # Check to see if Organization is in SCA Mode - assert entities.Organization(id=module_sca_manifest_org.id).read().simple_content_access is True + assert ( + target_sat.api.Organization(id=module_sca_manifest_org.id).read().simple_content_access + is True + ) # Verify that you cannot attach a subscription to an activation key in SCA Mode - subscription = entities.Subscription(organization=module_sca_manifest_org).search( + subscription = target_sat.api.Subscription(organization=module_sca_manifest_org).search( query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'} )[0] with pytest.raises(HTTPError) as ak_context: @@ -276,12 +280,12 @@ def test_sca_end_to_end( assert 'Simple Content Access' in ak_context.value.response.text # Verify that you cannot attach a subscription to an Host in SCA Mode with pytest.raises(HTTPError) as host_context: - entities.HostSubscription(host=rhel7_contenthost.nailgun_host.id).add_subscriptions( + target_sat.api.HostSubscription(host=rhel7_contenthost.nailgun_host.id).add_subscriptions( data={'subscriptions': [{'id': subscription.id, 'quantity': 1}]} ) assert 'Simple Content Access' in host_context.value.response.text # Create a content view with repos and check to see that the client has access - content_view = entities.ContentView(organization=module_sca_manifest_org).create() + content_view = target_sat.api.ContentView(organization=module_sca_manifest_org).create() content_view.repository = [rh_repo, custom_repo] content_view.update(['repository']) content_view.publish() @@ -327,34 +331,34 @@ def test_positive_candlepin_events_processed_by_stomp( :CaseImportance: High """ - repo = entities.Repository( - product=entities.Product(organization=function_org).create() + repo = target_sat.api.Repository( + product=target_sat.api.Product(organization=function_org).create() ).create() repo.sync() - ak = entities.ActivationKey( + ak = target_sat.api.ActivationKey( content_view=function_org.default_content_view, max_hosts=100, organization=function_org, - environment=entities.LifecycleEnvironment(id=function_org.library.id), + environment=target_sat.api.LifecycleEnvironment(id=function_org.library.id), auto_attach=True, ).create() rhel7_contenthost.install_katello_ca(target_sat) rhel7_contenthost.register_contenthost(function_org.name, ak.name) - host = entities.Host().search(query={'search': f'name={rhel7_contenthost.hostname}'}) + host = target_sat.api.Host().search(query={'search': f'name={rhel7_contenthost.hostname}'}) host_id = host[0].id - host_content = entities.Host(id=host_id).read_json() + host_content = target_sat.api.Host(id=host_id).read_json() assert host_content['subscription_status'] == 2 with function_entitlement_manifest as manifest: target_sat.upload_manifest(function_org.id, manifest.content) - subscription = entities.Subscription(organization=function_org).search( + subscription = target_sat.api.Subscription(organization=function_org).search( query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'} )[0] - entities.HostSubscription(host=host_id).add_subscriptions( + target_sat.api.HostSubscription(host=host_id).add_subscriptions( data={'subscriptions': [{'id': subscription.cp_id, 'quantity': 1}]} ) - host_content = entities.Host(id=host_id).read_json() + host_content = target_sat.api.Host(id=host_id).read_json() assert host_content['subscription_status'] == 0 - 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'] @@ -386,11 +390,11 @@ def test_positive_expired_SCA_cert_handling(module_sca_manifest_org, rhel7_conte :CaseImportance: High """ - ak = entities.ActivationKey( + ak = target_sat.api.ActivationKey( content_view=module_sca_manifest_org.default_content_view, max_hosts=100, organization=module_sca_manifest_org, - environment=entities.LifecycleEnvironment(id=module_sca_manifest_org.library.id), + environment=target_sat.api.LifecycleEnvironment(id=module_sca_manifest_org.library.id), auto_attach=True, ).create() # registering the content host with no content enabled/synced in the org @@ -411,7 +415,7 @@ def test_positive_expired_SCA_cert_handling(module_sca_manifest_org, rhel7_conte reposet=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() # re-registering the host should test whether Candlepin gracefully handles # registration of a host with an expired SCA cert diff --git a/tests/foreman/api/test_syncplan.py b/tests/foreman/api/test_syncplan.py index 9653322bd55..566d06d692a 100644 --- a/tests/foreman/api/test_syncplan.py +++ b/tests/foreman/api/test_syncplan.py @@ -24,7 +24,7 @@ from time import sleep from fauxfactory import gen_choice, gen_string -from nailgun import client, entities +from nailgun import client import pytest from requests.exceptions import HTTPError @@ -101,7 +101,7 @@ def validate_repo_content(repo, content_types, after_sync=True): @pytest.mark.tier1 -def test_positive_get_routes(): +def test_positive_get_routes(target_sat): """Issue an HTTP GET response to both available routes. :id: 9e40ea7f-71ea-4ced-94ba-cde03620c654 @@ -112,8 +112,8 @@ def test_positive_get_routes(): :CaseImportance: Critical """ - org = entities.Organization().create() - entities.SyncPlan(organization=org).create() + org = target_sat.api.Organization().create() + target_sat.api.SyncPlan(organization=org).create() response1 = client.get( f'{get_url()}/katello/api/v2/sync_plans', auth=get_credentials(), @@ -144,7 +144,7 @@ def test_positive_create_enabled_disabled(module_org, enabled, request, target_s :CaseImportance: Critical """ - sync_plan = entities.SyncPlan(enabled=enabled, organization=module_org).create() + sync_plan = target_sat.api.SyncPlan(enabled=enabled, organization=module_org).create() request.addfinalizer(lambda: target_sat.api_factory.disable_syncplan(sync_plan)) sync_plan = sync_plan.read() assert sync_plan.enabled == enabled @@ -152,7 +152,7 @@ def test_positive_create_enabled_disabled(module_org, enabled, request, target_s @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_create_with_name(module_org, name): +def test_positive_create_with_name(module_org, name, module_target_sat): """Create a sync plan with a random name. :id: c1263134-0d7c-425a-82fd-df5274e1f9ba @@ -163,14 +163,16 @@ def test_positive_create_with_name(module_org, name): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan(enabled=False, name=name, organization=module_org).create() + sync_plan = module_target_sat.api.SyncPlan( + enabled=False, name=name, organization=module_org + ).create() sync_plan = sync_plan.read() assert sync_plan.name == name @pytest.mark.parametrize('description', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_create_with_description(module_org, description): +def test_positive_create_with_description(module_org, description, module_target_sat): """Create a sync plan with a random description. :id: 3e5745e8-838d-44a5-ad61-7e56829ad47c @@ -182,7 +184,7 @@ def test_positive_create_with_description(module_org, description): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan( + sync_plan = module_target_sat.api.SyncPlan( enabled=False, description=description, organization=module_org ).create() sync_plan = sync_plan.read() @@ -191,7 +193,7 @@ def test_positive_create_with_description(module_org, description): @pytest.mark.parametrize('interval', **parametrized(valid_sync_interval())) @pytest.mark.tier1 -def test_positive_create_with_interval(module_org, interval): +def test_positive_create_with_interval(module_org, interval, module_target_sat): """Create a sync plan with a random interval. :id: d160ed1c-b698-42dc-be0b-67ac693c7840 @@ -202,7 +204,7 @@ def test_positive_create_with_interval(module_org, interval): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan( + sync_plan = module_target_sat.api.SyncPlan( enabled=False, description=gen_string('alpha'), organization=module_org, interval=interval ) if interval == SYNC_INTERVAL['custom']: @@ -235,7 +237,7 @@ def test_positive_create_with_sync_date(module_org, sync_delta, target_sat): @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_create_with_invalid_name(module_org, name): +def test_negative_create_with_invalid_name(module_org, name, module_target_sat): """Create a sync plan with an invalid name. :id: a3a0f844-2f81-4f87-9f68-c25506c29ce2 @@ -248,12 +250,12 @@ def test_negative_create_with_invalid_name(module_org, name): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.SyncPlan(name=name, organization=module_org).create() + module_target_sat.api.SyncPlan(name=name, organization=module_org).create() @pytest.mark.parametrize('interval', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_create_with_invalid_interval(module_org, interval): +def test_negative_create_with_invalid_interval(module_org, interval, module_target_sat): """Create a sync plan with invalid interval specified. :id: f5844526-9f58-4be3-8a96-3849a465fc02 @@ -266,11 +268,11 @@ def test_negative_create_with_invalid_interval(module_org, interval): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.SyncPlan(interval=interval, organization=module_org).create() + module_target_sat.api.SyncPlan(interval=interval, organization=module_org).create() @pytest.mark.tier1 -def test_negative_create_with_empty_interval(module_org): +def test_negative_create_with_empty_interval(module_org, module_target_sat): """Create a sync plan with no interval specified. :id: b4686463-69c8-4538-b040-6fb5246a7b00 @@ -280,7 +282,7 @@ def test_negative_create_with_empty_interval(module_org): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan(organization=module_org) + sync_plan = module_target_sat.api.SyncPlan(organization=module_org) sync_plan.create_missing() del sync_plan.interval with pytest.raises(HTTPError): @@ -300,7 +302,7 @@ def test_positive_update_enabled(module_org, enabled, request, target_sat): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan(enabled=not enabled, organization=module_org).create() + sync_plan = target_sat.api.SyncPlan(enabled=not enabled, organization=module_org).create() request.addfinalizer(lambda: target_sat.api_factory.disable_syncplan(sync_plan)) sync_plan.enabled = enabled sync_plan.update(['enabled']) @@ -310,7 +312,7 @@ def test_positive_update_enabled(module_org, enabled, request, target_sat): @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @pytest.mark.tier1 -def test_positive_update_name(module_org, name): +def test_positive_update_name(module_org, name, module_target_sat): """Create a sync plan and update its name. :id: dbfadf4f-50af-4aa8-8d7d-43988dc4528f @@ -322,7 +324,7 @@ def test_positive_update_name(module_org, name): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan(enabled=False, organization=module_org).create() + sync_plan = module_target_sat.api.SyncPlan(enabled=False, organization=module_org).create() sync_plan.name = name sync_plan.update(['name']) sync_plan = sync_plan.read() @@ -331,7 +333,7 @@ def test_positive_update_name(module_org, name): @pytest.mark.parametrize('description', **parametrized(valid_data_list())) @pytest.mark.tier2 -def test_positive_update_description(module_org, description): +def test_positive_update_description(module_org, description, module_target_sat): """Create a sync plan and update its description. :id: 4769fe9c-9eec-40c8-b015-1e3d7e570bec @@ -341,7 +343,7 @@ def test_positive_update_description(module_org, description): :expectedresults: A sync plan is created and its description can be updated with the specified description. """ - sync_plan = entities.SyncPlan( + sync_plan = module_target_sat.api.SyncPlan( enabled=False, description=gen_string('alpha'), organization=module_org ).create() sync_plan.description = description @@ -352,7 +354,7 @@ def test_positive_update_description(module_org, description): @pytest.mark.parametrize('interval', **parametrized(valid_sync_interval())) @pytest.mark.tier1 -def test_positive_update_interval(module_org, interval): +def test_positive_update_interval(module_org, interval, module_target_sat): """Create a sync plan and update its interval. :id: cf2eddf8-b4db-430e-a9b0-83c626b45068 @@ -364,7 +366,7 @@ def test_positive_update_interval(module_org, interval): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan( + sync_plan = module_target_sat.api.SyncPlan( enabled=False, description=gen_string('alpha'), organization=module_org, interval=interval ) if interval == SYNC_INTERVAL['custom']: @@ -384,7 +386,7 @@ def test_positive_update_interval(module_org, interval): @pytest.mark.parametrize('interval', **parametrized(valid_sync_interval())) @pytest.mark.tier1 -def test_positive_update_interval_custom_cron(module_org, interval): +def test_positive_update_interval_custom_cron(module_org, interval, module_target_sat): """Create a sync plan and update its interval to custom cron. :id: 26c58319-cae0-4b0c-b388-2a1fe3f22344 @@ -397,7 +399,7 @@ def test_positive_update_interval_custom_cron(module_org, interval): :CaseImportance: Critical """ if interval != SYNC_INTERVAL['custom']: - sync_plan = entities.SyncPlan( + sync_plan = module_target_sat.api.SyncPlan( enabled=False, description=gen_string('alpha'), organization=module_org, @@ -436,7 +438,7 @@ def test_positive_update_sync_date(module_org, sync_delta, target_sat): @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_update_name(module_org, name): +def test_negative_update_name(module_org, name, module_target_sat): """Try to update a sync plan with an invalid name. :id: ae502053-9d3c-4cad-aee4-821f846ceae5 @@ -448,7 +450,7 @@ def test_negative_update_name(module_org, name): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan(enabled=False, organization=module_org).create() + sync_plan = module_target_sat.api.SyncPlan(enabled=False, organization=module_org).create() sync_plan.name = name with pytest.raises(HTTPError): sync_plan.update(['name']) @@ -456,7 +458,7 @@ def test_negative_update_name(module_org, name): @pytest.mark.parametrize('interval', **parametrized(invalid_values_list())) @pytest.mark.tier1 -def test_negative_update_interval(module_org, interval): +def test_negative_update_interval(module_org, interval, module_target_sat): """Try to update a sync plan with invalid interval. :id: 8c981174-6f55-49c0-8baa-40e5c3fc598c @@ -468,7 +470,7 @@ def test_negative_update_interval(module_org, interval): :CaseImportance: Critical """ - sync_plan = entities.SyncPlan(enabled=False, organization=module_org).create() + sync_plan = module_target_sat.api.SyncPlan(enabled=False, organization=module_org).create() sync_plan.interval = interval with pytest.raises(HTTPError): sync_plan.update(['interval']) @@ -626,14 +628,14 @@ def test_negative_synchronize_custom_product_past_sync_date(module_org, request, :CaseLevel: System """ - product = entities.Product(organization=module_org).create() - repo = entities.Repository(product=product).create() + product = target_sat.api.Product(organization=module_org).create() + repo = target_sat.api.Repository(product=product).create() # Verify product is not synced and doesn't have any content with pytest.raises(AssertionError): validate_task_status(target_sat, repo.id, module_org.id, max_tries=2) validate_repo_content(repo, ['erratum', 'rpm', 'package_group'], after_sync=False) # Create and Associate sync plan with product - sync_plan = entities.SyncPlan( + sync_plan = target_sat.api.SyncPlan( organization=module_org, enabled=True, sync_date=datetime.utcnow().replace(second=0) ).create() request.addfinalizer(lambda: target_sat.api_factory.disable_syncplan(sync_plan)) @@ -660,10 +662,10 @@ def test_positive_synchronize_custom_product_past_sync_date(module_org, request, """ interval = 60 * 60 # 'hourly' sync interval in seconds delay = 2 * 60 - product = entities.Product(organization=module_org).create() - repo = entities.Repository(product=product).create() + product = target_sat.api.Product(organization=module_org).create() + repo = target_sat.api.Repository(product=product).create() # Create and Associate sync plan with product - sync_plan = entities.SyncPlan( + sync_plan = target_sat.api.SyncPlan( organization=module_org, enabled=True, interval='hourly', @@ -706,8 +708,8 @@ def test_positive_synchronize_custom_product_future_sync_date(module_org, reques :BZ: 1655595, 1695733 """ delay = 2 * 60 # delay for sync date in seconds - product = entities.Product(organization=module_org).create() - repo = entities.Repository(product=product).create() + product = target_sat.api.Product(organization=module_org).create() + repo = target_sat.api.Repository(product=product).create() # Verify product is not synced and doesn't have any content with pytest.raises(AssertionError): validate_task_status(target_sat, repo.id, module_org.id, max_tries=1) @@ -716,7 +718,7 @@ def test_positive_synchronize_custom_product_future_sync_date(module_org, reques # BZ:1695733 is closed WONTFIX so apply this workaround logger.info('Need to set seconds to zero because BZ#1695733') sync_date = datetime.utcnow().replace(second=0) + timedelta(seconds=delay) - sync_plan = entities.SyncPlan( + sync_plan = target_sat.api.SyncPlan( organization=module_org, enabled=True, sync_date=sync_date ).create() request.addfinalizer(lambda: target_sat.api_factory.disable_syncplan(sync_plan)) @@ -758,9 +760,11 @@ def test_positive_synchronize_custom_products_future_sync_date(module_org, reque """ # Test with multiple products and multiple repos needs more delay. delay = 8 * 60 # delay for sync date in seconds - products = [entities.Product(organization=module_org).create() for _ in range(2)] + products = [target_sat.api.Product(organization=module_org).create() for _ in range(2)] repos = [ - entities.Repository(product=product).create() for product in products for _ in range(2) + target_sat.api.Repository(product=product).create() + for product in products + for _ in range(2) ] # Verify products have not been synced yet logger.info( @@ -774,7 +778,7 @@ def test_positive_synchronize_custom_products_future_sync_date(module_org, reque # BZ:1695733 is closed WONTFIX so apply this workaround logger.info('Need to set seconds to zero because BZ#1695733') sync_date = datetime.utcnow().replace(second=0) + timedelta(seconds=delay) - sync_plan = entities.SyncPlan( + sync_plan = target_sat.api.SyncPlan( organization=module_org, enabled=True, sync_date=sync_date ).create() request.addfinalizer(lambda: target_sat.api_factory.disable_syncplan(sync_plan)) @@ -831,9 +835,9 @@ def test_positive_synchronize_rh_product_past_sync_date( reposet=REPOSET['rhst7'], releasever=None, ) - product = entities.Product(name=PRDS['rhel'], organization=org).search()[0] - repo = entities.Repository(id=repo_id).read() - sync_plan = entities.SyncPlan( + product = target_sat.api.Product(name=PRDS['rhel'], organization=org).search()[0] + repo = target_sat.api.Repository(id=repo_id).read() + sync_plan = target_sat.SyncPlan( organization=org, enabled=True, interval='hourly', @@ -864,7 +868,7 @@ def test_positive_synchronize_rh_product_past_sync_date( # Add disassociate RH product from sync plan check for BZ#1879537 assert len(sync_plan.read().product) == 1 # Disable the reposet - reposet = entities.RepositorySet(name=REPOSET['rhst7'], product=product).search()[0] + reposet = target_sat.api.RepositorySet(name=REPOSET['rhst7'], product=product).search()[0] reposet.disable(data={'basearch': 'x86_64', 'releasever': None, 'product_id': product.id}) # Assert that the Sync Plan now has no product associated with it assert len(sync_plan.read().product) == 0 @@ -895,12 +899,12 @@ def test_positive_synchronize_rh_product_future_sync_date( reposet=REPOSET['rhst7'], releasever=None, ) - product = entities.Product(name=PRDS['rhel'], organization=org).search()[0] - repo = entities.Repository(id=repo_id).read() + product = target_sat.api.Product(name=PRDS['rhel'], organization=org).search()[0] + repo = target_sat.api.Repository(id=repo_id).read() # BZ:1695733 is closed WONTFIX so apply this workaround logger.info('Need to set seconds to zero because BZ#1695733') sync_date = datetime.utcnow().replace(second=0) + timedelta(seconds=delay) - sync_plan = entities.SyncPlan( + sync_plan = target_sat.api.SyncPlan( organization=org, enabled=True, interval='hourly', sync_date=sync_date ).create() request.addfinalizer(lambda: target_sat.api_factory.disable_syncplan(sync_plan)) @@ -944,11 +948,11 @@ def test_positive_synchronize_custom_product_daily_recurrence(module_org, reques :CaseLevel: System """ delay = 2 * 60 - product = entities.Product(organization=module_org).create() - repo = entities.Repository(product=product).create() + product = target_sat.api.Product(organization=module_org).create() + repo = target_sat.api.Repository(product=product).create() start_date = datetime.utcnow().replace(second=0) - timedelta(days=1) + timedelta(seconds=delay) # Create and Associate sync plan with product - sync_plan = entities.SyncPlan( + sync_plan = target_sat.api.SyncPlan( organization=module_org, enabled=True, interval='daily', sync_date=start_date ).create() request.addfinalizer(lambda: target_sat.api_factory.disable_syncplan(sync_plan)) @@ -989,11 +993,11 @@ def test_positive_synchronize_custom_product_weekly_recurrence(module_org, reque :CaseLevel: System """ delay = 2 * 60 - product = entities.Product(organization=module_org).create() - repo = entities.Repository(product=product).create() + product = target_sat.api.Product(organization=module_org).create() + repo = target_sat.api.Repository(product=product).create() start_date = datetime.utcnow().replace(second=0) - timedelta(weeks=1) + timedelta(seconds=delay) # Create and Associate sync plan with product - sync_plan = entities.SyncPlan( + sync_plan = target_sat.api.SyncPlan( organization=module_org, enabled=True, interval='weekly', sync_date=start_date ).create() request.addfinalizer(lambda: target_sat.api_factory.disable_syncplan(sync_plan)) @@ -1061,7 +1065,7 @@ def test_positive_delete_products(module_org, target_sat): @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_delete_synced_product(module_org): +def test_positive_delete_synced_product(module_org, module_target_sat): """Create a sync plan with one synced product and delete it. :id: 195d8fec-1fa0-42ab-84a5-32dd81a285ca @@ -1071,9 +1075,9 @@ def test_positive_delete_synced_product(module_org): :CaseLevel: Integration """ - sync_plan = entities.SyncPlan(organization=module_org).create() - product = entities.Product(organization=module_org).create() - entities.Repository(product=product).create() + sync_plan = module_target_sat.api.SyncPlan(organization=module_org).create() + product = module_target_sat.api.Product(organization=module_org).create() + module_target_sat.api.Repository(product=product).create() sync_plan.add_products(data={'product_ids': [product.id]}) product.sync() sync_plan.delete() @@ -1083,7 +1087,7 @@ def test_positive_delete_synced_product(module_org): @pytest.mark.tier2 @pytest.mark.upgrade -def test_positive_delete_synced_product_custom_cron(module_org): +def test_positive_delete_synced_product_custom_cron(module_org, module_target_sat): """Create a sync plan with custom cron with one synced product and delete it. @@ -1094,13 +1098,13 @@ def test_positive_delete_synced_product_custom_cron(module_org): :CaseLevel: Integration """ - sync_plan = entities.SyncPlan( + sync_plan = module_target_sat.api.SyncPlan( organization=module_org, interval='custom cron', cron_expression=gen_choice(valid_cron_expressions()), ).create() - product = entities.Product(organization=module_org).create() - entities.Repository(product=product).create() + product = module_target_sat.api.Product(organization=module_org).create() + module_target_sat.api.Repository(product=product).create() sync_plan.add_products(data={'product_ids': [product.id]}) product.sync() product = product.read() diff --git a/tests/foreman/api/test_templatesync.py b/tests/foreman/api/test_templatesync.py index 061b8db1dd1..8e38540d395 100644 --- a/tests/foreman/api/test_templatesync.py +++ b/tests/foreman/api/test_templatesync.py @@ -19,7 +19,6 @@ import time from fauxfactory import gen_string -from nailgun import entities import pytest import requests @@ -67,7 +66,9 @@ def setUpClass(self, module_target_sat): ) @pytest.mark.tier2 - def test_positive_import_filtered_templates_from_git(self, module_org, module_location): + def test_positive_import_filtered_templates_from_git( + self, module_org, module_location, module_target_sat + ): """Assure only templates with a given filter regex are pulled from git repo. @@ -91,7 +92,7 @@ def test_positive_import_filtered_templates_from_git(self, module_org, module_lo :CaseImportance: High """ prefix = gen_string('alpha') - filtered_imported_templates = entities.Template().imports( + filtered_imported_templates = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'automation', @@ -105,7 +106,7 @@ def test_positive_import_filtered_templates_from_git(self, module_org, module_lo template['imported'] for template in filtered_imported_templates['message']['templates'] ].count(True) assert imported_count == 8 - ptemplates = entities.ProvisioningTemplate().search( + ptemplates = module_target_sat.api.ProvisioningTemplate().search( query={ 'per_page': '100', 'search': f'name~{prefix}', @@ -114,7 +115,7 @@ def test_positive_import_filtered_templates_from_git(self, module_org, module_lo } ) assert len(ptemplates) == 5 - ptables = entities.PartitionTable().search( + ptables = module_target_sat.api.PartitionTable().search( query={ 'per_page': '100', 'search': f'name~{prefix}', @@ -123,7 +124,7 @@ def test_positive_import_filtered_templates_from_git(self, module_org, module_lo } ) assert len(ptables) == 1 - jtemplates = entities.JobTemplate().search( + jtemplates = module_target_sat.api.JobTemplate().search( query={ 'per_page': '100', 'search': f'name~{prefix}', @@ -132,7 +133,7 @@ def test_positive_import_filtered_templates_from_git(self, module_org, module_lo } ) assert len(jtemplates) == 1 - rtemplates = entities.ReportTemplate().search( + rtemplates = module_target_sat.api.ReportTemplate().search( query={ 'per_page': '10', 'search': f'name~{prefix}', @@ -143,7 +144,7 @@ def test_positive_import_filtered_templates_from_git(self, module_org, module_lo assert len(rtemplates) == 1 @pytest.mark.tier2 - def test_import_filtered_templates_from_git_with_negate(self, module_org): + def test_import_filtered_templates_from_git_with_negate(self, module_org, module_target_sat): """Assure templates with a given filter regex are NOT pulled from git repo. @@ -162,7 +163,7 @@ def test_import_filtered_templates_from_git_with_negate(self, module_org): :CaseImportance: Medium """ prefix = gen_string('alpha') - filtered_imported_templates = entities.Template().imports( + filtered_imported_templates = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'automation', @@ -176,15 +177,15 @@ def test_import_filtered_templates_from_git_with_negate(self, module_org): template['imported'] for template in filtered_imported_templates['message']['templates'] ].count(False) assert not_imported_count == 9 - ptemplates = entities.ProvisioningTemplate().search( + ptemplates = module_target_sat.api.ProvisioningTemplate().search( query={'per_page': '100', 'search': 'name~jenkins', 'organization_id': module_org.id} ) assert len(ptemplates) == 6 - ptables = entities.PartitionTable().search( + ptables = module_target_sat.api.PartitionTable().search( query={'per_page': '100', 'search': 'name~jenkins', 'organization_id': module_org.id} ) assert len(ptables) == 1 - rtemplates = entities.ReportTemplate().search( + rtemplates = module_target_sat.api.ReportTemplate().search( query={'per_page': '100', 'search': 'name~jenkins', 'organization_id': module_org.id} ) assert len(rtemplates) == 1 @@ -267,7 +268,7 @@ def test_positive_import_and_associate( prefix = gen_string('alpha') _, dir_path = create_import_export_local_dir # Associate Never - entities.Template().imports( + target_sat.api.Template().imports( data={ 'repo': dir_path, 'prefix': prefix, @@ -277,7 +278,7 @@ def test_positive_import_and_associate( } ) # - Template 1 imported in X and Y taxonomies - ptemplate = entities.ProvisioningTemplate().search( + ptemplate = target_sat.api.ProvisioningTemplate().search( query={ 'per_page': '10', 'search': f'name~{prefix}', @@ -288,7 +289,7 @@ def test_positive_import_and_associate( assert ptemplate assert len(ptemplate[0].read().organization) == 1 # - Template 1 not imported in metadata taxonomies - ptemplate = entities.ProvisioningTemplate().search( + ptemplate = target_sat.api.ProvisioningTemplate().search( query={ 'per_page': '10', 'search': f'name~{prefix}', @@ -302,7 +303,7 @@ def test_positive_import_and_associate( f'cp {dir_path}/example_template.erb {dir_path}/another_template.erb && ' f'sed -ie "s/name: .*/name: another_template/" {dir_path}/another_template.erb' ) - entities.Template().imports( + target_sat.api.Template().imports( data={ 'repo': dir_path, 'prefix': prefix, @@ -312,7 +313,7 @@ def test_positive_import_and_associate( } ) # - Template 1 taxonomies are not changed - ptemplate = entities.ProvisioningTemplate().search( + ptemplate = target_sat.api.ProvisioningTemplate().search( query={ 'per_page': '10', 'search': f'name~{prefix}example_template', @@ -323,7 +324,7 @@ def test_positive_import_and_associate( assert ptemplate assert len(ptemplate[0].read().organization) == 1 # - Template 2 should be imported in importing taxonomies - ptemplate = entities.ProvisioningTemplate().search( + ptemplate = target_sat.api.ProvisioningTemplate().search( query={ 'per_page': '10', 'search': f'name~{prefix}another_template', @@ -334,7 +335,7 @@ def test_positive_import_and_associate( assert ptemplate assert len(ptemplate[0].read().organization) == 1 # Associate Always - entities.Template().imports( + target_sat.api.Template().imports( data={ 'repo': dir_path, 'prefix': prefix, @@ -344,7 +345,7 @@ def test_positive_import_and_associate( } ) # - Template 1 taxonomies are not changed - ptemplate = entities.ProvisioningTemplate().search( + ptemplate = target_sat.api.ProvisioningTemplate().search( query={ 'per_page': '10', 'search': f'name~{prefix}example_template', @@ -355,7 +356,7 @@ def test_positive_import_and_associate( assert ptemplate assert len(ptemplate[0].read().organization) == 1 # - Template 2 taxonomies are not changed - ptemplate = entities.ProvisioningTemplate().search( + ptemplate = target_sat.api.ProvisioningTemplate().search( query={ 'per_page': '10', 'search': f'name~{prefix}another_template', @@ -367,7 +368,7 @@ def test_positive_import_and_associate( assert len(ptemplate[0].read().organization) == 1 @pytest.mark.tier2 - def test_positive_import_from_subdirectory(self, module_org): + def test_positive_import_from_subdirectory(self, module_org, module_target_sat): """Assure templates are imported from specific repositories subdirectory :id: 8ea11a1a-165e-4834-9387-7accb4c94e77 @@ -384,7 +385,7 @@ def test_positive_import_from_subdirectory(self, module_org): :CaseImportance: Medium """ prefix = gen_string('alpha') - filtered_imported_templates = entities.Template().imports( + filtered_imported_templates = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'automation', @@ -423,7 +424,7 @@ def test_positive_export_filtered_templates_to_localdir( :CaseImportance: Low """ dir_name, dir_path = create_import_export_local_dir - exported_temps = entities.Template().exports( + exported_temps = target_sat.api.Template().exports( data={ 'repo': FOREMAN_TEMPLATE_ROOT_DIR, 'dirname': dir_name, @@ -459,7 +460,7 @@ def test_positive_export_filtered_templates_negate( """ # Export some filtered templates to local dir _, dir_path = create_import_export_local_dir - entities.Template().exports( + target_sat.api.Template().exports( data={ 'repo': dir_path, 'organization_ids': [module_org.id], @@ -498,7 +499,7 @@ def test_positive_export_and_import_with_metadata( ex_template = 'example_template.erb' prefix = gen_string('alpha') _, dir_path = create_import_export_local_dir - entities.Template().imports( + target_sat.api.Template().imports( data={ 'repo': dir_path, 'location_ids': [module_location.id], @@ -508,7 +509,7 @@ def test_positive_export_and_import_with_metadata( ) export_file = f'{prefix.lower()}{ex_template}' # Export same template to local dir with refreshed metadata - entities.Template().exports( + target_sat.api.Template().exports( data={ 'metadata_export_mode': 'refresh', 'repo': dir_path, @@ -522,7 +523,7 @@ def test_positive_export_and_import_with_metadata( ) assert result.status == 0 # Export same template to local dir with keeping metadata - entities.Template().exports( + target_sat.api.Template().exports( data={ 'metadata_export_mode': 'keep', 'repo': dir_path, @@ -536,7 +537,7 @@ def test_positive_export_and_import_with_metadata( ) assert result.status == 1 # Export same template to local dir with removed metadata - entities.Template().exports( + target_sat.api.Template().exports( data={ 'metadata_export_mode': 'remove', 'repo': dir_path, @@ -553,7 +554,7 @@ def test_positive_export_and_import_with_metadata( # Take Templates out of Tech Preview Feature Tests @pytest.mark.tier3 @pytest.mark.parametrize('verbose', [True, False]) - def test_positive_import_json_output_verbose(self, module_org, verbose): + def test_positive_import_json_output_verbose(self, module_org, verbose, module_target_sat): """Assert all the required fields displayed in import output when verbose is True and False @@ -575,7 +576,7 @@ def test_positive_import_json_output_verbose(self, module_org, verbose): :CaseImportance: Low """ prefix = gen_string('alpha') - templates = entities.Template().imports( + templates = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'master', @@ -628,19 +629,19 @@ def test_positive_import_json_output_changed_key_true( """ prefix = gen_string('alpha') _, dir_path = create_import_export_local_dir - pre_template = entities.Template().imports( + pre_template = target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id], 'prefix': prefix} ) assert bool(pre_template['message']['templates'][0]['imported']) target_sat.execute(f'echo " Updating Template data." >> {dir_path}/example_template.erb') - post_template = entities.Template().imports( + post_template = target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id], 'prefix': prefix} ) assert bool(post_template['message']['templates'][0]['changed']) @pytest.mark.tier2 def test_positive_import_json_output_changed_key_false( - self, create_import_export_local_dir, module_org + self, create_import_export_local_dir, module_org, module_target_sat ): """Assert template imports output `changed` key returns `False` when template data gets updated @@ -663,11 +664,11 @@ def test_positive_import_json_output_changed_key_false( """ prefix = gen_string('alpha') _, dir_path = create_import_export_local_dir - pre_template = entities.Template().imports( + pre_template = module_target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id], 'prefix': prefix} ) assert bool(pre_template['message']['templates'][0]['imported']) - post_template = entities.Template().imports( + post_template = module_target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id], 'prefix': prefix} ) assert not bool(post_template['message']['templates'][0]['changed']) @@ -697,7 +698,7 @@ def test_positive_import_json_output_name_key( target_sat.execute( f'sed -ie "s/name: .*/name: {template_name}/" {dir_path}/example_template.erb' ) - template = entities.Template().imports( + template = target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id]} ) assert 'name' in template['message']['templates'][0].keys() @@ -705,7 +706,7 @@ def test_positive_import_json_output_name_key( @pytest.mark.tier2 def test_positive_import_json_output_imported_key( - self, create_import_export_local_dir, module_org + self, create_import_export_local_dir, module_org, module_target_sat ): """Assert template imports output `imported` key returns `True` on successful import @@ -725,13 +726,15 @@ def test_positive_import_json_output_imported_key( """ prefix = gen_string('alpha') _, dir_path = create_import_export_local_dir - template = entities.Template().imports( + template = module_target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id], 'prefix': prefix} ) assert bool(template['message']['templates'][0]['imported']) @pytest.mark.tier2 - def test_positive_import_json_output_file_key(self, create_import_export_local_dir, module_org): + def test_positive_import_json_output_file_key( + self, create_import_export_local_dir, module_org, module_target_sat + ): """Assert template imports output `file` key returns correct file name from where the template is imported @@ -750,7 +753,7 @@ def test_positive_import_json_output_file_key(self, create_import_export_local_d :CaseImportance: Low """ _, dir_path = create_import_export_local_dir - template = entities.Template().imports( + template = module_target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id]} ) assert 'example_template.erb' == template['message']['templates'][0]['file'] @@ -780,7 +783,7 @@ def test_positive_import_json_output_corrupted_metadata( """ _, dir_path = create_import_export_local_dir target_sat.execute(f'sed -ie "s/<%#/$#$#@%^$^@@RT$$/" {dir_path}/example_template.erb') - template = entities.Template().imports( + template = target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id]} ) assert not bool(template['message']['templates'][0]['imported']) @@ -791,7 +794,7 @@ def test_positive_import_json_output_corrupted_metadata( @pytest.mark.skip_if_open('BZ:1787355') @pytest.mark.tier2 def test_positive_import_json_output_filtered_skip_message( - self, create_import_export_local_dir, module_org + self, create_import_export_local_dir, module_org, module_target_sat ): """Assert template imports output returns template import skipped info for templates whose name doesnt match the filter @@ -812,7 +815,7 @@ def test_positive_import_json_output_filtered_skip_message( :CaseImportance: Low """ _, dir_path = create_import_export_local_dir - template = entities.Template().imports( + template = module_target_sat.api.Template().imports( data={ 'repo': dir_path, 'organization_ids': [module_org.id], @@ -850,7 +853,7 @@ def test_positive_import_json_output_no_name_error( """ _, dir_path = create_import_export_local_dir target_sat.execute(f'sed -ie "s/name: .*/name: /" {dir_path}/example_template.erb') - template = entities.Template().imports( + template = target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id]} ) assert not bool(template['message']['templates'][0]['imported']) @@ -884,7 +887,7 @@ def test_positive_import_json_output_no_model_error( """ _, dir_path = create_import_export_local_dir target_sat.execute(f'sed -ie "/model: .*/d" {dir_path}/example_template.erb') - template = entities.Template().imports( + template = target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id]} ) assert not bool(template['message']['templates'][0]['imported']) @@ -918,7 +921,7 @@ def test_positive_import_json_output_blank_model_error( """ _, dir_path = create_import_export_local_dir target_sat.execute(f'sed -ie "s/model: .*/model: /" {dir_path}/example_template.erb') - template = entities.Template().imports( + template = target_sat.api.Template().imports( data={'repo': dir_path, 'organization_ids': [module_org.id]} ) assert not bool(template['message']['templates'][0]['imported']) @@ -948,7 +951,7 @@ def test_positive_export_json_output( :CaseImportance: Low """ prefix = gen_string('alpha') - imported_templates = entities.Template().imports( + imported_templates = target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'automation', @@ -963,7 +966,7 @@ def test_positive_export_json_output( assert imported_count == 17 # Total Count # Export some filtered templates to local dir _, dir_path = create_import_export_local_dir - exported_templates = entities.Template().exports( + exported_templates = target_sat.api.Template().exports( data={'repo': dir_path, 'organization_ids': [module_org.id], 'filter': prefix} ) exported_count = [ @@ -1000,7 +1003,7 @@ def test_positive_import_log_to_production(self, module_org, target_sat): :CaseImportance: Low """ - entities.Template().imports( + target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'master', @@ -1038,7 +1041,7 @@ def test_positive_export_log_to_production( :CaseImportance: Low """ - entities.Template().imports( + target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'master', @@ -1047,7 +1050,7 @@ def test_positive_export_log_to_production( } ) _, dir_path = create_import_export_local_dir - entities.Template().exports( + target_sat.api.Template().exports( data={'repo': dir_path, 'organization_ids': [module_org.id], 'filter': 'empty'} ) time.sleep(5) @@ -1076,7 +1079,7 @@ def test_positive_export_log_to_production( ids=['non_empty_repo', 'empty_repo'], ) def test_positive_export_all_templates_to_repo( - self, module_org, git_repository, git_branch, url + self, module_org, git_repository, git_branch, url, module_target_sat ): """Assure all templates are exported if no filter is specified. @@ -1094,7 +1097,7 @@ def test_positive_export_all_templates_to_repo( :CaseImportance: Low """ - output = entities.Template().exports( + output = module_target_sat.api.Template().exports( data={ 'repo': f'{url}/{git.username}/{git_repository["name"]}', 'branch': git_branch, @@ -1118,7 +1121,7 @@ def test_positive_export_all_templates_to_repo( assert len(output['message']['templates']) == git_count @pytest.mark.tier2 - def test_positive_import_all_templates_from_repo(self, module_org): + def test_positive_import_all_templates_from_repo(self, module_org, module_target_sat): """Assure all templates are imported if no filter is specified. :id: 95ac9543-d989-44f4-b4d9-18f20a0b58b9 @@ -1131,7 +1134,7 @@ def test_positive_import_all_templates_from_repo(self, module_org): :CaseImportance: Low """ - output = entities.Template().imports( + output = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'master', @@ -1150,7 +1153,7 @@ def test_positive_import_all_templates_from_repo(self, module_org): assert len(output['message']['templates']) == git_count @pytest.mark.tier2 - def test_negative_import_locked_template(self, module_org): + def test_negative_import_locked_template(self, module_org, module_target_sat): """Assure locked templates are not pulled from repository. :id: 88e21cad-448e-45e0-add2-94493a1319c5 @@ -1164,7 +1167,7 @@ def test_negative_import_locked_template(self, module_org): :CaseImportance: Medium """ # import template with lock - output = entities.Template().imports( + output = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'locked', @@ -1176,7 +1179,7 @@ def test_negative_import_locked_template(self, module_org): ) assert output['message']['templates'][0]['imported'] # try to import same template with changed content - output = entities.Template().imports( + output = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'locked', @@ -1193,13 +1196,13 @@ def test_negative_import_locked_template(self, module_org): ) res.raise_for_status() git_content = base64.b64decode(json.loads(res.text)['content']) - sat_content = entities.ProvisioningTemplate( + sat_content = module_target_sat.api.ProvisioningTemplate( id=output['message']['templates'][0]['id'] ).read() assert git_content.decode('utf-8') == sat_content.template @pytest.mark.tier2 - def test_positive_import_locked_template(self, module_org): + def test_positive_import_locked_template(self, module_org, module_target_sat): """Assure locked templates are pulled from repository while using force parameter. :id: 936c91cc-1947-45b0-8bf0-79ba4be87b97 @@ -1213,7 +1216,7 @@ def test_positive_import_locked_template(self, module_org): :CaseImportance: Medium """ # import template with lock - output = entities.Template().imports( + output = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'locked', @@ -1225,7 +1228,7 @@ def test_positive_import_locked_template(self, module_org): ) assert output['message']['templates'][0]['imported'] # force import same template with changed content - output = entities.Template().imports( + output = module_target_sat.api.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'locked', @@ -1244,7 +1247,7 @@ def test_positive_import_locked_template(self, module_org): ) res.raise_for_status() git_content = base64.b64decode(json.loads(res.text)['content']) - sat_content = entities.ProvisioningTemplate( + sat_content = module_target_sat.api.ProvisioningTemplate( id=output['message']['templates'][0]['id'] ).read() assert git_content.decode('utf-8') == sat_content.template diff --git a/tests/foreman/api/test_usergroup.py b/tests/foreman/api/test_usergroup.py index 01dcef27010..a01ee213a38 100644 --- a/tests/foreman/api/test_usergroup.py +++ b/tests/foreman/api/test_usergroup.py @@ -22,7 +22,6 @@ from random import randint from fauxfactory import gen_string -from nailgun import entities import pytest from requests.exceptions import HTTPError @@ -38,12 +37,12 @@ class TestUserGroup: """Tests for the ``usergroups`` path.""" @pytest.fixture - def user_group(self): - return entities.UserGroup().create() + def user_group(self, target_sat): + return target_sat.api.UserGroup().create() @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) - def test_positive_create_with_name(self, name): + def test_positive_create_with_name(self, target_sat, name): """Create new user group using different valid names :id: 3a2255d9-f48d-4f22-a4b9-132361bd9224 @@ -54,12 +53,12 @@ def test_positive_create_with_name(self, name): :CaseImportance: Critical """ - user_group = entities.UserGroup(name=name).create() + user_group = target_sat.api.UserGroup(name=name).create() assert user_group.name == name @pytest.mark.tier1 @pytest.mark.parametrize('login', **parametrized(valid_usernames_list())) - def test_positive_create_with_user(self, login): + def test_positive_create_with_user(self, target_sat, login): """Create new user group using valid user attached to that group. :id: ab127e09-31d2-4c5b-ae6c-726e4b11a21e @@ -70,13 +69,13 @@ def test_positive_create_with_user(self, login): :CaseImportance: Critical """ - user = entities.User(login=login).create() - user_group = entities.UserGroup(user=[user]).create() + user = target_sat.api.User(login=login).create() + user_group = target_sat.api.UserGroup(user=[user]).create() assert len(user_group.user) == 1 assert user_group.user[0].read().login == login @pytest.mark.tier1 - def test_positive_create_with_users(self): + def test_positive_create_with_users(self, target_sat): """Create new user group using multiple users attached to that group. :id: b8dbbacd-b5cb-49b1-985d-96df21440652 @@ -86,15 +85,15 @@ def test_positive_create_with_users(self): :CaseImportance: Critical """ - users = [entities.User().create() for _ in range(randint(3, 5))] - user_group = entities.UserGroup(user=users).create() + users = [target_sat.api.User().create() for _ in range(randint(3, 5))] + user_group = target_sat.api.UserGroup(user=users).create() assert sorted(user.login for user in users) == sorted( user.read().login for user in user_group.user ) @pytest.mark.tier1 @pytest.mark.parametrize('role_name', **parametrized(valid_data_list())) - def test_positive_create_with_role(self, role_name): + def test_positive_create_with_role(self, target_sat, role_name): """Create new user group using valid role attached to that group. :id: c4fac71a-9dda-4e5f-a5df-be362d3cbd52 @@ -105,13 +104,13 @@ def test_positive_create_with_role(self, role_name): :CaseImportance: Critical """ - role = entities.Role(name=role_name).create() - user_group = entities.UserGroup(role=[role]).create() + role = target_sat.api.Role(name=role_name).create() + user_group = target_sat.api.UserGroup(role=[role]).create() assert len(user_group.role) == 1 assert user_group.role[0].read().name == role_name @pytest.mark.tier1 - def test_positive_create_with_roles(self): + def test_positive_create_with_roles(self, target_sat): """Create new user group using multiple roles attached to that group. :id: 5838fcfd-e256-49cf-aef8-b2bf215b3586 @@ -121,15 +120,15 @@ def test_positive_create_with_roles(self): :CaseImportance: Critical """ - roles = [entities.Role().create() for _ in range(randint(3, 5))] - user_group = entities.UserGroup(role=roles).create() + roles = [target_sat.api.Role().create() for _ in range(randint(3, 5))] + user_group = target_sat.api.UserGroup(role=roles).create() assert sorted(role.name for role in roles) == sorted( role.read().name for role in user_group.role ) @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(valid_data_list())) - def test_positive_create_with_usergroup(self, name): + def test_positive_create_with_usergroup(self, target_sat, name): """Create new user group using another user group attached to the initial group. @@ -141,13 +140,13 @@ def test_positive_create_with_usergroup(self, name): :CaseImportance: Critical """ - sub_user_group = entities.UserGroup(name=name).create() - user_group = entities.UserGroup(usergroup=[sub_user_group]).create() + sub_user_group = target_sat.api.UserGroup(name=name).create() + user_group = target_sat.api.UserGroup(usergroup=[sub_user_group]).create() assert len(user_group.usergroup) == 1 assert user_group.usergroup[0].read().name == name @pytest.mark.tier2 - def test_positive_create_with_usergroups(self): + def test_positive_create_with_usergroups(self, target_sat): """Create new user group using multiple user groups attached to that initial group. @@ -158,15 +157,15 @@ def test_positive_create_with_usergroups(self): :CaseLevel: Integration """ - sub_user_groups = [entities.UserGroup().create() for _ in range(randint(3, 5))] - user_group = entities.UserGroup(usergroup=sub_user_groups).create() + sub_user_groups = [target_sat.api.UserGroup().create() for _ in range(randint(3, 5))] + user_group = target_sat.api.UserGroup(usergroup=sub_user_groups).create() assert sorted(usergroup.name for usergroup in sub_user_groups) == sorted( usergroup.read().name for usergroup in user_group.usergroup ) @pytest.mark.tier1 @pytest.mark.parametrize('name', **parametrized(invalid_values_list())) - def test_negative_create_with_name(self, name): + def test_negative_create_with_name(self, target_sat, name): """Attempt to create user group with invalid name. :id: 1a3384dc-5d52-442c-87c8-e38048a61dfa @@ -178,10 +177,10 @@ def test_negative_create_with_name(self, name): :CaseImportance: Critical """ with pytest.raises(HTTPError): - entities.UserGroup(name=name).create() + target_sat.api.UserGroup(name=name).create() @pytest.mark.tier1 - def test_negative_create_with_same_name(self): + def test_negative_create_with_same_name(self, target_sat): """Attempt to create user group with a name of already existent entity. :id: aba0925a-d5ec-4e90-86c6-404b9b6f0179 @@ -190,9 +189,9 @@ def test_negative_create_with_same_name(self): :CaseImportance: Critical """ - user_group = entities.UserGroup().create() + user_group = target_sat.api.UserGroup().create() with pytest.raises(HTTPError): - entities.UserGroup(name=user_group.name).create() + target_sat.api.UserGroup(name=user_group.name).create() @pytest.mark.tier1 @pytest.mark.parametrize('new_name', **parametrized(valid_data_list())) @@ -212,7 +211,7 @@ def test_positive_update(self, user_group, new_name): assert new_name == user_group.name @pytest.mark.tier1 - def test_positive_update_with_new_user(self): + def test_positive_update_with_new_user(self, target_sat): """Add new user to user group :id: e11b57c3-5f86-4963-9cc6-e10e2f02468b @@ -221,14 +220,14 @@ def test_positive_update_with_new_user(self): :CaseImportance: Critical """ - user = entities.User().create() - user_group = entities.UserGroup().create() + user = target_sat.api.User().create() + user_group = target_sat.api.UserGroup().create() user_group.user = [user] user_group = user_group.update(['user']) assert user.login == user_group.user[0].read().login @pytest.mark.tier2 - def test_positive_update_with_existing_user(self): + def test_positive_update_with_existing_user(self, target_sat): """Update user that assigned to user group with another one :id: 71b78f64-867d-4bf5-9b1e-02698a17fb38 @@ -237,14 +236,14 @@ def test_positive_update_with_existing_user(self): :CaseLevel: Integration """ - users = [entities.User().create() for _ in range(2)] - user_group = entities.UserGroup(user=[users[0]]).create() + users = [target_sat.api.User().create() for _ in range(2)] + user_group = target_sat.api.UserGroup(user=[users[0]]).create() user_group.user[0] = users[1] user_group = user_group.update(['user']) assert users[1].login == user_group.user[0].read().login @pytest.mark.tier1 - def test_positive_update_with_new_role(self): + def test_positive_update_with_new_role(self, target_sat): """Add new role to user group :id: 8e0872c1-ae88-4971-a6fc-cd60127d6663 @@ -253,15 +252,15 @@ def test_positive_update_with_new_role(self): :CaseImportance: Critical """ - new_role = entities.Role().create() - user_group = entities.UserGroup().create() + new_role = target_sat.api.Role().create() + user_group = target_sat.api.UserGroup().create() user_group.role = [new_role] user_group = user_group.update(['role']) assert new_role.name == user_group.role[0].read().name @pytest.mark.tier1 @pytest.mark.upgrade - def test_positive_update_with_new_usergroup(self): + def test_positive_update_with_new_usergroup(self, target_sat): """Add new user group to existing one :id: 3cb29d07-5789-4f94-9fd9-a7e494b3c110 @@ -270,8 +269,8 @@ def test_positive_update_with_new_usergroup(self): :CaseImportance: Critical """ - new_usergroup = entities.UserGroup().create() - user_group = entities.UserGroup().create() + new_usergroup = target_sat.api.UserGroup().create() + user_group = target_sat.api.UserGroup().create() user_group.usergroup = [new_usergroup] user_group = user_group.update(['usergroup']) assert new_usergroup.name == user_group.usergroup[0].read().name @@ -295,7 +294,7 @@ def test_negative_update(self, user_group, new_name): assert user_group.read().name != new_name @pytest.mark.tier1 - def test_negative_update_with_same_name(self): + def test_negative_update_with_same_name(self, target_sat): """Attempt to update user group with a name of already existent entity. :id: 14888998-9282-4d81-9e99-234d19706783 @@ -305,15 +304,15 @@ def test_negative_update_with_same_name(self): :CaseImportance: Critical """ name = gen_string('alphanumeric') - entities.UserGroup(name=name).create() - new_user_group = entities.UserGroup().create() + target_sat.api.UserGroup(name=name).create() + new_user_group = target_sat.api.UserGroup().create() new_user_group.name = name with pytest.raises(HTTPError): new_user_group.update(['name']) assert new_user_group.read().name != name @pytest.mark.tier1 - def test_positive_delete(self): + def test_positive_delete(self, target_sat): """Create user group with valid name and then delete it :id: c5cfcc4a-9177-47bb-8f19-7a8930eb7ca3 @@ -322,7 +321,7 @@ def test_positive_delete(self): :CaseImportance: Critical """ - user_group = entities.UserGroup().create() + user_group = target_sat.api.UserGroup().create() user_group.delete() with pytest.raises(HTTPError): user_group.read() diff --git a/tests/foreman/api/test_webhook.py b/tests/foreman/api/test_webhook.py index b806dbb24c0..a220b19af99 100644 --- a/tests/foreman/api/test_webhook.py +++ b/tests/foreman/api/test_webhook.py @@ -18,7 +18,6 @@ """ import re -from nailgun import entities import pytest from requests.exceptions import HTTPError from wait_for import TimedOutError, wait_for @@ -68,7 +67,7 @@ def assert_event_triggered(channel, event): class TestWebhook: @pytest.mark.tier2 - def test_negative_invalid_event(self): + def test_negative_invalid_event(self, target_sat): """Test negative webhook creation with an invalid event :id: 60cd456a-9943-45cb-a72e-23a83a691499 @@ -78,11 +77,11 @@ def test_negative_invalid_event(self): :CaseImportance: High """ with pytest.raises(HTTPError): - entities.Webhooks(event='invalid_event').create() + target_sat.api.Webhooks(event='invalid_event').create() @pytest.mark.tier2 @pytest.mark.parametrize('event', **parametrized(WEBHOOK_EVENTS)) - def test_positive_valid_event(self, event): + def test_positive_valid_event(self, event, target_sat): """Test positive webhook creation with a valid event :id: 9b505f1b-7ee1-4362-b44c-f3107d043a05 @@ -91,11 +90,11 @@ def test_positive_valid_event(self, event): :CaseImportance: High """ - hook = entities.Webhooks(event=event).create() + hook = target_sat.api.Webhooks(event=event).create() assert event in hook.event @pytest.mark.tier2 - def test_negative_invalid_method(self): + def test_negative_invalid_method(self, target_sat): """Test negative webhook creation with an invalid HTTP method :id: 573be312-7bf3-4d9e-aca1-e5cac810d04b @@ -105,11 +104,11 @@ def test_negative_invalid_method(self): :CaseImportance: High """ with pytest.raises(HTTPError): - entities.Webhooks(http_method='NONE').create() + target_sat.api.Webhooks(http_method='NONE').create() @pytest.mark.tier2 @pytest.mark.parametrize('method', **parametrized(WEBHOOK_METHODS)) - def test_positive_valid_method(self, method): + def test_positive_valid_method(self, method, target_sat): """Test positive webhook creation with a valid HTTP method :id: cf8f276a-d21e-44d0-92f2-657232240c7e @@ -118,12 +117,12 @@ def test_positive_valid_method(self, method): :CaseImportance: High """ - hook = entities.Webhooks(http_method=method).create() + hook = target_sat.api.Webhooks(http_method=method).create() assert hook.http_method == method @pytest.mark.tier1 @pytest.mark.e2e - def test_positive_end_to_end(self): + def test_positive_end_to_end(self, target_sat): """Create a new webhook. :id: 7593a04e-cf7e-414c-9e7e-3fe2936cc32a @@ -132,7 +131,7 @@ def test_positive_end_to_end(self): :CaseImportance: Critical """ - hook = entities.Webhooks().create() + hook = target_sat.api.Webhooks().create() assert hook hook.name = "testing" hook.http_method = "GET" @@ -149,7 +148,7 @@ def test_positive_end_to_end(self): (not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url' ) @pytest.mark.tier2 - def test_positive_event_triggered(self, module_org, target_sat): + def test_positive_event_triggered(self, module_org, module_target_sat): """Create a webhook and trigger the event associated with it. @@ -160,13 +159,13 @@ def test_positive_event_triggered(self, module_org, target_sat): :CaseImportance: Critical """ - hook = entities.Webhooks( + hook = module_target_sat.api.Webhooks( event='actions.katello.repository.sync_succeeded', http_method='GET' ).create() - repo = entities.Repository( + repo = module_target_sat.api.Repository( organization=module_org, content_type='yum', url=settings.repos.yum_0.url ).create() - with target_sat.session.shell() as shell: + with module_target_sat.api.session.shell() as shell: shell.send('foreman-tail') repo.sync() assert_event_triggered(shell, hook.event) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index 08ce12c02ff..6f5f34fb210 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -1271,9 +1271,9 @@ def test_global_registration_form_populate( 4. Open the global registration form and select the same host-group 5. check host registration form should be populated automatically based on the host-group - :BZ: 2056469 + :BZ: 2056469, 1994654 - :CaseAutomation: Automated + :customerscenario: true """ hg_name = gen_string('alpha') iface = gen_string('alpha') @@ -1287,6 +1287,8 @@ def test_global_registration_form_populate( content_view=module_promoted_cv, group_parameters_attributes=[group_params], ).create() + new_org = target_sat.api.Organization().create() + new_ak = target_sat.api.ActivationKey(organization=new_org).create() with session: session.hostgroup.update( hg_name, @@ -1302,12 +1304,23 @@ def test_global_registration_form_populate( }, full_read=True, ) - assert hg_name in cmd['general']['host_group'] assert module_ak_with_cv.name in cmd['general']['activation_key_helper'] assert module_lce.name in cmd['advanced']['life_cycle_env_helper'] assert constants.FAKE_0_CUSTOM_PACKAGE in cmd['advanced']['install_packages_helper'] + session.organization.select(org_name=new_org.name) + cmd = session.host.get_register_command( + { + 'general.organization': new_org.name, + 'general.operating_system': default_os.title, + 'general.insecure': True, + }, + full_read=True, + ) + assert new_org.name in cmd['general']['organization'] + assert new_ak.name in cmd['general']['activation_keys'] + @pytest.mark.tier2 def test_global_registration_with_capsule_host(