generated from coulomb/repo-seed
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib
|
|
import threading
|
|
from http.server import HTTPServer
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
VENDOR = ROOT / "ui" / "vendor" / "whynot-design"
|
|
|
|
REQUIRED_VENDOR_FILES = [
|
|
VENDOR / ".whynot-design-ref",
|
|
VENDOR / "colors_and_type.css",
|
|
VENDOR / "components.css",
|
|
VENDOR / "index.js",
|
|
VENDOR / "elements" / "atoms.js",
|
|
VENDOR / "elements" / "chrome.js",
|
|
VENDOR / "elements" / "form.js",
|
|
VENDOR / "elements" / "layout.js",
|
|
VENDOR / "elements" / "icons.js",
|
|
VENDOR / "elements" / "_styles.js",
|
|
VENDOR / "tokens" / "colors.json",
|
|
]
|
|
|
|
|
|
def test_vendor_tree_is_complete() -> None:
|
|
missing = [path for path in REQUIRED_VENDOR_FILES if not path.exists()]
|
|
assert not missing, f"Missing vendored whynot-design files: {missing}"
|
|
|
|
|
|
def test_vendor_ref_is_pinned() -> None:
|
|
ref = (VENDOR / ".whynot-design-ref").read_text(encoding="utf-8").strip()
|
|
assert len(ref) == 40
|
|
|
|
|
|
def test_server_serves_vendor_modules() -> None:
|
|
server_module = importlib.import_module("observatory.server")
|
|
handler = server_module.ObservatoryHandler
|
|
handler.data_dir = ROOT / "data"
|
|
|
|
try:
|
|
httpd = HTTPServer(("127.0.0.1", 0), handler)
|
|
except PermissionError:
|
|
pytest.skip("local socket binds are not permitted in this execution environment")
|
|
port = httpd.server_address[1]
|
|
thread = threading.Thread(target=httpd.serve_forever, daemon=True)
|
|
thread.start()
|
|
|
|
try:
|
|
import urllib.request
|
|
|
|
index = urllib.request.urlopen(f"http://127.0.0.1:{port}/", timeout=2)
|
|
assert "wn-top-nav" in index.read().decode("utf-8")
|
|
|
|
module = urllib.request.urlopen(
|
|
f"http://127.0.0.1:{port}/ui/vendor/whynot-design/index.js",
|
|
timeout=2,
|
|
)
|
|
assert module.headers["Content-Type"].startswith("application/javascript")
|
|
assert "defineAtoms" in module.read().decode("utf-8")
|
|
finally:
|
|
httpd.shutdown()
|
|
thread.join(timeout=2)
|