Browse Source

fix: get group by path should not raise on 404

pull/627/head
Richard Nemeth 1 week ago
parent
commit
b9f8bd29d0
No known key found for this signature in database GPG Key ID: 21C39470DF3DEC39
  1. 4
      src/keycloak/keycloak_admin.py
  2. 18
      tests/test_keycloak_admin.py

4
src/keycloak/keycloak_admin.py

@ -1149,7 +1149,7 @@ class KeycloakAdmin:
data_raw = self.connection.raw_get(
urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path)
)
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakGetError, [200, 404])
def create_group(self, payload, parent=None, skip_exists=False):
"""Create a group in the Realm.
@ -5460,7 +5460,7 @@ class KeycloakAdmin:
data_raw = await self.connection.a_raw_get(
urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path)
)
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakGetError, [200, 404])
async def a_create_group(self, payload, parent=None, skip_exists=False):
"""Create a group in the Realm asynchronously.

18
tests/test_keycloak_admin.py

@ -845,9 +845,12 @@ def test_groups(admin: KeycloakAdmin, user: str):
assert res is not None, res
assert res["id"] == subgroup_id_1, res
with pytest.raises(KeycloakGetError) as err:
admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
assert err.match('404: b\'{"error":"Group path does not exist".*}\'')
res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
assert res == {
"error": "Group path does not exist",
"error_description": "For more on this error consult the server log at the "
"debug level.",
}, res
res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1")
assert res is not None, res
@ -3947,9 +3950,12 @@ async def test_a_groups(admin: KeycloakAdmin, user: str):
assert res is not None, res
assert res["id"] == subgroup_id_1, res
with pytest.raises(KeycloakGetError) as err:
await admin.a_get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
assert err.match('404: b\'{"error":"Group path does not exist".*}\'')
res = await admin.a_get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
assert res == {
"error": "Group path does not exist",
"error_description": "For more on this error consult the server log at the "
"debug level.",
}, res
res = await admin.a_get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1")
assert res is not None, res

Loading…
Cancel
Save