Skip to content

Commit

Permalink
fix: Updates DummySchedule to fix broken tests
Browse files Browse the repository at this point in the history
Tests were failing due to receiving created and start_date in both
positional and keyword args via the init method. I've opted to just
remove the custom init method and just specify the created date
when making a DummySchedule
  • Loading branch information
Dillon-Dumesnil committed Dec 14, 2021
1 parent 06313b8 commit a0af634
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def setUp(self):
self.enrollment = DummyEnrollment(user=self.user, course=self.course)
self.enrollment.save()

self.schedule = DummySchedule(enrollment=self.enrollment, start_date=datetime(2019, 4, 1))
self.schedule = DummySchedule(
enrollment=self.enrollment, created=datetime(2019, 4, 1), start_date=datetime(2019, 4, 1)
)
self.schedule.save()

dummy_schedule_patcher = patch('edx_when.utils.Schedule', DummySchedule)
Expand Down Expand Up @@ -177,7 +179,7 @@ def test_get_dates_for_course(self):
enrollment2 = DummyEnrollment(user=self.user, course=course2)
enrollment2.save()

schedule2 = DummySchedule(enrollment=enrollment2, start_date=datetime(2019, 4, 1))
schedule2 = DummySchedule(enrollment=enrollment2, created=datetime(2019, 4, 1), start_date=datetime(2019, 4, 1))
schedule2.save()

api.set_dates_for_course(new_items[0][0].course_key, new_items)
Expand Down
16 changes: 11 additions & 5 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ class TestDatePolicy(TestCase):
@ddt.data(
(None, None, None, None),
(datetime(2020, 1, 1), None, None, datetime(2020, 1, 1)),
(datetime(2020, 1, 1), None, DummySchedule(start_date=datetime(2020, 3, 1)), datetime(2020, 1, 1)),
(None, timedelta(days=1), DummySchedule(start_date=datetime(2020, 1, 1)), datetime(2020, 1, 2)),
(datetime(2020, 3, 1), timedelta(days=1), DummySchedule(start_date=datetime(2020, 1, 1)), datetime(2020, 1, 2)),
(datetime(2020, 1, 1), None,
DummySchedule(created=datetime(2020, 3, 1), start_date=datetime(2020, 3, 1)), datetime(2020, 1, 1)
),
(None, timedelta(days=1),
DummySchedule(created=datetime(2020, 1, 1), start_date=datetime(2020, 1, 1)), datetime(2020, 1, 2)
),
(datetime(2020, 3, 1), timedelta(days=1),
DummySchedule(created=datetime(2020, 1, 1), start_date=datetime(2020, 1, 1)), datetime(2020, 1, 2)
),
)
@ddt.unpack
def test_actual_date(self, abs_date, rel_date, schedule, expected):
Expand All @@ -47,14 +53,14 @@ def test_actual_date_failure(self, abs_date, rel_date, schedule):
def test_actual_date_schedule_after_end(self):
# This only applies for relative dates so we are not testing abs date.
policy = DatePolicy(rel_date=timedelta(days=1))
schedule = DummySchedule(start_date=datetime(2020, 4, 1))
schedule = DummySchedule(created=datetime(2020, 4, 1), start_date=datetime(2020, 4, 1))
self.assertIsNone(policy.actual_date(schedule, end_datetime=datetime(2020, 1, 1)))

def test_actual_date_schedule_after_cutoff(self):
# This only applies for relative dates so we are not testing abs date.
day = timedelta(days=1)
policy = DatePolicy(rel_date=day)
schedule = DummySchedule(start_date=datetime(2020, 4, 1))
schedule = DummySchedule(created=datetime(2020, 4, 1), start_date=datetime(2020, 4, 1))
self.assertIsNone(policy.actual_date(schedule, cutoff_datetime=(schedule.created - day)))
self.assertIsNotNone(policy.actual_date(schedule, cutoff_datetime=(schedule.created + day)))

Expand Down
6 changes: 0 additions & 6 deletions tests/test_models_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,3 @@ class DummySchedule(models.Model):
db_index=True,
help_text='Date this schedule went into effect'
)

def __init__(self, *args, created=None, start_date=None, **kwargs):
# Ensure we have a created value, if possible
if not created and start_date:
created = start_date
super().__init__(*args, created=created, start_date=start_date, **kwargs)

0 comments on commit a0af634

Please sign in to comment.