Skip to content

Commit

Permalink
feat: add filter before render user setttings context
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrrypg committed Dec 7, 2022
1 parent 96da9f8 commit 1b72ef2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
41 changes: 41 additions & 0 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
"""
Package where filters related to the learning architectural subdomain are implemented.
"""

from openedx_filters.exceptions import OpenEdxFilterException
from openedx_filters.tooling import OpenEdxPublicFilter
from openedx_filters.utils import SensitiveDataManagementMixin


class AccountSettingsRenderStarted(OpenEdxPublicFilter):
"""
Custom class used to create Account settings filters.
"""

filter_type = "org.openedx.learning.student.settings.render.started.v1"

class PreventAccountSettingsRender(OpenEdxFilterException):
"""
Custom class used to stop the Account settings rendering process.
"""

class RedirectToPage(OpenEdxFilterException):
"""
Custom class used to redirect before account settings rendering process.
"""

def __init__(self, message, redirect_to=""):
"""
Override init that defines specific arguments used in the account settings render process.
Arguments:
message: error message for the exception.
redirect_to: URL to redirect to.
"""
super().__init__(message, redirect_to=redirect_to)

@classmethod
def run_filter(cls, context):
"""
Execute a filter with the signature specified.
Arguments:
context (dict): context for the account settings page.
"""
data = super().run_pipeline(context=context)
context = data.get("context")
return context


class StudentRegistrationRequested(OpenEdxPublicFilter, SensitiveDataManagementMixin):
"""
Custom class used to create registration filters and its custom methods.
Expand Down
19 changes: 19 additions & 0 deletions openedx_filters/learning/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.test import TestCase

from openedx_filters.learning.filters import (
AccountSettingsRenderStarted,
CertificateCreationRequested,
CertificateRenderStarted,
CohortAssignmentRequested,
Expand Down Expand Up @@ -274,6 +275,7 @@ class TestRenderingFilters(TestCase):
- CourseAboutRenderStarted
- DashboardRenderStarted
- VerticalBlockChildRenderStarted
- AccountSettingsRenderStarted
"""

def setUp(self):
Expand Down Expand Up @@ -376,6 +378,23 @@ def test_verticalblock_child_render_started(self):

self.assertTupleEqual((block, context,), result)

def test_account_settings_render_started(self):
"""
Test AccountSettingsRenderStarted filter behavior under normal conditions.
Expected behavior:
- The filter should return context.
"""
context = {
'duplicate_provider': None,
'disable_courseware_js': True,
'show_dashboard_tabs': True
}

result = AccountSettingsRenderStarted.run_filter(context=context)

self.assertEqual(result, context)


class TestCohortFilters(TestCase):
"""
Expand Down

0 comments on commit 1b72ef2

Please sign in to comment.