From d6c64aab322febf871aee96acdc1b27decb904b0 Mon Sep 17 00:00:00 2001 From: rverdile Date: Thu, 21 Nov 2024 08:37:33 -0500 Subject: [PATCH] cleanup --- src/rhsmlib/dbus/objects/register.py | 20 ++++++++++---------- src/rhsmlib/services/environment.py | 17 +++++------------ test/rhsmlib/services/test_environment.py | 8 +------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/rhsmlib/dbus/objects/register.py b/src/rhsmlib/dbus/objects/register.py index 0fe312094f..e2b68d559d 100644 --- a/src/rhsmlib/dbus/objects/register.py +++ b/src/rhsmlib/dbus/objects/register.py @@ -37,6 +37,14 @@ log = logging.getLogger(__name__) +ENVIRONMENTS_KEYS_TO_FILTER: List[str] = [ + "contentPrefix", + "created", + "environmentContent", + "owner", + "updated", +] + class RegisterDBusImplementation(base_object.BaseImplementation): def __init__(self): @@ -191,18 +199,10 @@ def get_environments(self, options: dict) -> List[dict]: uep: UEPConnection = self.build_uep(options, basic_auth_method=True) environment_service: EnvironmentService = EnvironmentService(uep) - environments = environment_service.list(options["org_id"], typed_environments=True) - - keys_to_remove: List[str] = [ - "created", - "updated", - "contentPrefix", - "owner", - "environmentContent", - ] + environments = environment_service.list(options["org_id"]) for environment in environments: - for key in keys_to_remove: + for key in ENVIRONMENTS_KEYS_TO_FILTER: environment.pop(key, None) if ("type" not in environment) or (environment["type"] is None): environment["type"] = "" diff --git a/src/rhsmlib/services/environment.py b/src/rhsmlib/services/environment.py index 7602b7498c..19dd110852 100644 --- a/src/rhsmlib/services/environment.py +++ b/src/rhsmlib/services/environment.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Red Hat, Inc. +# Copyright (c) 2024 Red Hat, Inc. # # This software is licensed to you under the GNU General Public License, # version 2 (GPLv2). There is NO WARRANTY for this software, express or @@ -23,30 +23,23 @@ class EnvironmentService: """ - Class for listing environments + Class for using environments """ def __init__(self, cp: UEPConnection) -> None: """ Initialization of EnvironmentService instance - :param cp: instance of connection? + :param cp: connection to Candlepin """ - self.plugin_manager = inj.require(inj.PLUGIN_MANAGER) self.cp = cp - def list(self, org_id: str, typed_environments: bool = True) -> List[dict]: + def list(self, org_id: str) -> List[dict]: """ Method for listing environments :param org_id: organization to list environments for - :param typed_environments: Whether output should include typed environments :return: List of environments. """ - list_all = False - if typed_environments: - list_all = self.cp.has_capability("typed_environments") - if not list_all: - log.debug("candlepin does not have typed_environments capability") - + list_all = self.cp.has_capability("typed_environments") environments = self.cp.getEnvironmentList(org_id, list_all=list_all) return environments diff --git a/test/rhsmlib/services/test_environment.py b/test/rhsmlib/services/test_environment.py index 25af9f58cc..1abc418ba9 100644 --- a/test/rhsmlib/services/test_environment.py +++ b/test/rhsmlib/services/test_environment.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Red Hat, Inc. +# Copyright (c) 2024 Red Hat, Inc. # # This software is licensed to you under the GNU General Public License, # version 2 (GPLv2). There is NO WARRANTY for this software, express or @@ -75,9 +75,3 @@ def test_list_environments(self): result = environment.EnvironmentService(self.mock_cp).list("org") self.assertEqual(ENVIRONMENTS_JSON, result) - - def test_list_environments_without_typed_environments(self): - self.mock_cp.getEnvironmentList.return_value = ENVIRONMENTS_JSON - - result = environment.EnvironmentService(self.mock_cp).list("org", typed_environments=False) - self.assertEqual(ENVIRONMENTS_JSON, result)