Files
feiqiu-ETL/etl_billiards/tests/unit/test_etl_tasks_online.py
2025-11-19 03:36:44 +08:00

33 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""在线模式下的端到端任务测试,验证所有任务在模拟 API 下能顺利执行。"""
import logging
import pytest
from .task_test_utils import (
TASK_SPECS,
FakeAPIClient,
create_test_config,
get_db_operations,
)
@pytest.mark.parametrize("spec", TASK_SPECS, ids=lambda spec: spec.code)
def test_task_online_mode(spec, tmp_path):
"""针对每个 TaskSpec 验证:模拟 API 数据下依旧能完整跑完 ETL并正确统计。"""
archive_dir = tmp_path / "archive"
temp_dir = tmp_path / "tmp"
config = create_test_config("ONLINE", archive_dir, temp_dir)
fake_api = FakeAPIClient({spec.endpoint: spec.sample_records})
logger = logging.getLogger(f"test_online_{spec.code.lower()}")
with get_db_operations() as db_ops:
task = spec.task_cls(config, db_ops, fake_api, logger)
result = task.execute()
assert result["status"] == "SUCCESS"
assert result["counts"]["fetched"] == len(spec.sample_records)
assert result["counts"]["inserted"] == len(spec.sample_records)
if hasattr(db_ops, "commits"):
assert db_ops.commits == 1
assert db_ops.rollbacks == 0