Files
Profeto/tests/test_matches_cursor.py

26 lines
1.2 KiB
Python

"""验证: matches 游标翻页方向正确且无重复 id。
scheduled 升序游标条件必须为 > 而非 <;翻页返回的 id 集合无重复。
端到端验证脚本(容器内运行,通过 nginx 代理):
python - <<'PY'
import urllib.parse, urllib.request, json
base = "http://localhost:3000/api/v1/matches?league=E0&status=scheduled&limit=50&cursor="
seen = set(); cursor = None; pages = 0
while True:
url = base + ("" if cursor is None else urllib.parse.quote(cursor, safe=""))
d = json.load(urllib.request.urlopen(url))
ids = [m["id"] for m in d["items"]]
dup = seen.intersection(ids)
assert not dup, f"页{pages}出现重复id: {dup}"
seen.update(ids); pages += 1
if not d["has_more"] or not d["next_cursor"]: break
cursor = d["next_cursor"]
import subprocess
total = int(subprocess.check_output(
["psql","-U","football","-d","football","-tAc",
"SELECT count(*) FROM matches WHERE match_status='scheduled' AND league_id=(SELECT id FROM leagues WHERE code='E0')"]))
assert len(seen) == total, f"翻页得{len(seen)}条,库中{total}条"
print(f"PASS: {pages}页共{len(seen)}条,无重复")
PY
"""