52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from web_core.settings.settings_schema import normalize_web_settings
|
|
|
|
|
|
def test_normalize_watchlist_from_string_and_deduplicates() -> None:
|
|
raw = {"watchlist": "aapl, msft\nAAPL\n btc-usd "}
|
|
out = normalize_web_settings(raw)
|
|
assert out["watchlist"] == ["AAPL", "MSFT", "BTC-USD"]
|
|
|
|
|
|
def test_normalize_watchlist_from_list_caps_length() -> None:
|
|
raw_list = [f"sym{i}" for i in range(60)]
|
|
out = normalize_web_settings({"watchlist": raw_list})
|
|
assert len(out["watchlist"]) == 40
|
|
assert out["watchlist"][0] == "SYM0"
|
|
|
|
|
|
def test_market_preset_defaults_to_custom_on_invalid_value() -> None:
|
|
out = normalize_web_settings({"market_preset": "not-real"})
|
|
assert out["market_preset"] == "Custom"
|
|
|
|
|
|
def test_normalize_watchlist_splits_legacy_escaped_newline_values() -> None:
|
|
out = normalize_web_settings({"watchlist": "AAPL\\nMSFT\\NTSLA"})
|
|
assert out["watchlist"] == ["AAPL", "MSFT", "TSLA"]
|
|
|
|
|
|
def test_normalize_watchlist_splits_escaped_newlines_inside_list_items() -> None:
|
|
out = normalize_web_settings({"watchlist": ["AMD\\NTSLA"]})
|
|
assert out["watchlist"] == ["AMD", "TSLA"]
|
|
|
|
|
|
def test_display_timezone_defaults_to_central_when_invalid() -> None:
|
|
out = normalize_web_settings({"display_timezone": "Europe/London"})
|
|
assert out["display_timezone"] == "America/Chicago"
|
|
|
|
|
|
def test_display_timezone_accepts_supported_us_timezone() -> None:
|
|
out = normalize_web_settings({"display_timezone": "America/Los_Angeles"})
|
|
assert out["display_timezone"] == "America/Los_Angeles"
|
|
|
|
|
|
def test_use_24h_time_defaults_false() -> None:
|
|
out = normalize_web_settings({})
|
|
assert out["use_24h_time"] is False
|
|
|
|
|
|
def test_use_24h_time_normalizes_truthy_values() -> None:
|
|
out = normalize_web_settings({"use_24h_time": "true"})
|
|
assert out["use_24h_time"] is True
|