move test dir creation to main.py
This commit is contained in:
parent
a7778b0e5e
commit
f277d95f2c
1 changed files with 49 additions and 3 deletions
52
src/main.py
52
src/main.py
|
|
@ -1,10 +1,22 @@
|
||||||
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Protocol
|
from typing import Protocol
|
||||||
|
|
||||||
from dotenv import dotenv_values
|
from dotenv import dotenv_values
|
||||||
from icecream import ic
|
from icecream import ic
|
||||||
|
from tests_authentik.runner_authentik import RunnerAuthentik
|
||||||
from tests_wordpress.runner_wordpress import RunnerWordpress
|
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):
|
class TestRunner(Protocol):
|
||||||
def __init__(self, dotenv_path: Path):
|
def __init__(self, dotenv_path: Path):
|
||||||
|
|
@ -18,13 +30,47 @@ RUNNER_DICT: dict[str, type[TestRunner]] = {"wordpress": RunnerWordpress}
|
||||||
|
|
||||||
|
|
||||||
class Wrapper:
|
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()
|
assert dotenv_path.is_file()
|
||||||
config: dict[str, str] = dotenv_values(dotenv_path)
|
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()
|
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"]
|
config_type = config["TYPE"]
|
||||||
ic(config_type)
|
ic(config_type)
|
||||||
RunnerClass = RUNNER_DICT[config_type]
|
RunnerClass = RUNNER_DICT[config_type]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue