test: flaky evaluation schedule

* Earlier logic was flaky because the test calculated the last expected date using a 56‑day window, while the production code builds
  schedules for 60 days. Those extra 4 days sometimes include another Monday or Wednesday, so the schedule ends later than the test
  expects.
This commit is contained in:
Hussain Nagaria
2026-01-17 23:22:38 +05:30
parent 3b88892905
commit 5ce8e8c4ff

View File

@@ -5,7 +5,10 @@
from frappe.tests import UnitTestCase
from frappe.utils import add_days, format_time, getdate
from lms.lms.doctype.course_evaluator.course_evaluator import get_schedule
from lms.lms.doctype.course_evaluator.course_evaluator import (
get_schedule,
get_schedule_range_end_date,
)
from lms.lms.test_utils import TestUtils
@@ -52,17 +55,9 @@ class TestCourseEvaluator(UnitTestCase):
return first_date
def calculated_last_date_of_schedule(self, first_date):
last_day = add_days(getdate(), 56)
offset_monday = (0 - last_day.weekday() + 7) % 7 # 0 for Monday
offset_wednesday = (2 - last_day.weekday() + 7) % 7 # 2 for Wednesday
if offset_monday < offset_wednesday and offset_monday <= 4:
last_day = add_days(last_day, offset_monday)
elif offset_wednesday <= 4:
last_day = add_days(last_day, offset_wednesday)
else:
last_day = add_days(last_day, min(offset_monday, offset_wednesday) + 7)
last_day = getdate(get_schedule_range_end_date(getdate(), self.batch.name))
while last_day.weekday() not in (0, 2):
last_day = add_days(last_day, -1)
return last_day
def test_unavailability_dates(self):