From 14c1a1c1f6368118fa21aa40364caf5ef87d2b3c Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 7 Dec 2023 22:07:25 +0100 Subject: [PATCH] rename dotenv_config fixture to env_config --- previous-work/wordpress_test.py | 4 ++-- pytest_abra/pytest_abra.py | 6 +++--- .../tests_authentik/runner_authentik.py | 4 ++-- .../authentik/tests_authentik/setup_authentik.py | 16 ++++++++-------- .../tests_nextcloud/runner_nextcloud.py | 2 +- .../nextcloud/tests_nextcloud/tests_nextcloud.py | 10 +++++----- .../tests_wordpress/runner_wordpress.py | 10 +++++----- .../wordpress/tests_wordpress/setup_wordpress.py | 4 ++-- .../test_wordpress_localization.py | 6 +++--- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/previous-work/wordpress_test.py b/previous-work/wordpress_test.py index 9f8173f..960fa72 100644 --- a/previous-work/wordpress_test.py +++ b/previous-work/wordpress_test.py @@ -3,12 +3,12 @@ from playwright.sync_api import BrowserContext, expect from pytest_abra.dir_manager import DirManager -def test_wordpress(admin_session: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager): +def test_wordpress(admin_session: BrowserContext, env_config: dict[str, str], DIR: DirManager): page_authentik = admin_session.new_page() with page_authentik.expect_popup() as event_context: page_authentik.get_by_role("link", name="Wordpress").click() page_wordpress = event_context.value expect(page_wordpress.locator("#wpcontent")).to_be_visible() - if "locale" in dotenv_config and "de" in dotenv_config["locale"]: + if "locale" in env_config and "de" in env_config["locale"]: expect(page_wordpress.get_by_role("heading")).to_have_text("Willkommen bei WordPress!") diff --git a/pytest_abra/pytest_abra.py b/pytest_abra/pytest_abra.py index db6514f..8762ad3 100644 --- a/pytest_abra/pytest_abra.py +++ b/pytest_abra/pytest_abra.py @@ -81,16 +81,16 @@ def ENV_FILES(DIR: DirManager) -> dict[int, EnvFile]: @pytest.fixture(scope="session") -def dotenv_config(request, ENV_FILES: dict[int, EnvFile]) -> dict[str, str]: +def env_config(request, ENV_FILES: dict[int, EnvFile]) -> dict[str, str]: """Current env_config""" runner_index = request.config.getoption("--runner_index") return ENV_FILES[runner_index].config @pytest.fixture(scope="session") -def URL(dotenv_config: dict[str, str]) -> BaseUrl: +def URL(env_config: dict[str, str]) -> BaseUrl: """BaseUrl object based on current DOMAIN""" - return BaseUrl(netloc=dotenv_config["DOMAIN"]) + return BaseUrl(netloc=env_config["DOMAIN"]) @pytest.fixture(scope="session") diff --git a/recipes/authentik/tests_authentik/runner_authentik.py b/recipes/authentik/tests_authentik/runner_authentik.py index fb8c3b2..b929945 100644 --- a/recipes/authentik/tests_authentik/runner_authentik.py +++ b/recipes/authentik/tests_authentik/runner_authentik.py @@ -1,11 +1,11 @@ from pytest_abra.runner import Runner, Test -def condition_always_true(dotenv_config: dict[str, str]) -> bool: +def condition_always_true(env_config: dict[str, str]) -> bool: return True -def condition_always_false(dotenv_config: dict[str, str]) -> bool: +def condition_always_false(env_config: dict[str, str]) -> bool: return False diff --git a/recipes/authentik/tests_authentik/setup_authentik.py b/recipes/authentik/tests_authentik/setup_authentik.py index 680a85d..60dd5ef 100644 --- a/recipes/authentik/tests_authentik/setup_authentik.py +++ b/recipes/authentik/tests_authentik/setup_authentik.py @@ -14,14 +14,14 @@ ADMIN_PASS = os.environ["ADMIN_PASS"] TESTUSER = {"username": "testuser", "name": "Test User", "password": "test123", "email": "test@example.com"} -def setup_admin_state(context: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager): +def setup_admin_state(context: BrowserContext, env_config: dict[str, str], DIR: DirManager): # go to page page = context.new_page() - url = "https://" + dotenv_config["DOMAIN"] + url = "https://" + env_config["DOMAIN"] page.goto(url) # check welcome message - welcome_message = dotenv_config.get("welcome_message") + welcome_message = env_config.get("welcome_message") if welcome_message: expect(page.get_by_text(welcome_message)).to_be_visible() @@ -35,7 +35,7 @@ def setup_admin_state(context: BrowserContext, dotenv_config: dict[str, str], DI context.storage_state(path=DIR.STATES / "authentik_admin_state.json") -def check_if_user_exists(admin_context: BrowserContext, dotenv_config: dict[str, str], URL: BaseUrl): +def check_if_user_exists(admin_context: BrowserContext, env_config: dict[str, str], URL: BaseUrl): # go to admin page page = admin_context.new_page() page.goto(URL.get()) @@ -49,7 +49,7 @@ def check_if_user_exists(admin_context: BrowserContext, dotenv_config: dict[str, return user.is_visible() -def create_invite_link(admin_context: BrowserContext, dotenv_config: dict[str, str], URL: BaseUrl): +def create_invite_link(admin_context: BrowserContext, env_config: dict[str, str], URL: BaseUrl): # go to admin page page = admin_context.new_page() page.goto(URL.get()) @@ -98,19 +98,19 @@ def create_user(user_context: BrowserContext, invitelink): expect(page.locator("ak-library")).to_be_visible() -def setup_user_state(context: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager, URL: BaseUrl): +def setup_user_state(context: BrowserContext, env_config: dict[str, str], DIR: DirManager, URL: BaseUrl): # load admin cookies to context state_file = DIR.STATES / "authentik_admin_state.json" storage_state = json.loads(state_file.read_bytes()) context.add_cookies(storage_state["cookies"]) - if check_if_user_exists(context, dotenv_config, URL): + if check_if_user_exists(context, env_config, URL): # just login with user pass context.clear_cookies() else: # get invite_link - invite_link = create_invite_link(context, dotenv_config, URL) + invite_link = create_invite_link(context, env_config, URL) # create user context.clear_cookies() create_user(context, invite_link) diff --git a/recipes/nextcloud/tests_nextcloud/runner_nextcloud.py b/recipes/nextcloud/tests_nextcloud/runner_nextcloud.py index 79b5050..f14e191 100644 --- a/recipes/nextcloud/tests_nextcloud/runner_nextcloud.py +++ b/recipes/nextcloud/tests_nextcloud/runner_nextcloud.py @@ -1,7 +1,7 @@ from pytest_abra.runner import Runner, Test -def condition_always_false(dotenv_config: dict[str, str]) -> bool: +def condition_always_false(env_config: dict[str, str]) -> bool: return False diff --git a/recipes/nextcloud/tests_nextcloud/tests_nextcloud.py b/recipes/nextcloud/tests_nextcloud/tests_nextcloud.py index b79150f..f96c368 100644 --- a/recipes/nextcloud/tests_nextcloud/tests_nextcloud.py +++ b/recipes/nextcloud/tests_nextcloud/tests_nextcloud.py @@ -4,9 +4,9 @@ import pytest from playwright.sync_api import Page, expect -def test_nextcloud_quota(nextcloud_admin_page: Page, dotenv_config: dict[str, str]): +def test_nextcloud_quota(nextcloud_admin_page: Page, env_config: dict[str, str]): """Test Nextcloud""" - if dotenv_config.get("DEFAULT_QUOTA"): + if env_config.get("DEFAULT_QUOTA"): # get quota from website quota_string = nextcloud_admin_page.get_by_text( re.compile(r"\d*,\d .* \d*,\d") @@ -17,7 +17,7 @@ def test_nextcloud_quota(nextcloud_admin_page: Page, dotenv_config: dict[str, st quota_website = float(out_number) # get quota from env - quota_config_string = dotenv_config["DEFAULT_QUOTA"] # "100 MB" + quota_config_string = env_config["DEFAULT_QUOTA"] # "100 MB" assert "MB" in quota_config_string quota_config = float(quota_config_string.strip("MB")) @@ -27,6 +27,6 @@ def test_nextcloud_quota(nextcloud_admin_page: Page, dotenv_config: dict[str, st @pytest.mark.skip -def test_nextcloud_apps(nextcloud_admin_page: Page, dotenv_config: dict[str, str]): - for app in dotenv_config["nc_apps"]: +def test_nextcloud_apps(nextcloud_admin_page: Page, env_config: dict[str, str]): + for app in env_config["nc_apps"]: expect(nextcloud_admin_page.get_by_role("link", name=app)).to_be_visible() diff --git a/recipes/wordpress/tests_wordpress/runner_wordpress.py b/recipes/wordpress/tests_wordpress/runner_wordpress.py index eae53ee..e235809 100644 --- a/recipes/wordpress/tests_wordpress/runner_wordpress.py +++ b/recipes/wordpress/tests_wordpress/runner_wordpress.py @@ -1,17 +1,17 @@ from pytest_abra.runner import Runner, Test -def condition_always_true(dotenv_config: dict[str, str]) -> bool: +def condition_always_true(env_config: dict[str, str]) -> bool: return True -def condition_always_false(dotenv_config: dict[str, str]) -> bool: +def condition_always_false(env_config: dict[str, str]) -> bool: return False -def condition_has_locale(dotenv_config: dict[str, str]) -> bool: - if "LOCALE" in dotenv_config: - if "de" in dotenv_config["LOCALE"]: +def condition_has_locale(env_config: dict[str, str]) -> bool: + if "LOCALE" in env_config: + if "de" in env_config["LOCALE"]: return True return False diff --git a/recipes/wordpress/tests_wordpress/setup_wordpress.py b/recipes/wordpress/tests_wordpress/setup_wordpress.py index b9fd773..4c44799 100644 --- a/recipes/wordpress/tests_wordpress/setup_wordpress.py +++ b/recipes/wordpress/tests_wordpress/setup_wordpress.py @@ -4,10 +4,10 @@ from playwright.sync_api import BrowserContext, Page, expect from pytest_abra.dir_manager import DirManager -def test_visit_from_domain(authentik_admin_context: BrowserContext, dotenv_config: dict[str, str]): +def test_visit_from_domain(authentik_admin_context: BrowserContext, env_config: dict[str, str]): """visit wordpress directly with admin_session, expect not to be logged in""" page = authentik_admin_context.new_page() - url = "https://" + dotenv_config["DOMAIN"] + url = "https://" + env_config["DOMAIN"] page.goto(url) with pytest.raises(AssertionError): # look for admin bar diff --git a/recipes/wordpress/tests_wordpress/test_wordpress_localization.py b/recipes/wordpress/tests_wordpress/test_wordpress_localization.py index a0c76ba..51601cb 100644 --- a/recipes/wordpress/tests_wordpress/test_wordpress_localization.py +++ b/recipes/wordpress/tests_wordpress/test_wordpress_localization.py @@ -5,11 +5,11 @@ from playwright.sync_api import BrowserContext, expect from pytest_abra.dir_manager import DirManager -def test_welcome_message(context: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager): +def test_welcome_message(context: BrowserContext, env_config: dict[str, str], DIR: DirManager): page = context.new_page() - url = "https://" + dotenv_config["DOMAIN"] + url = "https://" + env_config["DOMAIN"] page.goto(url) expect(page.locator(".wp-block-heading")).to_be_visible() - if "locale" in dotenv_config and "de" in dotenv_config["locale"]: + if "locale" in env_config and "de" in env_config["locale"]: expect(page.get_by_role("heading")).to_have_text("Willkommen bei WordPress!")