тесты: сессия из data/tg.json подхватывается, без файла — выключена (30 passed)
This commit is contained in:
@@ -186,8 +186,9 @@ def test_tag_command_readonly(monkeypatch):
|
|||||||
|
|
||||||
|
|
||||||
# ---------- 12. сессия Telegram: выключена без env, CVE в заголовке ----------
|
# ---------- 12. сессия Telegram: выключена без env, CVE в заголовке ----------
|
||||||
def test_tgsess_disabled_without_env(monkeypatch):
|
def test_tgsess_disabled_without_env(monkeypatch, tmp_path):
|
||||||
from omni import tgsess
|
from omni import config, tgsess
|
||||||
|
monkeypatch.setattr(config, "DATA", tmp_path) # пустая папка: data/tg.json нет
|
||||||
for k in ("OMNI_TG_SESSION", "OMNI_TG_API_ID", "OMNI_TG_API_HASH"):
|
for k in ("OMNI_TG_SESSION", "OMNI_TG_API_ID", "OMNI_TG_API_HASH"):
|
||||||
monkeypatch.delenv(k, raising=False)
|
monkeypatch.delenv(k, raising=False)
|
||||||
assert tgsess.enabled() is False
|
assert tgsess.enabled() is False
|
||||||
@@ -195,6 +196,20 @@ def test_tgsess_disabled_without_env(monkeypatch):
|
|||||||
assert tgsess._key("@SomeChan/") == "SomeChan"
|
assert tgsess._key("@SomeChan/") == "SomeChan"
|
||||||
|
|
||||||
|
|
||||||
|
def test_tgsess_picks_up_file_config(monkeypatch, tmp_path):
|
||||||
|
"""Креды из data/tg.json подхватываются без env."""
|
||||||
|
import json as _json
|
||||||
|
from omni import config, tgsess
|
||||||
|
monkeypatch.setattr(config, "DATA", tmp_path)
|
||||||
|
for k in ("OMNI_TG_SESSION", "OMNI_TG_API_ID", "OMNI_TG_API_HASH", "OMNI_TG_LIMIT"):
|
||||||
|
monkeypatch.delenv(k, raising=False)
|
||||||
|
(tmp_path / "tg.json").write_text(_json.dumps(
|
||||||
|
{"session": "C:/tmp/x", "api_id": "123", "api_hash": "abc", "limit": "7"}), encoding="utf-8")
|
||||||
|
cfg = config.tg_cfg()
|
||||||
|
assert cfg["session"] == "C:/tmp/x" and cfg["limit"] == "7"
|
||||||
|
assert tgsess.enabled() is True
|
||||||
|
|
||||||
|
|
||||||
def test_item_cve_prefix():
|
def test_item_cve_prefix():
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from omni.feeds import _item
|
from omni.feeds import _item
|
||||||
|
|||||||
Reference in New Issue
Block a user