Skip to content

Commit

Permalink
filter out unwanted fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rverdile committed Nov 18, 2024
1 parent b4030d0 commit af645b7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
15 changes: 5 additions & 10 deletions src/rhsmlib/dbus/objects/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 20 additions & 3 deletions test/rhsmlib/dbus/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
]
"""
Expand Down Expand Up @@ -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"}
)
Expand Down
35 changes: 10 additions & 25 deletions test/rhsmlib/services/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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},
],
},
]


Expand Down

0 comments on commit af645b7

Please sign in to comment.