authentik setup and tracing #2
1 changed files with 27 additions and 16 deletions
|
|
@ -2,6 +2,7 @@ import json
|
|||
import os
|
||||
import re
|
||||
|
||||
from icecream import ic
|
||||
from playwright.sync_api import BrowserContext, expect
|
||||
|
||||
from src.dirmanager import DirManager
|
||||
|
|
@ -35,24 +36,28 @@ def test_create_admin_login(context: BrowserContext, dotenv_config: dict[str, st
|
|||
context.storage_state(path=f"{DIR.STATES}/admin_state.json")
|
||||
|
||||
|
||||
def check_if_user_exists(admin_context: BrowserContext, dotenv_config: dict[str, str]):
|
||||
# go to admin page
|
||||
page = admin_context.new_page()
|
||||
url = "https://" + dotenv_config["DOMAIN"]
|
||||
page.goto(url)
|
||||
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()
|
||||
result = page.get_by_text(TESTUSER["username"]).is_visible(timeout=TIMEOUT)
|
||||
return result
|
||||
|
||||
|
||||
def create_invite_link(admin_context: BrowserContext, dotenv_config: dict[str, str]):
|
||||
# go to admin page
|
||||
page = admin_context.new_page()
|
||||
url = "https://" + dotenv_config["DOMAIN"]
|
||||
page.goto(url)
|
||||
page.get_by_role("link", name="Admin Interface").click()
|
||||
|
||||
# regex approach (shorter):
|
||||
page.get_by_role("button", name=re.compile(r"Directory|Verzeichnis")).click()
|
||||
# the or approach:
|
||||
# button_dir_en = page.get_by_role("button", name="Directory")
|
||||
# page.get_by_role("button").get_by_text(re.compile("Verzeichnis|Directory")).click()
|
||||
# button_dir_de = page.get_by_text("Verzeichnis")
|
||||
# button_dir_en.or_(button_dir_de).click()
|
||||
|
||||
nav = page.locator("ak-sidebar-item", has_text=re.compile(r"Directory|Verzeichnis"))
|
||||
nav.get_by_role("link", name=re.compile(r"Users|Benutzer")).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"Invitations|Einladungen")).click()
|
||||
|
||||
# todo: only works if no links have been created yet (empty list)
|
||||
|
|
@ -102,10 +107,16 @@ def test_create_user_session(context: BrowserContext, dotenv_config: dict[str, s
|
|||
storage_state = json.loads(state_file.read_bytes())
|
||||
context.add_cookies(storage_state["cookies"])
|
||||
|
||||
# create invite_link
|
||||
invite_link = create_invite_link(context, dotenv_config)
|
||||
if check_if_user_exists(context, dotenv_config):
|
||||
# just login with user
|
||||
pass
|
||||
context.clear_cookies()
|
||||
else:
|
||||
## create user
|
||||
# create invite_link
|
||||
invite_link = create_invite_link(context, dotenv_config)
|
||||
# create user
|
||||
context.clear_cookies()
|
||||
create_user(context, invite_link)
|
||||
|
||||
# create user
|
||||
context.clear_cookies()
|
||||
create_user(context, invite_link)
|
||||
context.storage_state(path=f"{DIR.STATES}/user_state.json")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue