83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""adapter 工厂 dispatch 单元测试。"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from service.amazon_report_adapter import (
|
|
DownloadSettlementResult,
|
|
MockDownloadSettlementAdapter,
|
|
SimulatorRpaDownloadSettlementAdapter,
|
|
get_adapter,
|
|
)
|
|
|
|
|
|
class TestAdapterDispatch(unittest.TestCase):
|
|
def test_default_returns_simulator_rpa(self) -> None:
|
|
with patch.dict(os.environ, {}, clear=False):
|
|
os.environ.pop("OPENCLAW_TEST_TARGET", None)
|
|
from jiangchang_skill_core import config
|
|
|
|
config.reset_cache()
|
|
adapter = get_adapter()
|
|
self.assertIsInstance(adapter, SimulatorRpaDownloadSettlementAdapter)
|
|
|
|
def test_unit_returns_mock(self) -> None:
|
|
with patch.dict(os.environ, {"OPENCLAW_TEST_TARGET": "unit"}):
|
|
from jiangchang_skill_core import config
|
|
|
|
config.reset_cache()
|
|
self.assertIsInstance(get_adapter(), MockDownloadSettlementAdapter)
|
|
|
|
def test_mock_returns_mock(self) -> None:
|
|
with patch.dict(os.environ, {"OPENCLAW_TEST_TARGET": "mock"}):
|
|
from jiangchang_skill_core import config
|
|
|
|
config.reset_cache()
|
|
self.assertIsInstance(get_adapter(), MockDownloadSettlementAdapter)
|
|
|
|
def test_simulator_rpa_returns_simulator(self) -> None:
|
|
with patch.dict(os.environ, {"OPENCLAW_TEST_TARGET": "simulator_rpa"}):
|
|
from jiangchang_skill_core import config
|
|
|
|
config.reset_cache()
|
|
self.assertIsInstance(get_adapter(), SimulatorRpaDownloadSettlementAdapter)
|
|
|
|
def test_real_rpa_falls_back_to_mock(self) -> None:
|
|
with patch.dict(os.environ, {"OPENCLAW_TEST_TARGET": "real_rpa"}):
|
|
from jiangchang_skill_core import config
|
|
|
|
config.reset_cache()
|
|
self.assertIsInstance(get_adapter(), MockDownloadSettlementAdapter)
|
|
|
|
def test_unknown_target_falls_back_simulator_rpa(self) -> None:
|
|
with patch.dict(os.environ, {"OPENCLAW_TEST_TARGET": "simulator_api"}):
|
|
from jiangchang_skill_core import config
|
|
|
|
config.reset_cache()
|
|
self.assertIsInstance(get_adapter(), SimulatorRpaDownloadSettlementAdapter)
|
|
|
|
|
|
class TestMockAdapter(unittest.TestCase):
|
|
def test_mock_success(self) -> None:
|
|
import tempfile
|
|
|
|
downloads = tempfile.mkdtemp()
|
|
result = MockDownloadSettlementAdapter().download_settlement(
|
|
date_from="2025-12-01",
|
|
date_to="2025-12-31",
|
|
seller_code="AMA1OF6T",
|
|
downloads_dir=downloads,
|
|
)
|
|
self.assertTrue(result.ok)
|
|
self.assertTrue((result.job_id or "").startswith("MOCK-"))
|
|
self.assertTrue(result.file_path and os.path.isfile(result.file_path))
|
|
self.assertTrue((result.filename or "").endswith(".xlsx"))
|
|
self.assertIsInstance(result, DownloadSettlementResult)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|