1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/ux-tests/conftest.py
Stefan Pratter be9deaf2f8 Support 202309 (#1458)
* fixes #1260 - playwright tests
fixes #1394 - v2 search failing to find some names
fixes #1374 - Search to include new objects: Campus & Carrier
fixes #1164 - better rdap error reporting
fixes #1368 - Facility data export into Google Earth KMZ
fixes #1328 - Support web updates from a source of truth
fixes #1257 - Help text covers non-compliant email addresses
fixes #1313 - Improve email confirmation control - add 3 month option & maybe set new default value
fixes #1380 - Reset 'Social Media' to '[]' if field has no value

* linting

* remove target=_blank

* bump ES version to 8.10

* Cache and ES updates (#1459)

* elasticsearch major version pin and relock

* set decimal fields to python value on client save for load_data

* force use of redis password

* add default_meta to render

* add generated, clean up var names

* run pre-commit

* update ES for https and password

* rm cruft

* isort

---------

Co-authored-by: 20C <code@20c.com>
Co-authored-by: Matt Griswold <grizz@20c.com>
2023-10-24 12:17:03 -05:00

135 lines
4.2 KiB
Python

import json
import pytest
from helpers import login
from playwright.sync_api import sync_playwright
def pytest_configure(config):
config.addinivalue_line(
"markers", "profile: run profile tests - requires --account to be set"
)
config.addinivalue_line("markers", "search: run search tests")
config.addinivalue_line("markers", "links: run follow links tests")
def pytest_addoption(parser):
parser.addoption(
"--account",
action="store",
default="unauthenticated",
help="What type of user to run the tests as",
)
parser.addoption(
"--config",
action="store",
default="config.json",
help="Specify a config file to run the tests off of.",
)
parser.addoption(
"--browser",
action="store",
default="all",
help="Specify a browser to run the tests on.",
choices=("chromium", "firefox", "webkit", "all"),
)
def pytest_runtest_setup(item):
if "profile" in item.keywords and "profile" not in item.config.option.markexpr:
pytest.skip("Test requires -m 'profile' to be set")
if "writes" in item.keywords and "writes" not in item.config.option.markexpr:
pytest.skip("Test requires -m 'writes' to be set")
@pytest.fixture
def account(request):
account_value = request.config.getoption("--account")
if account_value is None:
pytest.skip("Test requires --account to be set")
return account_value
@pytest.fixture(scope="session")
def config(request):
config_path = request.config.getoption("--config")
result = {}
with open(config_path) as config_file:
result = json.load(config_file)
return result
@pytest.fixture(scope="session", params=["chromium", "firefox", "webkit"])
def browser_type(request):
"""
This fixture returns the type of the browser to use for the current test session.
"""
# Use the --browser option to decide which browser to use
browser_option = request.config.getoption("--browser")
if browser_option == "all":
# If no specific browser is selected, return the current parameter
return request.param
elif request.param == browser_option:
# If a specific browser is selected, return it
return browser_option
else:
pytest.skip("Skipping tests for this browser")
@pytest.fixture(scope="session")
def account_credentials(config, request):
"""
This fixture returns the credentials for the type of user specified in the --account option.
"""
test_account = request.config.getoption("--account")
account_credentials = config["accounts"]
# if test account is found in credentials, return it
if test_account in account_credentials:
return account_credentials[test_account]
else:
return {}
@pytest.fixture(scope="session")
def page(request, config, browser_type):
"""
This fixture creates a new browser context for each test session.
"""
with sync_playwright() as p:
# Use the browser_type fixture to decide which browser to launch
if browser_type == "chromium":
browser = p.chromium.launch(headless=True)
elif browser_type == "firefox":
browser = p.firefox.launch(headless=True)
elif browser_type == "webkit":
browser = p.webkit.launch(headless=True)
else:
raise ValueError(f"Unsupported browser type: {browser_type}")
context = browser.new_context()
page = context.new_page()
page.goto(config["url"])
test_account = request.config.getoption("--account")
account_credentials = config["accounts"]
# if test account is found in credentials, login
if test_account in account_credentials:
login(
page,
account_credentials[test_account]["username"],
account_credentials[test_account]["password"],
)
page.goto(config["url"])
page.set_viewport_size({"width": 1920, "height": 1080})
yield page
context.close()
browser.close()