authentic setup is now handled via pytest plugin
This commit is contained in:
parent
5fea54a604
commit
387977a54a
2 changed files with 51 additions and 0 deletions
|
|
@ -4,6 +4,10 @@ import pytest
|
||||||
from dirmanager import DirManager
|
from dirmanager import DirManager
|
||||||
from dotenv import dotenv_values
|
from dotenv import dotenv_values
|
||||||
|
|
||||||
|
pytest_plugins = [
|
||||||
|
"setup.setup_authentik",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addoption(
|
parser.addoption(
|
||||||
|
|
|
||||||
47
src/setup/setup_authentik.py
Normal file
47
src/setup/setup_authentik.py
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from icecream import ic
|
||||||
|
from playwright.sync_api import Browser, Locator, expect
|
||||||
|
|
||||||
|
cred_file = Path("../credentials.json")
|
||||||
|
with open(cred_file, "r") as f:
|
||||||
|
CREDENTIALS = json.load(f)
|
||||||
|
|
||||||
|
print(CREDENTIALS)
|
||||||
|
|
||||||
|
TESTUSER = {"username": "testuser", "name": "Test User", "password": "test123", "email": "test@example.com"}
|
||||||
|
TIMEOUT = 5000
|
||||||
|
|
||||||
|
|
||||||
|
def check_for(locator: Locator):
|
||||||
|
expect(locator).to_be_visible(timeout=TIMEOUT)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
|
def admin_login(browser: Browser, dotenv_config, STATES):
|
||||||
|
# ic(dotenv_config)
|
||||||
|
|
||||||
|
# go to page
|
||||||
|
context = browser.new_context()
|
||||||
|
context.set_default_timeout(TIMEOUT)
|
||||||
|
page = context.new_page()
|
||||||
|
url = "https://" + dotenv_config["DOMAIN"]
|
||||||
|
page.goto(url)
|
||||||
|
|
||||||
|
# check welcome message
|
||||||
|
welcome_message = dotenv_config.get("welcome_message")
|
||||||
|
if welcome_message:
|
||||||
|
check_for(page.get_by_text(welcome_message))
|
||||||
|
|
||||||
|
# login
|
||||||
|
page.locator('input[name="uidField"]').fill(CREDENTIALS["admin"])
|
||||||
|
page.locator('ak-stage-identification input[name="password"]').fill(CREDENTIALS["admin_pw"])
|
||||||
|
page.get_by_role("button", name="Log In").click()
|
||||||
|
check_for(page.locator("ak-library"))
|
||||||
|
|
||||||
|
# save state
|
||||||
|
context.storage_state(path=f"{STATES}/admin_state.json")
|
||||||
|
page.close()
|
||||||
|
context.close()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue