feat: v4.0 - multi-day horizontal canvas, duration input, overnight blocks, PDF horizontal layout
Some checks failed
Build & Push Docker / build (push) Has been cancelled
Some checks failed
Build & Push Docker / build (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
API endpoint tests for Scenar Creator v3.
|
||||
API endpoint tests for Scenar Creator v4.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
@@ -13,19 +13,33 @@ def client():
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def make_valid_doc():
|
||||
def make_valid_doc(multiday=False):
|
||||
blocks = [{
|
||||
"id": "b1",
|
||||
"date": "2026-03-01",
|
||||
"start": "09:00",
|
||||
"end": "10:00",
|
||||
"title": "Opening",
|
||||
"type_id": "ws"
|
||||
}]
|
||||
if multiday:
|
||||
blocks.append({
|
||||
"id": "b2",
|
||||
"date": "2026-03-02",
|
||||
"start": "10:00",
|
||||
"end": "11:30",
|
||||
"title": "Day 2 Session",
|
||||
"type_id": "ws"
|
||||
})
|
||||
return {
|
||||
"version": "1.0",
|
||||
"event": {"title": "Test Event"},
|
||||
"event": {
|
||||
"title": "Test Event",
|
||||
"date_from": "2026-03-01",
|
||||
"date_to": "2026-03-02" if multiday else "2026-03-01"
|
||||
},
|
||||
"program_types": [{"id": "ws", "name": "Workshop", "color": "#FF0000"}],
|
||||
"blocks": [{
|
||||
"id": "b1",
|
||||
"date": "2026-03-01",
|
||||
"start": "09:00",
|
||||
"end": "10:00",
|
||||
"title": "Opening",
|
||||
"type_id": "ws"
|
||||
}]
|
||||
"blocks": blocks
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +48,7 @@ def test_health(client):
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
assert data["status"] == "ok"
|
||||
assert data["version"] == "3.0.0"
|
||||
assert data["version"] == "4.0.0"
|
||||
|
||||
|
||||
def test_root_returns_html(client):
|
||||
@@ -63,17 +77,6 @@ def test_validate_unknown_type(client):
|
||||
assert any("UNKNOWN" in e for e in data["errors"])
|
||||
|
||||
|
||||
def test_validate_bad_time_order(client):
|
||||
doc = make_valid_doc()
|
||||
doc["blocks"][0]["start"] = "10:00"
|
||||
doc["blocks"][0]["end"] = "09:00"
|
||||
r = client.post("/api/validate", json=doc)
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
assert data["valid"] is False
|
||||
assert any("start time" in e for e in data["errors"])
|
||||
|
||||
|
||||
def test_validate_no_blocks(client):
|
||||
doc = make_valid_doc()
|
||||
doc["blocks"] = []
|
||||
@@ -98,17 +101,14 @@ def test_sample_endpoint(client):
|
||||
data = r.json()
|
||||
assert data["version"] == "1.0"
|
||||
assert data["event"]["title"] == "Zimní výjezd oddílu"
|
||||
assert len(data["program_types"]) == 3
|
||||
assert len(data["blocks"]) >= 8
|
||||
|
||||
|
||||
def test_sample_blocks_valid(client):
|
||||
r = client.get("/api/sample")
|
||||
data = r.json()
|
||||
type_ids = {pt["id"] for pt in data["program_types"]}
|
||||
for block in data["blocks"]:
|
||||
assert block["type_id"] in type_ids
|
||||
assert block["start"] < block["end"]
|
||||
assert len(data["program_types"]) >= 3
|
||||
# multi-day sample
|
||||
assert data["event"]["date_from"] == "2026-03-01"
|
||||
assert data["event"]["date_to"] == "2026-03-02"
|
||||
# blocks for both days
|
||||
dates = {b["date"] for b in data["blocks"]}
|
||||
assert "2026-03-01" in dates
|
||||
assert "2026-03-02" in dates
|
||||
|
||||
|
||||
def test_generate_pdf(client):
|
||||
@@ -119,6 +119,23 @@ def test_generate_pdf(client):
|
||||
assert r.content[:5] == b'%PDF-'
|
||||
|
||||
|
||||
def test_generate_pdf_multiday(client):
|
||||
doc = make_valid_doc(multiday=True)
|
||||
r = client.post("/api/generate-pdf", json=doc)
|
||||
assert r.status_code == 200
|
||||
assert r.content[:5] == b'%PDF-'
|
||||
|
||||
|
||||
def test_generate_pdf_overnight_block(client):
|
||||
"""Block that crosses midnight: end < start."""
|
||||
doc = make_valid_doc()
|
||||
doc["blocks"][0]["start"] = "23:00"
|
||||
doc["blocks"][0]["end"] = "01:30" # overnight
|
||||
r = client.post("/api/generate-pdf", json=doc)
|
||||
assert r.status_code == 200
|
||||
assert r.content[:5] == b'%PDF-'
|
||||
|
||||
|
||||
def test_generate_pdf_no_blocks(client):
|
||||
doc = make_valid_doc()
|
||||
doc["blocks"] = []
|
||||
@@ -126,21 +143,26 @@ def test_generate_pdf_no_blocks(client):
|
||||
assert r.status_code == 422
|
||||
|
||||
|
||||
def test_generate_pdf_multiday(client):
|
||||
doc = make_valid_doc()
|
||||
doc["blocks"].append({
|
||||
"id": "b2",
|
||||
"date": "2026-03-02",
|
||||
"start": "14:00",
|
||||
"end": "15:00",
|
||||
"title": "Day 2 Session",
|
||||
"type_id": "ws"
|
||||
})
|
||||
r = client.post("/api/generate-pdf", json=doc)
|
||||
assert r.status_code == 200
|
||||
assert r.content[:5] == b'%PDF-'
|
||||
|
||||
|
||||
def test_swagger_docs(client):
|
||||
r = client.get("/docs")
|
||||
assert r.status_code == 200
|
||||
|
||||
|
||||
def test_backward_compat_date_field(client):
|
||||
"""Old JSON with 'date' (not date_from/date_to) should still validate."""
|
||||
doc = {
|
||||
"version": "1.0",
|
||||
"event": {"title": "Old Format", "date": "2026-03-01"},
|
||||
"program_types": [{"id": "t1", "name": "Type", "color": "#0000FF"}],
|
||||
"blocks": [{
|
||||
"id": "bx",
|
||||
"date": "2026-03-01",
|
||||
"start": "10:00",
|
||||
"end": "11:00",
|
||||
"title": "Session",
|
||||
"type_id": "t1"
|
||||
}]
|
||||
}
|
||||
r = client.post("/api/validate", json=doc)
|
||||
assert r.status_code == 200
|
||||
assert r.json()["valid"] is True
|
||||
|
||||
Reference in New Issue
Block a user