e2e_tests/recipes/authentik/tests_authentik/cleanup_authentik.py
Daniel 0fafa22272 cleanup (#18)
- remove demo runner

- improve docs

- rename all tests to test_* (previously, also setup_* and cleanup_* existed) to improve stability as it is not guaranteed that pytest.ini is loaded.

- improve logging formatting

- improve full integration test

Reviewed-on: local-it-infrastructure/e2e_tests#18
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
2023-12-15 17:57:48 +01:00

40 lines
1.4 KiB
Python

import json
import os
import re
from playwright.sync_api import BrowserContext
from pytest_abra import BaseUrl, DirManager
ADMIN_USER = os.environ["ADMIN_USER"]
ADMIN_PASS = os.environ["ADMIN_PASS"]
TEST_USER = os.environ["TEST_USER"]
TEST_PASS = os.environ["TEST_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 test_cleanup_delete_user(
context: BrowserContext, env_config: dict[str, str], DIR: DirManager, URL: BaseUrl, check_if_user_exists
):
# load admin cookies to context
state_file = DIR.STATES / "authentik_admin_state.json"
storage_state = json.loads(state_file.read_bytes())
context.add_cookies(storage_state["cookies"])
if check_if_user_exists(context, env_config, URL):
remove_user(context, URL)
assert not check_if_user_exists(context, env_config, URL)