55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import os
|
|
from pathlib import Path
|
|
from typing import Protocol
|
|
|
|
from dotenv import dotenv_values
|
|
|
|
from src.dirmanager import DirManager
|
|
from src.tests_authentik.runner_authentik import RunnerAuthentik
|
|
from src.tests_wordpress.runner_wordpress import RunnerWordpress
|
|
|
|
|
|
class TestRunner(Protocol):
|
|
def __init__(self, dotenv_path: Path, output_dir: Path, session_id: str):
|
|
...
|
|
|
|
def run_tests(self):
|
|
...
|
|
|
|
|
|
# Register all runners here. A .env file with TYPE=authentik will be ran with RunnerAuthentik
|
|
RUNNER_DICT: dict[str, type[TestRunner]] = {
|
|
"authentik": RunnerAuthentik,
|
|
"wordpress": RunnerWordpress,
|
|
}
|
|
|
|
|
|
class Wrapper:
|
|
def __init__(self, env_files: list[Path], output_dir: Path, session_id: str):
|
|
self.env_files = env_files
|
|
self.check_env_files(self.env_files)
|
|
self.output_dir = output_dir
|
|
self.session_id = session_id
|
|
|
|
def setup_test(self):
|
|
self.dir_manager = DirManager(output_dir=self.output_dir, session_id=self.session_id)
|
|
self.dir_manager.create_all_dirs()
|
|
|
|
def run_test(self):
|
|
self.runners: list[TestRunner] = self._load_runners(self.env_files)
|
|
for runner in self.runners:
|
|
runner.run_tests()
|
|
|
|
def _load_runners(self, env_files: list[Path]) -> list[TestRunner]:
|
|
runners = []
|
|
for env_file in env_files:
|
|
config: dict[str, str] = dotenv_values(env_file) # type: ignore
|
|
RunnerClass = RUNNER_DICT[config["TYPE"]]
|
|
runners.append(RunnerClass(dotenv_path=env_file, output_dir=self.output_dir, session_id=self.session_id))
|
|
return runners
|
|
|
|
@staticmethod
|
|
def check_env_files(env_files: list[Path]):
|
|
"""checks if file exist for every file in list"""
|
|
for env_file in env_files:
|
|
assert env_file.is_file()
|