Skip to content

Commit

Permalink
client as a param
Browse files Browse the repository at this point in the history
No-Issue
  • Loading branch information
chr-stian committed Mar 8, 2024
1 parent 4cbba91 commit f01ed2c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
20 changes: 11 additions & 9 deletions galaxy_ng/tests/integration/api/rbac_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@

from ansible.galaxy.api import GalaxyError

from galaxy_ng.tests.integration.utils.iqe_utils import is_ephemeral_env, get_ansible_config, \
from galaxy_ng.tests.integration.utils.iqe_utils import get_ansible_config, \
get_galaxy_client, AnsibleConfigFixture
from galaxy_ng.tests.integration.utils.rbac_utils import create_local_image_container
from galaxykit.container_images import get_container, get_container_images_latest
ansible_config = get_ansible_config()
CLIENT_CONFIG = ansible_config("admin")
ADMIN_CLIENT = get_client(CLIENT_CONFIG)

'''
ansible_config = get_ansible_config()
galaxy_client = get_galaxy_client(ansible_config)
if is_ephemeral_env():
gc_admin = galaxy_client("admin", basic_token=True)
else:
gc_admin = galaxy_client("admin", basic_token=False, ignore_cache=True)
'''

API_ROOT = CLIENT_CONFIG["url"]
PULP_API_ROOT = f"{API_ROOT}pulp/api/v3/"
Expand Down Expand Up @@ -524,11 +526,11 @@ def __del__(self):


class ReusableLocalContainer:
def __init__(self, name):
def __init__(self, name, gc):
self._ns_name = f"ee_ns_{name}"
self._repo_name = f"ee_local_{name}"
self._name = f"{self._ns_name}/{self._repo_name}"

self.gc = gc
self._reset()

def _reset(self):
Expand All @@ -541,19 +543,19 @@ def _reset(self):
# 2. get roles in namespace
# 3. remove roles and groups (clean container namespace)

self._container = get_container(gc_admin, self._name)
ns_r = gc_admin.get(f"pulp/api/v3/pulp_container/namespaces/?name={self._ns_name}")
self._container = get_container(self.gc, self._name)
ns_r = self.gc.get(f"pulp/api/v3/pulp_container/namespaces/?name={self._ns_name}")
pulp_namespace_path = ns_r["results"][0]["pulp_href"]
# get roles first
roles = gc_admin.get(f"{pulp_namespace_path}list_roles")
roles = self.gc.get(f"{pulp_namespace_path}list_roles")
for role in roles["roles"]:
body = {
'role': role["role"]
}
gc_admin.post(path=f"{pulp_namespace_path}remove_role/", body=body)
self.gc.post(path=f"{pulp_namespace_path}remove_role/", body=body)

self._namespace = gc_admin.get(pulp_namespace_path)
self._manifest = get_container_images_latest(gc_admin, self._name)
self._namespace = self.gc.get(pulp_namespace_path)
self._manifest = get_container_images_latest(self.gc, self._name)

def get_container(self):
return self._container
Expand Down
5 changes: 3 additions & 2 deletions galaxy_ng/tests/integration/api/test_pulp_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@


@pytest.fixture
def local_container():
return ReusableLocalContainer('int_tests')
def local_container(galaxy_client):
gc = galaxy_client("admin", ignore_cache=True)
return ReusableLocalContainer('int_tests', gc)


@pytest.mark.deployment_standalone
Expand Down
20 changes: 11 additions & 9 deletions galaxy_ng/tests/integration/api/test_rbac_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@


# initialize the extra objects once for all the tests. This saves ~20 seconds per test
def _get_reusable_extras():
def _get_reusable_extras(gc):
global REUSABLE_EXTRA

if len(REUSABLE_EXTRA) == 0:
Expand All @@ -635,7 +635,7 @@ def _get_reusable_extras():
"collection": ReusableCollection(gen_string()),
"registry": _registry,
"remote_ee": ReusableRemoteContainer(gen_string(), _registry_pk),
"local_ee": ReusableLocalContainer(gen_string()),
"local_ee": ReusableLocalContainer(gen_string(), gc),
"custom_staging_repo": ReusableAnsibleRepository(
f"repo-test-{generate_random_string()}", is_staging=True),
"custom_repo": ReusableAnsibleRepository(
Expand All @@ -650,16 +650,16 @@ def _get_reusable_extras():

@pytest.mark.rbac_roles
@pytest.mark.parametrize("role", ROLES_TO_TEST)
def test_global_role_actions(role):
def test_global_role_actions(role, galaxy_client):
USERNAME = f"{NAMESPACE}_user_{gen_string()}"

user = create_user(USERNAME, PASSWORD)
group = create_group_for_user(user, role)
group_id = group['id']

expected_allows = ROLES_TO_TEST[role]

extra = _get_reusable_extras()
gc = galaxy_client("admin", ignore_cache=True)
extra = _get_reusable_extras(gc)

failures = []
# Test global actions
Expand All @@ -679,10 +679,11 @@ def test_global_role_actions(role):

@pytest.mark.rbac_roles
@pytest.mark.parametrize("role", OBJECT_ROLES_TO_TEST)
def test_object_role_actions(role):
def test_object_role_actions(role, galaxy_client):
USERNAME = f"{NAMESPACE}_user_{gen_string()}"

extra = _get_reusable_extras()
gc = galaxy_client("admin", ignore_cache=True)
extra = _get_reusable_extras(gc)

namespace_href = extra["collection"].get_namespace()["pulp_href"]
repo_href = extra["custom_repo"].get_repo()["pulp_href"]
Expand Down Expand Up @@ -740,8 +741,9 @@ def _apply_roles():


@pytest.mark.rbac_roles
def test_role_actions_for_admin():
extra = _get_reusable_extras()
def test_role_actions_for_admin(galaxy_client):
gc = galaxy_client("admin", ignore_cache=True)
extra = _get_reusable_extras(gc)
failures = []

# Test global actions
Expand Down
5 changes: 3 additions & 2 deletions galaxy_ng/tests/integration/api/test_ui_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ def test_api_ui_v1_execution_environments_registries(ansible_config):
# /api/automation-hub/_ui/v1/execution-environments/remotes/{pulp_id}/

@pytest.fixture
def local_container():
return ReusableLocalContainer('int_tests')
def local_container(galaxy_client):
gc = galaxy_client("admin", ignore_cache=True)
return ReusableLocalContainer('int_tests', gc)


# /api/automation-hub/_ui/v1/feature-flags/
Expand Down

0 comments on commit f01ed2c

Please sign in to comment.