Skip to content

Commit

Permalink
Add few more fixtures and resolve jyejare
Browse files Browse the repository at this point in the history
  • Loading branch information
jameerpathan111 committed Oct 13, 2020
1 parent 7253937 commit 84c4d2e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 127 deletions.
40 changes: 40 additions & 0 deletions pytest_fixtures/oscap_fixtures.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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'],
}
9 changes: 2 additions & 7 deletions pytest_fixtures/smartproxy_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
9 changes: 2 additions & 7 deletions pytest_fixtures/user_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
60 changes: 7 additions & 53 deletions tests/foreman/api/test_oscappolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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."""

Expand Down Expand Up @@ -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],
Expand All @@ -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
Expand Down
Loading

0 comments on commit 84c4d2e

Please sign in to comment.