kin: BATON-BIZ-002 Убрать hardcoded VAPID key из meta-тега, читать с /api/push/public-key
This commit is contained in:
parent
ea06309a6e
commit
6444b30d17
7 changed files with 488 additions and 159 deletions
96
tests/test_biz_004.py
Normal file
96
tests/test_biz_004.py
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
"""
|
||||
BATON-BIZ-004: Verify removal of dead code from backend/telegram.py.
|
||||
|
||||
Acceptance criteria:
|
||||
1. telegram.py does NOT contain duplicate logging setLevel calls for httpx/httpcore.
|
||||
2. telegram.py does NOT contain the SignalAggregator class.
|
||||
3. httpx/httpcore logging suppression is still configured in main.py (globally).
|
||||
4. SignalAggregator is NOT importable from backend.telegram.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import importlib
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_BACKEND_DIR = Path(__file__).parent.parent / "backend"
|
||||
_TELEGRAM_SRC = (_BACKEND_DIR / "telegram.py").read_text(encoding="utf-8")
|
||||
_MAIN_SRC = (_BACKEND_DIR / "main.py").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Criteria 1 — no setLevel for httpx/httpcore in telegram.py
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_telegram_has_no_httpx_setlevel():
|
||||
"""telegram.py must not set log level for 'httpx'."""
|
||||
assert 'getLogger("httpx").setLevel' not in _TELEGRAM_SRC
|
||||
assert "getLogger('httpx').setLevel" not in _TELEGRAM_SRC
|
||||
|
||||
|
||||
def test_telegram_has_no_httpcore_setlevel():
|
||||
"""telegram.py must not set log level for 'httpcore'."""
|
||||
assert 'getLogger("httpcore").setLevel' not in _TELEGRAM_SRC
|
||||
assert "getLogger('httpcore').setLevel" not in _TELEGRAM_SRC
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Criteria 2 — SignalAggregator absent from telegram.py source
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_telegram_source_has_no_signal_aggregator_class():
|
||||
"""telegram.py source text must not contain the class definition."""
|
||||
assert "class SignalAggregator" not in _TELEGRAM_SRC
|
||||
|
||||
|
||||
def test_telegram_source_has_no_signal_aggregator_reference():
|
||||
"""telegram.py source text must not reference SignalAggregator at all."""
|
||||
assert "SignalAggregator" not in _TELEGRAM_SRC
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Criteria 3 — httpx/httpcore suppression still lives in main.py
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_main_suppresses_httpx_logging():
|
||||
"""main.py must call getLogger('httpx').setLevel to suppress noise."""
|
||||
assert (
|
||||
'getLogger("httpx").setLevel' in _MAIN_SRC
|
||||
or "getLogger('httpx').setLevel" in _MAIN_SRC
|
||||
)
|
||||
|
||||
|
||||
def test_main_suppresses_httpcore_logging():
|
||||
"""main.py must call getLogger('httpcore').setLevel to suppress noise."""
|
||||
assert (
|
||||
'getLogger("httpcore").setLevel' in _MAIN_SRC
|
||||
or "getLogger('httpcore').setLevel" in _MAIN_SRC
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Criteria 4 — SignalAggregator not importable from backend.telegram
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_signal_aggregator_not_importable_from_telegram():
|
||||
"""Importing SignalAggregator from backend.telegram must raise ImportError."""
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
# Force a fresh import so changes to the module are reflected
|
||||
mod_name = "backend.telegram"
|
||||
if mod_name in sys.modules:
|
||||
del sys.modules[mod_name]
|
||||
|
||||
import backend.telegram as tg_mod # noqa: F401
|
||||
assert not hasattr(tg_mod, "SignalAggregator"), (
|
||||
"SignalAggregator should not be an attribute of backend.telegram"
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue