move all tests to their own dir
This commit is contained in:
parent
d38808ac65
commit
ce76e14358
22 changed files with 0 additions and 0 deletions
0
src-tests/tests_wordpress/__init__.py
Normal file
0
src-tests/tests_wordpress/__init__.py
Normal file
34
src-tests/tests_wordpress/conftest.py
Normal file
34
src-tests/tests_wordpress/conftest.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import json
|
||||
|
||||
import pytest
|
||||
from dotenv import dotenv_values
|
||||
from playwright.sync_api import BrowserContext, Page
|
||||
|
||||
from src.dir_manager import DirManager
|
||||
|
||||
# from src.tests_authentik.fixtures_authentik import (
|
||||
# authentik_admin_context,
|
||||
# authentik_admin_page,
|
||||
# authentik_user_context,
|
||||
# authentik_user_page,
|
||||
# )
|
||||
|
||||
pytest_plugins = "src.tests_authentik.fixtures_authentik"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def wordpress_admin_context(context: BrowserContext, DIR: DirManager) -> BrowserContext:
|
||||
state_file = DIR.STATES / "wordpress_admin_state.json"
|
||||
storage_state = json.loads(state_file.read_bytes())
|
||||
context.add_cookies(storage_state["cookies"])
|
||||
return context
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def wordpress_admin_page(wordpress_admin_context: BrowserContext, DIR: DirManager) -> 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)
|
||||
return page
|
||||
27
src-tests/tests_wordpress/runner_wordpress.py
Normal file
27
src-tests/tests_wordpress/runner_wordpress.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from src.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
|
||||
|
||||
|
||||
def condition_has_locale(dotenv_config: dict[str, str]) -> bool:
|
||||
if "LOCALE" in dotenv_config:
|
||||
if "de" in dotenv_config["LOCALE"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class RunnerWordpress(Runner):
|
||||
name = "wordpress"
|
||||
test_dir_name = "tests_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"),
|
||||
]
|
||||
28
src-tests/tests_wordpress/setup_wordpress.py
Normal file
28
src-tests/tests_wordpress/setup_wordpress.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import pytest
|
||||
from playwright.sync_api import BrowserContext, Page, expect
|
||||
|
||||
from src.dir_manager import DirManager
|
||||
|
||||
|
||||
def test_visit_from_domain(authentik_admin_context: BrowserContext, dotenv_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"]
|
||||
page.goto(url)
|
||||
with pytest.raises(AssertionError):
|
||||
# look for admin bar
|
||||
expect(page.locator("#wpadminbar")).to_be_visible(timeout=3_000)
|
||||
|
||||
|
||||
def setup_wordpress_admin_session(authentik_admin_page: Page, DIR: DirManager):
|
||||
"""visit wordpress from authentik with admin_session to create wordpress_admin_session"""
|
||||
with authentik_admin_page.expect_popup() as event_context:
|
||||
authentik_admin_page.get_by_role("link", name="Wordpress").click()
|
||||
page_wordpress = event_context.value
|
||||
# look for content wrapper
|
||||
expect(page_wordpress.locator("#wpcontent")).to_be_visible()
|
||||
# look for admin bar
|
||||
expect(page_wordpress.locator("#wpadminbar")).to_be_visible()
|
||||
# save session
|
||||
context = page_wordpress.context
|
||||
context.storage_state(path=DIR.STATES / "wordpress_admin_state.json")
|
||||
0
src-tests/tests_wordpress/test_wordpress.py
Normal file
0
src-tests/tests_wordpress/test_wordpress.py
Normal file
15
src-tests/tests_wordpress/test_wordpress_localization.py
Normal file
15
src-tests/tests_wordpress/test_wordpress_localization.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# WIP localization
|
||||
|
||||
from playwright.sync_api import BrowserContext, expect
|
||||
|
||||
from src.dir_manager import DirManager
|
||||
|
||||
|
||||
def test_welcome_message(context: BrowserContext, dotenv_config: dict[str, str], DIR: DirManager):
|
||||
page = context.new_page()
|
||||
url = "https://" + dotenv_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"]:
|
||||
expect(page.get_by_role("heading")).to_have_text("Willkommen bei WordPress!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue