Skip to content

Commit

Permalink
Add ansible, oscap, smartproxy and user component fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
Jameer Pathan committed Oct 8, 2020
1 parent c001f61 commit 7253937
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 64 deletions.
4 changes: 4 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
10 changes: 10 additions & 0 deletions pytest_fixtures/ansible_fixtures.py
Original file line number Diff line number Diff line change
@@ -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})
63 changes: 0 additions & 63 deletions pytest_fixtures/api_fixtures.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
26 changes: 26 additions & 0 deletions pytest_fixtures/oscap_fixtures.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions pytest_fixtures/smartproxy_fixtures.py
Original file line number Diff line number Diff line change
@@ -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')
27 changes: 27 additions & 0 deletions pytest_fixtures/user_fixtures.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/foreman/cli/test_oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7253937

Please sign in to comment.