Browse Source

fix: removed dead code, stabilized tests

pull/556/head
Richard Nemeth 8 months ago
parent
commit
4bd55baea7
No known key found for this signature in database GPG Key ID: 21C39470DF3DEC39
  1. 6
      src/keycloak/keycloak_admin.py
  2. 9
      tests/test_keycloak_admin.py

6
src/keycloak/keycloak_admin.py

@ -989,8 +989,6 @@ class KeycloakAdmin:
group["subGroups"] = self.get_group_children(
group_id=group.get("id"), full_hierarchy=full_hierarchy
)
else:
group["subGroups"] = []
return groups
@ -1022,8 +1020,6 @@ class KeycloakAdmin:
group["subGroups"] = self.get_group_children(
group.get("id"), full_hierarchy=full_hierarchy
)
else:
group["subGroups"] = []
return group
@ -1086,8 +1082,6 @@ class KeycloakAdmin:
group["subGroups"] = self.get_group_children(
group_id=group.get("id"), full_hierarchy=full_hierarchy
)
else:
group["subGroups"] = []
return res

9
tests/test_keycloak_admin.py

@ -1,12 +1,14 @@
"""Test the keycloak admin object."""
import copy
import os
import uuid
from typing import Tuple
import freezegun
import pytest
from dateutil import parser as datetime_parser
from packaging.version import Version
import keycloak
from keycloak import KeycloakAdmin, KeycloakOpenID, KeycloakOpenIDConnection
@ -805,14 +807,17 @@ def test_groups(admin: KeycloakAdmin, user: str):
res = admin.get_groups(full_hierarchy=True)
assert len(res) == 1
assert len(res[0]["subGroups"]) == 2
assert len(res[0]["subGroups"][0]["subGroups"]) == 0
assert len(res[0]["subGroups"][1]["subGroups"]) == 1
assert len([x for x in res[0]["subGroups"] if x["id"] == subgroup_id_1][0]["subGroups"]) == 0
assert len([x for x in res[0]["subGroups"] if x["id"] == subgroup_id_2][0]["subGroups"]) == 1
# Test that query params are not allowed for full hierarchy
with pytest.raises(ValueError) as err:
admin.get_group_children(group_id=group_id, full_hierarchy=True, query={"max": 10})
# Test that query params are passed
if os.environ["KEYCLOAK_DOCKER_IMAGE_TAG"] == "latest" or Version(
os.environ["KEYCLOAK_DOCKER_IMAGE_TAG"]
) >= Version("23"):
res = admin.get_group_children(group_id=group_id, query={"max": 1})
assert len(res) == 1

Loading…
Cancel
Save