Simplify telethon unit tests for CI (don't use TestExtractorBase - it causes loading issues)

This commit is contained in:
Patrick Robertson
2025-03-26 23:51:21 +04:00
parent e0e9f93065
commit b7949a489f
2 changed files with 17 additions and 29 deletions

View File

@@ -3,36 +3,24 @@ from datetime import date
import pytest
from .test_extractor_base import TestExtractorBase
from auto_archiver.modules.telethon_extractor import TelethonExtractor
@pytest.fixture(autouse=True)
def mock_client_setup(mocker):
mocker.patch("telethon.client.auth.AuthMethods.start")
class TestTelethonExtractor(TestExtractorBase):
extractor_module = "telethon_extractor"
extractor: TelethonExtractor
config = {
"api_id": 123,
"api_hash": "ABC",
}
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")
@pytest.fixture(autouse=True)
def mock_client_setup(self, mocker):
mocker.patch("telethon.client.auth.AuthMethods.start")
# make sure the default setup file is created
session_file = tmp_path / "test.session"
def test_setup_fails_clear_session_file(self, get_lazy_module, tmp_path, mocker):
start = mocker.patch("telethon.client.auth.AuthMethods.start")
start.side_effect = Exception("Test exception")
lazy_module = get_lazy_module("telethon_extractor")
# make sure the default setup file is created
session_file = tmp_path / "test.session"
with pytest.raises(Exception):
lazy_module.load({"telethon_extractor": {"session_file": str(session_file), "api_id": 123, "api_hash": "ABC"}})
lazy_module = get_lazy_module("telethon_extractor")
with pytest.raises(Exception):
lazy_module.load(
{"telethon_extractor": {"session_file": str(session_file), "api_id": 123, "api_hash": "ABC"}}
)
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")
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")