Browse Source

fix: lint test fix

pull/566/head
David 11 months ago
parent
commit
7e13b682d9
  1. 10
      src/keycloak/keycloak_admin.py
  2. 36
      tests/test_keycloak_admin.py
  3. 8
      tests/test_keycloak_openid.py
  4. 2
      tests/test_keycloak_uma.py

10
src/keycloak/keycloak_admin.py

@ -4719,7 +4719,9 @@ class KeycloakAdmin:
:return: UserRepresentation
"""
params_path = {"realm-name": self.connection.realm_name, "id": user_id}
data_raw = await self.connection.a_raw_get(urls_patterns.URL_ADMIN_USER.format(**params_path))
data_raw = await self.connection.a_raw_get(
urls_patterns.URL_ADMIN_USER.format(**params_path)
)
return raise_error_from_response(data_raw, KeycloakGetError)
async def a_get_user_groups(self, user_id, query=None, brief_representation=True):
@ -5405,7 +5407,7 @@ class KeycloakAdmin:
:rtype: list
"""
params_path = {"realm-name": self.connection.realm_name}
data_raw =await self.connection.a_raw_get(
data_raw = await self.connection.a_raw_get(
urls_patterns.URL_ADMIN_CLIENTS.format(**params_path)
)
return raise_error_from_response(data_raw, KeycloakGetError)
@ -5422,7 +5424,7 @@ class KeycloakAdmin:
:rtype: dict
"""
params_path = {"realm-name": self.connection.realm_name, "id": client_id}
data_raw =await self.connection.a_raw_get(
data_raw = await self.connection.a_raw_get(
urls_patterns.URL_ADMIN_CLIENT.format(**params_path)
)
return raise_error_from_response(data_raw, KeycloakGetError)
@ -8197,7 +8199,7 @@ class KeycloakAdmin:
async def a_get_composite_client_roles_of_group(
self, client_id, group_id, brief_representation=True
):
):
"""Get the composite client roles of the given group for the given client asynchronously.
:param client_id: id of the client.

36
tests/test_keycloak_admin.py

@ -3066,6 +3066,7 @@ def test_refresh_token(admin: KeycloakAdmin):
# async function start
@pytest.mark.asyncio
async def test_a_realms(admin: KeycloakAdmin):
"""Test realms.
@ -3456,7 +3457,9 @@ async def test_a_user_groups_pagination(admin: KeycloakAdmin, realm: str):
groups = await admin.a_get_user_groups(user_id=user_id)
assert len(groups) == admin.PAGE_SIZE + 50, len(groups)
groups = await admin.a_get_user_groups(user_id=user_id, query={"first": 100, "max": -1, "search": ""})
groups = await admin.a_get_user_groups(
user_id=user_id, query={"first": 100, "max": -1, "search": ""}
)
assert len(groups) == 50, len(groups)
groups = await admin.a_get_user_groups(
@ -3736,7 +3739,7 @@ async def test_a_groups(admin: KeycloakAdmin, user: str):
# Create 1 more subgroup
subsubgroup_id_1 = await admin.a_create_group(
payload={"name": "subsubgroup-1"}, parent=subgroup_id_2
)
)
main_group = await admin.a_get_group(group_id=group_id)
# Test nested searches
@ -3749,7 +3752,7 @@ async def test_a_groups(admin: KeycloakAdmin, user: str):
# Test nested search from main group
res = await admin.a_get_subgroups(
group = await admin.a_get_group(group_id=group_id, full_hierarchy=True),
group=await admin.a_get_group(group_id=group_id, full_hierarchy=True),
path="/main-group/subgroup-2/subsubgroup-1",
)
assert res["id"] == subsubgroup_id_1
@ -4311,7 +4314,7 @@ async def test_a_realm_roles(admin: KeycloakAdmin, realm: str):
x["username"] for x in await admin.a_get_realm_role_members(role_name="offline_access")
]
assert admin.get_user(user_id=user_id)["username"] in [
x["username"]
x["username"]
for x in await admin.a_get_realm_role_members(role_name="test-realm-role-update")
]
@ -5439,10 +5442,9 @@ async def test_a_client_scopes(admin: KeycloakAdmin, realm: str):
client_scope_id=res, protocol_mapper_id=test_mapper["id"], payload=test_mapper
)
assert res_update == dict()
assert ((await admin.a_get_mappers_from_client_scope(client_scope_id=res))[0]["config"][
"user.attribute"
] == "test"
)
assert (await admin.a_get_mappers_from_client_scope(client_scope_id=res))[0]["config"][
"user.attribute"
] == "test"
# Test delete mapper
res_del = await admin.a_delete_mapper_from_client_scope(
@ -5572,10 +5574,10 @@ async def test_a_keys(admin: KeycloakAdmin, realm: str):
"""
await admin.a_change_current_realm(realm)
assert set((await admin.a_get_keys())["active"].keys()) == {
"AES",
"HS256",
"RS256",
"RSA-OAEP"
"AES",
"HS256",
"RS256",
"RSA-OAEP",
} or set((await admin.a_get_keys())["active"].keys()) == {"RSA-OAEP", "RS256", "HS512", "AES"}
assert {k["algorithm"] for k in (await admin.a_get_keys())["keys"]} == {
"HS256",
@ -5811,7 +5813,7 @@ async def test_a_get_role_client_level_children(
@pytest.mark.asyncio
async def test_a_upload_certificate(
admin: KeycloakAdmin, realm: str, client: str, selfsigned_cert: tuple
):
):
"""Test upload certificate.
:param admin: Keycloak Admin client
@ -5965,8 +5967,8 @@ async def test_a_default_realm_role_present(realm: str, admin: KeycloakAdmin) ->
assert (
len(
[
x["name"]
for x in await admin.a_get_realm_roles()
x["name"]
for x in await admin.a_get_realm_roles()
if x["name"] == f"default-roles-{realm}"
]
)
@ -5987,8 +5989,8 @@ async def test_a_get_default_realm_role_id(realm: str, admin: KeycloakAdmin) ->
assert (
await admin.a_get_default_realm_role_id()
== [
x["id"]
for x in await admin.a_get_realm_roles()
x["id"]
for x in await admin.a_get_realm_roles()
if x["name"] == f"default-roles-{realm}"
][0]
)

8
tests/test_keycloak_openid.py

@ -488,8 +488,10 @@ def test_device(oid_with_credentials_device: Tuple[KeycloakOpenID, str, str]):
"interval": 5,
}
# async function start
@pytest.mark.asyncio
async def test_a_well_known(oid: KeycloakOpenID):
"""Test the well_known method.
@ -781,7 +783,7 @@ async def test_a_decode_token(oid_with_credentials: Tuple[KeycloakOpenID, str, s
@pytest.mark.asyncio
async def test_a_load_authorization_config(
oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str]
):
):
"""Test load authorization config.
:param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization
@ -825,11 +827,11 @@ async def test_a_get_policies(oid_with_credentials_authz: Tuple[KeycloakOpenID,
policy.add_role(role="account/view-profile")
oid.authorization.policies["test"] = policy
assert [
str(x)
str(x)
for x in await oid.a_get_policies(token=token["access_token"], method_token_info="decode")
] == ["Policy: test (role)"]
assert [
repr(x)
repr(x)
for x in await oid.a_get_policies(token=token["access_token"], method_token_info="decode")
] == ["<Policy: test (role)>"]
oid.client_id = orig_client_id

2
tests/test_keycloak_uma.py

@ -311,8 +311,10 @@ def test_uma_permission_ticket(uma: KeycloakUMA):
uma.resource_set_delete(resource["_id"])
# async function start
@pytest.mark.asyncio
async def test_a_uma_well_known(uma: KeycloakUMA):
"""Test the well_known method.

Loading…
Cancel
Save