From 41bd2f025981b7d45d8e4debb4be581f267de275 Mon Sep 17 00:00:00 2001 From: jajjibhai008 Date: Fri, 18 Aug 2023 12:34:28 +0500 Subject: [PATCH] feat: add filter to modify the courserun data for externally hosted courses --- CHANGELOG.rst | 9 +++++++++ openedx_filters/__init__.py | 2 +- openedx_filters/learning/filters.py | 19 +++++++++++++++++++ .../learning/tests/test_filters.py | 15 +++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 95da525..c8439f1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,15 @@ Change Log Unreleased ---------- +[1.6.0] - 2023-08-18 +-------------------- + +Added +~~~~~ + +* CourseRunAPIRenderStarted filter added which can be used to modify the courserun data for B2C dashboard rendering process. + + [1.5.0] - 2023-07-19 -------------------- diff --git a/openedx_filters/__init__.py b/openedx_filters/__init__.py index 62846b8..f223944 100644 --- a/openedx_filters/__init__.py +++ b/openedx_filters/__init__.py @@ -3,4 +3,4 @@ """ from openedx_filters.filters import * -__version__ = "1.5.0" +__version__ = "1.6.0" diff --git a/openedx_filters/learning/filters.py b/openedx_filters/learning/filters.py index 16a7d38..3e968d8 100644 --- a/openedx_filters/learning/filters.py +++ b/openedx_filters/learning/filters.py @@ -611,6 +611,25 @@ def run_filter(cls, course_key, serialized_enrollment): return data.get("course_key"), data.get("serialized_enrollment") +class CourseRunAPIRenderStarted(OpenEdxPublicFilter): + """ + Custom class used to create filters for course run data. + """ + + filter_type = "org.openedx.learning.home.courserun.api.rendered.started.v1" + + @classmethod + def run_filter(cls, serialized_courserun): + """ + Execute a filter with the specified signature. + + Arguments: + serialized_courserun (dict): courserun data + """ + data = super().run_pipeline(serialized_courserun=serialized_courserun) + return data.get("serialized_courserun") + + class InstructorDashboardRenderStarted(OpenEdxPublicFilter): """ Custom class used to create instructor dashboard filters and its custom methods. diff --git a/openedx_filters/learning/tests/test_filters.py b/openedx_filters/learning/tests/test_filters.py index 4c1db26..c8e8f91 100644 --- a/openedx_filters/learning/tests/test_filters.py +++ b/openedx_filters/learning/tests/test_filters.py @@ -17,6 +17,7 @@ CourseEnrollmentQuerysetRequested, CourseEnrollmentStarted, CourseHomeUrlCreationStarted, + CourseRunAPIRenderStarted, CourseUnenrollmentStarted, DashboardRenderStarted, InstructorDashboardRenderStarted, @@ -619,3 +620,17 @@ def test_course_enrollment_api_render_started(self): result = CourseEnrollmentAPIRenderStarted.run_filter(course_key, serialized_enrollment) self.assertTupleEqual((course_key, serialized_enrollment,), result) + + def test_course_run_api_render_started(self): + """ + Test CourseRunAPIRenderStarted filter behavior under normal conditions. + + Expected behavior: + - The filter must have the signature specified. + - The filter should return serialized_courserun. + """ + serialized_courserun = Mock() + + result = CourseRunAPIRenderStarted.run_filter(serialized_courserun) + + self.assertEqual(serialized_courserun, result)