diff --git a/daily_digest.py b/daily_digest.py index ef98f52..cf9f49d 100644 --- a/daily_digest.py +++ b/daily_digest.py @@ -70,8 +70,11 @@ def collect(hours: int = 24) -> dict: "broken_users": sorted({r[0] for r in broken}), } out["topups"] = _topups(since) + t = out["topups"] + # Cron sends with --quiet-ok and decides by this flag: a day of payments is not quiet. out["quiet"] = (out["broken_runs"] == 0 and out["masked_errors"] == 0 - and out["feedback"] == 0) + and out["feedback"] == 0 + and not (t["count"] or t["refunds"] or t["unpaid"])) return out diff --git a/health_checks.py b/health_checks.py index 82e187f..829c6d0 100644 --- a/health_checks.py +++ b/health_checks.py @@ -994,8 +994,8 @@ def check_npd_year_income() -> Check: alarm = _rub_setting("npd_alarm_rub", NPD_ALARM_RUB) text = f"выручка по пополнениям за {now.tm_year} год: {rub:,.0f} ₽".replace(",", " ") if rub >= alarm: - return Check("npd_year_income", False, text + f" — до предела НПД 2,4 млн рукой " - f"подать (порог {alarm:,} ₽)".replace(",", " ")) + return Check("npd_year_income", False, text + " — до предела НПД 2,4 млн рукой " + + f"подать (порог {alarm:,} ₽)".replace(",", " ")) if rub >= warn: return Check("npd_year_income", False, text + f" — выше {warn:,} ₽".replace(",", " "), level="warn") diff --git a/tests/test_topup_health.py b/tests/test_topup_health.py index 9e73851..1a3b5df 100644 --- a/tests/test_topup_health.py +++ b/tests/test_topup_health.py @@ -140,3 +140,22 @@ def test_daily_digest_topup_line(env): _topup(db, "canceled", age=3 * 86400) text = dd.render(dd.collect(24)) assert "Пополнений за сутки: 1 на 1 000 ₽; возвратов 1; неоплаченных 1" in text + + +def test_daily_digest_day_with_only_topups_is_not_quiet(env): + """День, где были только пополнения, — не тихий: крон шлёт сводку с --quiet-ok и + решает по флагу quiet, а не по тексту. Порча: не учитывать пополнения во флаге.""" + db, hc, dd, prov = env + assert dd.collect(24)["quiet"] is True + tid = _topup(db, "pending") + db.credit_topup(tid, 100_000, "{}") + assert dd.collect(24)["quiet"] is False + + +def test_npd_alarm_text_keeps_decimal_comma(env): + """Текст тревоги НПД читаем: «2,4 млн», а не «2 4 млн» — замена разделителя тысяч не + трогает десятичную запятую. Порча: заменять запятые во всей фразе.""" + db, hc, dd, prov = env + _topup(db, "succeeded", kop=240_000_000) + c = hc.check_npd_year_income() + assert not c.ok and "2,4 млн" in c.detail and "2 300 000 ₽" in c.detail