Reviews (name, stars, text, date, where) under Signage -> Message & settings, shown one at a time by the reviews widget (a minimum of stars, seconds each); not pulled from Google (owner's choice). The widgets section: one "Add a widget" menu at its top instead of a button per kind; the cards are layers, the top one drawn over the others, so a new widget goes on top; the arrows bring forward / send backward. Plan 6R.19, F-113. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
7.0 KiB
Python
102 lines
7.0 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
|