test(stock): tolerate timezone slack in test_heatmap_data on Postgres

get_timeline_data uses UnixTimestamp(posting_date); on Postgres that is the date's
midnight epoch in the DB session timezone, which can sit up to a day ahead of the
Python time.time() instant when the app timezone is ahead of UTC. The strict
'<= now' upper bound is therefore flaky on Postgres. Allow a day of slack on the
upper bound; MariaDB's UNIX_TIMESTAMP stays <= now so its pass/fail is unchanged.
This commit is contained in:
Mihir Kandoi
2026-06-21 15:59:04 +05:30
parent f1a7b14e25
commit 3cd2a36117

View File

@@ -770,10 +770,14 @@ class TestItem(ERPNextTestSuite):
now = time.time()
one_year_ago = now - 366 * 24 * 60 * 60
# posting_date is a calendar date; its midnight unix timestamp (taken in the database
# session timezone) can sit up to a day ahead of the precise current instant when the app
# timezone is ahead of UTC, so allow a day of slack on the upper bound.
one_day = 24 * 60 * 60
for timestamp, count in data.items():
self.assertIsInstance(timestamp, int)
self.assertTrue(one_year_ago <= timestamp <= now)
self.assertTrue(one_year_ago <= timestamp <= now + one_day)
self.assertIsInstance(count, int)
self.assertGreaterEqual(count, 0)