auto-archiver/tests/extractors/test_telethon_extractor.py

27 wiersze
885 B
Python
Czysty Zwykły widok Historia

2025-03-26 18:53:27 +00:00
import os
from datetime import date
import pytest
@pytest.fixture(autouse=True)
def mock_client_setup(mocker):
mocker.patch("telethon.client.auth.AuthMethods.start")
2025-03-26 18:53:27 +00:00
def test_setup_fails_clear_session_file(get_lazy_module, tmp_path, mocker):
start = mocker.patch("telethon.client.auth.AuthMethods.start")
start.side_effect = Exception("Test exception")
2025-03-26 18:53:27 +00:00
# make sure the default setup file is created
session_file = tmp_path / "test.session"
2025-03-26 18:53:27 +00:00
lazy_module = get_lazy_module("telethon_extractor")
2025-03-26 18:53:27 +00:00
with pytest.raises(Exception):
lazy_module.load({"telethon_extractor": {"session_file": str(session_file), "api_id": 123, "api_hash": "ABC"}})
2025-03-26 18:53:27 +00:00
assert session_file.exists()
assert f"telethon-{date.today().strftime('%Y-%m-%d')}" in lazy_module._instance.session_file
assert os.path.exists(lazy_module._instance.session_file + ".session")