Skip to content

Commit

Permalink
feat: add schedule queryset request filter integration (#35982)
Browse files Browse the repository at this point in the history
* feat: add schedule queryset request filter integration

* chore: remove try-except when running filter

* chore: upgrade openedx-filters to v1.12.0

* test: add filter unit tests

* test: inherit of ModuleStoreTestCase

* fix: add missing attribute in resolver instance
  • Loading branch information
BryanttV authored Dec 17, 2024
1 parent 53de406 commit 5bf0b27
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
5 changes: 5 additions & 0 deletions openedx/core/djangoapps/schedules/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from edx_ace.recipient import Recipient
from edx_ace.recipient_resolver import RecipientResolver
from edx_django_utils.monitoring import function_trace, set_custom_attribute
from openedx_filters.learning.filters import ScheduleQuerySetRequested

from lms.djangoapps.courseware.utils import verified_upgrade_deadline_link, can_show_verified_upgrade
from lms.djangoapps.discussion.notification_prefs.views import UsernameCipher
Expand Down Expand Up @@ -154,6 +155,10 @@ def get_schedules_with_target_date_by_bin_and_orgs(

schedules = self.filter_by_org(schedules)

# .. filter_implemented_name: ScheduleQuerySetRequested
# .. filter_type: org.openedx.learning.schedule.queryset.requested.v1
schedules = ScheduleQuerySetRequested.run_filter(schedules)

if "read_replica" in settings.DATABASES:
schedules = schedules.using("read_replica")

Expand Down
71 changes: 71 additions & 0 deletions openedx/core/djangoapps/schedules/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
Test cases for the Open edX Filters associated with the schedule app.
"""

import datetime
from unittest.mock import Mock

from django.db.models.query import QuerySet
from django.test import override_settings
from openedx_filters import PipelineStep

from openedx.core.djangoapps.schedules.resolvers import BinnedSchedulesBaseResolver
from openedx.core.djangoapps.schedules.tests.test_resolvers import SchedulesResolverTestMixin
from openedx.core.djangolib.testing.utils import skip_unless_lms
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase


class TestScheduleQuerySetRequestedPipelineStep(PipelineStep):
"""Pipeline step class to test a configured pipeline step"""

filtered_schedules = Mock(spec=QuerySet, __len__=Mock(return_value=0))

def run_filter(self, schedules: QuerySet): # pylint: disable=arguments-differ
"""Pipeline step to filter the schedules"""
return {
"schedules": self.filtered_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=2,
)
self.resolver.schedule_date_field = "created"

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

self.assertEqual(TestScheduleQuerySetRequestedPipelineStep.filtered_schedules, schedules)

@override_settings(OPEN_EDX_FILTERS_CONFIG={})
def test_schedule_with_queryset_requested_filter_disabled(self) -> None:
"""Test to verify the schedule queryset was not modified when the pipeline step is not configured."""
schedules = self.resolver.get_schedules_with_target_date_by_bin_and_orgs()

self.assertNotEqual(TestScheduleQuerySetRequestedPipelineStep.filtered_schedules, schedules)
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ openedx-events==9.15.0
# edx-name-affirmation
# event-tracking
# ora2
openedx-filters==1.11.0
openedx-filters==1.12.0
# via
# -r requirements/edx/kernel.in
# lti-consumer-xblock
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ openedx-events==9.15.0
# edx-name-affirmation
# event-tracking
# ora2
openedx-filters==1.11.0
openedx-filters==1.12.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ openedx-events==9.15.0
# edx-name-affirmation
# event-tracking
# ora2
openedx-filters==1.11.0
openedx-filters==1.12.0
# via
# -r requirements/edx/base.txt
# lti-consumer-xblock
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ openedx-events==9.15.0
# edx-name-affirmation
# event-tracking
# ora2
openedx-filters==1.11.0
openedx-filters==1.12.0
# via
# -r requirements/edx/base.txt
# lti-consumer-xblock
Expand Down

0 comments on commit 5bf0b27

Please sign in to comment.