Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/keycloak/keycloak_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
HTTP_CONFLICT,
HTTP_CREATED,
HTTP_NO_CONTENT,
HTTP_NOT_FOUND,
HTTP_OK,
KeycloakDeleteError,
KeycloakGetError,
Expand Down Expand Up @@ -1942,6 +1941,8 @@ def get_group_by_path(self, path: str) -> dict:

Returns full group details for a group defined by path

Raises an `KeycloakGetError` if the group was not found.

GroupRepresentation
https://www.keycloak.org/docs-api/24.0.2/rest-api/#_grouprepresentation

Expand All @@ -1954,7 +1955,11 @@ def get_group_by_path(self, path: str) -> dict:
data_raw = self.connection.raw_get(
urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path),
)
return raise_error_from_response(data_raw, KeycloakGetError, [HTTP_OK, HTTP_NOT_FOUND])
# PR https://github.com/marcospereirampj/python-keycloak/pull/627
# added `HTTP_NOT_FOUND` to the `expected_codes` argument.
# This change has since been reverted, see:
# https://github.com/marcospereirampj/python-keycloak/issues/675
return raise_error_from_response(data_raw, KeycloakGetError)

def create_group(
self,
Expand Down
6 changes: 4 additions & 2 deletions tests/test_keycloak_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,10 @@ def test_groups(admin: KeycloakAdmin, user: str) -> None:
assert res is not None, res
assert res["id"] == subgroup_id_1, res

res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
assert res["error"] == "Group path does not exist"
# See https://github.com/marcospereirampj/python-keycloak/issues/675
with pytest.raises(KeycloakGetError) as err:
admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/does-not-exist")
assert err.match('404: b\'{"error":"Group path does not exist".*}\'')

res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1")
assert res is not None, res
Expand Down
Loading