Skip to content

Commit 2d90827

Browse files
committed
revert: Revert error handling change in KeycloakAdmin.get_group_by_path
This change was introduced in #627
1 parent ed0fd6d commit 2d90827

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/keycloak/keycloak_admin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
HTTP_CONFLICT,
4040
HTTP_CREATED,
4141
HTTP_NO_CONTENT,
42-
HTTP_NOT_FOUND,
4342
HTTP_OK,
4443
KeycloakDeleteError,
4544
KeycloakGetError,
@@ -1942,6 +1941,8 @@ def get_group_by_path(self, path: str) -> dict:
19421941
19431942
Returns full group details for a group defined by path
19441943
1944+
Raises an `KeycloakGetError` if the group was not found.
1945+
19451946
GroupRepresentation
19461947
https://www.keycloak.org/docs-api/24.0.2/rest-api/#_grouprepresentation
19471948
@@ -1954,7 +1955,11 @@ def get_group_by_path(self, path: str) -> dict:
19541955
data_raw = self.connection.raw_get(
19551956
urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path),
19561957
)
1957-
return raise_error_from_response(data_raw, KeycloakGetError, [HTTP_OK, HTTP_NOT_FOUND])
1958+
# PR https://github.com/marcospereirampj/python-keycloak/pull/627
1959+
# added `HTTP_NOT_FOUND` to the `expected_codes` argument.
1960+
# This change has since been reverted, see:
1961+
# https://github.com/marcospereirampj/python-keycloak/issues/675
1962+
return raise_error_from_response(data_raw, KeycloakGetError)
19581963

19591964
def create_group(
19601965
self,

tests/test_keycloak_admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,10 @@ def test_groups(admin: KeycloakAdmin, user: str) -> None:
10111011
assert res is not None, res
10121012
assert res["id"] == subgroup_id_1, res
10131013

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

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

0 commit comments

Comments
 (0)