refactoring (#13)
* general project refactoring * various small improvements * improve imap fixture with helper functions and typing * add wordpress send email setup * add wordpress receive email test * add various documentation Reviewed-on: local-it-infrastructure/e2e_tests#13 Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
parent
41a042f07d
commit
d1ff1183a5
29 changed files with 323 additions and 175 deletions
|
|
@ -1,12 +1,4 @@
|
|||
from pytest_abra.runner import Runner, Test
|
||||
|
||||
|
||||
def condition_always_true(dotenv_config: dict[str, str]) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def condition_always_false(dotenv_config: dict[str, str]) -> bool:
|
||||
return False
|
||||
from pytest_abra import Runner, Test
|
||||
|
||||
|
||||
class RunnerAuthentik(Runner):
|
||||
|
|
|
|||
|
|
@ -14,20 +14,20 @@ 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()
|
||||
|
||||
# login
|
||||
page.locator('input[name="uidField"]').fill(ADMIN_USER)
|
||||
page.locator('ak-stage-identification input[name="password"]').fill(ADMIN_PASS)
|
||||
page.locator("input[name='uidField']").fill(ADMIN_USER)
|
||||
page.locator("ak-stage-identification input[name='password']").fill(ADMIN_PASS)
|
||||
page.get_by_role("button", name="Log In").click()
|
||||
expect(page.locator("ak-library")).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,8 +1,4 @@
|
|||
from pytest_abra.runner import Runner, Test
|
||||
|
||||
|
||||
def condition_always_false(dotenv_config: dict[str, str]) -> bool:
|
||||
return False
|
||||
from pytest_abra import Runner, Test
|
||||
|
||||
|
||||
class RunnerNextcloud(Runner):
|
||||
|
|
|
|||
|
|
@ -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]):
|
||||
"""Test Nextcloud"""
|
||||
if dotenv_config.get("DEFAULT_QUOTA"):
|
||||
def test_nextcloud_quota(nextcloud_admin_page: Page, env_config: dict[str, str]):
|
||||
"""Tests if the quota set in .env file matches the actual quota shown on the page within 10%"""
|
||||
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,10 +1,9 @@
|
|||
import json
|
||||
|
||||
import pytest
|
||||
from dotenv import dotenv_values
|
||||
from playwright.sync_api import BrowserContext, Page
|
||||
|
||||
from pytest_abra.dir_manager import DirManager
|
||||
from pytest_abra import BaseUrl, DirManager
|
||||
|
||||
pytest_plugins = "authentik.tests_authentik.fixtures_authentik"
|
||||
|
||||
|
|
@ -18,10 +17,7 @@ def wordpress_admin_context(context: BrowserContext, DIR: DirManager) -> Browser
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def wordpress_admin_page(wordpress_admin_context: BrowserContext, DIR: DirManager) -> Page:
|
||||
def wordpress_admin_page(wordpress_admin_context: BrowserContext, URL: BaseUrl) -> Page:
|
||||
page = wordpress_admin_context.new_page()
|
||||
env_file = DIR.ENV_FILES / "wordpress"
|
||||
config: dict[str, str] = dotenv_values(env_file) # type: ignore
|
||||
url = "https://" + config["DOMAIN"]
|
||||
page.goto(url)
|
||||
page.goto(URL.get())
|
||||
return page
|
||||
|
|
|
|||
|
|
@ -1,26 +1,21 @@
|
|||
from pytest_abra.runner import Runner, Test
|
||||
from pytest_abra import ConditionArgs, Runner, Test
|
||||
|
||||
|
||||
def condition_always_true(dotenv_config: dict[str, str]) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def condition_always_false(dotenv_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"]:
|
||||
return True
|
||||
def condition_has_locale(args: ConditionArgs) -> bool:
|
||||
env_config = args.env_config
|
||||
if "de" in env_config.get("LOCALE", ""):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class RunnerWordpress(Runner):
|
||||
env_type = "wordpress"
|
||||
dependencies = ["authentik"]
|
||||
setups = [Test(test_file="setup_wordpress.py")]
|
||||
tests = [
|
||||
Test(test_file="test_wordpress.py"),
|
||||
Test(condition=condition_has_locale, test_file="test_wordpress_localization.py"),
|
||||
setups = [
|
||||
Test(test_file="setup_wordpress.py"),
|
||||
Test(test_file="setup_wordpress_trigger_email.py"),
|
||||
]
|
||||
tests = [
|
||||
Test(test_file="test_wordpress_receive_email.py", prevent_skip=True),
|
||||
# Test(condition=condition_has_locale, test_file="test_wordpress_localization.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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
import os
|
||||
|
||||
from playwright.sync_api import Page, expect
|
||||
|
||||
from pytest_abra import BaseUrl
|
||||
|
||||
|
||||
def setup_trigger_email(wordpress_admin_page: Page, URL: BaseUrl):
|
||||
"""change profile email to EMAIL to trigger email"""
|
||||
page = wordpress_admin_page
|
||||
page.goto(URL.get("wp-admin/profile.php"))
|
||||
EMAIL = os.environ["IMAP_EMAIL"]
|
||||
print(EMAIL)
|
||||
# breakpoint()
|
||||
page.pause()
|
||||
page.locator("input[id='email']").fill(EMAIL)
|
||||
page.locator("input[id='submit']").click()
|
||||
|
||||
expect(page.locator("div.notice").get_by_text(EMAIL)).to_be_visible()
|
||||
|
|
@ -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!")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
from icecream import ic
|
||||
|
||||
from pytest_abra.custom_fixtures import Message
|
||||
|
||||
|
||||
def test_demo(imap_recent_messages: list[Message]):
|
||||
for message in imap_recent_messages:
|
||||
print(dir(message))
|
||||
ic(message.subject)
|
||||
ic(message.body["plain"])
|
||||
|
||||
exit()
|
||||
assert False
|
||||
Loading…
Add table
Add a link
Reference in a new issue