use URL fixture
This commit is contained in:
parent
e98f93557b
commit
8b1b30d907
1 changed files with 9 additions and 10 deletions
|
|
@ -5,6 +5,7 @@ import re
|
||||||
from playwright.sync_api import BrowserContext, expect
|
from playwright.sync_api import BrowserContext, expect
|
||||||
|
|
||||||
from src.dir_manager import DirManager
|
from src.dir_manager import DirManager
|
||||||
|
from src.utils import BaseUrl
|
||||||
|
|
||||||
ADMIN_USER = os.environ["ADMIN_USER"]
|
ADMIN_USER = os.environ["ADMIN_USER"]
|
||||||
ADMIN_PASS = os.environ["ADMIN_PASS"]
|
ADMIN_PASS = os.environ["ADMIN_PASS"]
|
||||||
|
|
@ -34,11 +35,10 @@ def setup_admin_state(context: BrowserContext, dotenv_config: dict[str, str], DI
|
||||||
context.storage_state(path=DIR.STATES / "authentik_admin_state.json")
|
context.storage_state(path=DIR.STATES / "authentik_admin_state.json")
|
||||||
|
|
||||||
|
|
||||||
def check_if_user_exists(admin_context: BrowserContext, dotenv_config: dict[str, str]):
|
def check_if_user_exists(admin_context: BrowserContext, dotenv_config: dict[str, str], URL: BaseUrl):
|
||||||
# go to admin page
|
# go to admin page
|
||||||
page = admin_context.new_page()
|
page = admin_context.new_page()
|
||||||
url = "https://" + dotenv_config["DOMAIN"]
|
page.goto(URL.get())
|
||||||
page.goto(url)
|
|
||||||
page.get_by_role("link", name="Admin Interface").click()
|
page.get_by_role("link", name="Admin Interface").click()
|
||||||
nav = page.locator("ak-sidebar-item", has_text=re.compile(r"Directory|Verzeichnis"))
|
nav = page.locator("ak-sidebar-item", has_text=re.compile(r"Directory|Verzeichnis"))
|
||||||
nav.click()
|
nav.click()
|
||||||
|
|
@ -49,11 +49,10 @@ def check_if_user_exists(admin_context: BrowserContext, dotenv_config: dict[str,
|
||||||
return user.is_visible()
|
return user.is_visible()
|
||||||
|
|
||||||
|
|
||||||
def create_invite_link(admin_context: BrowserContext, dotenv_config: dict[str, str]):
|
def create_invite_link(admin_context: BrowserContext, dotenv_config: dict[str, str], URL: BaseUrl):
|
||||||
# go to admin page
|
# go to admin page
|
||||||
page = admin_context.new_page()
|
page = admin_context.new_page()
|
||||||
url = "https://" + dotenv_config["DOMAIN"]
|
page.goto(URL.get())
|
||||||
page.goto(url)
|
|
||||||
page.get_by_role("link", name="Admin Interface").click()
|
page.get_by_role("link", name="Admin Interface").click()
|
||||||
|
|
||||||
nav = page.locator("ak-sidebar-item", has_text=re.compile(r"Directory|Verzeichnis"))
|
nav = page.locator("ak-sidebar-item", has_text=re.compile(r"Directory|Verzeichnis"))
|
||||||
|
|
@ -99,19 +98,19 @@ def create_user(user_context: BrowserContext, invitelink):
|
||||||
expect(page.locator("ak-library")).to_be_visible()
|
expect(page.locator("ak-library")).to_be_visible()
|
||||||
|
|
||||||
|
|
||||||
def setup_user_state(context: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager):
|
def setup_user_state(context: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager, URL: BaseUrl):
|
||||||
# load admin cookies
|
# load admin cookies to context
|
||||||
state_file = DIR.STATES / "authentik_admin_state.json"
|
state_file = DIR.STATES / "authentik_admin_state.json"
|
||||||
storage_state = json.loads(state_file.read_bytes())
|
storage_state = json.loads(state_file.read_bytes())
|
||||||
context.add_cookies(storage_state["cookies"])
|
context.add_cookies(storage_state["cookies"])
|
||||||
|
|
||||||
if check_if_user_exists(context, dotenv_config):
|
if check_if_user_exists(context, dotenv_config, URL):
|
||||||
# just login with user
|
# just login with user
|
||||||
pass
|
pass
|
||||||
context.clear_cookies()
|
context.clear_cookies()
|
||||||
else:
|
else:
|
||||||
# get invite_link
|
# get invite_link
|
||||||
invite_link = create_invite_link(context, dotenv_config)
|
invite_link = create_invite_link(context, dotenv_config, URL)
|
||||||
# create user
|
# create user
|
||||||
context.clear_cookies()
|
context.clear_cookies()
|
||||||
create_user(context, invite_link)
|
create_user(context, invite_link)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue