Files
bonaminandClaude Opus 5.5 673113aff7 feat(signage): More settings for every widget (opacity, rotation, shadow, border, entrance animation, a logo's fit; text weight, highlight, typing out; date and clock formats; a logo in a QR code)
Folded under each widget card like Text and colours. The TV puts them on the element
that places the widget (fx), animations on translate / scale so its place's transform
stays (an older TV only fades); an entrance animates to the widget's own opacity.
Calibrating: a strict-mode remount no longer ends it. Plan 6R.17, F-115.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:01:42 +02:00

119 lines
8.1 KiB
Python

"""The venue's identity (6R.14): name, slogan, colours, logos, Wi-Fi and contact saved together,
logos protected in the media library, signage screens told and given it with their venue."""
from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures)
from tests.test_media import jpeg, media_dir, up # noqa: F401 (fixture + helpers)
from tests.test_signage import screens, sent # noqa: F401 (fixtures)
def test_empty_at_first(client, owner_h):
r = client.get("/api/identity", headers=owner_h)
assert r.status_code == 200
j = r.json()
assert j["colours"] == [] and j["logos"] == {"main": None, "light": None, "dark": None, "icon": None}
assert j["wifi"]["security"] == "WPA" and j["contact"]["phone"] is None
def test_saved_together_and_shown_to_the_screens(client, owner_h, screens, sent, media_dir):
logo = up(client, owner_h, jpeg(400, 200)).json()
body = {"name": " Taverna Xenia ", "slogan": "Since 1987", "colours": [{"name": "Main", "colour": "#1E3A8A"}, {"name": "Olive", "colour": "#556b2f80"}],
"logos": {"main": logo["id"]}, "wifi": {"ssid": "Xenia Guests", "password": "kalimera 2026", "security": "WPA"},
"contact": {"phone": " 2310 123456 ", "instagram": "@xenia"}}
sent.clear()
r = client.put("/api/identity", headers=owner_h, json=body)
assert r.status_code == 200, r.text
j = r.json()
assert j["name"] == "Taverna Xenia" and j["slogan"] == "Since 1987"
assert j["colours"] == [{"name": "Main", "colour": "#1e3a8a"}, {"name": "Olive", "colour": "#556b2f80"}]
assert j["logos"]["main"]["id"] == logo["id"] and j["logos"]["main"]["card"]
assert j["wifi"]["password"] == "kalimera 2026" and j["contact"]["phone"] == "2310 123456"
assert ("signage.changed", sorted([screens[1]["id"], screens[2]["id"]])) in sent
# the venue name is the one every app already reads
assert client.get("/api/settings/", headers=owner_h).json()["venue.name"]["value"] == "Taverna Xenia"
# the screens get it with their venue
venue = client.get("/api/signage/screen", headers=screens[1]["h"]).json()["venue"]
assert venue["name"] == "Taverna Xenia" and venue["identity"]["wifi"]["ssid"] == "Xenia Guests"
assert venue["identity"]["logos"]["main"]["id"] == logo["id"]
# a logo in use can't be deleted
assert err(client.delete(f"/api/media/{logo['id']}", headers=owner_h)) == "media.in_use"
def test_checked(client, owner_h):
assert client.put("/api/identity", headers=owner_h, json={"colours": [{"name": "", "colour": "#000000"}]}).status_code == 422
assert client.put("/api/identity", headers=owner_h, json={"colours": [{"name": "x", "colour": "red"}]}).status_code == 422
assert client.put("/api/identity", headers=owner_h, json={"wifi": {"security": "WPA9"}}).status_code == 422
assert client.put("/api/identity", headers=owner_h, json={"nope": 1}).status_code == 422
assert err(client.put("/api/identity", headers=owner_h, json={"logos": {"main": 99999}})) == "media.not_found"
too_many = [{"name": f"c{i}", "colour": "#000000"} for i in range(13)]
assert client.put("/api/identity", headers=owner_h, json={"colours": too_many}).status_code == 422
def test_opening_hours(client, owner_h, screens, sent):
assert client.get("/api/identity/hours", headers=owner_h).json() == {"days": [[]] * 7, "note": None, "set": False}
days = [[{"from": "18:00", "to": "23:00"}, {"from": "12:00", "to": "15:00"}]] * 5 + [[{"from": "12:00", "to": "01:00"}], []]
sent.clear()
r = client.put("/api/identity/hours", headers=owner_h, json={"days": days, "note": " Closed on holidays "})
assert r.status_code == 200, r.text
j = r.json()
assert j["set"] is True and j["days"][0] == [{"from": "12:00", "to": "15:00"}, {"from": "18:00", "to": "23:00"}]
assert j["days"][6] == [] and j["note"] == "Closed on holidays"
assert ("signage.changed", sorted([screens[1]["id"], screens[2]["id"]])) in sent
assert client.get("/api/signage/screen", headers=screens[1]["h"]).json()["venue"]["hours"]["days"][5] == [{"from": "12:00", "to": "01:00"}]
assert client.put("/api/identity/hours", headers=owner_h, json={"days": [[]] * 6}).status_code == 422
assert client.put("/api/identity/hours", headers=owner_h, json={"days": [[{"from": "25:00", "to": "01:00"}]] + [[]] * 6}).status_code == 422
def test_new_widgets_are_typed(client, owner_h):
from tests.test_signage import playlist, slide
p = playlist(client, owner_h)
widgets = [
{"kind": "shape", "position": "custom", "box": {"x": 10, "y": 10, "w": 20, "h": 20}, "shape": "star", "shape_sides": 5, "fill": "#ff0000", "fill_to": "#0000ff"},
{"kind": "ticker", "position": "bottom-bar", "text": "Fresh fish today " * 10, "ticker_speed": 7},
{"kind": "countdown", "countdown_to": "17:00", "countdown_start": "before", "countdown_before": 120, "countdown_done": "Happy hour!"},
{"kind": "countdown", "countdown_to": "2026-12-31T23:59"},
{"kind": "hours", "hours_style": "today"},
{"kind": "wifi", "wifi_qr": False},
{"kind": "contact", "contact_fields": ["phone", "instagram"]},
]
s = slide(client, owner_h, p["id"], "blank", content={"widgets": widgets})
got = s["content"]["widgets"]
assert [w["kind"] for w in got] == [w["kind"] for w in widgets]
assert got[0]["shape"] == "star" and got[2]["countdown_before"] == 120 and got[6]["contact_fields"] == ["phone", "instagram"]
bad = client.post(f"/api/signage/playlists/{p['id']}/slides", headers=owner_h,
json={"kind": "blank", "content": {"widgets": [{"kind": "countdown", "countdown_to": "5pm"}]}})
assert err(bad) == "signage.content_invalid"
bad = client.post(f"/api/signage/playlists/{p['id']}/slides", headers=owner_h,
json={"kind": "blank", "content": {"widgets": [{"kind": "contact", "contact_fields": ["fax"]}]}})
assert err(bad) == "signage.content_invalid"
def test_reviews_typed_in_by_hand(client, owner_h, screens, sent):
body = {"reviews": [{"name": " Maria K. ", "stars": 5, "text": "Best octopus on the island", "date": "2026-11-01", "source": "Google"},
{"name": "John", "stars": 3, "text": "OK"}]}
sent.clear()
r = client.put("/api/signage/reviews", headers=owner_h, json=body)
assert r.status_code == 200, r.text
got = r.json()["reviews"]
assert got[0]["name"] == "Maria K." and got[0]["text"] == "Best octopus on the island" and got[1]["date"] is None
assert ("signage.changed", sorted([screens[1]["id"], screens[2]["id"]])) in sent
assert client.get("/api/signage/screen", headers=screens[1]["h"]).json()["venue"]["reviews"][0]["stars"] == 5
assert client.get("/api/signage/reviews", headers=owner_h).json()["reviews"][1]["name"] == "John"
assert client.put("/api/signage/reviews", headers=owner_h, json={"reviews": [{"name": "x", "stars": 6, "text": "y"}]}).status_code == 422
assert client.put("/api/signage/reviews", headers=owner_h, json={"reviews": [{"name": "x", "stars": 5, "text": ""}]}).status_code == 422
def test_more_settings_of_widgets(client, owner_h, media_dir):
from tests.test_signage import playlist, slide
logo = up(client, owner_h, jpeg(200, 200)).json()
p = playlist(client, owner_h)
w = {"kind": "date", "opacity": 60, "rotation": -15, "shadow": "glow", "border_width": 4, "border_colour": "#ff0000", "border_radius": 20,
"animation": "pop", "animation_delay": 5, "weight": 300, "highlight": "#ffff0080", "text_effect": "typewriter",
"date_format": "numeric", "date_separator": "."}
q = {"kind": "qr", "media_id": logo["id"], "clock_format": "12", "clock_blink": True}
s = slide(client, owner_h, p["id"], "blank", content={"widgets": [w, q]})
got = s["content"]["widgets"][0]
assert {k: got[k] for k in w} == w
assert s["content"]["widgets"][1]["media_id"] == logo["id"]
for bad in ({"kind": "date", "opacity": 5}, {"kind": "date", "animation": "spin"}, {"kind": "date", "date_separator": "|"}, {"kind": "clock", "weight": 1000}):
r = client.post(f"/api/signage/playlists/{p['id']}/slides", headers=owner_h, json={"kind": "blank", "content": {"widgets": [bad]}})
assert err(r) == "signage.content_invalid", bad