From 24796041fcd59e5107370c12a46ed104d5fcb58b Mon Sep 17 00:00:00 2001 From: Jameer Pathan Date: Tue, 13 Oct 2020 17:49:18 +0530 Subject: [PATCH] Add few more fixtures and resolve jyejare --- pytest_fixtures/oscap_fixtures.py | 40 +++++++++++++ pytest_fixtures/smartproxy_fixtures.py | 9 +-- pytest_fixtures/user_fixtures.py | 9 +-- tests/foreman/api/test_oscappolicy.py | 60 +++---------------- tests/foreman/cli/test_oscap.py | 81 +++++++++++++------------- tests/foreman/ui/test_host.py | 24 +------- 6 files changed, 95 insertions(+), 128 deletions(-) diff --git a/pytest_fixtures/oscap_fixtures.py b/pytest_fixtures/oscap_fixtures.py index d06bb175a3c..5928ebcfa98 100644 --- a/pytest_fixtures/oscap_fixtures.py +++ b/pytest_fixtures/oscap_fixtures.py @@ -1,8 +1,12 @@ import os import pytest +from fauxfactory import gen_string +from nailgun import entities from robottelo import ssh +from robottelo.cli.factory import make_scapcontent +from robottelo.constants import OSCAP_PROFILE from robottelo.helpers import file_downloader from robottelo.test import settings @@ -24,3 +28,39 @@ def oscap_content_path(): local_file = f"/tmp/{file_name}" ssh.download_file(settings.oscap.content_path, local_file) return local_file + + +@pytest.fixture(scope="module") +def scap_content(import_ansible_roles, import_puppet_classes): + title = f"rhel-content-{gen_string('alpha')}" + scap_info = make_scapcontent({'title': title, 'scap-file': f'{settings.oscap.content_path}'}) + scap_id = scap_info['id'] + scap_info = entities.ScapContents(id=scap_id).read() + + scap_profile_id = [ + profile['id'] + for profile in scap_info['scap-content-profiles'] + if OSCAP_PROFILE['security7'] in profile['title'] + ][0] + return { + "title": title, + "scap_id": scap_id, + "scap_profile_id": scap_profile_id, + } + + +@pytest.fixture(scope="module") +def tailoring_file(module_org, module_location, tailoring_file_path): + """ Create Tailoring file.""" + tailoring_file_name = f"tailoring-file-{gen_string('alpha')}" + tf_info = entities.TailoringFile( + name=f"{tailoring_file_name}", + scap_file=f"{tailoring_file_path['local']}", + organization=[module_org], + location=[module_location], + ).create() + return { + "name": tailoring_file_name, + "tailoring_file_id": tf_info['id'], + "tailoring_file_profile_id": tf_info.tailoring_file_profiles[0]['id'], + } diff --git a/pytest_fixtures/smartproxy_fixtures.py b/pytest_fixtures/smartproxy_fixtures.py index 57a4b11db9b..a371fd20cde 100644 --- a/pytest_fixtures/smartproxy_fixtures.py +++ b/pytest_fixtures/smartproxy_fixtures.py @@ -15,10 +15,5 @@ def default_smart_proxy(): @pytest.fixture(scope='session') -def import_puppet_classes(): - smart_proxy = ( - entities.SmartProxy() - .search(query={'search': f'name={settings.server.hostname}'})[0] - .read() - ) - smart_proxy.import_puppetclasses(environment='production') +def import_puppet_classes(default_smart_proxy): + default_smart_proxy.import_puppetclasses(environment='production') diff --git a/pytest_fixtures/user_fixtures.py b/pytest_fixtures/user_fixtures.py index 896cf10fb25..765a24fc20e 100644 --- a/pytest_fixtures/user_fixtures.py +++ b/pytest_fixtures/user_fixtures.py @@ -2,23 +2,18 @@ from fauxfactory import gen_string from nailgun import entities -from robottelo.constants import DEFAULT_LOC - @pytest.fixture(scope='module') -def module_viewer_user(module_org): +def module_viewer_user(module_org, default_location): """Custom user with viewer role for tests validating visibility of entities or fields created by some other user. Created only when accessed, unlike `module_user`. """ viewer_role = entities.Role().search(query={'search': 'name="Viewer"'})[0] - default_loc_id = ( - entities.Location().search(query={'search': 'name="{}"'.format(DEFAULT_LOC)})[0].id - ) custom_password = gen_string('alphanumeric') custom_user = entities.User( admin=False, default_organization=module_org, - location=[default_loc_id], + location=[default_location], organization=[module_org], role=[viewer_role], password=custom_password, diff --git a/tests/foreman/api/test_oscappolicy.py b/tests/foreman/api/test_oscappolicy.py index af309805207..73d9ef7f1cc 100644 --- a/tests/foreman/api/test_oscappolicy.py +++ b/tests/foreman/api/test_oscappolicy.py @@ -19,8 +19,6 @@ from fauxfactory import gen_string from nailgun import entities -from robottelo.cli.ansible import Ansible -from robottelo.constants import OSCAP_PROFILE from robottelo.decorators import tier1 @@ -36,50 +34,6 @@ def module_org(module_org): module_org.delete() -@pytest.fixture(scope="module") -def scap_content(module_org, module_location, oscap_content_path): - """ Import Ansible roles, Ansible variables, create Scap content.""" - # Import Ansible roles and variables. - Ansible.roles_import({'proxy-id': 1}) - Ansible.variables_import({'proxy-id': 1}) - sc_title = gen_string('alpha') - entity = entities.ScapContents().search(query={'search': f'title="{sc_title}"'}) - # Create Scap content. - if not entity: - result = entities.ScapContents( - title=f"{sc_title}", - scap_file=f"{oscap_content_path}", - organization=[module_org], - location=[module_location], - ).create() - else: - result = entities.ScapContents(id=entity[0].id).read() - scap_profile_id_rhel7 = [ - profile['id'] - for profile in result.scap_content_profiles - if OSCAP_PROFILE['security7'] in profile['title'] - ][0] - return (result, scap_profile_id_rhel7) - - -@pytest.fixture(scope="module") -def tailoring_file(module_org, module_location, tailoring_file_path): - """ Create Tailoring file.""" - tf_name = gen_string('alpha') - entity = entities.TailoringFile().search(query={'search': f'name="{tf_name}"'}) - if not entity: - result = entities.TailoringFile( - name=f"{tf_name}", - scap_file=f"{tailoring_file_path['local']}", - organization=[module_org], - location=[module_location], - ).create() - else: - result = entities.TailoringFile(id=entity[0].id).read() - tailor_profile_id = result.tailoring_file_profiles[0]['id'] - return (result, tailor_profile_id) - - class TestOscapPolicy: """Implements Oscap Policy tests in API.""" @@ -108,10 +62,10 @@ def test_positive_crud_scap_policy( name=name, deploy_by='puppet', description=description, - scap_content_id=scap_content[0].id, - scap_content_profile_id=scap_content[1], - tailoring_file_id=tailoring_file[0].id, - tailoring_file_profile_id=tailoring_file[1], + scap_content_id=scap_content["scap_id"], + scap_content_profile_id=scap_content["scap_profile_id"], + tailoring_file_id=tailoring_file["tailoring_file_id"], + tailoring_file_profile_id=tailoring_file["tailoring_file_profile_id"], period="monthly", day_of_month="5", hostgroup=[hostgroup], @@ -123,9 +77,9 @@ def test_positive_crud_scap_policy( assert policy.deploy_by == 'puppet' assert policy.name == name assert policy.description == description - assert policy.scap_content_id == scap_content[0].id - assert policy.scap_content_profile_id == scap_content[1] - assert policy.tailoring_file_id == tailoring_file[0].id + assert policy.scap_content_id == scap_content["scap_id"] + assert policy.scap_content_profile_id == scap_content["scap_profile_id"] + assert policy.tailoring_file_id == tailoring_file["tailoring_file_id"] assert policy.period == "monthly" assert policy.day_of_month == 5 assert policy.hostgroup[0].id == hostgroup.id diff --git a/tests/foreman/cli/test_oscap.py b/tests/foreman/cli/test_oscap.py index e1cf70d64e9..caeb58ee896 100644 --- a/tests/foreman/cli/test_oscap.py +++ b/tests/foreman/cli/test_oscap.py @@ -62,21 +62,6 @@ def fetch_scap_and_profile_id(cls, scap_name, scap_profile): ] return scap_id, scap_profile_ids - @pytest.fixture(scope="class") - def scap_content(self, import_ansible_roles, import_puppet_classes): - title = gen_string('alpha') - result = [scap['title'] for scap in Scapcontent.list() if scap.get('title') in title] - if not result: - make_scapcontent({'title': title, 'scap-file': settings.oscap.content_path}) - scap_id_rhel7, scap_profile_id_rhel7 = self.fetch_scap_and_profile_id( - title, OSCAP_PROFILE['security7'] - ) - return { - "title": title, - "scap_id_rhel7": scap_id_rhel7, - "scap_profile_id_rhel7": scap_profile_id_rhel7, - } - @tier1 def test_positive_list_default_content_with_admin(self): """List the default scap content with admin account @@ -200,6 +185,8 @@ def test_positive_create_scap_content_with_valid_title(self, title): :id: 68e9fbe2-e3c3-48e7-a774-f1260a3b7f4f + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -262,6 +249,8 @@ def test_negative_create_scap_content_with_invalid_title(self, title): :id: 90a2590e-a6ff-41f1-9e0a-67d4b16435c0 + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -288,6 +277,8 @@ def test_positive_create_scap_content_with_valid_originalfile_name(self, name): :id: 25441174-11cb-4d9b-9ec5-b1c69411b5bc + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -316,6 +307,8 @@ def test_negative_create_scap_content_with_invalid_originalfile_name(self, name) :id: 83feb67a-a6bf-4a99-923d-889e8d1013fa + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -344,6 +337,8 @@ def test_negative_create_scap_content_without_dsfile(self, title): :id: ea811994-12cd-4382-9382-37fa806cc26f + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -454,6 +449,8 @@ def test_postive_create_scap_policy_with_valid_name(self, name, scap_content): :id: c9327675-62b2-4e22-933a-02818ef68c11 + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -471,8 +468,8 @@ def test_postive_create_scap_policy_with_valid_name(self, name, scap_content): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), } @@ -486,6 +483,8 @@ def test_negative_create_scap_policy_with_invalid_name(self, name, scap_content) :id: 0d163968-7759-4cfd-9c4d-98533d8db925 + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -504,8 +503,8 @@ def test_negative_create_scap_policy_with_invalid_name(self, name, scap_content) { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), } @@ -534,7 +533,7 @@ def test_negative_create_scap_policy_without_content(self, scap_content): make_scap_policy( { 'deploy-by': 'puppet', - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), } @@ -567,8 +566,8 @@ def test_positive_associate_scap_policy_with_hostgroups(self, scap_content): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), 'hostgroups': hostgroup['name'], @@ -605,8 +604,8 @@ def test_positive_associate_scap_policy_with_hostgroup_via_ansible(self, scap_co { 'name': name, 'deploy-by': 'ansible', - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), 'hostgroups': hostgroup['name'], @@ -625,6 +624,8 @@ def test_positive_associate_scap_policy_with_tailoringfiles( :id: d0f9b244-b92d-4889-ba6a-8973ea05bf43 + :parametrized: yes + :steps: 1. Login to hammer shell. @@ -641,9 +642,9 @@ def test_positive_associate_scap_policy_with_tailoringfiles( scap_policy = make_scap_policy( { - 'scap-content-id': scap_content["scap_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], 'deploy-by': deploy, - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), 'tailoring-file': tailoring_file_a['name'], @@ -671,9 +672,9 @@ def test_positive_associate_scap_policy_with_tailoringfiles( scap_policy = make_scap_policy( { - 'scap-content-id': scap_content["scap_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], 'deploy-by': deploy, - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), 'tailoring-file-id': tailoring_file_a['id'], @@ -707,6 +708,8 @@ def test_positive_scap_policy_end_to_end(self, deploy, scap_content): :id: d14ab43e-c7a9-4eee-b61c-420b07ca1da9 + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -729,8 +732,8 @@ def test_positive_scap_policy_end_to_end(self, deploy, scap_content): { 'name': name, 'deploy-by': deploy, - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), 'hostgroups': hostgroup['name'], @@ -782,8 +785,8 @@ def test_positive_update_scap_policy_with_hostgroup(self, scap_content): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), 'hostgroups': hostgroup['name'], @@ -826,8 +829,8 @@ def test_positive_update_scap_policy_period(self, scap_content): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), } @@ -871,13 +874,13 @@ def test_positive_update_scap_policy_with_content(self, scap_content): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), } ) - assert scap_policy['scap-content-id'] == scap_content["scap_id_rhel7"] + assert scap_policy['scap-content-id'] == scap_content["scap_id"] scap_id, scap_profile_id = self.fetch_scap_and_profile_id( OSCAP_DEFAULT_CONTENT['rhel_firefox'], OSCAP_PROFILE['firefox'] ) @@ -915,8 +918,8 @@ def test_positive_associate_scap_policy_with_single_server(self, scap_content): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': scap_content["scap_id_rhel7"], - 'scap-content-profile-id': scap_content["scap_profile_id_rhel7"], + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), } diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index ee5335f2ef8..edd6fc3fedb 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -41,7 +41,6 @@ from robottelo.cli.factory import make_hostgroup from robottelo.cli.factory import make_lifecycle_environment from robottelo.cli.factory import make_scap_policy -from robottelo.cli.factory import make_scapcontent from robottelo.cli.proxy import Proxy from robottelo.cli.scap_policy import Scappolicy from robottelo.cli.scapcontent import Scapcontent @@ -53,7 +52,6 @@ from robottelo.constants import ENVIRONMENT from robottelo.constants import FOREMAN_PROVIDERS from robottelo.constants import OSCAP_PERIOD -from robottelo.constants import OSCAP_PROFILE from robottelo.constants import OSCAP_WEEKDAY from robottelo.constants import PERMISSIONS from robottelo.constants import RHEL_6_MAJOR_VERSION @@ -80,32 +78,14 @@ def _get_set_from_list_of_dict(value): } -@pytest.fixture -def scap_content(): - title = 'rhel-content-{0}'.format(gen_string('alpha')) - scap_info = make_scapcontent( - {'title': title, 'scap-file': '{0}'.format(settings.oscap.content_path)} - ) - scap_id = scap_info['id'] - scap_info = Scapcontent.info({'id': scap_id}, output_format='json') - - scap_profile_id = [ - profile['id'] - for profile in scap_info['scap-content-profiles'] - if OSCAP_PROFILE['security7'] in profile['title'] - ][0] - return scap_id, scap_profile_id - - @pytest.fixture def scap_policy(scap_content): - scap_id, scap_profile_id = scap_content scap_policy = make_scap_policy( { 'name': gen_string('alpha'), 'deploy-by': 'puppet', - 'scap-content-id': scap_id, - 'scap-content-profile-id': scap_profile_id, + 'scap-content-id': scap_content["scap_id"], + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), }