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. 13
      tests/test_keycloak_admin.py

6
src/keycloak/keycloak_admin.py

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

13
tests/test_keycloak_admin.py

@ -1,12 +1,14 @@
"""Test the keycloak admin object.""" """Test the keycloak admin object."""
import copy import copy
import os
import uuid import uuid
from typing import Tuple from typing import Tuple
import freezegun import freezegun
import pytest import pytest
from dateutil import parser as datetime_parser from dateutil import parser as datetime_parser
from packaging.version import Version
import keycloak import keycloak
from keycloak import KeycloakAdmin, KeycloakOpenID, KeycloakOpenIDConnection from keycloak import KeycloakAdmin, KeycloakOpenID, KeycloakOpenIDConnection
@ -805,16 +807,19 @@ def test_groups(admin: KeycloakAdmin, user: str):
res = admin.get_groups(full_hierarchy=True) res = admin.get_groups(full_hierarchy=True)
assert len(res) == 1 assert len(res) == 1
assert len(res[0]["subGroups"]) == 2 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 # Test that query params are not allowed for full hierarchy
with pytest.raises(ValueError) as err: with pytest.raises(ValueError) as err:
admin.get_group_children(group_id=group_id, full_hierarchy=True, query={"max": 10}) admin.get_group_children(group_id=group_id, full_hierarchy=True, query={"max": 10})
# Test that query params are passed # Test that query params are passed
res = admin.get_group_children(group_id=group_id, query={"max": 1})
assert len(res) == 1
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
assert err.match("Cannot use both query and full_hierarchy parameters") assert err.match("Cannot use both query and full_hierarchy parameters")

Loading…
Cancel
Save