Extract HTML5 SSE helpers
This commit is contained in:
@@ -7,6 +7,7 @@ import zipfile
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from api_server import main
|
||||
from api_server.html5_sse import html5_sse_comment, html5_sse_event, html5_sse_if_changed
|
||||
from api_server.main import app
|
||||
from one_c_normalizer import ConfigurationRoot, MetadataGroup, MetadataObject, Module, NormalizedProject
|
||||
|
||||
@@ -51,6 +52,26 @@ def assert_html5_response_contract(response, *markers: str, full_page: bool = Fa
|
||||
assert_html5_contract(response.text, *markers, full_page=full_page)
|
||||
|
||||
|
||||
def test_html5_sse_formatters_emit_stable_event_stream_chunks():
|
||||
assert html5_sse_comment("heartbeat") == ": heartbeat\n\n"
|
||||
assert html5_sse_event("status", "<div>\nready</div>") == (
|
||||
"event: status\n"
|
||||
"retry: 5000\n"
|
||||
"data: <div>\n"
|
||||
"data: ready</div>\n\n"
|
||||
)
|
||||
|
||||
last_fragments: dict[str, str] = {}
|
||||
first = list(html5_sse_if_changed(last_fragments, "status", "<div>ready</div>"))
|
||||
second = list(html5_sse_if_changed(last_fragments, "status", "<div>ready</div>"))
|
||||
third = list(html5_sse_if_changed(last_fragments, "status", "<div>done</div>"))
|
||||
|
||||
assert len(first) == 1
|
||||
assert second == []
|
||||
assert len(third) == 1
|
||||
assert "data: <div>done</div>" in third[0]
|
||||
|
||||
|
||||
def test_cors_allows_lan_panel_origin():
|
||||
client = TestClient(app)
|
||||
response = client.options(
|
||||
|
||||
Reference in New Issue
Block a user