test: add edge cases for backup cutoff filtering
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -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")) == []
|
||||
|
||||
Reference in New Issue
Block a user