Files
Home_assistant/backend/tests/test_weather_dashboard.py
T
2026-06-15 03:15:08 +00:00

58 lines
2.0 KiB
Python

from unittest.mock import patch
from app.homelab.openmeteo import build_weather_dashboard
def test_build_weather_dashboard_structure():
fake_weather = {
"ok": True,
"location": "Test City",
"current": {
"time": "2026-06-13T12:00",
"temperature_c": 18.5,
"apparent_temperature_c": 17.0,
"humidity_pct": 55,
"precipitation_mm": 0.0,
"wind_speed_kmh": 12.0,
"weather_code": 2,
"conditions": "переменная облачность",
},
"hourly": [
{
"time": "2026-06-13T12:00",
"temperature_c": 18.5,
"precipitation_mm": 0.0,
"precipitation_probability": 10,
"weather_code": 2,
"conditions": "переменная облачность",
}
],
}
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 = "Существенных осадков в ближайшие часы не ожидается."
client.cache_status.return_value = {
"has_data": True,
"cached": True,
"fetched_at": 1.0,
"age_sec": 10,
"ttl_sec": 300,
"expires_in_sec": 290,
}
client.location_name = "Test City"
client.lat = 59.9
client.lon = 30.3
client.base_url = "http://openmeteo.test"
client.cache_ttl = 300
result = build_weather_dashboard(hours_ahead=6)
assert result["weather"]["ok"] is True
assert "[Погода]" in result["assistant_context"]
assert "None" not in result["assistant_context"]
assert "temperature_2m" in result["available_fields"]["current"]
assert "get_weather" in result["assistant_tools"]
assert result["config"]["location"] == "Test City"