Files
skill-template/scripts/service/amazon_report_adapter/mock.py
chendelian 4a0be93b4a
All checks were successful
技能自动化发布 / release (push) Successful in 5s
chore: auto release commit (2026-07-03 12:09:55)
2026-07-03 12:09:55 +08:00

45 lines
1.3 KiB
Python

"""mock / unit 档位:不启动浏览器,返回假 job_id 与假 xlsx 路径。"""
from __future__ import annotations
import os
import time
from typing import Optional
from service.amazon_report_adapter.base import DownloadSettlementAdapterBase, DownloadSettlementResult
class MockDownloadSettlementAdapter(DownloadSettlementAdapterBase):
name = "mock"
def download_settlement(
self,
*,
date_from: str,
date_to: str,
seller_code: Optional[str] = None,
downloads_dir: str = "",
artifacts_dir: str = "",
) -> DownloadSettlementResult:
del artifacts_dir
os.makedirs(downloads_dir, exist_ok=True)
time.sleep(0.05)
ts = int(time.time())
job_id = f"MOCK-{ts}"
seller = seller_code or "MOCK-SELLER"
filename = f"settlement_{seller}_{date_from}_{date_to}_{ts}.xlsx"
file_path = os.path.join(downloads_dir, filename)
with open(file_path, "wb") as fh:
fh.write(b"PK\x03\x04mock-settlement-xlsx")
return DownloadSettlementResult(
ok=True,
job_id=job_id,
file_path=file_path,
filename=filename,
date_from=date_from,
date_to=date_to,
seller_code=seller,
error_msg=None,
artifacts={"adapter": self.name},
)