Skip to content

Commit b9f8bd2

Browse files
committed
fix: get group by path should not raise on 404
1 parent 4d269ba commit b9f8bd2

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/keycloak/keycloak_admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ def get_group_by_path(self, path):
11491149
data_raw = self.connection.raw_get(
11501150
urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path)
11511151
)
1152-
return raise_error_from_response(data_raw, KeycloakGetError)
1152+
return raise_error_from_response(data_raw, KeycloakGetError, [200, 404])
11531153

11541154
def create_group(self, payload, parent=None, skip_exists=False):
11551155
"""Create a group in the Realm.
@@ -5460,7 +5460,7 @@ async def a_get_group_by_path(self, path):
54605460
data_raw = await self.connection.a_raw_get(
54615461
urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path)
54625462
)
5463-
return raise_error_from_response(data_raw, KeycloakGetError)
5463+
return raise_error_from_response(data_raw, KeycloakGetError, [200, 404])
54645464

54655465
async def a_create_group(self, payload, parent=None, skip_exists=False):
54665466
"""Create a group in the Realm asynchronously.

tests/test_keycloak_admin.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,12 @@ def test_groups(admin: KeycloakAdmin, user: str):
845845
assert res is not None, res
846846
assert res["id"] == subgroup_id_1, res
847847

848-
with pytest.raises(KeycloakGetError) as err:
849-
admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
850-
assert err.match('404: b\'{"error":"Group path does not exist".*}\'')
848+
res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
849+
assert res == {
850+
"error": "Group path does not exist",
851+
"error_description": "For more on this error consult the server log at the "
852+
"debug level.",
853+
}, res
851854

852855
res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1")
853856
assert res is not None, res
@@ -3947,9 +3950,12 @@ async def test_a_groups(admin: KeycloakAdmin, user: str):
39473950
assert res is not None, res
39483951
assert res["id"] == subgroup_id_1, res
39493952

3950-
with pytest.raises(KeycloakGetError) as err:
3951-
await admin.a_get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
3952-
assert err.match('404: b\'{"error":"Group path does not exist".*}\'')
3953+
res = await admin.a_get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
3954+
assert res == {
3955+
"error": "Group path does not exist",
3956+
"error_description": "For more on this error consult the server log at the "
3957+
"debug level.",
3958+
}, res
39533959

39543960
res = await admin.a_get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1")
39553961
assert res is not None, res

0 commit comments

Comments
 (0)