55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
import os
|
|
import sys
|
|
|
|
|
|
# Ensure repo root is on sys.path when running as a script.
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
if ROOT not in sys.path:
|
|
sys.path.insert(0, ROOT)
|
|
|
|
from app import create_app
|
|
from app.extensions import db
|
|
from app.models import Company, Display
|
|
|
|
|
|
def main():
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
# Create a company + display
|
|
c = Company(name="TestCo_DisplayLimit")
|
|
db.session.add(c)
|
|
db.session.commit()
|
|
|
|
d = Display(company_id=c.id, name="Lobby")
|
|
db.session.add(d)
|
|
db.session.commit()
|
|
|
|
token = d.token
|
|
|
|
client = app.test_client()
|
|
|
|
def hit(sid: str):
|
|
return client.get(f"/api/display/{token}/playlist?sid={sid}")
|
|
|
|
# First 3 should be accepted (200 with JSON)
|
|
for sid in ("s1", "s2", "s3"):
|
|
r = hit(sid)
|
|
assert r.status_code == 200, (sid, r.status_code, r.data)
|
|
|
|
# 4th should be rejected with 429 and a clear message
|
|
r4 = hit("s4")
|
|
assert r4.status_code == 429, (r4.status_code, r4.data)
|
|
payload = r4.get_json(silent=True) or {}
|
|
assert payload.get("error") == "display_limit_reached", payload
|
|
msg = payload.get("message") or ""
|
|
assert "open on 3" in msg, msg
|
|
|
|
print("OK: display session limit allows 3 sessions; 4th is rejected with 429.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|