From dba7f7bdc9607259a4a02d1750a53089a6f29eab Mon Sep 17 00:00:00 2001 From: tech Date: Tue, 21 Apr 2026 23:24:32 +0800 Subject: [PATCH] test: add edge cases for backup cutoff filtering Co-Authored-By: Claude Opus 4.7 --- tests/test_backup.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/test_backup.py b/tests/test_backup.py index 7e39a84..803df79 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -80,3 +80,51 @@ def test_backup_filters_by_cutoff(tmp_path): assert (backup_dir / "2025-01-01.csv").exists() assert (backup_dir / "2025-01-02.csv").exists() assert not (backup_dir / "2025-01-03.csv").exists() + + +def test_backup_cutoff_at_midnight(tmp_path): + """Order exactly at cutoff midnight should be excluded.""" + scan_dir = tmp_path / "scan" + backup_dir = tmp_path / "backups" + scan_dir.mkdir() + backup_dir.mkdir() + + entities = [ + _make_entity("u1", "o1", datetime(2025, 1, 3, 0, 0, 0, tzinfo=timezone.utc), 1), # exactly at cutoff + _make_entity("u2", "o2", datetime(2025, 1, 2, 23, 59, 59, tzinfo=timezone.utc), 1), # just before + ] + scan_csv = scan_dir / "scan.csv" + write_csv(scan_csv, entities) + + result = backup_orders( + scan_path=scan_csv, + backup_dir=backup_dir, + cutoff=datetime(2025, 1, 3, tzinfo=timezone.utc), + ) + + assert result == 1 + assert (backup_dir / "2025-01-02.csv").exists() + assert not (backup_dir / "2025-01-03.csv").exists() + + +def test_backup_empty_result(tmp_path): + """No orders before cutoff returns 0 and no files.""" + scan_dir = tmp_path / "scan" + backup_dir = tmp_path / "backups" + scan_dir.mkdir() + backup_dir.mkdir() + + entities = [ + _make_entity("u1", "o1", datetime(2025, 1, 5, 10, tzinfo=timezone.utc), 1), + ] + scan_csv = scan_dir / "scan.csv" + write_csv(scan_csv, entities) + + result = backup_orders( + scan_path=scan_csv, + backup_dir=backup_dir, + cutoff=datetime(2025, 1, 1, tzinfo=timezone.utc), + ) + + assert result == 0 + assert list(backup_dir.glob("*.csv")) == []