93 lines
2.6 KiB
Python
93 lines
2.6 KiB
Python
# This file is registered as a pytest plugin, meaning it will automatically loaded.
|
|
# All fixtures in this file will be available without manual loading.
|
|
|
|
import os
|
|
from imaplib import IMAP4_SSL
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from dotenv import dotenv_values
|
|
from playwright.sync_api import BrowserContext, expect
|
|
from pytest import Parser
|
|
|
|
from pytest_abra.dir_manager import DirManager
|
|
from pytest_abra.utils import BaseUrl
|
|
|
|
# global timeout and LOCALE
|
|
LOCALE = {"Accept-Language": "de_DE"}
|
|
TIMEOUT = 20_000
|
|
expect.set_options(timeout=TIMEOUT)
|
|
|
|
|
|
@pytest.fixture
|
|
def context(context: BrowserContext) -> BrowserContext:
|
|
# note: because this has the existing context fixture as an argument, it is ensured
|
|
# that the original fixture is called first and then overwritten by this custom one.
|
|
|
|
context.set_default_timeout(TIMEOUT)
|
|
context.set_extra_http_headers(LOCALE)
|
|
return context
|
|
|
|
|
|
def pytest_addoption(parser: Parser):
|
|
parser.addoption(
|
|
"--env_file",
|
|
action="store",
|
|
required=True,
|
|
)
|
|
parser.addoption(
|
|
"--output_dir",
|
|
action="store",
|
|
required=True,
|
|
)
|
|
parser.addoption(
|
|
"--session_id",
|
|
action="store",
|
|
required=True,
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def DIR(request) -> DirManager:
|
|
"""Fixture holding test directories
|
|
|
|
DIR.OUTPUT
|
|
DIR.SESSION
|
|
DIR.RECORDS
|
|
DIR.STATES
|
|
DIR.RESULTS"""
|
|
|
|
output_dir = request.config.getoption("--output_dir")
|
|
output_dir = Path(output_dir)
|
|
session_id = request.config.getoption("--session_id")
|
|
dirmanager = DirManager(output_dir=output_dir, session_id=session_id)
|
|
dirmanager.create_all_dirs()
|
|
return dirmanager
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def dotenv_config(request) -> dict[str, str]:
|
|
dotenv_path = request.config.getoption("--env_file")
|
|
dotenv_path = Path(dotenv_path)
|
|
assert dotenv_path.is_file()
|
|
return dotenv_values(dotenv_path) # type: ignore
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def URL(dotenv_config: dict[str, str]) -> BaseUrl:
|
|
return BaseUrl(netloc=dotenv_config["DOMAIN"])
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def imap_ssl_email_client() -> None:
|
|
assert os.environ["IMAP_HOST"]
|
|
assert os.environ["IMAP_PORT"]
|
|
assert os.environ["IMAP_USER"]
|
|
assert os.environ["IMAP_PASS"]
|
|
port = int(os.environ["IMAP_PORT"])
|
|
imap_client = IMAP4_SSL(host=os.environ["IMAP_HOST"], port=port)
|
|
imap_client.login(os.environ["IMAP_USER"], os.environ["IMAP_PASS"])
|
|
imap_client.select("INBOX")
|
|
yield imap_client
|
|
imap_client.close()
|
|
imap_client.logout()
|