separeate pages

This commit is contained in:
Abel Luck 2026-03-30 13:11:37 +02:00
parent 3fc999a69b
commit 9e826fcee8
9 changed files with 1376 additions and 924 deletions

View file

@ -6,16 +6,18 @@ from typing import Any, cast
from repub.datastar import RefreshBroker, render_sse_event, render_stream
from repub.web import (
create_app,
get_active_jobs,
get_refresh_broker,
render_create_source,
render_dashboard,
set_active_jobs,
render_execution_logs,
render_runs,
render_sources,
)
def test_root_get_serves_datastar_shim() -> None:
async def run() -> None:
client = create_app(enable_demo_refresh=False).test_client()
client = create_app().test_client()
response = await client.get("/")
body = await response.get_data(as_text=True)
@ -38,7 +40,7 @@ def test_root_get_serves_datastar_shim() -> None:
def test_root_get_honors_if_none_match() -> None:
async def run() -> None:
client = create_app(enable_demo_refresh=False).test_client()
client = create_app().test_client()
initial = await client.get("/")
etag = initial.headers["ETag"]
@ -51,9 +53,9 @@ def test_root_get_honors_if_none_match() -> None:
asyncio.run(run())
def test_root_post_serves_morph_component() -> None:
def test_dashboard_post_serves_morph_component() -> None:
async def run() -> None:
client = create_app(enable_demo_refresh=False).test_client()
client = create_app().test_client()
async with client.request("/?u=shim", method="POST") as connection:
await connection.send_complete()
chunk = await asyncio.wait_for(connection.receive(), timeout=1)
@ -64,6 +66,8 @@ def test_root_post_serves_morph_component() -> None:
assert b"event: datastar-patch-elements" in chunk
assert b"id: " in chunk
assert b'<main id="morph"' in chunk
assert b"Operational snapshot" in chunk
assert b"Running executions" in chunk
await connection.disconnect()
asyncio.run(run())
@ -88,7 +92,7 @@ def test_render_sse_event_skips_unchanged_view() -> None:
def test_app_refresh_broker_publishes_events() -> None:
async def run() -> None:
app = create_app(enable_demo_refresh=False)
app = create_app()
broker = get_refresh_broker(app)
queue = broker.subscribe()
@ -123,72 +127,75 @@ def test_render_stream_yields_on_connect_and_refresh() -> None:
asyncio.run(run())
def test_render_dashboard_uses_active_jobs_from_app_state() -> None:
def test_render_dashboard_shows_dashboard_information_architecture() -> None:
async def run() -> None:
app = create_app(enable_demo_refresh=False)
assert get_active_jobs(app) == 12
set_active_jobs(app, 27)
body = str(await render_dashboard())
async with app.app_context():
body = str(await render_dashboard(app))
assert "27" in body
assert "Temporary live demo counter for Datastar refresh testing" in body
assert "/demo/decrement" in body
assert "data-bind:decrement-amount" in body
assert "Operational snapshot" in body
assert "Running executions" in body
assert 'href="/sources"' in body
assert 'href="/runs"' in body
assert "/job/7/execution/104/logs" in body
assert "Create source" in body
asyncio.run(run())
def test_demo_decrement_action_decrements_active_jobs() -> None:
def test_render_sources_shows_table_and_create_link() -> None:
async def run() -> None:
app = create_app(enable_demo_refresh=False)
broker = get_refresh_broker(app)
queue = broker.subscribe()
client = app.test_client()
body = str(await render_sources())
response = await client.post(
"/demo/decrement",
headers={"Datastar-Request": "true"},
json={"decrementAmount": "3"},
)
body = await response.get_data(as_text=True)
event = await asyncio.wait_for(queue.get(), timeout=1)
assert response.status_code == 200
assert get_active_jobs(app) == 9
assert event == "refresh-event"
assert 'data: signals {"decrementError":""}' in body
broker.unsubscribe(queue)
assert "Configured feed and Pangea sources live here as tables" in body
assert ">Sources<" in body
assert 'href="/sources/create"' in body
assert "guardian-feed" in body
assert "podcast-audio" in body
asyncio.run(run())
def test_demo_decrement_action_validates_odd_amount() -> None:
def test_render_create_source_shows_dedicated_form_page() -> None:
async def run() -> None:
app = create_app(enable_demo_refresh=False)
broker = get_refresh_broker(app)
queue = broker.subscribe()
client = app.test_client()
body = str(await render_create_source())
response = await client.post(
"/demo/decrement",
headers={"Datastar-Request": "true"},
json={"decrementAmount": "2"},
)
body = await response.get_data(as_text=True)
assert response.status_code == 200
assert get_active_jobs(app) == 12
assert "odd integer" in body
try:
await asyncio.wait_for(queue.get(), timeout=0.1)
except TimeoutError:
pass
else:
raise AssertionError("invalid decrement should not publish a refresh")
finally:
broker.unsubscribe(queue)
assert "Dedicated create page for the source form" in body
assert "Source and job setup" in body
assert "data-signals__ifmissing" in body
assert 'data-show="$sourceType === &#39;feed&#39;"' in body
assert 'data-show="$sourceType === &#39;pangea&#39;"' in body
assert "jobEnabled" in body
assert "onlyNewest" in body
assert "includeAuthors" in body
assert "excludeMedia" in body
assert "Pangea domain" in body
assert "Feed URL" in body
assert "Cron schedule" in body
assert "Initial job state" in body
asyncio.run(run())
def test_render_runs_shows_running_upcoming_and_completed_tables() -> None:
async def run() -> None:
body = str(await render_runs())
assert "Running job executions" in body
assert "Upcoming jobs" in body
assert "Completed job executions" in body
assert "Delete confirmation" in body
assert "/job/11/execution/101/logs" in body
assert "Already running" in body
asyncio.run(run())
def test_render_execution_logs_uses_app_route() -> None:
async def run() -> None:
body = str(await render_execution_logs(job_id=7, execution_id=104))
assert "Job 7 / execution 104" in body
assert "/job/7/execution/104/logs" in body
assert "Streaming text log view" in body
assert "waiting for more log lines" in body
asyncio.run(run())