Files
xenia-pos-local/local_backend/tests/test_identity.py
T
bonaminandClaude Opus 5.5 f26e51273c feat(signage): new widgets (shape, scrolling text, countdown, opening hours, Wi-Fi, contact details); the venue's opening hours on the server, edited on the Schedule page
Shapes: rectangle, circle, triangle, polygon, star or own corners, fill or gradient,
border. Countdown: to a time every day or a date, from now / a span before / a set
time, in venue time (the slide shows what is left right now). Opening hours, Wi-Fi
(with a join-the-network code) and contact details read the venue's identity and
opening hours (GET/PUT /api/identity/hours; Schedule -> Opening hours, shaded on its
timeline); the editor warns with a link when they're missing. Plan 6R.15, F-112.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:24:54 +02:00

87 lines
5.9 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"