tests: unittest QETransactionListModel date format
What changed, and why it matters
This commit only adds new automated tests for how transaction dates are displayed and grouped in Electrum's mobile/QML user interface. It does not change any production code, fix a bug, or alter program behavior. There is no security relevance.
No action needed. This is a test-only change with no security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff creates tests/test_qml_qetransactionlistmodel.py with unit tests for QETransactionListModel.get_section_by_timestamp and QETransactionListModel.format_date_by_section. It verifies date bucketing (today/yesterday/lastweek/lastmonth/older) and string formatting using mocked datetime values. No application logic is modified.
Changed components
tests/test_qml_qetransactionlistmodel.pyInspect captured patch +71 / −0
diff --git a/tests/test_qml_qetransactionlistmodel.py b/tests/test_qml_qetransactionlistmodel.py
new file mode 100644
index 0000000..7c2b8af
--- /dev/null
+++ b/tests/test_qml_qetransactionlistmodel.py
@@ -0,0 +1,71 @@
+from datetime import datetime
+from unittest.mock import patch
+
+from electrum.gui.qml.qetransactionlistmodel import QETransactionListModel
+
+from . import ElectrumTestCase
+
+
+class TestQETransactionListModel(ElectrumTestCase):
+
+ def test_get_section_by_timestamp(self):
+ f = QETransactionListModel.get_section_by_timestamp
+
+ mock_today = datetime(2023, 6, 15, 0, 0, 0, 0)
+ with patch('electrum.gui.qml.qetransactionlistmodel.datetime') as mock_dt:
+ mock_dt.today.return_value = mock_today
+ mock_dt.fromtimestamp = datetime.fromtimestamp
+
+ today_ts = datetime(2023, 6, 15, 10, 30, 0).timestamp()
+ self.assertEqual(f(today_ts), 'today')
+
+ today_edge_ts = datetime(2023, 6, 15, 0, 0, 1).timestamp()
+ self.assertEqual(f(today_edge_ts), 'today')
+
+ yesterday_ts = datetime(2023, 6, 14, 15, 0, 0).timestamp()
+ self.assertEqual(f(yesterday_ts), 'yesterday')
+
+ yesterday_edge_ts = datetime(2023, 6, 13, 23, 59, 59).timestamp()
+ self.assertEqual(f(yesterday_edge_ts), 'lastweek')
+
+ lastweek_ts = datetime(2023, 6, 12, 12, 0, 0).timestamp()
+ self.assertEqual(f(lastweek_ts), 'lastweek')
+
+ lastweek_boundary_ts = datetime(2023, 6, 8, 12, 0, 0).timestamp()
+ self.assertEqual(f(lastweek_boundary_ts), 'lastweek')
+
+ lastmonth_ts = datetime(2023, 6, 5, 9, 0, 0).timestamp()
+ self.assertEqual(f(lastmonth_ts), 'lastmonth')
+
+ lastmonth_boundary_ts = datetime(2023, 5, 15, 8, 0, 0).timestamp()
+ self.assertEqual(f(lastmonth_boundary_ts), 'lastmonth')
+
+ older_ts = datetime(2023, 5, 14, 10, 0, 0).timestamp()
+ self.assertEqual(f(older_ts), 'older')
+
+ much_older_ts = datetime(2022, 1, 1, 0, 0, 0).timestamp()
+ self.assertEqual(f(much_older_ts), 'older')
+
+ def test_format_date_by_section(self):
+ f = QETransactionListModel.format_date_by_section
+
+ test_date = datetime(2023, 6, 15, 14, 30, 45)
+
+ result = f('today', test_date)
+ self.assertEqual(result, '14:30')
+
+ result = f('yesterday', test_date)
+ self.assertEqual(result, '14:30')
+
+ result = f('lastweek', test_date)
+ self.assertEqual(result, 'Thu, 14:30')
+
+ result = f('lastmonth', test_date)
+ self.assertEqual(result, 'Thu 15, 14:30')
+
+ result = f('older', test_date)
+ self.assertEqual(result, '2023-06-15 14:30')
+
+ result = f('unknown_section', test_date)
+ self.assertEqual(result, '2023-06-15 14:30')
+
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.