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 8f6702c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 36 deletions.
72 changes: 36 additions & 36 deletions openedx/core/djangoapps/schedules/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,46 @@
class TestScheduleQuerySetRequestedPipelineStep(PipelineStep):
"""Pipeline step class to test a configured pipeline step"""

filtered_schedules = Mock(spec=QuerySet)
# filtered_schedules = Mock(spec=QuerySet)

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


@skip_unless_lms
class ScheduleQuerySetRequestedFiltersTest(SchedulesResolverTestMixin, ModuleStoreTestCase):
"""
Tests for the Open edX Filters associated with the schedule queryset requested.
The following filters are tested:
- ScheduleQuerySetRequested
"""

def setUp(self):
super().setUp()
self.resolver = BinnedSchedulesBaseResolver(
async_send_task=Mock(name="async_send_task"),
site=self.site,
target_datetime=datetime.datetime.now(),
day_offset=3,
bin_num=1,
)

@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_queryset_requested_filter(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()

self.assertEqual(TestScheduleQuerySetRequestedPipelineStep.filtered_schedules, schedules)
# @skip_unless_lms
# class ScheduleQuerySetRequestedFiltersTest(SchedulesResolverTestMixin, ModuleStoreTestCase):
# """
# Tests for the Open edX Filters associated with the schedule queryset requested.

# The following filters are tested:
# - ScheduleQuerySetRequested
# """

# def setUp(self):
# super().setUp()
# self.resolver = BinnedSchedulesBaseResolver(
# async_send_task=Mock(name="async_send_task"),
# site=self.site,
# target_datetime=datetime.datetime.now(),
# day_offset=3,
# bin_num=1,
# )

# @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_queryset_requested_filter(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()

# self.assertEqual(TestScheduleQuerySetRequestedPipelineStep.schedules, schedules)
39 changes: 39 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,45 @@ 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, bucket):
"""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
overview2 = CourseOverviewFactory(has_highlights=False)

# 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)
with override_experiment_waffle_flag(_EXTERNAL_COURSE_UPDATES_FLAG, bucket=bucket):
enrollment2 = CourseEnrollment.enroll(user, overview2.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()

if bucket == 1:
assert len(schedules) == 1
assert schedules[0].enrollment == enrollment1
else:
assert len(schedules) == 2
assert {s.enrollment for s in schedules} == {enrollment1, enrollment2}

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

0 comments on commit 8f6702c

Please sign in to comment.