Browse Source

fix: Initializing KeycloakAdmin without server_url (#439)

* fix: initializing KeycloakAdmin without server_url

According to the project readme, we could initialize a KeycloakAdmin object with a KeycloakOpenIDConnection object without other arguments but, server_url is required.

I made server_url optional and wrote a test for it.

* Revert "fix: initializing KeycloakAdmin without server_url"

This reverts commit 09cf503415.

* fix: initializing KeycloakAdmin without server_url

According to the project readme, we could initialize a KeycloakAdmin object with a KeycloakOpenIDConnection object without other arguments but, server_url is required.

I made server_url optional and wrote a test for it.

* fix: check linting, formatting

---------

Co-authored-by: Armin Shoughi <a.shoughi@hesaba.co>
pull/441/head v2.16.1
armin shoughi 2 years ago
committed by GitHub
parent
commit
fab186501b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/keycloak/keycloak_admin.py
  2. 13
      tests/test_keycloak_admin.py

2
src/keycloak/keycloak_admin.py

@ -88,7 +88,7 @@ class KeycloakAdmin:
def __init__(
self,
server_url,
server_url=None,
username=None,
password=None,
token=None,

13
tests/test_keycloak_admin.py

@ -9,7 +9,7 @@ import pytest
from dateutil import parser as datetime_parser
import keycloak
from keycloak import KeycloakAdmin, KeycloakOpenID
from keycloak import KeycloakAdmin, KeycloakOpenID, KeycloakOpenIDConnection
from keycloak.connection import ConnectionManager
from keycloak.exceptions import (
KeycloakAuthenticationError,
@ -111,6 +111,17 @@ def test_keycloak_admin_init(env):
is None
)
keycloak_connection = KeycloakOpenIDConnection(
server_url=f"http://{env.KEYCLOAK_HOST}:{env.KEYCLOAK_PORT}",
username=env.KEYCLOAK_ADMIN,
password=env.KEYCLOAK_ADMIN_PASSWORD,
realm_name="master",
client_id="admin-cli",
verify=True,
)
keycloak_admin = KeycloakAdmin(connection=keycloak_connection)
assert keycloak_admin.token
def test_realms(admin: KeycloakAdmin):
"""Test realms.

Loading…
Cancel
Save