Browse Source

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.
pull/439/head
Armin Shoughi 2 years ago
parent
commit
09cf503415
  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__( def __init__(
self, self,
server_url,
server_url=None,
username=None, username=None,
password=None, password=None,
token=None, token=None,

13
tests/test_keycloak_admin.py

@ -19,6 +19,8 @@ from keycloak.exceptions import (
KeycloakPutError, KeycloakPutError,
) )
from src.keycloak import KeycloakOpenIDConnection
def test_keycloak_version(): def test_keycloak_version():
"""Test version.""" """Test version."""
@ -111,6 +113,17 @@ def test_keycloak_admin_init(env):
is None 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): def test_realms(admin: KeycloakAdmin):
"""Test realms. """Test realms.

Loading…
Cancel
Save