Skip to content

Commit

Permalink
Remove nailgun.entities imports in tests/foreman/cli (#15033)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapaioa committed May 29, 2024
1 parent 942b03e commit 4634b36
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 62 deletions.
7 changes: 4 additions & 3 deletions tests/foreman/cli/test_contentaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import time

from nailgun import entities
import pytest

from robottelo.config import settings
Expand Down Expand Up @@ -88,9 +87,11 @@ def vm(
rhel7_contenthost_module.register(
module_sca_manifest_org, None, rh_repo_setup_ak.name, module_target_sat
)
host = entities.Host().search(query={'search': f'name={rhel7_contenthost_module.hostname}'})
host = module_target_sat.api.Host().search(
query={'search': f'name={rhel7_contenthost_module.hostname}'}
)
host_id = host[0].id
host_content = entities.Host(id=host_id).read_json()
host_content = module_target_sat.api.Host(id=host_id).read_json()
assert host_content["subscription_status"] == 5
rhel7_contenthost_module.install_katello_host_tools()
return rhel7_contenthost_module
Expand Down
17 changes: 10 additions & 7 deletions tests/foreman/cli/test_contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import random

from fauxfactory import gen_alphanumeric, gen_string
from nailgun import entities
import pytest
from wrapanapi.entities.vm import VmState

Expand All @@ -38,10 +37,12 @@
@pytest.fixture(scope='module')
def module_rhel_content(module_entitlement_manifest_org, module_target_sat):
"""Returns RH repo after syncing it"""
product = entities.Product(
product = module_target_sat.api.Product(
name=constants.PRDS['rhel'], organization=module_entitlement_manifest_org
).search()[0]
reposet = entities.RepositorySet(name=constants.REPOSET['rhva6'], product=product).search()[0]
reposet = module_target_sat.api.RepositorySet(
name=constants.REPOSET['rhva6'], product=product
).search()[0]
data = {'basearch': 'x86_64', 'releasever': '6Server', 'product_id': product.id}
reposet.enable(data=data)

Expand Down Expand Up @@ -1044,10 +1045,12 @@ def test_positive_add_module_stream_filter_rule(self, module_org, target_sat):
repo_name=repo_name,
repo_url=settings.repos.module_stream_1.url,
)
repo = entities.Repository(name=repo_name).search(query={'organization_id': module_org.id})[
0
]
content_view = entities.ContentView(organization=module_org.id, repository=[repo]).create()
repo = target_sat.api.Repository(name=repo_name).search(
query={'organization_id': module_org.id}
)[0]
content_view = target_sat.api.ContentView(
organization=module_org.id, repository=[repo]
).create()
walrus_stream = target_sat.cli.ModuleStream.list({'search': "name=walrus, stream=5.21"})[0]
content_view = target_sat.cli.ContentView.info({'id': content_view.id})
assert content_view['yum-repositories'][0]['name'] == repo.name
Expand Down
17 changes: 10 additions & 7 deletions tests/foreman/cli/test_discoveryrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from box import Box
from fauxfactory import gen_choice, gen_integer, gen_string
from nailgun.entities import Role as RoleEntity, User as UserEntity
import pytest
from requests import HTTPError

Expand Down Expand Up @@ -439,12 +438,14 @@ class TestDiscoveryRuleRole:
"""Implements Foreman discovery Rules tests along with roles from CLI."""

@pytest.fixture(scope='class')
def class_user_manager(self, class_user_password, class_org, class_location):
def class_user_manager(self, class_target_sat, class_user_password, class_org, class_location):
try:
manager_role = RoleEntity().search(query={'search': 'name="Discovery Manager"'})[0]
manager_role = class_target_sat.api.Role().search(
query={'search': 'name="Discovery Manager"'}
)[0]
except IndexError:
pytest.fail('Discovery Manager role was not found, setup cannot continue')
user = UserEntity(
user = class_target_sat.api.User(
organization=[class_org],
location=[class_location],
password=class_user_password,
Expand All @@ -458,12 +459,14 @@ def class_user_manager(self, class_user_password, class_org, class_location):
logger.error('Exception while deleting class scope user entity in teardown')

@pytest.fixture(scope='class')
def class_user_reader(self, class_user_password, class_org, class_location):
def class_user_reader(self, class_target_sat, class_user_password, class_org, class_location):
try:
reader_role = RoleEntity().search(query={'search': 'name="Discovery Reader"'})[0]
reader_role = class_target_sat.api.Role().search(
query={'search': 'name="Discovery Reader"'}
)[0]
except IndexError:
pytest.fail('Discovery Manager role was not found, setup cannot continue')
user = UserEntity(
user = class_target_sat.api.User(
organization=[class_org],
location=[class_location],
password=class_user_password,
Expand Down
3 changes: 1 addition & 2 deletions tests/foreman/cli/test_hostgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

from fauxfactory import gen_integer
from nailgun import entities
import pytest

from robottelo.config import settings
Expand Down Expand Up @@ -117,7 +116,7 @@ def test_positive_create_with_multiple_entities_and_delete(
# Common entities
name = valid_hostgroups_list()[0]
loc = session_puppet_enabled_sat.cli_factory.make_location()
org_2 = entities.Organization().create()
org_2 = session_puppet_enabled_sat.api.Organization().create()
orgs = [module_puppet_org, org_2]
env = session_puppet_enabled_sat.cli_factory.make_environment(
{'location-ids': loc['id'], 'organization-ids': org_2.id}
Expand Down
21 changes: 10 additions & 11 deletions tests/foreman/cli/test_ldapauthsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

from fauxfactory import gen_string
from nailgun import entities
import pytest

from robottelo.constants import LDAP_ATTR, LDAP_SERVER_TYPE
Expand All @@ -22,15 +21,15 @@


@pytest.fixture
def ldap_tear_down():
def ldap_tear_down(module_target_sat):
"""Teardown the all ldap settings user, usergroup and ldap delete"""
yield
ldap_auth_sources = entities.AuthSourceLDAP().search()
ldap_auth_sources = module_target_sat.api.AuthSourceLDAP().search()
for ldap_auth in ldap_auth_sources:
users = entities.User(auth_source=ldap_auth).search()
users = module_target_sat.api.User(auth_source=ldap_auth).search()
for user in users:
user.delete()
user_groups = entities.UserGroup().search()
user_groups = module_target_sat.api.UserGroup().search()
if user_groups:
user_groups[0].delete()
ldap_auth.delete()
Expand Down Expand Up @@ -150,15 +149,15 @@ def test_positive_refresh_usergroup_with_ad(self, member_group, ad_data, module_
class TestIPAAuthSource:
"""Implements FreeIPA ldap auth feature tests in CLI"""

def _clean_up_previous_ldap(self):
def _clean_up_previous_ldap(self, sat_instance):
"""clean up the all ldap settings user, usergroup and ldap delete"""
ldap = entities.AuthSourceLDAP().search()
ldap = sat_instance.api.AuthSourceLDAP().search()
for ldap_auth in range(len(ldap)):
users = entities.User(auth_source=ldap[ldap_auth]).search()
users = sat_instance.api.User(auth_source=ldap[ldap_auth]).search()
for user in range(len(users)):
users[user].delete()
ldap[ldap_auth].delete()
user_groups = entities.UserGroup().search()
user_groups = sat_instance.api.UserGroup().search()
for user_group in user_groups:
user_group.delete()

Expand Down Expand Up @@ -218,7 +217,7 @@ def test_usergroup_sync_with_refresh(self, default_ipa_host, module_target_sat):
:CaseImportance: Medium
"""
self._clean_up_previous_ldap()
self._clean_up_previous_ldap(module_target_sat)
ipa_group_base_dn = default_ipa_host.group_base_dn.replace('foobargroup', 'foreman_group')
member_username = 'foreman_test'
member_group = 'foreman_group'
Expand Down Expand Up @@ -305,7 +304,7 @@ def test_usergroup_with_usergroup_sync(self, default_ipa_host, module_target_sat
:CaseImportance: Medium
"""
self._clean_up_previous_ldap()
self._clean_up_previous_ldap(module_target_sat)
ipa_group_base_dn = default_ipa_host.group_base_dn.replace('foobargroup', 'foreman_group')
member_username = 'foreman_test'
member_group = 'foreman_group'
Expand Down
3 changes: 1 addition & 2 deletions tests/foreman/cli/test_oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

from fauxfactory import gen_string
from nailgun import entities
import pytest

from robottelo.config import settings
Expand Down Expand Up @@ -956,7 +955,7 @@ def test_positive_associate_scap_policy_with_single_server(
:CaseImportance: Medium
"""
host = entities.Host()
host = module_target_sat.api.Host()
host.create()
name = gen_string('alpha')
scap_policy = module_target_sat.cli_factory.make_scap_policy(
Expand Down
5 changes: 2 additions & 3 deletions tests/foreman/cli/test_ostreebranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import random

from nailgun import entities
import pytest

from robottelo.config import settings
Expand All @@ -29,9 +28,9 @@


@pytest.fixture(scope='module')
def ostree_user_credentials():
def ostree_user_credentials(module_target_sat):
password = 'password'
user = entities.User(admin=True, password=password).create()
user = module_target_sat.api.User(admin=True, password=password).create()
return user.login, password


Expand Down
11 changes: 5 additions & 6 deletions tests/foreman/cli/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from string import punctuation

from fauxfactory import gen_alphanumeric, gen_integer, gen_string, gen_url
from nailgun import entities
import pytest
import requests
from wait_for import wait_for
Expand Down Expand Up @@ -230,7 +229,7 @@ def test_positive_create_with_yum_repo(self, repo_options, repo):
),
indirect=True,
)
def test_positive_create_with_auth_yum_repo(self, repo_options, repo):
def test_positive_create_with_auth_yum_repo(self, target_sat, repo_options, repo):
"""Create YUM repository with basic HTTP authentication
:id: da8309fd-3076-427b-a96f-8d883d6e944f
Expand All @@ -243,7 +242,7 @@ def test_positive_create_with_auth_yum_repo(self, repo_options, repo):
"""
for key in 'url', 'content-type':
assert repo.get(key) == repo_options[key]
repo = entities.Repository(id=repo['id']).read()
repo = target_sat.api.Repository(id=repo['id']).read()
assert repo.upstream_username == repo_options['upstream-username']

@pytest.mark.tier1
Expand Down Expand Up @@ -2624,7 +2623,7 @@ def test_positive_upload_file_to_file_repo(self, repo_options, repo, target_sat)
assert f'Successfully uploaded file {RPM_TO_UPLOAD}' in result[0]['message']
repo = target_sat.cli.Repository.info({'id': repo['id']})
assert repo['content-counts']['files'] == '1'
filesearch = entities.File().search(
filesearch = target_sat.api.File().search(
query={"search": f"name={RPM_TO_UPLOAD} and repository={repo['name']}"}
)
assert filesearch[0].name == RPM_TO_UPLOAD
Expand Down Expand Up @@ -2835,7 +2834,7 @@ def test_file_repo_contains_only_newer_file(self, repo_options, repo, target_sat
repo = target_sat.cli.Repository.info({'id': repo['id']})
# Assert there is only one file
assert repo['content-counts']['files'] == '1'
filesearch = entities.File().search(
filesearch = target_sat.api.File().search(
query={"search": f"name={text_file_name} and repository={repo['name']}"}
)
assert text_file_name == filesearch[0].name
Expand All @@ -2853,7 +2852,7 @@ def test_file_repo_contains_only_newer_file(self, repo_options, repo, target_sat
repo = target_sat.cli.Repository.info({'id': repo['id']})
# Assert there is still only one file
assert repo['content-counts']['files'] == '1'
filesearch = entities.File().search(
filesearch = target_sat.api.File().search(
query={"search": f"name={text_file_name} and repository={repo['name']}"}
)
# Assert file name has not changed
Expand Down
7 changes: 3 additions & 4 deletions tests/foreman/cli/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

from fauxfactory import gen_string
from nailgun import entities
import pytest

from robottelo.constants import PRDS, REPOS, REPOSET
Expand Down Expand Up @@ -184,13 +183,13 @@ def test_positive_delete_manifest_as_another_user(target_sat, function_entitleme
:CaseImportance: Medium
"""
org = entities.Organization().create()
org = target_sat.api.Organization().create()
user1_password = gen_string('alphanumeric')
user1 = entities.User(
user1 = target_sat.api.User(
admin=True, password=user1_password, organization=[org], default_organization=org
).create()
user2_password = gen_string('alphanumeric')
user2 = entities.User(
user2 = target_sat.api.User(
admin=True, password=user2_password, organization=[org], default_organization=org
).create()
# use the first admin to upload a manifest
Expand Down
Loading

0 comments on commit 4634b36

Please sign in to comment.