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/430/head
armin shoughi 2 years ago
committed by elias.hamacher
parent
commit
d0f10806e6
  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

@ -9,7 +9,7 @@ import pytest
from dateutil import parser as datetime_parser from dateutil import parser as datetime_parser
import keycloak import keycloak
from keycloak import KeycloakAdmin, KeycloakOpenID
from keycloak import KeycloakAdmin, KeycloakOpenID, KeycloakOpenIDConnection
from keycloak.connection import ConnectionManager from keycloak.connection import ConnectionManager
from keycloak.exceptions import ( from keycloak.exceptions import (
KeycloakAuthenticationError, KeycloakAuthenticationError,
@ -111,6 +111,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