From 905e0caa038ed77b3bb8ed9a442ded435c3fb7c4 Mon Sep 17 00:00:00 2001 From: Richard Nemeth Date: Tue, 19 Jul 2022 17:44:09 +0200 Subject: [PATCH] test: improved the tests on urls, back to 100% --- tests/test_keycloak_admin.py | 1 + tests/test_keycloak_openid.py | 2 +- tests/test_urls_patterns.py | 12 ++++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index 6d62f22..2d34a18 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -1844,6 +1844,7 @@ def test_get_required_action_by_alias(admin: KeycloakAdmin, realm: str): ra = admin.get_required_action_by_alias("UPDATE_PASSWORD") assert ra in ractions assert ra["alias"] == "UPDATE_PASSWORD" + assert admin.get_required_action_by_alias("does-not-exist") is None def test_update_required_action(admin: KeycloakAdmin, realm: str): diff --git a/tests/test_keycloak_openid.py b/tests/test_keycloak_openid.py index 8eccb0f..6bee648 100644 --- a/tests/test_keycloak_openid.py +++ b/tests/test_keycloak_openid.py @@ -106,7 +106,7 @@ def test_auth_url(env, oid: KeycloakOpenID): res == f"http://{env.KEYCLOAK_HOST}:{env.KEYCLOAK_PORT}/realms/{oid.realm_name}" + f"/protocol/openid-connect/auth?client_id={oid.client_id}&response_type=code" - + "&redirect_uri=http://test.test/*&scope=email&state= " + + "&redirect_uri=http://test.test/*&scope=email&state=" ) diff --git a/tests/test_urls_patterns.py b/tests/test_urls_patterns.py index 5fae847..5c412b2 100644 --- a/tests/test_urls_patterns.py +++ b/tests/test_urls_patterns.py @@ -1,5 +1,5 @@ """Test URL patterns.""" - +import inspect from keycloak import urls_patterns @@ -15,7 +15,12 @@ def test_correctness_of_patterns(): # Test that the patterns have unique names seen_urls = list() - for url in urls: + urls_from_src = [ + x.split("=")[0].strip() + for x in inspect.getsource(urls_patterns).splitlines() + if x.startswith("URL_") + ] + for url in urls_from_src: assert url not in seen_urls, f"The url pattern {url} is present twice." seen_urls.append(url) @@ -24,4 +29,7 @@ def test_correctness_of_patterns(): for url in urls: url_value = urls_patterns.__dict__[url] assert url_value not in seen_url_values, f"The url {url} has a duplicate value {url_value}" + assert ( + url_value == url_value.strip() + ), f"The url {url} with value '{url_value}' has whitespace values" seen_url_values.append(url_value)