|
6 | 6 | from datetime import date |
7 | 7 | from pathlib import Path |
8 | 8 |
|
| 9 | +from quantclass_sync_internal.reporting import _append_result, _new_report |
9 | 10 | from quantclass_sync_internal.data_query import ( |
10 | 11 | _days_behind, |
11 | 12 | _status_color, |
|
14 | 15 | get_run_detail, |
15 | 16 | get_run_history, |
16 | 17 | ) |
17 | | -from quantclass_sync_internal.status_store import update_api_latest_dates |
| 18 | +from quantclass_sync_internal.status_store import _update_product_last_status, update_api_latest_dates |
18 | 19 |
|
19 | 20 |
|
20 | 21 | class TestDaysBehind(unittest.TestCase): |
@@ -407,6 +408,35 @@ def test_overview_same_api_date_after_check_updates_keeps_no_valid_output_suppre |
407 | 408 | self.assertEqual(overview[0]["days_behind"], 0) |
408 | 409 | self.assertEqual(overview[0]["status_color"], "green") |
409 | 410 |
|
| 411 | + def test_overview_preserves_green_after_sync_when_api_cache_exists(self): |
| 412 | + """同步结果为 up_to_date 时,若保留 API 缓存字段,总览仍应显示绿色。""" |
| 413 | + self._write_timestamp("coin-cap", "2026-03-11") |
| 414 | + update_api_latest_dates(self.log_dir, {"coin-cap": "2026-03-11"}) |
| 415 | + report = _new_report("test", mode="network") |
| 416 | + _append_result( |
| 417 | + report, |
| 418 | + product="coin-cap", |
| 419 | + status="skipped", |
| 420 | + reason_code="up_to_date", |
| 421 | + error="本地 timestamp 已是最新(local=2026-03-11, api=2026-03-11)。", |
| 422 | + date_time="2026-03-11", |
| 423 | + ) |
| 424 | + _update_product_last_status(self.log_dir, report) |
| 425 | + |
| 426 | + import unittest.mock |
| 427 | + with unittest.mock.patch( |
| 428 | + "quantclass_sync_internal.data_query.report_dir_path", |
| 429 | + return_value=self.log_dir, |
| 430 | + ): |
| 431 | + overview = get_products_overview( |
| 432 | + self.data_root, |
| 433 | + ["coin-cap"], |
| 434 | + today=date(2026, 3, 13), |
| 435 | + ) |
| 436 | + |
| 437 | + self.assertEqual(overview[0]["days_behind"], 0) |
| 438 | + self.assertEqual(overview[0]["status_color"], "green") |
| 439 | + |
410 | 440 | def test_overview_suppresses_same_date_no_valid_output_even_if_source_was_polluted(self): |
411 | 441 | """旧状态文件 source 被污染为 api_check 时,same-date no_valid_output 仍应抑制待更新。""" |
412 | 442 | self._write_timestamp("coin-cap", "2026-03-10") |
|
0 commit comments