05/23 Phase 12
This commit is contained in:
@@ -4,6 +4,8 @@ tests/test_dashboard.py
|
||||
Tests for the Dashboard screen data layer and UI smoke tests.
|
||||
"""
|
||||
|
||||
from datetime import date
|
||||
|
||||
import pytest
|
||||
from db.models import (
|
||||
get_all_games, get_game_by_name, get_last_draw,
|
||||
@@ -11,6 +13,7 @@ from db.models import (
|
||||
)
|
||||
from db.database import get_db_stats
|
||||
from core.analyzer import frequency_analysis
|
||||
from ui.dashboard import _next_draw_date
|
||||
|
||||
|
||||
# ── Data-layer checks used by the Dashboard ───────────────────────────────────
|
||||
@@ -77,6 +80,48 @@ def test_predictions_count_correct(tmp_db):
|
||||
assert len(get_predictions(limit=100_000)) == 2
|
||||
|
||||
|
||||
|
||||
# ── _next_draw_date ───────────────────────────────────────────────────────────
|
||||
|
||||
def test_next_draw_powerball_from_friday():
|
||||
# Friday → next Powerball is Saturday
|
||||
fri = date(2024, 5, 24) # Friday, weekday=4
|
||||
result = _next_draw_date("Powerball", from_date=fri)
|
||||
assert "Sat" in result
|
||||
|
||||
|
||||
def test_next_draw_powerball_from_saturday():
|
||||
# Saturday → next Powerball is Monday
|
||||
sat = date(2024, 5, 25) # Saturday, weekday=5
|
||||
result = _next_draw_date("Powerball", from_date=sat)
|
||||
assert "Mon" in result
|
||||
|
||||
|
||||
def test_next_draw_mega_millions_from_friday():
|
||||
# Friday → next MM is Tuesday (4 days away)
|
||||
fri = date(2024, 5, 24)
|
||||
result = _next_draw_date("Mega Millions", from_date=fri)
|
||||
assert "Tue" in result
|
||||
|
||||
|
||||
def test_next_draw_mega_millions_from_monday():
|
||||
# Monday → next MM is Tuesday (1 day away)
|
||||
mon = date(2024, 5, 20) # Monday, weekday=0
|
||||
result = _next_draw_date("Mega Millions", from_date=mon)
|
||||
assert "Tue" in result
|
||||
|
||||
|
||||
def test_next_draw_unknown_game_returns_empty():
|
||||
assert _next_draw_date("Unknown Game") == ""
|
||||
|
||||
|
||||
def test_next_draw_always_in_future():
|
||||
today = date.today()
|
||||
for name in ("Powerball", "Mega Millions"):
|
||||
result = _next_draw_date(name, from_date=today)
|
||||
assert result != "" # always finds a future date within 7 days
|
||||
|
||||
|
||||
# ── UI smoke tests ────────────────────────────────────────────────────────────
|
||||
|
||||
def _has_display():
|
||||
|
||||
@@ -122,6 +122,72 @@ def test_combined_filters(tmp_db):
|
||||
assert rows[0]["draw_date"] == "2024-03-01"
|
||||
|
||||
|
||||
|
||||
# ── number filter ─────────────────────────────────────────────────────────────
|
||||
|
||||
def test_number_filter_returns_matching_draws(tmp_db):
|
||||
pb = get_game_by_name("Powerball")
|
||||
insert_draw(pb["id"], "2024-01-01", [1, 13, 36, 61, 69], bonus=7)
|
||||
insert_draw(pb["id"], "2024-01-03", [2, 14, 37, 55, 68], bonus=10)
|
||||
|
||||
rows = get_draws_with_game(number=13)
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["draw_date"] == "2024-01-01"
|
||||
|
||||
|
||||
def test_number_filter_no_match_returns_empty(tmp_db):
|
||||
pb = get_game_by_name("Powerball")
|
||||
insert_draw(pb["id"], "2024-01-01", [1, 2, 3, 4, 5], bonus=7)
|
||||
|
||||
rows = get_draws_with_game(number=99)
|
||||
assert rows == []
|
||||
|
||||
|
||||
def test_number_filter_does_not_false_match_substring(tmp_db):
|
||||
pb = get_game_by_name("Powerball")
|
||||
# numbers 1 and 13 — searching for 1 must NOT return the draw containing 13
|
||||
insert_draw(pb["id"], "2024-01-01", [13, 23, 33, 43, 53], bonus=7)
|
||||
|
||||
rows = get_draws_with_game(number=1)
|
||||
assert rows == []
|
||||
|
||||
|
||||
def test_number_filter_matches_first_position(tmp_db):
|
||||
pb = get_game_by_name("Powerball")
|
||||
insert_draw(pb["id"], "2024-01-01", [1, 2, 3, 4, 5], bonus=7)
|
||||
|
||||
rows = get_draws_with_game(number=1)
|
||||
assert len(rows) == 1
|
||||
|
||||
|
||||
def test_number_filter_matches_last_position(tmp_db):
|
||||
pb = get_game_by_name("Powerball")
|
||||
insert_draw(pb["id"], "2024-01-01", [1, 2, 3, 4, 69], bonus=7)
|
||||
|
||||
rows = get_draws_with_game(number=69)
|
||||
assert len(rows) == 1
|
||||
|
||||
|
||||
def test_number_filter_combined_with_game(tmp_db):
|
||||
pb = get_game_by_name("Powerball")
|
||||
mm = get_game_by_name("Mega Millions")
|
||||
insert_draw(pb["id"], "2024-01-01", [1, 13, 36, 61, 69], bonus=7)
|
||||
insert_draw(mm["id"], "2024-01-02", [1, 14, 37, 55, 68], bonus=4)
|
||||
|
||||
rows = get_draws_with_game(game_id=pb["id"], number=1)
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["game_name"] == "Powerball"
|
||||
|
||||
|
||||
def test_number_filter_none_returns_all(tmp_db):
|
||||
pb = get_game_by_name("Powerball")
|
||||
insert_draw(pb["id"], "2024-01-01", [1, 2, 3, 4, 5], bonus=7)
|
||||
insert_draw(pb["id"], "2024-01-03", [6, 7, 8, 9, 10], bonus=2)
|
||||
|
||||
rows = get_draws_with_game(number=None)
|
||||
assert len(rows) == 2
|
||||
|
||||
|
||||
# ── UI smoke test (skipped on headless) ───────────────────────────────────────
|
||||
|
||||
def _has_display():
|
||||
|
||||
Reference in New Issue
Block a user