Fix flaky chart date windows: use calendar months, not 30-day steps

_monthly and signup_split approximated "N months ago" as N*30 days, which
drifts against real calendar months by several days a year. Late in some
months that drift undershot a full month, so the "dense 13-point series"
tests flaked depending on which day they ran (confirmed: every 28th+ of
most months). Switched to dateutil.relativedelta for exact calendar-month
arithmetic, which is stable on every day of every month.
This commit is contained in:
2026-07-27 10:37:37 +02:00
parent 90a99fb03e
commit 0223383c9d
2 changed files with 14 additions and 2 deletions

View File

@@ -779,6 +779,17 @@ class PlatformChartTests(TestCase):
self.assertEqual(len(series), 13)
self.assertTrue(all(point["new"] == 0 and point["returning"] == 0 for point in series))
def test_the_series_stays_dense_on_a_late_day_of_the_month(self):
# A 30-days-per-month approximation of "12 months ago" drifts by a few days a
# year, and on the tail end of a month that drift used to fall short of a full
# calendar month, silently dropping the series to 12 points instead of 13.
late_month_day = timezone.now().replace(day=28)
with mock.patch.object(timezone, "now", return_value=late_month_day):
series = platform_charts()["signups"]
self.assertEqual(len(series), 13)
def test_signups_land_in_the_month_they_happened(self):
ClubMembership.objects.create(club=self.club, season=self.season, member=self.member, signed_up_at=timezone.localdate())