mirror of
https://git.zavage.net/Zavage-Software/wabot.git
synced 2026-07-21 13:06:08 -06:00
test: integration fixtures — static site server, auto-marking conftest
This commit is contained in:
parent
8ed9565c88
commit
8682ec28fe
17
tests/fixtures/login.html
vendored
Normal file
17
tests/fixtures/login.html
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>Login</title></head>
|
||||
<body>
|
||||
<h1 id="page-title">Test Login</h1>
|
||||
<form action="/welcome.html" method="get">
|
||||
<input type="text" id="username" name="username">
|
||||
<select id="state" name="state">
|
||||
<option value="">--</option>
|
||||
<option value="CO">Colorado</option>
|
||||
<option value="NM">New Mexico</option>
|
||||
</select>
|
||||
<input type="checkbox" id="agree" name="agree" value="yes">
|
||||
<button type="submit" id="submit-btn">Sign in</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
8
tests/fixtures/welcome.html
vendored
Normal file
8
tests/fixtures/welcome.html
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>Welcome</title></head>
|
||||
<body>
|
||||
<h1 id="page-title">Welcome!</h1>
|
||||
<p id="greeting">You made it.</p>
|
||||
</body>
|
||||
</html>
|
||||
43
tests/integration/conftest.py
Normal file
43
tests/integration/conftest.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""Shared fixtures for real-browser integration tests.
|
||||
|
||||
Every test in this directory is marked ``integration`` automatically and
|
||||
runs with NoPacing (human delays would make the suite glacial). Browsers
|
||||
run headless against static HTML served from tests/fixtures.
|
||||
"""
|
||||
|
||||
import functools
|
||||
import http.server
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
FIXTURES = Path(__file__).parent.parent / "fixtures"
|
||||
BROWSERS = ["firefox", "chromium"]
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(items):
|
||||
integration_dir = Path(__file__).parent
|
||||
for item in items:
|
||||
if integration_dir in item.path.parents:
|
||||
item.add_marker(pytest.mark.integration)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def site_url():
|
||||
"""Serve tests/fixtures over HTTP on an ephemeral port."""
|
||||
handler = functools.partial(
|
||||
http.server.SimpleHTTPRequestHandler, directory=str(FIXTURES)
|
||||
)
|
||||
server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), handler)
|
||||
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
||||
thread.start()
|
||||
yield f"http://127.0.0.1:{server.server_address[1]}"
|
||||
server.shutdown()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(tmp_path):
|
||||
from wabot.sessions import SessionStore
|
||||
|
||||
return SessionStore(path=tmp_path / "sessions.json")
|
||||
Loading…
Reference in New Issue
Block a user