From aab12178eee0a36eef91cb86a36af4b7c042b863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ignacio=20Palma?= Date: Mon, 30 Sep 2024 15:56:35 -0400 Subject: [PATCH] feat: adds CourseAboutPageURLRequested and LMSPageURLRequested filters (#200) --- CHANGELOG.rst | 11 ++++++- openedx_filters/__init__.py | 2 +- openedx_filters/course_authoring/__init__.py | 6 ++++ openedx_filters/course_authoring/filters.py | 25 +++++++++++++++ .../course_authoring/tests/__init__.py | 3 ++ .../course_authoring/tests/test_filters.py | 32 +++++++++++++++++++ openedx_filters/learning/filters.py | 20 ++++++++++++ .../learning/tests/test_filters.py | 24 ++++++++++++++ 8 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 openedx_filters/course_authoring/__init__.py create mode 100644 openedx_filters/course_authoring/filters.py create mode 100644 openedx_filters/course_authoring/tests/__init__.py create mode 100644 openedx_filters/course_authoring/tests/test_filters.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 40ec1ed..2ecc289 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,8 +15,17 @@ Unreleased ---------- * Configuration for automatic filters docs generation. +[1.11.0] - 2024-09-30 +--------------------- + +Added +~~~~~ + +* CourseAboutPageURLRequested filter added which can be used to modify the URL for the course about page. +* LMSPageURLRequested filter added which can be used to modify the URL for the LMS page. + [1.10.0] - 2024-09-20 --------------------- +--------------------- Added ~~~~~ diff --git a/openedx_filters/__init__.py b/openedx_filters/__init__.py index fd05025..46c4729 100644 --- a/openedx_filters/__init__.py +++ b/openedx_filters/__init__.py @@ -3,4 +3,4 @@ """ from openedx_filters.filters import * -__version__ = "1.10.0" +__version__ = "1.11.0" diff --git a/openedx_filters/course_authoring/__init__.py b/openedx_filters/course_authoring/__init__.py new file mode 100644 index 0000000..bef19c1 --- /dev/null +++ b/openedx_filters/course_authoring/__init__.py @@ -0,0 +1,6 @@ +""" +Package where events related to the ``content_authoring`` subdomain are implemented. + +The ``content_authoring`` subdomain corresponds to {Architecture Subdomain} defined in OEP-41. +https://open-edx-proposals.readthedocs.io/en/latest/architectural-decisions/oep-0041-arch-async-server-event-messaging.html +""" diff --git a/openedx_filters/course_authoring/filters.py b/openedx_filters/course_authoring/filters.py new file mode 100644 index 0000000..fd8c42b --- /dev/null +++ b/openedx_filters/course_authoring/filters.py @@ -0,0 +1,25 @@ +""" +Package where filters related to the Course Authoring architectural subdomain are implemented. +""" + +from openedx_filters.tooling import OpenEdxPublicFilter + + +class LMSPageURLRequested(OpenEdxPublicFilter): + """ + Custom class used to get lms page url filters and its custom methods. + """ + + filter_type = "org.openedx.course_authoring.lms.page.url.requested.v1" + + @classmethod + def run_filter(cls, url, org): + """ + Execute a filter with the signature specified. + + Arguments: + url (str): the URL of the page to be modified. + org (str): Course org filter used as context data to get LMS configurations. + """ + data = super().run_pipeline(url=url, org=org) + return data.get("url"), data.get("org") diff --git a/openedx_filters/course_authoring/tests/__init__.py b/openedx_filters/course_authoring/tests/__init__.py new file mode 100644 index 0000000..deb4697 --- /dev/null +++ b/openedx_filters/course_authoring/tests/__init__.py @@ -0,0 +1,3 @@ +""" +Package where unittest for authoring subdomain filters are located. +""" diff --git a/openedx_filters/course_authoring/tests/test_filters.py b/openedx_filters/course_authoring/tests/test_filters.py new file mode 100644 index 0000000..46d17fd --- /dev/null +++ b/openedx_filters/course_authoring/tests/test_filters.py @@ -0,0 +1,32 @@ +""" +Tests for authoring subdomain filters. +""" +from unittest.mock import Mock + +from django.test import TestCase + +from openedx_filters.course_authoring.filters import LMSPageURLRequested + + +class TestCourseAuthoringFilters(TestCase): + """ + Test class to verify standard behavior of the filters located in rendering views. + You'll find test suites for: + + - LMSPageURLRequested + """ + + def test_lms_page_url_requested(self): + """ + Test LMSPageURLRequested filter behavior under normal conditions. + + Expected behavior: + - The filter should return lms page url requested. + """ + url = Mock() + org = Mock() + + url_result, org_result = LMSPageURLRequested.run_filter(url, org) + + self.assertEqual(url, url_result) + self.assertEqual(org, org_result) diff --git a/openedx_filters/learning/filters.py b/openedx_filters/learning/filters.py index dc39b8d..011d014 100644 --- a/openedx_filters/learning/filters.py +++ b/openedx_filters/learning/filters.py @@ -798,3 +798,23 @@ def run_filter(cls, url: str): """ data = super().run_pipeline(url=url) return data.get("url") + + +class CourseAboutPageURLRequested(OpenEdxPublicFilter): + """ + Custom class used to get course about page url filters and its custom methods. + """ + + filter_type = "org.openedx.learning.course_about.page.url.requested.v1" + + @classmethod + def run_filter(cls, url, org): + """ + Execute a filter with the specified signature. + + Arguments: + url (str): the URL of the page to be modified. + org (str): Course org filter used as context data to get LMS configurations. + """ + data = super().run_pipeline(url=url, org=org) + return data.get("url"), data.get("org") diff --git a/openedx_filters/learning/tests/test_filters.py b/openedx_filters/learning/tests/test_filters.py index 203728c..41896cc 100644 --- a/openedx_filters/learning/tests/test_filters.py +++ b/openedx_filters/learning/tests/test_filters.py @@ -12,6 +12,7 @@ CertificateRenderStarted, CohortAssignmentRequested, CohortChangeRequested, + CourseAboutPageURLRequested, CourseAboutRenderStarted, CourseEnrollmentAPIRenderStarted, CourseEnrollmentQuerysetRequested, @@ -752,3 +753,26 @@ def test_idv_page_url_requested(self): result = IDVPageURLRequested.run_filter(url) self.assertEqual(url, result) + + +class TestCourseAboutPageURLRequested(TestCase): + """ + Test class to verify standard behavior of the ID verification filters. + You'll find test suites for: + + - CourseAboutPageURLRequested + """ + + def test_lms_page_url_requested(self): + """ + Test CourseAboutPageURLRequested filter behavior under normal conditions. + Expected behavior: + - The filter should return lms page url requested. + """ + url = Mock() + org = Mock() + + url_result, org_result = CourseAboutPageURLRequested.run_filter(url, org) + + self.assertEqual(url, url_result) + self.assertEqual(org, org_result)