Files
Lottery-Tracker/tests/test_config.py
2026-02-18 08:24:54 -05:00

48 lines
1.2 KiB
Python

"""Tests for config.py."""
from __future__ import annotations
import os
from unittest.mock import patch
from config import LOTTERY_ODDS, STATE_TAX_RATES, load_config
def test_all_states_present():
assert len(STATE_TAX_RATES) == 51 # 50 states + DC
def test_all_lottery_odds_present():
assert "powerball" in LOTTERY_ODDS
assert "megaMillions" in LOTTERY_ODDS
assert "lottoMax" in LOTTERY_ODDS
assert "lotto649" in LOTTERY_ODDS
def test_load_config_defaults():
cfg = load_config()
assert cfg.debug is False
assert cfg.port == 5000
assert cfg.tax.lump_sum_rate == 0.52
assert cfg.investment.cycles == 8
@patch.dict(os.environ, {"FLASK_DEBUG": "true", "FLASK_PORT": "8080"})
def test_load_config_from_env():
cfg = load_config()
assert cfg.debug is True
assert cfg.port == 8080
@patch.dict(os.environ, {"LUMP_SUM_RATE": "0.60"})
def test_tax_config_from_env():
cfg = load_config()
assert cfg.tax.lump_sum_rate == 0.60
def test_no_tax_states():
"""Florida, Texas, Nevada, etc. should have 0% tax."""
no_tax = ["AK", "FL", "NV", "NH", "SD", "TN", "TX", "WA", "WY"]
for code in no_tax:
assert STATE_TAX_RATES[code]["rate"] == 0.0, f"{code} should have 0% tax"