Skip to content

Commit

Permalink
normalize type to empty string
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
rverdile committed Nov 19, 2024
1 parent af645b7 commit 0cd4904
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
11 changes: 10 additions & 1 deletion src/rhsmlib/dbus/objects/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,19 @@ def get_environments(self, options: dict) -> List[dict]:

environments = environment_service.list(options["org_id"], typed_environments=True)

keys_to_remove: List[str] = ["created", "updated", "contentPrefix", "owner", "environmentContent"]
keys_to_remove: List[str] = [
"created",
"updated",
"contentPrefix",
"owner",
"environmentContent",
]

for environment in environments:
for key in keys_to_remove:
environment.pop(key, None)
if ("type" not in environment) or (environment["type"] is None):
environment["type"] = ""

return environments

Expand Down
11 changes: 4 additions & 7 deletions src/rhsmlib/services/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ def list(self, org_id: str, typed_environments: bool = True) -> List[dict]:
:param typed_environments: Whether output should include typed environments
:return: List of environments.
"""

list_all = False
if typed_environments:
has_typed_environments = self.cp.has_capability("typed_environments")

if not has_typed_environments:
list_all = self.cp.has_capability("typed_environments")
if not list_all:
log.debug("candlepin does not have typed_environments capability")

environments = self.cp.getEnvironmentList(org_id, list_all=has_typed_environments)
else:
environments = self.cp.getEnvironmentList(org_id)
environments = self.cp.getEnvironmentList(org_id, list_all=list_all)

return environments
47 changes: 40 additions & 7 deletions test/rhsmlib/dbus/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from unittest import mock
from test.rhsmlib.base import SubManDBusFixture


CONSUMER_CONTENT_JSON_SCA = """{"hypervisorId": null,
"serviceLevel": "",
"autoheal": true,
Expand Down Expand Up @@ -150,12 +151,49 @@
"name": "test-environment-3",
"description": "test description",
"contentPrefix": null,
"type": "content-template",
"type": null,
"environmentContent": []
},
{
"created": "2024-11-07T20:01:47+0000",
"updated": "2024-11-07T20:01:47+0000",
"id": "fake-id-4",
"name": "test-environment-4",
"description": "test description",
"contentPrefix": null,
"environmentContent": []
}
]
"""

ENVIRONMENTS_DBUS_JSON = """[
{
"id": "fake-id",
"name": "test-environment",
"description": "test description",
"type": "content-template"
},
{
"id": "fake-id-2",
"name": "test-environment-2",
"description": "test description",
"type": "content-template"
},
{
"id": "fake-id-3",
"name": "test-environment-3",
"description": "test description",
"type": ""
},
{
"id": "fake-id-4",
"name": "test-environment-4",
"description": "test description",
"type": ""
}
]
"""


class RegisterDBusObjectTest(SubManDBusFixture):
socket_dir: Optional[tempfile.TemporaryDirectory] = None
Expand Down Expand Up @@ -350,12 +388,7 @@ def test_GetEnvironments(self):
mock_cp.getEnvironmentList.return_value = json.loads(ENVIRONMENTS_CONTENT_JSON)
self.patches["build_uep"].return_value = mock_cp

expected = json.loads(ENVIRONMENTS_CONTENT_JSON)
keys_to_remove = ["created", "updated", "contentPrefix", "owner", "environmentContent"]
for environment in expected:
for key in keys_to_remove:
environment.pop(key, None)

expected = json.loads(ENVIRONMENTS_DBUS_JSON)
result = self.impl.get_environments(
{"username": "username", "password": "password", "org_id": "org_id"}
)
Expand Down

0 comments on commit 0cd4904

Please sign in to comment.