47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import json
|
|
|
|
import pytest
|
|
from dotenv import dotenv_values
|
|
from playwright.sync_api import BrowserContext, Page
|
|
|
|
from src.dirmanager import DirManager
|
|
|
|
TIMEOUT = 5000
|
|
|
|
|
|
@pytest.fixture
|
|
def admin_context(context: BrowserContext, DIR: DirManager) -> BrowserContext:
|
|
state_file = DIR.STATES / "admin_state.json"
|
|
storage_state = json.loads(state_file.read_bytes())
|
|
context.add_cookies(storage_state["cookies"])
|
|
context.set_default_timeout(TIMEOUT)
|
|
return context
|
|
|
|
|
|
@pytest.fixture
|
|
def authentik_admin_page(admin_context: BrowserContext, DIR: DirManager) -> Page:
|
|
page = admin_context.new_page()
|
|
authentik_env_file = DIR.ENV_FILES / "authentik"
|
|
authentik_config: dict[str, str] = dotenv_values(authentik_env_file) # type: ignore
|
|
url = "https://" + authentik_config["DOMAIN"]
|
|
page.goto(url)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def user_context(context: BrowserContext, DIR: DirManager) -> BrowserContext:
|
|
state_file = DIR.STATES / "user_state.json"
|
|
storage_state = json.loads(state_file.read_bytes())
|
|
context.add_cookies(storage_state["cookies"])
|
|
context.set_default_timeout(TIMEOUT)
|
|
return context
|
|
|
|
|
|
@pytest.fixture
|
|
def authentik_user_page(user_context: BrowserContext, DIR: DirManager) -> Page:
|
|
page = user_context.new_page()
|
|
authentik_env_file = DIR.ENV_FILES / "authentik"
|
|
authentik_config: dict[str, str] = dotenv_values(authentik_env_file) # type: ignore
|
|
url = "https://" + authentik_config["DOMAIN"]
|
|
page.goto(url)
|
|
return page
|