Files
Home_assistant/backend/tests/test_weather_dashboard.py
T
2026-06-16 04:38:23 +00:00

76 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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",
"data_source": "local",
"local_field_coverage": {"current": ["temperature_2m"], "hourly": [], "daily": []},
"field_coverage": {"current": ["temperature_2m"], "hourly": [], "daily": []},
"sync_hint": "",
"merged_fields": [],
"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": "переменная облачность",
}
],
"daily": [
{
"date": "2026-06-14",
"label": "Завтра",
"temperature_max_c": 20.0,
"temperature_min_c": 12.0,
"conditions": "дождь",
}
],
}
with patch("app.homelab.openmeteo.OpenMeteoClient") as mock_cls:
client = mock_cls.return_value
client.fetch_forecast.return_value = fake_weather
client.rain_summary.return_value = "Существенных осадков в ближайшие часы не ожидается."
client.daily_summary.return_value = "Завтра: 1220°C"
client.cache_status.return_value = {
"has_data": True,
"cached": True,
"fetched_at": 1.0,
"age_sec": 10,
"ttl_sec": 300,
"expires_in_sec": 290,
"source": "local",
"merged_fields": [],
}
client.location_name = "Test City"
client.lat = 59.9
client.lon = 30.3
client.base_url = "http://openmeteo.test"
client.cache_ttl = 300
client.forecast_days = 7
result = build_weather_dashboard(hours_ahead=6, days_ahead=7)
assert result["weather"]["ok"] is True
assert "[Погода]" in result["assistant_context"]
assert "None" not in result["assistant_context"]
assert "daily" in result["available_fields"]
assert result["daily_summary"]
assert result["config"]["location"] == "Test City"