Skip to content

Commit

Permalink
temp: add sample unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV committed Dec 16, 2024
1 parent 1d46fa7 commit 07d604c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
9 changes: 5 additions & 4 deletions openedx/core/djangoapps/schedules/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
class TestScheduleQuerySetRequestedPipelineStep(PipelineStep):
"""Pipeline step class to test a configured pipeline step"""

filtered_schedules = Mock(spec=QuerySet)
filtered_schedules = None

def run_filter(self, schedules): # pylint: disable=arguments-differ
def run_filter(self, schedules: QuerySet): # pylint: disable=arguments-differ
"""Pipeline step to filter the schedules"""
self.filtered_schedules = schedules
return {
"schedules": self.filtered_schedules,
"schedules": schedules,
}


Expand Down Expand Up @@ -56,7 +57,7 @@ def setUp(self):
},
},
)
def test_schedule_queryset_requested_filter(self) -> None:
def test_schedule_with_queryset_requested_filter_enabled(self) -> None:
"""Test to verify the schedule queryset was modified by the pipeline step."""
schedules = self.resolver.get_schedules_with_target_date_by_bin_and_orgs()

Expand Down
32 changes: 32 additions & 0 deletions openedx/core/djangoapps/schedules/tests/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,38 @@ def test_external_course_updates(self, bucket):
assert len(schedules) == 2
assert {s.enrollment for s in schedules} == {enrollment1, enrollment2}

@override_settings(
OPEN_EDX_FILTERS_CONFIG={
"org.openedx.learning.schedule.queryset.requested.v1": {
"pipeline": [
"openedx.core.djangoapps.schedules.tests.test_filters.TestScheduleQuerySetRequestedPipelineStep",
],
"fail_silently": False,
},
},
)
def test_schedule_filter(self):
"""Confirm that we exclude enrollments in the external course updates experiment"""
user = UserFactory()
overview1 = CourseOverviewFactory(has_highlights=False) # set has_highlights just to avoid a modulestore lookup

# We need to enroll with a request, because our specific experiment code expects it
self.addCleanup(crum.set_current_request, None)
request = RequestFactory().get(self.site)
request.user = user
crum.set_current_request(request)
enrollment1 = CourseEnrollment.enroll(user, overview1.id)
# OK, at this point, we'd expect course1 to be returned, but course2's enrollment to be excluded by the
# experiment. Note that the experiment waffle is currently inactive, but they should still be excluded because
# they were bucketed at enrollment time.
bin_num = BinnedSchedulesBaseResolver.bin_num_for_user_id(user.id)
resolver = BinnedSchedulesBaseResolver(None, self.site, datetime.datetime.now(pytz.UTC), 0, bin_num)
resolver.schedule_date_field = 'created'
schedules = resolver.get_schedules_with_target_date_by_bin_and_orgs()

assert len(schedules) == 1
assert schedules[0].enrollment == enrollment1


@skip_unless_lms
class TestCourseUpdateResolver(SchedulesResolverTestMixin, ModuleStoreTestCase):
Expand Down

0 comments on commit 07d604c

Please sign in to comment.