diff --git a/recipes/authentik/tests_authentik/fixtures_authentik.py b/recipes/authentik/tests_authentik/fixtures_authentik.py index b19b06a..f1c5823 100644 --- a/recipes/authentik/tests_authentik/fixtures_authentik.py +++ b/recipes/authentik/tests_authentik/fixtures_authentik.py @@ -9,6 +9,7 @@ from pytest_abra import BaseUrl, DirManager @pytest.fixture def authentik_admin_context(context: BrowserContext, DIR: DirManager) -> BrowserContext: state_file = DIR.STATES / "authentik_admin_state.json" + assert state_file.is_file() storage_state = json.loads(state_file.read_bytes()) context.add_cookies(storage_state["cookies"]) return context @@ -26,6 +27,7 @@ def authentik_admin_page(authentik_admin_context: BrowserContext, DIR: DirManage @pytest.fixture def authentik_user_context(context: BrowserContext, DIR: DirManager) -> BrowserContext: state_file = DIR.STATES / "authentik_user_state.json" + assert state_file.is_file() storage_state = json.loads(state_file.read_bytes()) context.add_cookies(storage_state["cookies"]) return context diff --git a/recipes/authentik/tests_authentik/test_authentik_blueprint_api.py b/recipes/authentik/tests_authentik/test_authentik_blueprint_api.py index 87eb452..cf5914b 100644 --- a/recipes/authentik/tests_authentik/test_authentik_blueprint_api.py +++ b/recipes/authentik/tests_authentik/test_authentik_blueprint_api.py @@ -17,7 +17,7 @@ def test_authentik_blueprint_status( blueprints = api_request_context.get(URL.get("api/v3/managed/blueprints")) assert blueprints.ok blueprints_data = blueprints.json() - ic(blueprints_data) + # ic(blueprints_data) # fake failed blueprint # blueprints_data["results"][10]["status"] = "failed" diff --git a/recipes/wordpress/tests_wordpress/test_wordpress_receive_email.py b/recipes/wordpress/tests_wordpress/test_wordpress_receive_email.py index 736f18d..f806d13 100644 --- a/recipes/wordpress/tests_wordpress/test_wordpress_receive_email.py +++ b/recipes/wordpress/tests_wordpress/test_wordpress_receive_email.py @@ -1,8 +1,10 @@ +import pytest from icecream import ic from pytest_abra.custom_fixtures import Message +@pytest.mark.skip def test_demo(imap_recent_messages: list[Message]): for message in imap_recent_messages: print(dir(message)) diff --git a/tests/test_pytest_abra.py b/tests/test_pytest_abra.py new file mode 100644 index 0000000..b87e788 --- /dev/null +++ b/tests/test_pytest_abra.py @@ -0,0 +1,77 @@ +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_abratest_cli_full_integration(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, + ], + capture_output=True, + ) + + with open(OUTPUT_DIR / "tempfile_stdout.txt", "w") as f: + f.write(str(result.stdout)) + + with open(OUTPUT_DIR / "tempfile_stderr.txt", "w") as f: + f.write(str(result.stderr)) + + # print(result) + + assert result.returncode == 0 + + assert "failed" not in str(result.stdout) + + # assert False + + +# @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