* add full integration test of cli / pytest_abra with all tests * save path of runner_*.py in runner subclass to improve test discovery -> allows for same test name in two different runners * reorganize output dir names * use URL fixture everywhere * rework coordinator interface * add --session_id to cli args * add log results table * plenty of refactoring * add assert messages * add plenty of tests * add /docs dir with plenty of documentation * fix authentik setup * add authentik cleanup, remove test user * add random test user credential generation and integrate into test routine. random creds are saved to STATES Reviewed-on: local-it-infrastructure/e2e_tests#16 Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
import os
|
|
import re
|
|
from typing import Callable, Generator
|
|
|
|
import pytest
|
|
from playwright.sync_api import APIRequestContext, BrowserContext, Playwright, TimeoutError
|
|
|
|
from pytest_abra import BaseUrl, DirManager
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def api_request_context(
|
|
playwright: Playwright,
|
|
DIR: DirManager,
|
|
) -> Generator[APIRequestContext, None, None]:
|
|
state_file = DIR.STATES / "authentik_admin_state.json"
|
|
request_context = playwright.request.new_context(storage_state=state_file)
|
|
yield request_context
|
|
request_context.dispose()
|
|
|
|
|
|
@pytest.fixture
|
|
def check_if_user_exists() -> Callable[[BrowserContext, dict[str, str], BaseUrl], bool]:
|
|
"""This is actually a normal function supplied by a fixture. We do this, because imports from
|
|
tests_authentik are difficult as it is not part of the python environment. We expect
|
|
from X import function
|
|
to fail here. However, pytest handles the loading of fixtures from conftest.py automatically,
|
|
hence we use that to load functions too."""
|
|
|
|
def inner_check_if_user_exists(admin_context: BrowserContext, env_config: dict[str, str], URL: BaseUrl) -> bool:
|
|
# go to admin page
|
|
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()
|
|
|
|
user = page.get_by_text(os.environ["TEST_USER"])
|
|
try:
|
|
user.wait_for(state="visible", timeout=5_000)
|
|
return True
|
|
except TimeoutError:
|
|
return False
|
|
|
|
return inner_check_if_user_exists
|