diff --git a/conftest.py b/conftest.py index ba17fc44c0b..2dc850eff75 100644 --- a/conftest.py +++ b/conftest.py @@ -12,4 +12,8 @@ # Component Fixtures "pytest_fixtures.satellite_auth", "pytest_fixtures.templatesync_fixtures", + "pytest_fixtures.ansible_fixtures", + "pytest_fixtures.oscap_fixtures", + "pytest_fixtures.smartproxy_fixtures", + "pytest_fixtures.user_fixtures", ] diff --git a/pytest_fixtures/ansible_fixtures.py b/pytest_fixtures/ansible_fixtures.py new file mode 100644 index 00000000000..2bcfa02e280 --- /dev/null +++ b/pytest_fixtures/ansible_fixtures.py @@ -0,0 +1,10 @@ +import pytest + +from robottelo.cli.ansible import Ansible + + +@pytest.fixture(scope="session") +def import_ansible_roles(default_smart_proxy): + """ Import ansible roles to default_smart_proxy for tests""" + Ansible.roles_import({'proxy-id': default_smart_proxy.id}) + Ansible.variables_import({'proxy-id': default_smart_proxy.id}) diff --git a/pytest_fixtures/api_fixtures.py b/pytest_fixtures/api_fixtures.py index 4325eaeb782..0f8f3213261 100644 --- a/pytest_fixtures/api_fixtures.py +++ b/pytest_fixtures/api_fixtures.py @@ -1,13 +1,10 @@ # Module-wide Nailgun Entity Fixtures to be used by API, CLI and UI Tests -import os - import pytest from fauxfactory import gen_string from nailgun import entities from wrapanapi import AzureSystem from wrapanapi import GoogleCloudSystem -from robottelo import ssh from robottelo.api.utils import publish_puppet_module from robottelo.constants import AZURERM_RG_DEFAULT from robottelo.constants import AZURERM_RHEL7_FT_BYOS_IMG_URN @@ -27,7 +24,6 @@ from robottelo.constants.repos import CUSTOM_PUPPET_REPO from robottelo.decorators import skip_if from robottelo.helpers import download_gce_cert -from robottelo.helpers import file_downloader from robottelo.test import settings # Global Satellite Entities @@ -81,16 +77,6 @@ def module_compute_profile(): return entities.ComputeProfile().create() -@pytest.fixture(scope='session') -def default_smart_proxy(): - smart_proxy = ( - entities.SmartProxy() - .search(query={'search': 'name={0}'.format(settings.server.hostname)})[0] - .read() - ) - return entities.SmartProxy(id=smart_proxy.id).read() - - @pytest.fixture(scope='session') def default_domain(default_smart_proxy): domain_name = settings.server.hostname.partition('.')[-1] @@ -458,25 +444,6 @@ def module_cv_with_puppet_module(module_org): ) -@pytest.fixture(scope="session") -def tailoring_file_path(): - """ Return Tailoring file path.""" - local = file_downloader(file_url=settings.oscap.tailoring_path)[0] - satellite = file_downloader( - file_url=settings.oscap.tailoring_path, hostname=settings.server.hostname - )[0] - return {'local': local, 'satellite': satellite} - - -@pytest.fixture(scope="session") -def oscap_content_path(): - """ Download scap content from satellite and return local path of it.""" - _, file_name = os.path.split(settings.oscap.content_path) - local_file = f"/tmp/{file_name}" - ssh.download_file(settings.oscap.content_path, local_file) - return local_file - - @pytest.fixture(scope='session') def default_pxetemplate(): pxe_template = entities.ProvisioningTemplate().search(query={'search': DEFAULT_PXE_TEMPLATE}) diff --git a/pytest_fixtures/oscap_fixtures.py b/pytest_fixtures/oscap_fixtures.py new file mode 100644 index 00000000000..5928ebcfa98 --- /dev/null +++ b/pytest_fixtures/oscap_fixtures.py @@ -0,0 +1,66 @@ +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 + + +@pytest.fixture(scope="session") +def tailoring_file_path(): + """ Return Tailoring file path.""" + local = file_downloader(file_url=settings.oscap.tailoring_path)[0] + satellite = file_downloader( + file_url=settings.oscap.tailoring_path, hostname=settings.server.hostname + )[0] + return {'local': local, 'satellite': satellite} + + +@pytest.fixture(scope="session") +def oscap_content_path(): + """ Download scap content from satellite and return local path of it.""" + _, file_name = os.path.split(settings.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 new file mode 100644 index 00000000000..a371fd20cde --- /dev/null +++ b/pytest_fixtures/smartproxy_fixtures.py @@ -0,0 +1,19 @@ +import pytest +from nailgun import entities + +from robottelo.test import settings + + +@pytest.fixture(scope='session') +def default_smart_proxy(): + smart_proxy = ( + entities.SmartProxy() + .search(query={'search': f'name={settings.server.hostname}'})[0] + .read() + ) + return entities.SmartProxy(id=smart_proxy.id).read() + + +@pytest.fixture(scope='session') +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 new file mode 100644 index 00000000000..a11209c4984 --- /dev/null +++ b/pytest_fixtures/user_fixtures.py @@ -0,0 +1,22 @@ +import pytest +from fauxfactory import gen_string +from nailgun import entities + + +@pytest.fixture(scope='module') +def default_viewer_role(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] + custom_password = gen_string('alphanumeric') + custom_user = entities.User( + admin=False, + default_organization=module_org, + location=[default_location], + organization=[module_org], + role=[viewer_role], + password=custom_password, + ).create() + custom_user.password = custom_password + return custom_user 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 5027991f93d..1e14b170199 100644 --- a/tests/foreman/cli/test_oscap.py +++ b/tests/foreman/cli/test_oscap.py @@ -18,47 +18,32 @@ from fauxfactory import gen_string from nailgun import entities -from robottelo.cli.ansible import Ansible from robottelo.cli.base import CLIReturnCodeError from robottelo.cli.factory import CLIFactoryError from robottelo.cli.factory import make_hostgroup from robottelo.cli.factory import make_scap_policy from robottelo.cli.factory import make_scapcontent from robottelo.cli.factory import make_tailoringfile -from robottelo.cli.factory import make_user from robottelo.cli.host import Host -from robottelo.cli.role import Role from robottelo.cli.scap_policy import Scappolicy from robottelo.cli.scapcontent import Scapcontent -from robottelo.cli.user import User from robottelo.config import settings from robottelo.constants import OSCAP_DEFAULT_CONTENT from robottelo.constants import OSCAP_PERIOD from robottelo.constants import OSCAP_PROFILE from robottelo.constants import OSCAP_WEEKDAY from robottelo.datafactory import invalid_names_list +from robottelo.datafactory import parametrized from robottelo.datafactory import valid_data_list from robottelo.decorators import tier1 from robottelo.decorators import tier2 from robottelo.decorators import tier4 from robottelo.decorators import upgrade -from robottelo.helpers import file_downloader -from robottelo.test import CLITestCase -class OpenScapTestCase(CLITestCase): +class TestOpenScap: """Tests related to the oscap cli hammer plugin""" - @classmethod - def create_test_user_viewer_role(cls): - """Create's a user with Viewer role""" - cls.login = gen_string('alpha') - cls.password = gen_string('alpha') - user = make_user({'login': cls.login, 'password': cls.password, 'admin': False}) - role = Role.info({'name': 'Viewer'}) - User.add_role({'login': user['login'], 'role-id': role['id']}) - return cls.login, cls.password - @classmethod def fetch_scap_and_profile_id(cls, scap_name, scap_profile): """Extracts the scap ID and scap profile id @@ -77,22 +62,6 @@ def fetch_scap_and_profile_id(cls, scap_name, scap_profile): ] return scap_id, scap_profile_ids - @classmethod - def setUpClass(cls): - super(OpenScapTestCase, cls).setUpClass() - cls.title = gen_string('alpha') - result = [scap['title'] for scap in Scapcontent.list() if scap.get('title') in cls.title] - if not result: - make_scapcontent({'title': cls.title, 'scap-file': settings.oscap.content_path}) - cls.scap_id_rhel7, cls.scap_profile_id_rhel7 = cls.fetch_scap_and_profile_id( - cls.title, OSCAP_PROFILE['security7'] - ) - cls.tailoring_file_path = file_downloader( - file_url=settings.oscap.tailoring_path, hostname=settings.server.hostname - )[0] - Ansible.roles_import({'proxy-id': 1}) - Ansible.variables_import({'proxy-id': 1}) - @tier1 def test_positive_list_default_content_with_admin(self): """List the default scap content with admin account @@ -123,7 +92,9 @@ def test_positive_list_default_content_with_admin(self): assert title in scap_contents @tier1 - def test_negative_list_default_content_with_viewer_role(self): + def test_negative_list_default_content_with_viewer_role( + self, scap_content, default_viewer_role + ): """List the default scap content by user with viewer role :id: 1e909ffc-10d9-4bcd-b4bb-c26981912bb4 @@ -145,11 +116,14 @@ def test_negative_list_default_content_with_viewer_role(self): :CaseImportance: Critical """ - login, password = self.create_test_user_viewer_role() - result = Scapcontent.with_user(login, password).list() + result = Scapcontent.with_user( + default_viewer_role.login, default_viewer_role.password + ).list() assert len(result) == 0 with pytest.raises(CLIReturnCodeError): - Scapcontent.with_user(login, password).info({'title': self.title}) + Scapcontent.with_user(default_viewer_role.login, default_viewer_role.password).info( + {'title': scap_content['title']} + ) @tier1 def test_positive_view_scap_content_info_admin(self): @@ -204,12 +178,15 @@ def test_negative_info_scap_content(self): with pytest.raises(CLIReturnCodeError): Scapcontent.info({'id': invalid_scap_id}) + @pytest.mark.parametrize('title', **parametrized(valid_data_list())) @tier1 - def test_positive_create_scap_content_with_valid_title(self): + def test_positive_create_scap_content_with_valid_title(self, title): """Create scap-content with valid title :id: 68e9fbe2-e3c3-48e7-a774-f1260a3b7f4f + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -228,12 +205,8 @@ def test_positive_create_scap_content_with_valid_title(self): :CaseImportance: Critical """ - for title in valid_data_list(): - with self.subTest(title): - scap_content = make_scapcontent( - {'title': title, 'scap-file': settings.oscap.content_path} - ) - assert scap_content['title'] == title + scap_content = make_scapcontent({'title': title, 'scap-file': settings.oscap.content_path}) + assert scap_content['title'] == title @tier1 def test_negative_create_scap_content_with_same_title(self): @@ -269,12 +242,15 @@ def test_negative_create_scap_content_with_same_title(self): with pytest.raises(CLIFactoryError): make_scapcontent({'title': title, 'scap-file': settings.oscap.content_path}) + @pytest.mark.parametrize('title', **parametrized(invalid_names_list())) @tier1 - def test_negative_create_scap_content_with_invalid_title(self): + def test_negative_create_scap_content_with_invalid_title(self, title): """Create scap-content with invalid title :id: 90a2590e-a6ff-41f1-9e0a-67d4b16435c0 + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -291,17 +267,18 @@ def test_negative_create_scap_content_with_invalid_title(self): :CaseImportance: Critical """ - for title in invalid_names_list(): - with self.subTest(title): - with pytest.raises(CLIFactoryError): - make_scapcontent({'title': title, 'scap-file': settings.oscap.content_path}) + with pytest.raises(CLIFactoryError): + make_scapcontent({'title': title, 'scap-file': settings.oscap.content_path}) + @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @tier1 - def test_positive_create_scap_content_with_valid_originalfile_name(self): + def test_positive_create_scap_content_with_valid_originalfile_name(self, name): """Create scap-content with valid original file name :id: 25441174-11cb-4d9b-9ec5-b1c69411b5bc + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -318,19 +295,20 @@ def test_positive_create_scap_content_with_valid_originalfile_name(self): :CaseImportance: Critical """ - for name in valid_data_list(): - with self.subTest(name): - scap_content = make_scapcontent( - {'original-filename': name, 'scap-file': settings.oscap.content_path} - ) - assert scap_content['original-filename'] == name + scap_content = make_scapcontent( + {'original-filename': name, 'scap-file': settings.oscap.content_path} + ) + assert scap_content['original-filename'] == name + @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) @tier1 - def test_negative_create_scap_content_with_invalid_originalfile_name(self): + def test_negative_create_scap_content_with_invalid_originalfile_name(self, name): """Create scap-content with invalid original file name :id: 83feb67a-a6bf-4a99-923d-889e8d1013fa + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -349,19 +327,18 @@ def test_negative_create_scap_content_with_invalid_originalfile_name(self): :BZ: 1482395 """ - for name in invalid_names_list(): - with self.subTest(name): - with pytest.raises(CLIFactoryError): - make_scapcontent( - {'original-filename': name, 'scap-file': settings.oscap.content_path} - ) + with pytest.raises(CLIFactoryError): + make_scapcontent({'original-filename': name, 'scap-file': settings.oscap.content_path}) + @pytest.mark.parametrize('title', **parametrized(valid_data_list())) @tier1 - def test_negative_create_scap_content_without_dsfile(self): + def test_negative_create_scap_content_without_dsfile(self, title): """Create scap-content without scap data stream xml file :id: ea811994-12cd-4382-9382-37fa806cc26f + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -377,10 +354,8 @@ def test_negative_create_scap_content_without_dsfile(self): :CaseImportance: Critical """ - for title in valid_data_list(): - with self.subTest(title): - with pytest.raises(CLIFactoryError): - make_scapcontent({'title': title}) + with pytest.raises(CLIFactoryError): + make_scapcontent({'title': title}) @tier1 def test_positive_update_scap_content_with_newtitle(self): @@ -467,12 +442,15 @@ def test_positive_delete_scap_content_with_title(self): with pytest.raises(CLIReturnCodeError): Scapcontent.info({'title': scap_content['title']}) + @pytest.mark.parametrize('name', **parametrized(valid_data_list())) @tier2 - def test_postive_create_scap_policy_with_valid_name(self): + def test_postive_create_scap_policy_with_valid_name(self, name, scap_content): """Create scap policy with valid name :id: c9327675-62b2-4e22-933a-02818ef68c11 + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -486,26 +464,27 @@ def test_postive_create_scap_policy_with_valid_name(self): :expectedresults: The policy is created successfully. """ - for name in valid_data_list(): - with self.subTest(name): - scap_policy = make_scap_policy( - { - 'name': name, - 'deploy-by': 'puppet', - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.scap_profile_id_rhel7, - 'period': OSCAP_PERIOD['weekly'].lower(), - 'weekday': OSCAP_WEEKDAY['friday'].lower(), - } - ) - assert scap_policy['name'] == name + scap_policy = make_scap_policy( + { + 'name': name, + 'deploy-by': 'puppet', + '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['name'] == name + @pytest.mark.parametrize('name', **parametrized(invalid_names_list())) @tier2 - def test_negative_create_scap_policy_with_invalid_name(self): + def test_negative_create_scap_policy_with_invalid_name(self, name, scap_content): """Create scap policy with invalid name :id: 0d163968-7759-4cfd-9c4d-98533d8db925 + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -519,22 +498,20 @@ def test_negative_create_scap_policy_with_invalid_name(self): :expectedresults: The policy is not created. """ - for name in invalid_names_list(): - with self.subTest(name): - with pytest.raises(CLIFactoryError): - make_scap_policy( - { - 'name': name, - 'deploy-by': 'puppet', - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.scap_profile_id_rhel7, - 'period': OSCAP_PERIOD['weekly'].lower(), - 'weekday': OSCAP_WEEKDAY['friday'].lower(), - } - ) + with pytest.raises(CLIFactoryError): + make_scap_policy( + { + 'name': name, + 'deploy-by': 'puppet', + '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(), + } + ) @tier2 - def test_negative_create_scap_policy_without_content(self): + def test_negative_create_scap_policy_without_content(self, scap_content): """Create scap policy without scap content :id: 88a8fba3-f45a-4e22-9ee1-f0d701f1135f @@ -556,14 +533,14 @@ def test_negative_create_scap_policy_without_content(self): make_scap_policy( { 'deploy-by': 'puppet', - 'scap-content-profile-id': self.scap_profile_id_rhel7, + 'scap-content-profile-id': scap_content["scap_profile_id"], 'period': OSCAP_PERIOD['weekly'].lower(), 'weekday': OSCAP_WEEKDAY['friday'].lower(), } ) @tier2 - def test_positive_associate_scap_policy_with_hostgroups(self): + def test_positive_associate_scap_policy_with_hostgroups(self, scap_content): """Associate hostgroups to scap policy :id: 916403a0-572d-4cf3-9155-3e3d0373577f @@ -589,8 +566,8 @@ def test_positive_associate_scap_policy_with_hostgroups(self): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.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'], @@ -599,7 +576,7 @@ def test_positive_associate_scap_policy_with_hostgroups(self): assert scap_policy['hostgroups'][0] == hostgroup['name'] @tier2 - def test_positive_associate_scap_policy_with_hostgroup_via_ansible(self): + def test_positive_associate_scap_policy_with_hostgroup_via_ansible(self, scap_content): """Associate hostgroup to scap policy via ansible :id: 2df303c6-bff5-4977-a865-a3afabfb8726 @@ -627,8 +604,8 @@ def test_positive_associate_scap_policy_with_hostgroup_via_ansible(self): { 'name': name, 'deploy-by': 'ansible', - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.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'], @@ -637,13 +614,18 @@ def test_positive_associate_scap_policy_with_hostgroup_via_ansible(self): assert scap_policy['deployment-option'] == 'ansible' assert scap_policy['hostgroups'][0] == hostgroup['name'] + @pytest.mark.parametrize('deploy', **parametrized(['manual', 'puppet', 'ansible'])) @upgrade @tier2 - def test_positive_associate_scap_policy_with_tailoringfiles(self): + def test_positive_associate_scap_policy_with_tailoringfiles( + self, deploy, scap_content, tailoring_file_path + ): """Associate tailoring file by name/id to scap policy with all deployments :id: d0f9b244-b92d-4889-ba6a-8973ea05bf43 + :parametrized: yes + :steps: 1. Login to hammer shell. @@ -653,79 +635,81 @@ def test_positive_associate_scap_policy_with_tailoringfiles(self): :expectedresults: The policy is created and associated successfully. """ - tailoring_file_a = make_tailoringfile({'scap-file': self.tailoring_file_path}) + tailoring_file_a = make_tailoringfile({'scap-file': tailoring_file_path['satellite']}) tailoring_file_profile_a_id = tailoring_file_a['tailoring-file-profiles'][0]['id'] - tailoring_file_b = make_tailoringfile({'scap-file': self.tailoring_file_path}) + tailoring_file_b = make_tailoringfile({'scap-file': tailoring_file_path['satellite']}) tailoring_file_profile_b_id = tailoring_file_b['tailoring-file-profiles'][0]['id'] - for deploy in ['manual', 'puppet', 'ansible']: - with self.subTest(deploy): - scap_policy = make_scap_policy( - { - 'scap-content-id': self.scap_id_rhel7, - 'deploy-by': deploy, - 'scap-content-profile-id': self.scap_profile_id_rhel7, - 'period': OSCAP_PERIOD['weekly'].lower(), - 'weekday': OSCAP_WEEKDAY['friday'].lower(), - 'tailoring-file': tailoring_file_a['name'], - 'tailoring-file-profile-id': tailoring_file_profile_a_id, - } - ) - assert scap_policy['deployment-option'] == deploy - assert scap_policy['tailoring-file-id'] == tailoring_file_a['id'] - assert scap_policy['tailoring-file-profile-id'] == tailoring_file_profile_a_id - - Scappolicy.update( - { - 'name': scap_policy['name'], - 'tailoring-file': tailoring_file_b['name'], - 'tailoring-file-profile-id': tailoring_file_profile_b_id, - } - ) - scap_info = Scappolicy.info({'name': scap_policy['name']}) - assert scap_info['tailoring-file-id'] == tailoring_file_b['id'] - assert scap_info['tailoring-file-profile-id'] == tailoring_file_profile_b_id - - Scappolicy.delete({'name': scap_policy['name']}) - with pytest.raises(CLIReturnCodeError): - Scapcontent.info({'name': scap_policy['name']}) - - scap_policy = make_scap_policy( - { - 'scap-content-id': self.scap_id_rhel7, - 'deploy-by': deploy, - 'scap-content-profile-id': self.scap_profile_id_rhel7, - 'period': OSCAP_PERIOD['weekly'].lower(), - 'weekday': OSCAP_WEEKDAY['friday'].lower(), - 'tailoring-file-id': tailoring_file_a['id'], - 'tailoring-file-profile-id': tailoring_file_profile_a_id, - } - ) - assert scap_policy['deployment-option'] == deploy - assert scap_policy['tailoring-file-id'] == tailoring_file_a['id'] - assert scap_policy['tailoring-file-profile-id'] == tailoring_file_profile_a_id - - Scappolicy.update( - { - 'id': scap_policy['id'], - 'tailoring-file-id': tailoring_file_b['id'], - 'tailoring-file-profile-id': tailoring_file_profile_b_id, - } - ) - scap_info = Scappolicy.info({'id': scap_policy['id']}) - assert scap_info['tailoring-file-id'] == tailoring_file_b['id'] - assert scap_info['tailoring-file-profile-id'] == tailoring_file_profile_b_id - - Scappolicy.delete({'id': scap_policy['id']}) - with pytest.raises(CLIReturnCodeError): - Scapcontent.info({'name': scap_policy['name']}) + scap_policy = make_scap_policy( + { + 'scap-content-id': scap_content["scap_id"], + 'deploy-by': deploy, + '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'], + 'tailoring-file-profile-id': tailoring_file_profile_a_id, + } + ) + assert scap_policy['deployment-option'] == deploy + assert scap_policy['tailoring-file-id'] == tailoring_file_a['id'] + assert scap_policy['tailoring-file-profile-id'] == tailoring_file_profile_a_id + + Scappolicy.update( + { + 'name': scap_policy['name'], + 'tailoring-file': tailoring_file_b['name'], + 'tailoring-file-profile-id': tailoring_file_profile_b_id, + } + ) + scap_info = Scappolicy.info({'name': scap_policy['name']}) + assert scap_info['tailoring-file-id'] == tailoring_file_b['id'] + assert scap_info['tailoring-file-profile-id'] == tailoring_file_profile_b_id + + Scappolicy.delete({'name': scap_policy['name']}) + with pytest.raises(CLIReturnCodeError): + Scapcontent.info({'name': scap_policy['name']}) + + scap_policy = make_scap_policy( + { + 'scap-content-id': scap_content["scap_id"], + 'deploy-by': deploy, + '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'], + 'tailoring-file-profile-id': tailoring_file_profile_a_id, + } + ) + assert scap_policy['deployment-option'] == deploy + assert scap_policy['tailoring-file-id'] == tailoring_file_a['id'] + assert scap_policy['tailoring-file-profile-id'] == tailoring_file_profile_a_id + + Scappolicy.update( + { + 'id': scap_policy['id'], + 'tailoring-file-id': tailoring_file_b['id'], + 'tailoring-file-profile-id': tailoring_file_profile_b_id, + } + ) + scap_info = Scappolicy.info({'id': scap_policy['id']}) + assert scap_info['tailoring-file-id'] == tailoring_file_b['id'] + assert scap_info['tailoring-file-profile-id'] == tailoring_file_profile_b_id + + Scappolicy.delete({'id': scap_policy['id']}) + with pytest.raises(CLIReturnCodeError): + Scapcontent.info({'name': scap_policy['name']}) + + @pytest.mark.parametrize('deploy', **parametrized(['manual', 'puppet', 'ansible'])) @upgrade @tier2 - def test_positive_scap_policy_end_to_end(self): + def test_positive_scap_policy_end_to_end(self, deploy, scap_content): """List all scap policies and read info using id, name :id: d14ab43e-c7a9-4eee-b61c-420b07ca1da9 + :parametrized: yes + :setup: 1. Oscap should be enabled. @@ -742,43 +726,41 @@ def test_positive_scap_policy_end_to_end(self): :expectedresults: The policies are listed successfully and information is displayed. """ - for deploy in ['manual', 'puppet', 'ansible']: - with self.subTest(deploy): - hostgroup = make_hostgroup() - name = gen_string('alphanumeric') - scap_policy = make_scap_policy( - { - 'name': name, - 'deploy-by': deploy, - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.scap_profile_id_rhel7, - 'period': OSCAP_PERIOD['weekly'].lower(), - 'weekday': OSCAP_WEEKDAY['friday'].lower(), - 'hostgroups': hostgroup['name'], - } - ) - result = Scappolicy.list() - assert name in [policy['name'] for policy in result] - assert Scappolicy.info({'id': scap_policy['id']})['id'] == scap_policy['id'] - assert Scappolicy.info({'name': scap_policy['name']})['name'] == name - - Scappolicy.update( - { - 'id': scap_policy['id'], - 'period': OSCAP_PERIOD['monthly'].lower(), - 'day-of-month': 15, - } - ) - scap_info = Scappolicy.info({'name': name}) - assert scap_info['period'] == OSCAP_PERIOD['monthly'].lower() - assert scap_info['day-of-month'] == '15' - Scappolicy.delete({'id': scap_policy['id']}) - with pytest.raises(CLIReturnCodeError): - Scappolicy.info({'id': scap_policy['id']}) + hostgroup = make_hostgroup() + name = gen_string('alphanumeric') + scap_policy = make_scap_policy( + { + 'name': name, + 'deploy-by': deploy, + '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'], + } + ) + result = Scappolicy.list() + assert name in [policy['name'] for policy in result] + assert Scappolicy.info({'id': scap_policy['id']})['id'] == scap_policy['id'] + assert Scappolicy.info({'name': scap_policy['name']})['name'] == name + + Scappolicy.update( + { + 'id': scap_policy['id'], + 'period': OSCAP_PERIOD['monthly'].lower(), + 'day-of-month': 15, + } + ) + scap_info = Scappolicy.info({'name': name}) + assert scap_info['period'] == OSCAP_PERIOD['monthly'].lower() + assert scap_info['day-of-month'] == '15' + Scappolicy.delete({'id': scap_policy['id']}) + with pytest.raises(CLIReturnCodeError): + Scappolicy.info({'id': scap_policy['id']}) @upgrade @tier2 - def test_positive_update_scap_policy_with_hostgroup(self): + def test_positive_update_scap_policy_with_hostgroup(self, scap_content): """Update scap policy by addition of hostgroup :id: 21b9b82b-7c6c-4944-bc2f-67631e1d4086 @@ -803,8 +785,8 @@ def test_positive_update_scap_policy_with_hostgroup(self): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.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'], @@ -822,7 +804,7 @@ def test_positive_update_scap_policy_with_hostgroup(self): assert scap_info['deployment-option'] == 'ansible' @tier2 - def test_positive_update_scap_policy_period(self): + def test_positive_update_scap_policy_period(self, scap_content): """Update scap policy by updating the period strategy from monthly to weekly @@ -847,8 +829,8 @@ def test_positive_update_scap_policy_period(self): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.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(), } @@ -867,7 +849,7 @@ def test_positive_update_scap_policy_period(self): @tier2 @upgrade - def test_positive_update_scap_policy_with_content(self): + def test_positive_update_scap_policy_with_content(self, scap_content): """Update the scap policy by updating the scap content associated with the policy @@ -892,13 +874,13 @@ def test_positive_update_scap_policy_with_content(self): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.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'] == self.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'] ) @@ -910,7 +892,7 @@ def test_positive_update_scap_policy_with_content(self): assert scap_info['scap-content-profile-id'] == scap_profile_id[0] @tier2 - def test_positive_associate_scap_policy_with_single_server(self): + def test_positive_associate_scap_policy_with_single_server(self, scap_content): """Assign an audit policy to a single server :id: 30566c27-f466-4b4d-beaf-0a5bfda98b89 @@ -936,8 +918,8 @@ def test_positive_associate_scap_policy_with_single_server(self): { 'name': name, 'deploy-by': 'puppet', - 'scap-content-id': self.scap_id_rhel7, - 'scap-content-profile-id': self.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/conftest.py b/tests/foreman/ui/conftest.py index 0b9355a9dd5..ae9ad48ea18 100644 --- a/tests/foreman/ui/conftest.py +++ b/tests/foreman/ui/conftest.py @@ -71,28 +71,6 @@ def module_user(request, module_org, module_loc): LOGGER.warning('Unable to delete session user: %s', str(err)) -@fixture(scope='module') -def module_viewer_user(module_org): - """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 = nailgun.entities.Role().search(query={'search': 'name="Viewer"'})[0] - default_loc_id = ( - nailgun.entities.Location().search(query={'search': 'name="{}"'.format(DEFAULT_LOC)})[0].id - ) - custom_password = gen_string('alphanumeric') - custom_user = nailgun.entities.User( - admin=False, - default_organization=module_org, - location=[default_loc_id], - organization=[module_org], - role=[viewer_role], - password=custom_password, - ).create() - custom_user.password = custom_password - return custom_user - - @fixture() def test_name(request): """Returns current test full name, prefixed by module name and test class diff --git a/tests/foreman/ui/test_bookmarks.py b/tests/foreman/ui/test_bookmarks.py index 9823038ae6e..d84daa212a3 100644 --- a/tests/foreman/ui/test_bookmarks.py +++ b/tests/foreman/ui/test_bookmarks.py @@ -119,7 +119,7 @@ def test_positive_end_to_end(session, random_entity): @tier2 -def test_positive_create_bookmark_public(session, random_entity, module_viewer_user, test_name): +def test_positive_create_bookmark_public(session, random_entity, default_viewer_role, test_name): """Create and check visibility of the (non)public bookmarks :id: 93139529-7690-429b-83fe-3dcbac4f91dc @@ -153,14 +153,14 @@ def test_positive_create_bookmark_public(session, random_entity, module_viewer_u {'name': name, 'query': gen_string('alphanumeric'), 'public': name == public_name} ) assert session.bookmark.search(name)[0]['Name'] == name - with Session(test_name, module_viewer_user.login, module_viewer_user.password) as session: + with Session(test_name, default_viewer_role.login, default_viewer_role.password) as session: assert session.bookmark.search(public_name)[0]['Name'] == public_name assert not session.bookmark.search(nonpublic_name) @tier2 def test_positive_update_bookmark_public( - session, random_entity, module_viewer_user, module_user, test_name + session, random_entity, default_viewer_role, module_user, test_name ): """Update and save a bookmark public state @@ -209,7 +209,7 @@ def test_positive_update_bookmark_public( cfg, name=name, controller=random_entity['controller'], public=name == public_name ).create() with Session( - test_name, module_viewer_user.login, module_viewer_user.password + test_name, default_viewer_role.login, default_viewer_role.password ) as non_admin_session: assert non_admin_session.bookmark.search(public_name)[0]['Name'] == public_name assert not non_admin_session.bookmark.search(nonpublic_name) @@ -217,14 +217,14 @@ def test_positive_update_bookmark_public( session.bookmark.update(public_name, {'public': False}) session.bookmark.update(nonpublic_name, {'public': True}) with Session( - test_name, module_viewer_user.login, module_viewer_user.password + test_name, default_viewer_role.login, default_viewer_role.password ) as non_admin_session: assert non_admin_session.bookmark.search(nonpublic_name)[0]['Name'] == nonpublic_name assert not non_admin_session.bookmark.search(public_name) @tier2 -def test_negative_delete_bookmark(random_entity, module_viewer_user, test_name): +def test_negative_delete_bookmark(random_entity, default_viewer_role, test_name): """Simple removal of a bookmark query without permissions :id: 1a94bf2b-bcc6-4663-b70d-e13244a0783b @@ -247,7 +247,7 @@ def test_negative_delete_bookmark(random_entity, module_viewer_user, test_name): """ bookmark = entities.Bookmark(controller=random_entity['controller'], public=True).create() with Session( - test_name, module_viewer_user.login, module_viewer_user.password + test_name, default_viewer_role.login, default_viewer_role.password ) as non_admin_session: assert non_admin_session.bookmark.search(bookmark.name)[0]['Name'] == bookmark.name with raises(NoSuchElementException): diff --git a/tests/foreman/ui/test_contenthost.py b/tests/foreman/ui/test_contenthost.py index b3281ba9b61..4adce9649c6 100644 --- a/tests/foreman/ui/test_contenthost.py +++ b/tests/foreman/ui/test_contenthost.py @@ -495,7 +495,7 @@ def test_actions_katello_host_package_update_timeout(session, vm): @tier3 -def test_positive_search_errata_non_admin(session, vm, module_org, test_name, module_viewer_user): +def test_positive_search_errata_non_admin(session, vm, module_org, test_name, default_viewer_role): """Search for host's errata by non-admin user with enough permissions :id: 5b8887d2-987f-4bce-86a1-8f65ca7e1195 @@ -511,7 +511,7 @@ def test_positive_search_errata_non_admin(session, vm, module_org, test_name, mo """ vm.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) with Session( - test_name, user=module_viewer_user.login, password=module_viewer_user.password + test_name, user=default_viewer_role.login, password=default_viewer_role.password ) as session: chost = session.contenthost.read(vm.hostname, widget_names='errata') assert FAKE_2_ERRATA_ID in {errata['Id'] for errata in chost['errata']['table']} 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(), }