From 7253937445af6aec1797b79d5def96d8b0968271 Mon Sep 17 00:00:00 2001 From: Jameer Pathan Date: Thu, 8 Oct 2020 12:47:38 +0530 Subject: [PATCH] Add ansible, oscap, smartproxy and user component fixtures --- conftest.py | 4 ++ pytest_fixtures/ansible_fixtures.py | 10 ++++ pytest_fixtures/api_fixtures.py | 63 -------------------------- pytest_fixtures/oscap_fixtures.py | 26 +++++++++++ pytest_fixtures/smartproxy_fixtures.py | 24 ++++++++++ pytest_fixtures/user_fixtures.py | 27 +++++++++++ tests/foreman/cli/test_oscap.py | 2 +- 7 files changed, 92 insertions(+), 64 deletions(-) create mode 100644 pytest_fixtures/ansible_fixtures.py create mode 100644 pytest_fixtures/oscap_fixtures.py create mode 100644 pytest_fixtures/smartproxy_fixtures.py create mode 100644 pytest_fixtures/user_fixtures.py diff --git a/conftest.py b/conftest.py index 23f0f3db4e6..4d81758a6ab 100644 --- a/conftest.py +++ b/conftest.py @@ -11,4 +11,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 5d88d4515b0..43d58bd3879 100644 --- a/pytest_fixtures/api_fixtures.py +++ b/pytest_fixtures/api_fixtures.py @@ -1,14 +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.cli.ansible import Ansible from robottelo.constants import AZURERM_RG_DEFAULT from robottelo.constants import AZURERM_RHEL7_FT_BYOS_IMG_URN from robottelo.constants import AZURERM_RHEL7_FT_CUSTOM_IMG_URN @@ -25,7 +21,6 @@ from robottelo.constants import RHEL_6_MAJOR_VERSION from robottelo.constants import RHEL_7_MAJOR_VERSION from robottelo.helpers import download_gce_cert -from robottelo.helpers import file_downloader from robottelo.test import settings # Global Satellite Entities @@ -64,16 +59,6 @@ def module_lce(module_org): return entities.LifecycleEnvironment(organization=module_org).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] @@ -393,55 +378,7 @@ def default_contentview(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 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}) - - @pytest.fixture(scope='session') def default_pxetemplate(): pxe_template = entities.ProvisioningTemplate().search(query={'search': DEFAULT_PXE_TEMPLATE}) return pxe_template[0].read() - - -@pytest.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 = 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], - organization=[module_org], - role=[viewer_role], - password=custom_password, - ).create() - custom_user.password = custom_password - return custom_user diff --git a/pytest_fixtures/oscap_fixtures.py b/pytest_fixtures/oscap_fixtures.py new file mode 100644 index 00000000000..d06bb175a3c --- /dev/null +++ b/pytest_fixtures/oscap_fixtures.py @@ -0,0 +1,26 @@ +import os + +import pytest + +from robottelo import ssh +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 diff --git a/pytest_fixtures/smartproxy_fixtures.py b/pytest_fixtures/smartproxy_fixtures.py new file mode 100644 index 00000000000..57a4b11db9b --- /dev/null +++ b/pytest_fixtures/smartproxy_fixtures.py @@ -0,0 +1,24 @@ +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(): + smart_proxy = ( + entities.SmartProxy() + .search(query={'search': f'name={settings.server.hostname}'})[0] + .read() + ) + 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..896cf10fb25 --- /dev/null +++ b/pytest_fixtures/user_fixtures.py @@ -0,0 +1,27 @@ +import pytest +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): + """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], + organization=[module_org], + role=[viewer_role], + password=custom_password, + ).create() + custom_user.password = custom_password + return custom_user diff --git a/tests/foreman/cli/test_oscap.py b/tests/foreman/cli/test_oscap.py index 8eb4a430f29..e1cf70d64e9 100644 --- a/tests/foreman/cli/test_oscap.py +++ b/tests/foreman/cli/test_oscap.py @@ -63,7 +63,7 @@ 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): + 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: