-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3462 from rverdile/764
feat: add GetEnvironments method to DBus register
- Loading branch information
Showing
5 changed files
with
273 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# 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 | ||
# implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
# along with this software; if not, see | ||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
# | ||
# Red Hat trademarks are not licensed under GPLv2. No permission is | ||
# granted to use or replicate Red Hat trademarks that are incorporated | ||
# in this software or its documentation. | ||
import logging | ||
from typing import List | ||
|
||
|
||
from rhsm.connection import UEPConnection | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class EnvironmentService: | ||
""" | ||
Class for using environments | ||
""" | ||
|
||
def __init__(self, cp: UEPConnection) -> None: | ||
""" | ||
Initialization of EnvironmentService instance | ||
:param cp: connection to Candlepin | ||
""" | ||
self.cp = cp | ||
|
||
def list(self, org_id: str) -> List[dict]: | ||
""" | ||
Method for listing environments | ||
:param org_id: organization to list environments for | ||
:return: List of environments. | ||
""" | ||
list_all = self.cp.has_capability("typed_environments") | ||
environments = self.cp.getEnvironmentList(org_id, list_all=list_all) | ||
|
||
return environments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# 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 | ||
# implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
# along with this software; if not, see | ||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
# | ||
# Red Hat trademarks are not licensed under GPLv2. No permission is | ||
# granted to use or replicate Red Hat trademarks that are incorporated | ||
# in this software or its documentation. | ||
from unittest import mock | ||
|
||
from test.rhsmlib.base import InjectionMockingTest | ||
|
||
from rhsm import connection | ||
|
||
from rhsmlib.services import environment | ||
|
||
|
||
ENVIRONMENTS_JSON = [ | ||
{ | ||
"created": "2024-10-03T18:12:56+0000", | ||
"updated": "2024-10-03T18:12:56+0000", | ||
"id": "8bdf14cf9e534119a1fe617c03304768", | ||
"name": "template 1", | ||
"type": "content-template", | ||
"description": "my template", | ||
"owner": { | ||
"id": "8ad980939253781c01925378340e0002", | ||
"key": "content-sources-test", | ||
"displayName": "ContentSourcesTest", | ||
"href": "/owners/content-sources-test", | ||
"contentAccessMode": "org_environment", | ||
}, | ||
"environmentContent": [ | ||
{"contentId": "11055", "enabled": True}, | ||
{"contentId": "56a3a98c76ea4e16bd68424a2c9cc1c1", "enabled": True}, | ||
{"contentId": "11049", "enabled": True}, | ||
], | ||
}, | ||
{ | ||
"created": "2024-10-09T19:08:14+0000", | ||
"updated": "2024-10-09T19:08:14+0000", | ||
"id": "6c62889601be41128fe2fece53141fd4", | ||
"name": "template 2", | ||
"type": "content-template", | ||
"description": "my template", | ||
"owner": { | ||
"id": "8ad980939253781c01925378340e0002", | ||
"key": "content-sources-test", | ||
"displayName": "ContentSourcesTest", | ||
"href": "/owners/content-sources-test", | ||
"contentAccessMode": "org_environment", | ||
}, | ||
"environmentContent": [ | ||
{"contentId": "11055", "enabled": True}, | ||
{"contentId": "11049", "enabled": True}, | ||
], | ||
}, | ||
] | ||
|
||
|
||
class TestEnvironmentService(InjectionMockingTest): | ||
def setUp(self): | ||
super(TestEnvironmentService, self).setUp() | ||
self.mock_cp = mock.Mock(spec=connection.UEPConnection, name="UEPConnection") | ||
|
||
def injection_definitions(self, *args, **kwargs): | ||
return None | ||
|
||
def test_list_environments(self): | ||
self.mock_cp.getEnvironmentList.return_value = ENVIRONMENTS_JSON | ||
|
||
result = environment.EnvironmentService(self.mock_cp).list("org") | ||
self.assertEqual(ENVIRONMENTS_JSON, result) |