refactoring #13
9 changed files with 31 additions and 31 deletions
|
|
@ -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!")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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!")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue