diff --git a/tests/test_pytest_abra.py b/tests/test_pytest_abra.py new file mode 100644 index 0000000..4418064 --- /dev/null +++ b/tests/test_pytest_abra.py @@ -0,0 +1,69 @@ +import json +import os +import subprocess +from pathlib import Path + +import pytest + + +@pytest.fixture(scope="session") +def session_tmp_path_testout(tmp_path_factory: pytest.TempPathFactory) -> Path: + return tmp_path_factory.mktemp("test_out") + + +@pytest.mark.slow +def test_pytest_abra(session_tmp_path_testout: Path): + """run abratest against the dev instance""" + + # --------------------- load credentials to env variables -------------------- # + + cred_file = Path("credentials.json") + with open(cred_file, "r") as f: + CREDENTIALS = json.load(f) + + for key, value in CREDENTIALS.items(): + os.environ[key] = value + + # --------------------------------- env files -------------------------------- # + + ENV_FILES_ROOT = Path("../envfiles").resolve() + ENV_FILES = [ + ENV_FILES_ROOT / "login.test.dev.local-it.cloud.env", # authentik + ENV_FILES_ROOT / "blog.test.dev.local-it.cloud.env", # wordpress + ENV_FILES_ROOT / "files.test.dev.local-it.cloud.env", # nextcloud + ] + ENV_PATHS = ";".join([x.as_posix() for x in ENV_FILES]) + + # ----------------------------------- dirs ----------------------------------- # + + RECIPES_DIR = Path("../recipes").resolve() + OUTPUT_DIR = Path("./test-output").resolve() + # OUTPUT_DIR = session_tmp_path_testout.resolve() + + # ------------------------------------ run ----------------------------------- # + + result = subprocess.run( + [ + "abratest", + "--env_paths", + ENV_PATHS, + "--recipes_dir", + RECIPES_DIR, + "--output_dir", + OUTPUT_DIR, + ] + ) + + assert result.returncode == 0 + + assert "failed" not in str(result.stdout) + + with open(OUTPUT_DIR / "tempfile.txt", "w") as f: + f.write(str(result.stdout)) + + +# @pytest.mark.slow +# def test_results_abra(session_tmp_path_testout: Path): +# OUTPUT_DIR = Path("./test-output").resolve() +# print(list(OUTPUT_DIR.rglob("*"))) +# assert False