Skip to content

Commit

Permalink
feat: add schedule queryset requested filter
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV committed Dec 9, 2024
1 parent 6b8354e commit a476204
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
39 changes: 39 additions & 0 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from typing import Optional

from django.db.models.query import QuerySet

from openedx_filters.exceptions import OpenEdxFilterException
from openedx_filters.tooling import OpenEdxPublicFilter
from openedx_filters.utils import SensitiveDataManagementMixin
Expand Down Expand Up @@ -818,3 +820,40 @@ def run_filter(cls, url, org):
"""
data = super().run_pipeline(url=url, org=org)
return data.get("url"), data.get("org")


class ScheduleQuerySetRequested(OpenEdxPublicFilter):
"""
Custom class used to create schedule queryset filters filters and its custom methods.
"""

filter_type = "org.openedx.learning.schedule.queryset.requested.v1"

class PreventScheduleQuerySetRequest(OpenEdxFilterException):
"""
Custom class used to stop the schedule queryset request process.
"""

def __init__(self, message: str, schedules: QuerySet):
"""
Override init that defines specific arguments used in the schedule queryset request process.
Arguments:
message (str): error message for the exception.
schedules (QuerySet): Queryset of schedules to be sent
"""
super().__init__(message, schedules=schedules)

@classmethod
def run_filter(cls, schedules: QuerySet) -> QuerySet:
"""
Execute a filter with the signature specified.
Arguments:
schedules (QuerySet): Queryset of schedules to be sent.
Returns:
QuerySet: Schedules to be sent.
"""
data = super().run_pipeline(schedules=schedules)
return data.get("schedules")
42 changes: 42 additions & 0 deletions openedx_filters/learning/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
InstructorDashboardRenderStarted,
ORASubmissionViewRenderStarted,
RenderXBlockStarted,
ScheduleQuerySetRequested,
StudentLoginRequested,
StudentRegistrationRequested,
VerticalBlockChildRenderStarted,
Expand Down Expand Up @@ -776,3 +777,44 @@ def test_lms_page_url_requested(self):

self.assertEqual(url, url_result)
self.assertEqual(org, org_result)


@ddt
class TestScheduleFilters(TestCase):
"""
Test class to verify standard behavior of the schedule filters.
You'll find test suites for:
- `ScheduleQuerySetRequested`
"""

def test_schedule_requested(self):
"""
Test schedule requested filter.
Expected behavior:
- The filter should return the filterd schedules.
"""
schedules = Mock()

result = ScheduleQuerySetRequested.run_filter(schedules)

self.assertEqual(schedules, result)

@data(
(
ScheduleQuerySetRequested.PreventScheduleQuerySetRequest,
{"schedules": Mock(), "message": "Can't request QuerySet Schedule."}
)
)
@unpack
def test_halt_queryset_request(self, request_exception, attributes):
"""
Test for queryset request exceptions attributes.
Expected behavior:
- The exception must have the attributes specified.
"""
exception = request_exception(**attributes)

self.assertDictContainsSubset(attributes, exception.__dict__)

0 comments on commit a476204

Please sign in to comment.