Coverage for notifications/event_keys.py: 100.00%
7 statements
« prev ^ index » next coverage.py v7.10.6, created at 2026-11-30 18:53 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2026-11-30 18:53 +0000
1"""Stable identities for match events (SB-1603).
3The delivery ledger allows one post per (channel, event_key), so a key must be
4the same every time the same event is announced and different for different
5events. Pure, so those rules are testable without a database.
6"""
8from __future__ import annotations
11def recorded_event_key(match_id: int, event_id: int) -> str:
12 """A goal or card, identified by its `match_events` row."""
13 return f"match:{match_id}:event:{event_id}"
16def clock_event_key(match_id: int, event_type: str) -> str:
17 """Kickoff or halftime, which happen once per match."""
18 return f"match:{match_id}:{event_type}"
21def fulltime_event_key(match_id: int, home_score: int | None, away_score: int | None) -> str:
22 """Full time, keyed by score.
24 Live scoring and a later match write announcing the same result share a
25 key, so it posts once. A corrected score is a new key, so it posts again.
26 A live match with no goals can still hold NULL scores, which is 0-0 here.
27 """
28 return f"match:{match_id}:fulltime:{home_score or 0}-{away_score or 0}"