60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import asyncio
|
||
|
|
|
||
|
|
from repub.web import create_app
|
||
|
|
|
||
|
|
|
||
|
|
def test_root_get_serves_datastar_shim() -> None:
|
||
|
|
async def run() -> None:
|
||
|
|
client = create_app().test_client()
|
||
|
|
|
||
|
|
response = await client.get("/")
|
||
|
|
body = await response.get_data(as_text=True)
|
||
|
|
|
||
|
|
assert response.status_code == 200
|
||
|
|
assert response.headers["ETag"]
|
||
|
|
assert body.startswith("<!doctype html>")
|
||
|
|
assert (
|
||
|
|
'<script id="js" defer type="module" src="/static/datastar@1.0.0-RC.8.js"></script>'
|
||
|
|
in body
|
||
|
|
)
|
||
|
|
assert 'data-signals:tabid="self.crypto.randomUUID().substring(0,8)"' in body
|
||
|
|
assert 'data-init="@post(window.location.pathname +' in body
|
||
|
|
assert "retryMaxCount: Infinity" in body
|
||
|
|
assert "data-on:online__window=" in body
|
||
|
|
assert '<main id="morph"></main>' in body
|
||
|
|
|
||
|
|
asyncio.run(run())
|
||
|
|
|
||
|
|
|
||
|
|
def test_root_get_honors_if_none_match() -> None:
|
||
|
|
async def run() -> None:
|
||
|
|
client = create_app().test_client()
|
||
|
|
|
||
|
|
initial = await client.get("/")
|
||
|
|
etag = initial.headers["ETag"]
|
||
|
|
|
||
|
|
response = await client.get("/", headers={"If-None-Match": etag})
|
||
|
|
|
||
|
|
assert response.status_code == 304
|
||
|
|
assert response.headers["ETag"] == etag
|
||
|
|
|
||
|
|
asyncio.run(run())
|
||
|
|
|
||
|
|
|
||
|
|
def test_root_post_serves_morph_component() -> None:
|
||
|
|
async def run() -> None:
|
||
|
|
client = create_app().test_client()
|
||
|
|
|
||
|
|
response = await client.post("/?u=shim")
|
||
|
|
body = await response.get_data(as_text=True)
|
||
|
|
|
||
|
|
assert response.status_code == 200
|
||
|
|
assert response.content_type == "text/html; charset=utf-8"
|
||
|
|
assert body.startswith('<main id="morph"')
|
||
|
|
assert "Admin UI" in body
|
||
|
|
assert "All on one page for the v1 spike" not in body
|
||
|
|
|
||
|
|
asyncio.run(run())
|