daily
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.homelab.openmeteo import (
|
||||
RECOMMENDED_SYNC_DOMAINS,
|
||||
RECOMMENDED_SYNC_VARIABLES,
|
||||
SYNC_HINT,
|
||||
_coverage_sufficient,
|
||||
_field_coverage,
|
||||
_hourly_start_index,
|
||||
build_weather_dashboard,
|
||||
)
|
||||
|
||||
|
||||
def test_hourly_start_index_from_current():
|
||||
times = ["2026-06-14T00:00", "2026-06-14T01:00", "2026-06-14T18:00", "2026-06-14T19:00"]
|
||||
assert _hourly_start_index(times, "2026-06-14T18:15") == 2
|
||||
|
||||
|
||||
def test_coverage_sufficient():
|
||||
assert _coverage_sufficient({"current": ["temperature_2m"], "hourly": ["temperature_2m"]}) is False
|
||||
assert _coverage_sufficient(
|
||||
{
|
||||
"current": ["temperature_2m", "weather_code", "wind_speed_10m"],
|
||||
"hourly": ["temperature_2m", "precipitation_probability", "weather_code"],
|
||||
}
|
||||
) is True
|
||||
|
||||
|
||||
def test_field_coverage_partial():
|
||||
raw = {
|
||||
"current": {"time": "2026-06-14T18:15", "temperature_2m": 20.6},
|
||||
"hourly": {
|
||||
"time": ["2026-06-14T18:00", "2026-06-14T19:00"],
|
||||
"temperature_2m": [20.0, 19.5],
|
||||
"precipitation": [0.0, 0.0],
|
||||
},
|
||||
}
|
||||
coverage = _field_coverage(raw)
|
||||
assert coverage["current"] == ["temperature_2m"]
|
||||
assert "temperature_2m" in coverage["hourly"]
|
||||
assert "precipitation" in coverage["hourly"]
|
||||
assert "weather_code" not in coverage["hourly"]
|
||||
|
||||
|
||||
def test_build_weather_dashboard_includes_sync_hint():
|
||||
fake_weather = {
|
||||
"ok": True,
|
||||
"location": "Test",
|
||||
"data_source": "local",
|
||||
"local_field_coverage": {"current": ["temperature_2m"], "hourly": ["temperature_2m"]},
|
||||
"field_coverage": {"current": ["temperature_2m"], "hourly": ["temperature_2m"]},
|
||||
"sync_hint": SYNC_HINT,
|
||||
"current": {"temperature_c": 10, "conditions": "неизвестно"},
|
||||
"hourly": [],
|
||||
}
|
||||
with patch("app.homelab.openmeteo.OpenMeteoClient") as mock_cls:
|
||||
client = mock_cls.return_value
|
||||
client.fetch_current_and_hourly.return_value = fake_weather
|
||||
client.rain_summary.return_value = "ok"
|
||||
client.cache_status.return_value = {"source": "local", "has_data": True, "cached": True, "ttl_sec": 300}
|
||||
client.location_name = "Test"
|
||||
client.lat = 1.0
|
||||
client.lon = 2.0
|
||||
client.base_url = "http://local"
|
||||
client.cache_ttl = 300
|
||||
result = build_weather_dashboard()
|
||||
assert result["sync_hint"]
|
||||
assert result["recommended_sync"]["domains"] == RECOMMENDED_SYNC_DOMAINS
|
||||
assert result["recommended_sync"]["variables"] == RECOMMENDED_SYNC_VARIABLES
|
||||
Reference in New Issue
Block a user