-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest conversion for tests/foreman/cli/test_oscap.py (#8011)
* pytest conversion for tests/foreman/cli/test_oscap.py * Add ansible, oscap, smartproxy and user component fixtures * Add few more fixtures and resolve jyejare * rename fixture module_viewer_user Co-authored-by: Jameer Pathan <[email protected]>
- Loading branch information
1 parent
4ff06d4
commit d8131a0
Showing
12 changed files
with
336 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.