From ed403954b6261dd312a492b9eae4c48c116236ec Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Dec 2023 15:42:27 +0100 Subject: [PATCH 1/5] wip test_pytest_abra --- tests/test_pytest_abra.py | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/test_pytest_abra.py 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 From 24b1ca3bf70c444678fbb913b76ffd69f51edd9c Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Dec 2023 15:42:27 +0100 Subject: [PATCH 2/5] skip test --- .../wordpress/tests_wordpress/test_wordpress_receive_email.py | 2 ++ 1 file changed, 2 insertions(+) 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)) From 4882df4d78875c77166f7da4feac7ee8367dbea7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Dec 2023 15:42:27 +0100 Subject: [PATCH 3/5] assert state_file.is_file() --- recipes/authentik/tests_authentik/fixtures_authentik.py | 2 ++ 1 file changed, 2 insertions(+) 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 From 44203f3050c5c513b4d9a3cb032e38e6e352a00f Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Dec 2023 15:42:27 +0100 Subject: [PATCH 4/5] remove print --- .../authentik/tests_authentik/test_authentik_blueprint_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 8feebb92704f05c032911dc5cd2a5a9a7b2e8211 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Dec 2023 15:42:27 +0100 Subject: [PATCH 5/5] rename test --- tests/test_pytest_abra.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/test_pytest_abra.py b/tests/test_pytest_abra.py index 4418064..b87e788 100644 --- a/tests/test_pytest_abra.py +++ b/tests/test_pytest_abra.py @@ -12,7 +12,7 @@ def session_tmp_path_testout(tmp_path_factory: pytest.TempPathFactory) -> Path: @pytest.mark.slow -def test_pytest_abra(session_tmp_path_testout: Path): +def test_abratest_cli_full_integration(session_tmp_path_testout: Path): """run abratest against the dev instance""" # --------------------- load credentials to env variables -------------------- # @@ -51,15 +51,23 @@ def test_pytest_abra(session_tmp_path_testout: Path): 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) - with open(OUTPUT_DIR / "tempfile.txt", "w") as f: - f.write(str(result.stdout)) + # assert False # @pytest.mark.slow