add-resume (#12)

* add functionality to --resume flag. latest test will resume by running failed tests again

* fix nextcloud setup -> all tests passing

* fix expect timeout by moving it to its own fixture

Reviewed-on: local-it-infrastructure/e2e_tests#12
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
Daniel 2023-12-07 19:38:17 +01:00 committed by dan
parent 0b4e0a0c16
commit 41a042f07d
6 changed files with 33 additions and 6 deletions

View file

@ -42,6 +42,7 @@ subprocess.run(
RECIPES_DIR,
"--output_dir",
OUTPUT_DIR,
"--resume",
# "--debug",
]
)

View file

@ -29,9 +29,9 @@ def run():
session_id = "test-" + get_datetime_string()
if args.resume:
# look for previous session_id
pass
# session_id = "abc"
latest_session_id = DirManager.get_latest_session_id(args.output_dir)
if latest_session_id:
session_id = DirManager.get_latest_session_id(args.output_dir)
# ------------------------------- setup logging ------------------------------ #

View file

@ -14,7 +14,12 @@ from pytest_abra.utils import rmtree
class Coordinator:
def __init__(
self, env_paths_list: list[Path], output_dir: Path, session_id: str, recipes_dir: Path, timeout: int
self,
env_paths_list: list[Path],
output_dir: Path,
session_id: str,
recipes_dir: Path,
timeout: int,
) -> None:
# logging
out_string = "".join([e.name + "\n" for e in env_paths_list])

View file

@ -1,4 +1,5 @@
from pathlib import Path
from typing import Optional
from dotenv import dotenv_values
@ -76,3 +77,13 @@ class DirManager:
env_file = next(self.ENV_FILES.glob(f"*{search_string}*"))
config: dict[str, str] = dotenv_values(env_file) # type: ignore
return config
@staticmethod
def get_latest_session_id(output_dir: Path) -> Optional[str]:
"""returns the name of the newest dir inside of output_dir"""
all_dirs = [d for d in output_dir.iterdir() if d.is_dir()]
if all_dirs:
newest_dir: Path = max(all_dirs, key=lambda x: x.stat().st_ctime)
return newest_dir.name
else:
return None

View file

@ -23,6 +23,12 @@ def pytest_addoption(parser: Parser):
parser.addoption("--timeout", action="store", type=int, default=20_000)
@pytest.fixture(autouse=True)
def set_expect_timeout(request):
TIMEOUT = request.config.getoption("--timeout")
expect.set_options(timeout=TIMEOUT)
@pytest.fixture
def context(context: BrowserContext, request) -> BrowserContext:
# note: because this has the existing context fixture as an argument, it is ensured
@ -33,7 +39,6 @@ def context(context: BrowserContext, request) -> BrowserContext:
context.set_default_timeout(TIMEOUT)
context.set_extra_http_headers(LOCALE)
expect.set_options(timeout=TIMEOUT)
return context

View file

@ -1,3 +1,5 @@
import re
from playwright.sync_api import Page, expect
from pytest_abra.dir_manager import DirManager
@ -16,6 +18,9 @@ def setup_nextcloud_admin_session(authentik_admin_page: Page, DIR: DirManager, U
page_nextcloud = event_context.value
context = page_nextcloud.context
# expect quota stats on files page to confirm successful login
page_nextcloud.goto(URL.get("/apps/files"))
expect(page_nextcloud.get_by_role("link", name="Name")).to_be_visible()
quota_pattern = re.compile(r"\d*,\d .* (\d*,\d).")
expect(page_nextcloud.get_by_text(quota_pattern)).to_be_visible()
context.storage_state(path=DIR.STATES / "nextcloud_admin_state.json")