various (#16)
* 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>
This commit is contained in:
parent
016b88a68d
commit
2dd765a974
36 changed files with 1145 additions and 432 deletions
46
recipes/authentik/tests_authentik/conftest.py
Normal file
46
recipes/authentik/tests_authentik/conftest.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue