"""Slide shapes and a screen's picture (6R.13, owner 2026-11-22): custom shapes for playlists and library slides, a screen's picture area (insets) and fit, calibrating told to that screen only, the window size a screen reports.""" from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures) from tests.test_signage import playlist, screens, sent, slide # noqa: F401 (fixtures + helpers) def test_custom_shapes_for_playlists_and_library_slides(client, owner_h): p = playlist(client, owner_h, aspect="21:9") assert (p["orientation"], p["aspect"]) == ("landscape", "21:9") r = client.put(f"/api/signage/playlists/{p['id']}", headers=owner_h, json={"aspect": "10:16"}) assert (r.json()["orientation"], r.json()["aspect"]) == ("portrait", "10:16") # the plain shapes are landscape / portrait; picking one drops a custom shape r = client.put(f"/api/signage/playlists/{p['id']}", headers=owner_h, json={"aspect": "16:9"}) assert (r.json()["orientation"], r.json()["aspect"]) == ("landscape", None) client.put(f"/api/signage/playlists/{p['id']}", headers=owner_h, json={"aspect": "32:9"}) r = client.put(f"/api/signage/playlists/{p['id']}", headers=owner_h, json={"orientation": "portrait"}) assert (r.json()["orientation"], r.json()["aspect"]) == ("portrait", None) for bad in ("21x9", "9:1", "0:5"): assert client.put(f"/api/signage/playlists/{p['id']}", headers=owner_h, json={"aspect": bad}).status_code == 422 dup = client.post(f"/api/signage/playlists/{p['id']}/duplicate", headers=owner_h).json() assert dup["orientation"] == "portrait" s = client.post("/api/signage/library", headers=owner_h, json={"name": "Wide", "kind": "text", "aspect": "16:10"}).json() assert (s["orientation"], s["aspect"]) == ("landscape", "16:10") r = client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"aspect": None, "orientation": "portrait"}) assert (r.json()["orientation"], r.json()["aspect"]) == ("portrait", None) def test_a_screens_picture_area_and_calibration(client, owner_h, screens, sent): tv, other = screens[1], screens[2] p = playlist(client, owner_h, aspect="21:9") slide(client, owner_h, p["id"], "text", content={"title": "Wide"}) client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"playlist_id": p["id"]}) got = client.get("/api/signage/screen", headers=tv["h"]).json() assert got["playlist"]["aspect"] == "21:9" and got["screen"]["fit"] == "keep" and got["screen"]["calibrating"] is False # the TV reports its window; the manager sees it assert client.post("/api/signage/screen/viewport", headers=tv["h"], json={"width": 2560, "height": 1080, "ratio": 1}).status_code == 200 one = next(s for s in client.get("/api/signage/screens", headers=owner_h).json() if s["id"] == tv["id"]) assert one["viewport"] == {"width": 2560, "height": 1080, "ratio": 1.0} and one["area"] == {"left": 0, "top": 0, "right": 0, "bottom": 0} # calibrating: only that TV hears it, with its area; every change of the insets follows at once sent.clear() r = client.post(f"/api/signage/screens/{tv['id']}/calibrate", headers=owner_h, json={"on": True}) assert r.json()["calibrating"] is True and sent == [("signage.calibrate", [tv["id"]])] sent.clear() r = client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"area_left": 320, "area_right": 320, "fit": "stretch"}) assert r.json()["area"] == {"left": 320, "top": 0, "right": 320, "bottom": 0} and r.json()["fit"] == "stretch" assert sent[0] == ("signage.calibrate", [tv["id"]]) and ("signage.changed", [tv["id"]]) in sent scr = client.get("/api/signage/screen", headers=tv["h"]).json()["screen"] assert scr["area"]["left"] == 320 and scr["calibrating"] is True sent.clear() client.post(f"/api/signage/screens/{tv['id']}/calibrate", headers=owner_h, json={"on": False}) assert sent == [("signage.calibrate", [tv["id"]])] sent.clear() client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"area_top": 5}) assert ("signage.calibrate", [tv["id"]]) not in sent # limits; not a screen assert client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"area_left": 5000}).status_code == 422 assert err(client.post("/api/signage/screens/99999/calibrate", headers=owner_h, json={"on": True})) == "signage.not_a_screen" # a screen can't calibrate itself or report for another assert client.post(f"/api/signage/screens/{other['id']}/calibrate", headers=tv["h"], json={"on": True}).status_code in (401, 403) def test_calibration_ends_by_itself(client, owner_h, screens, monkeypatch): import routers.signage as sg tv = screens[1] client.post(f"/api/signage/screens/{tv['id']}/calibrate", headers=owner_h, json={"on": True}) assert sg.calibrating(tv["id"]) is True sg._calibrating[tv["id"]] -= sg.CALIBRATE_S + 1 assert client.get("/api/signage/screen", headers=tv["h"]).json()["screen"]["calibrating"] is False