From af645b7192060d774e7bebd281011aee7d40cee2 Mon Sep 17 00:00:00 2001 From: rverdile Date: Mon, 18 Nov 2024 11:28:30 -0500 Subject: [PATCH] filter out unwanted fields --- src/rhsmlib/dbus/objects/register.py | 15 ++++------ test/rhsmlib/dbus/test_register.py | 23 +++++++++++++-- test/rhsmlib/services/test_environment.py | 35 +++++++---------------- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/rhsmlib/dbus/objects/register.py b/src/rhsmlib/dbus/objects/register.py index 0209059a3c..b516f0d8c5 100644 --- a/src/rhsmlib/dbus/objects/register.py +++ b/src/rhsmlib/dbus/objects/register.py @@ -193,17 +193,12 @@ def get_environments(self, options: dict) -> List[dict]: environments = environment_service.list(options["org_id"], typed_environments=True) - result: List[dict] = [] + keys_to_remove: List[str] = ["created", "updated", "contentPrefix", "owner", "environmentContent"] for environment in environments: - result.append( - { - "id": environment["id"], - "name": environment["name"], - "description": environment["description"], - "type": environment["type"], - }) - - return result + for key in keys_to_remove: + environment.pop(key, None) + + return environments def register_with_credentials( self, organization: Optional[str], register_options: dict, connection_options: dict diff --git a/test/rhsmlib/dbus/test_register.py b/test/rhsmlib/dbus/test_register.py index b6dda48105..d7408ea7b2 100644 --- a/test/rhsmlib/dbus/test_register.py +++ b/test/rhsmlib/dbus/test_register.py @@ -124,22 +124,34 @@ ENVIRONMENTS_CONTENT_JSON = """[ { + "created": "2024-11-07T20:01:47+0000", + "updated": "2024-11-07T20:01:47+0000", "id": "fake-id", "name": "test-environment", "description": "test description", - "type": "content-template" + "contentPrefix": null, + "type": "content-template", + "environmentContent": [] }, { + "created": "2024-11-07T20:01:47+0000", + "updated": "2024-11-07T20:01:47+0000", "id": "fake-id-2", "name": "test-environment-2", "description": "test description", - "type": "content-template" + "contentPrefix": null, + "type": "content-template", + "environmentContent": [] }, { + "created": "2024-11-07T20:01:47+0000", + "updated": "2024-11-07T20:01:47+0000", "id": "fake-id-3", "name": "test-environment-3", "description": "test description", - "type": "content-template" + "contentPrefix": null, + "type": "content-template", + "environmentContent": [] } ] """ @@ -339,6 +351,11 @@ def test_GetEnvironments(self): 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) + result = self.impl.get_environments( {"username": "username", "password": "password", "org_id": "org_id"} ) diff --git a/test/rhsmlib/services/test_environment.py b/test/rhsmlib/services/test_environment.py index 5aa4b57038..25af9f58cc 100644 --- a/test/rhsmlib/services/test_environment.py +++ b/test/rhsmlib/services/test_environment.py @@ -32,22 +32,13 @@ "key": "content-sources-test", "displayName": "ContentSourcesTest", "href": "/owners/content-sources-test", - "contentAccessMode": "org_environment" + "contentAccessMode": "org_environment", }, "environmentContent": [ - { - "contentId": "11055", - "enabled": True - }, - { - "contentId": "56a3a98c76ea4e16bd68424a2c9cc1c1", - "enabled": True - }, - { - "contentId": "11049", - "enabled": True - }, - ] + {"contentId": "11055", "enabled": True}, + {"contentId": "56a3a98c76ea4e16bd68424a2c9cc1c1", "enabled": True}, + {"contentId": "11049", "enabled": True}, + ], }, { "created": "2024-10-09T19:08:14+0000", @@ -61,19 +52,13 @@ "key": "content-sources-test", "displayName": "ContentSourcesTest", "href": "/owners/content-sources-test", - "contentAccessMode": "org_environment" + "contentAccessMode": "org_environment", }, "environmentContent": [ - { - "contentId": "11055", - "enabled": True - }, - { - "contentId": "11049", - "enabled": True - }, - ] - } + {"contentId": "11055", "enabled": True}, + {"contentId": "11049", "enabled": True}, + ], + }, ]