From baf6f6a6557c022af54eca2679da5494e74807b7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 14 Dec 2023 13:15:17 +0100 Subject: [PATCH] implement remove_user in authentik --- .../tests_authentik/cleanup_authentik.py | 22 ++++++++++++++----- .../tests_authentik/runner_authentik.py | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/recipes/authentik/tests_authentik/cleanup_authentik.py b/recipes/authentik/tests_authentik/cleanup_authentik.py index 3d65308..b556ea4 100644 --- a/recipes/authentik/tests_authentik/cleanup_authentik.py +++ b/recipes/authentik/tests_authentik/cleanup_authentik.py @@ -1,5 +1,6 @@ import json import os +import re from playwright.sync_api import BrowserContext @@ -11,8 +12,19 @@ TEST_USER = os.environ["TEST_USER"] TEST_PASS = os.environ["TEST_PASS"] -def remove_user(): - pass +def remove_user(admin_context: BrowserContext, URL: BaseUrl): + """removes TEST_USER account from authentik""" + page = admin_context.new_page() + page.goto(URL.get()) + page.get_by_role("link", name="Admin Interface").click() + nav = page.locator("ak-sidebar-item", has_text=re.compile(r"Directory|Verzeichnis")) + nav.click() + nav.get_by_role("link", name=re.compile(r"Users|Benutzer")).click() + + name_pattern = re.compile(TEST_USER) + page.get_by_role("row", name=name_pattern).get_by_label("").check() + page.get_by_role("button", name=re.compile(r"Löschen|Delete")).click() + page.get_by_role("dialog").get_by_role("button", name=re.compile(r"Löschen|Delete")).click() def cleanup_delete_user( @@ -24,7 +36,5 @@ def cleanup_delete_user( context.add_cookies(storage_state["cookies"]) if check_if_user_exists(context, env_config, URL): - # just login with user - assert False, "yes" - remove_user() - assert False, "no" + remove_user(context, URL) + assert not check_if_user_exists(context, env_config, URL) diff --git a/recipes/authentik/tests_authentik/runner_authentik.py b/recipes/authentik/tests_authentik/runner_authentik.py index 1079409..4e9b81a 100644 --- a/recipes/authentik/tests_authentik/runner_authentik.py +++ b/recipes/authentik/tests_authentik/runner_authentik.py @@ -5,4 +5,4 @@ class RunnerAuthentik(Runner): env_type = "authentik" setups = [Test(test_file="setup_authentik.py")] tests = [Test(test_file="test_authentik_blueprint_api.py")] - cleanups = [Test(test_file="cleanup_authentik.py", prevent_skip=True)] + cleanups = [Test(test_file="cleanup_authentik.py")]