/sync-bank now uses one shared default window in both implementations: 1 November of the previous year to 31 December of the current year. Payments dated around New Year are picked up in January; duplicates are still filtered by Sync ID. Python used a hardcoded 2026 window and would have stopped syncing on 2027-01-01; Go used the current calendar year only. Adds make sync-year [YEAR=N] with the same window. The CLI default without flags (last 30 days) is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.8 KiB
Python
42 lines
1.8 KiB
Python
import contextlib
|
|
import io
|
|
import unittest
|
|
from datetime import datetime
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from scripts.sync_fio_to_sheets import COLUMN_LABELS, as_text_cell, default_sync_window, sync_to_sheets
|
|
|
|
|
|
class TestDefaultSyncWindow(unittest.TestCase):
|
|
def test_current_year_plus_last_two_months_of_previous(self):
|
|
self.assertEqual(default_sync_window(datetime(2026, 10, 8)), ("2025-11-01", "2026-12-31"))
|
|
self.assertEqual(default_sync_window(datetime(2027, 1, 1)), ("2026-11-01", "2027-12-31"))
|
|
self.assertEqual(default_sync_window(datetime(2027, 12, 31)), ("2026-11-01", "2027-12-31"))
|
|
|
|
|
|
class TestAsTextCell(unittest.TestCase):
|
|
def test_digits_get_text_marker(self):
|
|
self.assertEqual(as_text_cell("0308"), "'0308")
|
|
self.assertEqual(as_text_cell(123), "'123")
|
|
|
|
def test_empty_stays_empty(self):
|
|
self.assertEqual(as_text_cell(""), "")
|
|
self.assertEqual(as_text_cell(None), "")
|
|
|
|
|
|
class TestSyncWritesVSAsText(unittest.TestCase):
|
|
def test_appended_row_has_text_vs(self):
|
|
service = MagicMock()
|
|
sheet = service.spreadsheets.return_value
|
|
sheet.values.return_value.get.return_value.execute.return_value = {"values": [COLUMN_LABELS]}
|
|
tx = {"date": "2026-04-10", "amount": 750.0, "sender": "Test Sender",
|
|
"vs": "0308", "message": "fee", "bank_id": "111"}
|
|
with patch("scripts.sync_fio_to_sheets.get_sheets_service", return_value=service), \
|
|
patch("scripts.sync_fio_to_sheets.fetch_transactions_all", return_value=[tx]), \
|
|
contextlib.redirect_stdout(io.StringIO()):
|
|
sync_to_sheets("sheet-id", "creds.json", days=30)
|
|
|
|
body = sheet.values.return_value.append.call_args.kwargs["body"]
|
|
self.assertEqual(len(body["values"]), 1)
|
|
self.assertEqual(body["values"][0][7], "'0308")
|