feat: implement Telegram push utility and corresponding hashtag validation tests

This commit is contained in:
2569718930@qq.com
2026-05-17 13:37:51 +08:00
parent 8e2317592d
commit 07bb8e1d15
2 changed files with 155 additions and 6 deletions
+56
View File
@@ -1,4 +1,7 @@
from src.utils.telegram_push import (
HIGH_FREQ_AIRPORT_CITIES,
HIGH_FREQ_AIRPORT_ICAO,
MARKET_MONITOR_CITIES,
MARKET_MONITOR_INTERVAL_SEC,
_build_airport_status_message,
_build_market_monitor_message,
@@ -52,5 +55,58 @@ def test_market_monitor_message_starts_with_market_hashtag_and_city():
assert "当前:29.4°C · DEB31.2°C" in text
def test_market_monitor_uses_focus_runway_temperature_for_key_airports():
text = _build_market_monitor_message(
"shanghai",
{
"local_time": "14:01",
"airport_current": {"temp": 29.4},
"deb": {"prediction": 31.2},
"amos": {
"source": "amsc_awos",
"runway_obs": {
"runway_pairs": [("16L", "34R"), ("17L", "35R")],
"temperatures": [(36.0, None), (31.8, None)],
},
},
},
)
assert "当前:31.8°C · DEB31.2°C" in text
def test_airport_status_hides_non_focus_runways_for_key_airports():
text = _build_airport_status_message(
"chongqing",
{
"current": {"temp": 28.0},
"airport_current": {"max_so_far": 30.0, "max_temp_time": "13:00"},
"amos": {
"source": "amsc_awos",
"runway_obs": {
"runway_pairs": [("02L", "20R"), ("02R", "20L")],
"temperatures": [(31.1, None), (34.9, None)],
"point_temperatures": [
{"tdz_temp": 31.0, "mid_temp": 31.1, "end_temp": 31.2},
{"tdz_temp": 34.8, "mid_temp": 34.9, "end_temp": 35.0},
],
},
},
},
32.0,
"13:00",
)
assert "02L/20R" in text
assert "02R/20L" not in text
assert "当前:31.1°C" in text
def test_market_monitor_default_interval_is_five_minutes():
assert MARKET_MONITOR_INTERVAL_SEC == 300
def test_singapore_is_in_telegram_push_city_lists():
assert "singapore" not in MARKET_MONITOR_CITIES
assert "singapore" in HIGH_FREQ_AIRPORT_CITIES
assert HIGH_FREQ_AIRPORT_ICAO["singapore"] == "WSSS"