move test dir creation to main.py

This commit is contained in:
Daniel 2023-11-22 12:53:09 +01:00
parent a7778b0e5e
commit f277d95f2c

View file

@ -1,10 +1,22 @@
from datetime import datetime
from pathlib import Path
from typing import Protocol
from dotenv import dotenv_values
from icecream import ic
from tests_authentik.runner_authentik import RunnerAuthentik
from tests_wordpress.runner_wordpress import RunnerWordpress
TESTS_DIR = Path("tests")
ENV_FILES = [
Path("../envfiles/login.test.dev.local-it.cloud.env"), # authentik
Path("../envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
]
ic(ENV_FILES[0].is_file())
ic(ENV_FILES[1].is_file())
class TestRunner(Protocol):
def __init__(self, dotenv_path: Path):
@ -18,13 +30,47 @@ RUNNER_DICT: dict[str, type[TestRunner]] = {"wordpress": RunnerWordpress}
class Wrapper:
def __init__(self, dotenv_path: Path):
def __init__(self, env_files: list[Path]):
self.env_files = env_files
self.setup_tests()
return
dotenv_path = self.env_files[0]
assert dotenv_path.is_file()
config: dict[str, str] = dotenv_values(dotenv_path)
runner = self.load_runner(config, dotenv_path)
runner = self.load_runners(config, dotenv_path)
runner.run_tests()
def load_runner(self, config: dict[str, str], dotenv_path: Path) -> TestRunner:
def setup_tests(self):
session_id = self.get_session_id()
test_dir = self.create_test_dir(session_id)
@staticmethod
def get_session_id() -> str:
current_datetime = datetime.now()
return current_datetime.strftime("%Y-%m-%d-%H-%M")
@staticmethod
def create_test_dir(session_id: str) -> Path:
TESTS_DIR.mkdir(exist_ok=True)
test_dir = TESTS_DIR / Path(f"test_{session_id}")
test_dir.mkdir()
return test_dir
@staticmethod
def create_records_dir(test_dir: Path) -> Path:
records = test_dir / Path("records")
records.mkdir()
return records
@staticmethod
def create_states_dir(test_dir: Path) -> Path:
states = test_dir / Path("states")
states.mkdir()
return states
def load_runners(self, config: dict[str, str], dotenv_path: Path) -> TestRunner:
config_type = config["TYPE"]
ic(config_type)
RunnerClass = RUNNER_DICT[config_type]