Browse Source
Merge pull request #325 from marcospereirampj/213-allow-query-parameters-for-users_count
fix: allow query parameters for users count
163-remove-forced-selfget_token-or-allow-override
v1.0.1
Richard Nemeth
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
11 additions and
2 deletions
-
src/keycloak/keycloak_admin.py
-
tests/test_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): |
|
|
|
|
|
@ -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 |
|
|
|