Tests cover providers, dedup, Telegram, scoring, main runner, and Airbnb stubs. Ticketmaster and SeatGeek use configurable lat/lon/radius (Thornhill default). Pipeline filters noise listings, merges same-day sports duplicates, optional MIN_ALERT_SCORE, and Telegram severity summary. Made-with: Cursor
130 lines
4.3 KiB
Python
130 lines
4.3 KiB
Python
"""Tests for the impact scoring module."""
|
|
|
|
from datetime import date
|
|
|
|
from src.models import NormalizedEvent
|
|
from src.scoring.impact import score_event, score_events, VENUE_CAPACITY, MAX_CAPACITY, _team_boost
|
|
|
|
|
|
def _make_event(
|
|
venue: str, event_date: date = date(2026, 5, 10), name: str = "Test Event",
|
|
) -> NormalizedEvent:
|
|
return NormalizedEvent(
|
|
name=name, event_date=event_date,
|
|
venue=venue, source="test",
|
|
)
|
|
|
|
|
|
class TestScoreEvent:
|
|
def test_rogers_centre_gets_highest_score(self):
|
|
event = _make_event("Rogers Centre")
|
|
scored = score_event(event)
|
|
assert scored.score == 1.0
|
|
|
|
def test_scotiabank_arena_proportion(self):
|
|
event = _make_event("Scotiabank Arena")
|
|
scored = score_event(event)
|
|
expected = round(19800 / MAX_CAPACITY, 2)
|
|
assert scored.score == expected
|
|
|
|
def test_unknown_venue_gets_default(self):
|
|
event = _make_event("Random Bar")
|
|
scored = score_event(event)
|
|
assert scored.score == 0.3
|
|
|
|
def test_case_insensitive_venue_matching(self):
|
|
event = _make_event("SCOTIABANK ARENA")
|
|
scored = score_event(event)
|
|
expected = round(19800 / MAX_CAPACITY, 2)
|
|
assert scored.score == expected
|
|
|
|
def test_preserves_other_fields(self):
|
|
original = NormalizedEvent(
|
|
name="Some Concert", event_date=date(2026, 5, 10),
|
|
venue="Scotiabank Arena", source="ticketmaster",
|
|
url="https://example.com", raw={"key": "value"},
|
|
)
|
|
scored = score_event(original)
|
|
assert scored.name == original.name
|
|
assert scored.event_date == original.event_date
|
|
assert scored.venue == original.venue
|
|
assert scored.source == original.source
|
|
assert scored.url == original.url
|
|
assert scored.raw == original.raw
|
|
|
|
def test_all_known_venues_score_above_zero(self):
|
|
for venue_name in VENUE_CAPACITY:
|
|
event = _make_event(venue_name)
|
|
scored = score_event(event)
|
|
assert scored.score > 0, f"{venue_name} scored 0"
|
|
|
|
|
|
class TestScoreEvents:
|
|
def test_empty_list(self):
|
|
assert score_events([]) == []
|
|
|
|
def test_sorts_by_score_descending(self):
|
|
events = [
|
|
_make_event("Massey Hall"),
|
|
_make_event("Rogers Centre"),
|
|
_make_event("Scotiabank Arena"),
|
|
]
|
|
scored = score_events(events)
|
|
scores = [e.score for e in scored]
|
|
assert scores == sorted(scores, reverse=True)
|
|
|
|
def test_tiebreaker_is_date(self):
|
|
events = [
|
|
_make_event("Scotiabank Arena", date(2026, 5, 15)),
|
|
_make_event("Scotiabank Arena", date(2026, 5, 10)),
|
|
]
|
|
scored = score_events(events)
|
|
assert scored[0].event_date == date(2026, 5, 10)
|
|
assert scored[1].event_date == date(2026, 5, 15)
|
|
|
|
def test_scores_all_events(self):
|
|
events = [_make_event("Venue A"), _make_event("Venue B")]
|
|
scored = score_events(events)
|
|
assert len(scored) == 2
|
|
assert all(e.score > 0 for e in scored)
|
|
|
|
|
|
class TestTeamBoost:
|
|
def test_raptors_get_boost(self):
|
|
assert _team_boost("Toronto Raptors vs. Miami Heat") == 0.42
|
|
|
|
def test_blue_jays_get_boost(self):
|
|
assert _team_boost("Toronto Blue Jays vs. Yankees") == 0.20
|
|
|
|
def test_leafs_get_boost(self):
|
|
assert _team_boost("Maple Leafs vs Bruins") == 0.42
|
|
|
|
def test_no_team_no_boost(self):
|
|
assert _team_boost("Drake Concert") == 0.0
|
|
|
|
def test_case_insensitive(self):
|
|
assert _team_boost("RAPTORS vs celtics") == 0.42
|
|
|
|
def test_boost_added_to_venue_score(self):
|
|
event = _make_event("Scotiabank Arena", name="Toronto Raptors vs Heat")
|
|
scored = score_event(event)
|
|
base = round(19800 / MAX_CAPACITY, 2)
|
|
assert scored.score == min(base + 0.42, 1.0)
|
|
|
|
def test_boost_capped_at_one(self):
|
|
event = _make_event("Rogers Centre", name="Blue Jays vs Yankees")
|
|
scored = score_event(event)
|
|
assert scored.score == 1.0
|
|
|
|
def test_marlies_smaller_boost(self):
|
|
assert _team_boost("Toronto Marlies v Charlotte") == 0.05
|
|
|
|
|
|
class TestVenueCapacity:
|
|
def test_max_capacity_is_rogers_centre(self):
|
|
assert MAX_CAPACITY == 49000
|
|
|
|
def test_all_capacities_positive(self):
|
|
for venue, cap in VENUE_CAPACITY.items():
|
|
assert cap > 0, f"{venue} has non-positive capacity"
|