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_nextcloud/__init__.py
Normal file
0
src-tests/tests_nextcloud/__init__.py
Normal file
17
src-tests/tests_nextcloud/cleanup_nextcloud.py
Normal file
17
src-tests/tests_nextcloud/cleanup_nextcloud.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import os
|
||||
|
||||
from playwright.sync_api import Page
|
||||
|
||||
|
||||
def delete_nextcloud_user(authentik_admin_page: Page):
|
||||
"""Delete Nextcloud User"""
|
||||
with authentik_admin_page.expect_popup() as nextcloud_info:
|
||||
authentik_admin_page.get_by_role("link", name="Nextcloud").click()
|
||||
nextcloud = nextcloud_info.value
|
||||
nextcloud.get_by_role("link", name="Open settings menu").click()
|
||||
nextcloud.get_by_role("link", name="Users").click()
|
||||
nextcloud.locator("#app-content div").filter(has_text=os.environ["NEXTCLOUD_USER"]).get_by_role(
|
||||
"button", name="Toggle user actions menu"
|
||||
).click()
|
||||
nextcloud.get_by_role("button", name="Delete user").click()
|
||||
nextcloud.get_by_role("button", name=f"Delete authentik-{os.environ["NEXTCLOUD_USER"]}'s account").click()
|
||||
33
src-tests/tests_nextcloud/conftest.py
Normal file
33
src-tests/tests_nextcloud/conftest.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from playwright.sync_api import BrowserContext, Page
|
||||
|
||||
from src.dir_manager import DirManager
|
||||
from src.utils import BaseUrl
|
||||
|
||||
pytest_plugins = "src.tests_authentik.fixtures_authentik"
|
||||
|
||||
NEXTCLOUD_DEMO_USER = {
|
||||
"NEXTCLOUD_USER": "next_demo_user",
|
||||
"NEXTCLOUD_PASS": "P@ss.123",
|
||||
}
|
||||
|
||||
for key, value in NEXTCLOUD_DEMO_USER.items():
|
||||
os.environ[key] = value
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def nextcloud_admin_context(context: BrowserContext, DIR: DirManager) -> BrowserContext:
|
||||
state_file = DIR.STATES / "nextcloud_admin_state.json"
|
||||
storage_state = json.loads(state_file.read_bytes())
|
||||
context.add_cookies(storage_state["cookies"])
|
||||
return context
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def nextcloud_admin_page(nextcloud_admin_context: BrowserContext, DIR: DirManager, URL: BaseUrl) -> Page:
|
||||
page = nextcloud_admin_context.new_page()
|
||||
page.goto(URL.get("/apps/files"))
|
||||
return page
|
||||
17
src-tests/tests_nextcloud/runner_nextcloud.py
Normal file
17
src-tests/tests_nextcloud/runner_nextcloud.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from src.runner import Runner, Test
|
||||
|
||||
|
||||
def condition_always_false(dotenv_config: dict[str, str]) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
class RunnerNextcloud(Runner):
|
||||
name: str = "nextcloud"
|
||||
test_dir_name: str = "tests_nextcloud"
|
||||
dependencies = ["authentik"]
|
||||
setups = [Test(test_file="setup_nextcloud.py", prevent_skip=False)]
|
||||
tests = [
|
||||
Test(test_file="tests_nextcloud.py", prevent_skip=True),
|
||||
# Test(condition=condition_always_false, test_file="tests_nextcloud_onlyoffice.py"),
|
||||
]
|
||||
# cleanups = [Test(test_file="cleanup_nextcloud.py")]
|
||||
21
src-tests/tests_nextcloud/setup_nextcloud.py
Normal file
21
src-tests/tests_nextcloud/setup_nextcloud.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from playwright.sync_api import Page, expect
|
||||
|
||||
from src.dir_manager import DirManager
|
||||
from src.utils import BaseUrl
|
||||
|
||||
# url dashboard
|
||||
# https://files.test.dev.local-it.cloud/apps/dashboard/
|
||||
# url files
|
||||
# https://files.test.dev.local-it.cloud/apps/files/
|
||||
|
||||
|
||||
def setup_nextcloud_admin_session(authentik_admin_page: Page, DIR: DirManager, URL: BaseUrl):
|
||||
"""visit nextcloud 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="Nextcloud").click()
|
||||
page_nextcloud = event_context.value
|
||||
context = page_nextcloud.context
|
||||
|
||||
page_nextcloud.goto(URL.get("/apps/files"))
|
||||
expect(page_nextcloud.get_by_role("link", name="Name")).to_be_visible()
|
||||
context.storage_state(path=DIR.STATES / "nextcloud_admin_state.json")
|
||||
32
src-tests/tests_nextcloud/tests_nextcloud.py
Normal file
32
src-tests/tests_nextcloud/tests_nextcloud.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import re
|
||||
|
||||
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"):
|
||||
# get quota from website
|
||||
quota_string = nextcloud_admin_page.get_by_text(
|
||||
re.compile(r"\d*,\d .* \d*,\d")
|
||||
).inner_text() # "37,7 MB von 104,9 MB verwendet"
|
||||
out = re.search(r"\d*,\d .* (\d*,\d).", quota_string)
|
||||
out_number = out[1] # 104,9
|
||||
out_number = out_number.replace(",", ".")
|
||||
quota_website = float(out_number)
|
||||
|
||||
# get quota from env
|
||||
quota_config_string = dotenv_config["DEFAULT_QUOTA"] # "100 MB"
|
||||
assert "MB" in quota_config_string
|
||||
quota_config = float(quota_config_string.strip("MB"))
|
||||
|
||||
assert quota_website == pytest.approx(quota_config, rel=0.1) # within 10%
|
||||
else:
|
||||
pytest.skip("DEFAULT_QUOTA not defined in env file")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_nextcloud_apps(nextcloud_admin_page: Page, dotenv_config: dict[str, str]):
|
||||
for app in dotenv_config["nc_apps"]:
|
||||
expect(nextcloud_admin_page.get_by_role("link", name=app)).to_be_visible()
|
||||
19
src-tests/tests_nextcloud/tests_nextcloud_onlyoffice.py
Normal file
19
src-tests/tests_nextcloud/tests_nextcloud_onlyoffice.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
def test_onlyoffice(nc_session):
|
||||
"""Test Onlyoffice in Nextcloud"""
|
||||
context, page = nc_session
|
||||
# if page.query_selector('.close-icon'):
|
||||
# page.get_by_role("button", name="Close modal").click()
|
||||
page.get_by_role("link", name="New file/folder menu").click()
|
||||
page.get_by_role("link", name="New document").click()
|
||||
page.locator("#view9-input-file").fill("test.docx")
|
||||
page.get_by_role("button", name="Submit").click()
|
||||
outer_frame = page.frame_locator("#onlyofficeFrame")
|
||||
check_for(outer_frame.locator("body"))
|
||||
inner_frame = outer_frame.frame_locator("#app > iframe")
|
||||
check_for(inner_frame.locator("body"))
|
||||
onlyoffice = page.frame("frameEditor")
|
||||
check_for(onlyoffice.locator('//*[@id="area_id"]'))
|
||||
onlyoffice.locator("#btn-goback").click()
|
||||
page.get_by_role("link", name="Not favorited test .docx Share Actions").get_by_role("link", name="Actions").click()
|
||||
page.get_by_role("link", name="Delete file").click()
|
||||
context.tracing.stop(path=f"{RECORDS}/onlyoffice.zip")
|
||||
Loading…
Add table
Add a link
Reference in a new issue