Browse Source

fix: allow query parameters for users count

pull/325/head
Richard Nemeth 3 years ago
parent
commit
d9c3326fd1
No known key found for this signature in database GPG Key ID: 21C39470DF3DEC39
  1. 9
      src/keycloak/keycloak_admin.py
  2. 4
      tests/test_keycloak_admin.py

9
src/keycloak/keycloak_admin.py

@ -464,14 +464,19 @@ class KeycloakAdmin:
_last_slash_idx = data_raw.headers["Location"].rindex("/")
return data_raw.headers["Location"][_last_slash_idx + 1 :] # noqa: E203
def users_count(self):
def users_count(self, query=None):
"""
User counter
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_users_resource
:param query: (dict) Query parameters for users count
:return: counter
"""
query = query or dict()
params_path = {"realm-name": self.realm_name}
data_raw = self.raw_get(urls_patterns.URL_ADMIN_USERS_COUNT.format(**params_path))
data_raw = self.raw_get(urls_patterns.URL_ADMIN_USERS_COUNT.format(**params_path), **query)
return raise_error_from_response(data_raw, KeycloakGetError)
def get_user_id(self, username):

4
tests/test_keycloak_admin.py

@ -184,6 +184,10 @@ def test_users(admin: KeycloakAdmin, realm: str):
count = admin.users_count()
assert count == 1, count
# Test users count with query
count = admin.users_count(query={"username": "notpresent"})
assert count == 0
# Test user groups
groups = admin.get_user_groups(user_id=user["id"])
assert len(groups) == 0

Loading…
Cancel
Save