pageparse.ai / tests /test_e2e.py
Varun2007's picture
initial clean deployment commit with compilers
8c3e275
Raw
History Blame Contribute Delete
2.99 kB
"""End-to-end tests for PageParse using Playwright.
Requires: pip install playwright && playwright install chromium
Run: pytest tests/test_e2e.py
"""
import pytest
import subprocess
import time
import sys
from pathlib import Path
pytest.importorskip("playwright")
HERE = Path(__file__).resolve().parent.parent
SERVER_SCRIPT = str(HERE / "src" / "pageparse" / "cli.py")
@pytest.fixture(scope="module")
def server():
proc = subprocess.Popen(
[sys.executable, "-m", "pageparse.cli", "serve", "--port", "8765"],
cwd=HERE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
time.sleep(3)
yield
proc.terminate()
proc.wait()
@pytest.fixture(scope="module")
def browser():
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
yield browser
browser.close()
def test_homepage_loads(server, browser):
page = browser.new_page()
page.goto("http://127.0.0.1:8765/")
assert "PageParse" in page.title() or "PageParse" in page.content()
page.close()
def test_upload_form_present(server, browser):
page = browser.new_page()
page.goto("http://127.0.0.1:8765/")
content = page.content()
assert "upload" in content.lower() or "ingest" in content.lower()
page.close()
def test_telemetry_endpoint(server):
import urllib.request
import json
resp = urllib.request.urlopen("http://127.0.0.1:8765/telemetry")
data = json.loads(resp.read())
assert "cpu_percent" in data
assert "total_gb" in data
def test_airgap_mode(server):
import urllib.request
import json
req = urllib.request.Request(
"http://127.0.0.1:8765/airgap",
data=json.dumps({"airgap": True}).encode(),
headers={"Content-Type": "application/json"},
method="POST",
)
resp = urllib.request.urlopen(req)
data = json.loads(resp.read())
assert data["airgap"] is True
resp = urllib.request.urlopen("http://127.0.0.1:8765/airgap")
data = json.loads(resp.read())
assert data["airgap"] is True
def test_stats_endpoint(server):
import urllib.request
import json
resp = urllib.request.urlopen("http://127.0.0.1:8765/stats")
data = json.loads(resp.read())
assert "sources" in data
assert "records" in data
def test_metrics_endpoint(server):
import urllib.request
resp = urllib.request.urlopen("http://127.0.0.1:8765/metrics")
content = resp.read().decode()
assert "pageparse_http_requests_total" in content
def test_translate_endpoint(server):
import urllib.request
import json
req = urllib.request.Request(
"http://127.0.0.1:8765/translate",
data=json.dumps({"text": "Hello", "target_lang": "Hindi"}).encode(),
headers={"Content-Type": "application/json"},
)
resp = urllib.request.urlopen(req)
data = json.loads(resp.read())
assert "translated_text" in data