Skip to content

Commit

Permalink
feat: add filter exception for rendering custom response
Browse files Browse the repository at this point in the history
  • Loading branch information
nsprenkle committed Jun 10, 2024
1 parent 0738e99 commit c585d5b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
17 changes: 16 additions & 1 deletion openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,23 @@ class RenderXBlockStarted(OpenEdxPublicFilter):

class PreventXBlockBlockRender(OpenEdxFilterException):
"""
Custom class used to prevent the vertical block from rendering for the user.
Custom class used to prevent the XBlock from rendering for the user.
"""

class RenderCustomResponse(OpenEdxFilterException):
"""
Custom class used to stop the XBlock rendering process and return a custom response.
"""

def __init__(self, message, response=None):
"""
Override init that defines specific arguments used in the XBlock render process.
Arguments:
message: error message for the exception.
response: custom response which will be returned by the XBlock render view.
"""
super().__init__(message, response=response)

@classmethod
def run_filter(cls, context, student_view_context):
Expand Down
20 changes: 20 additions & 0 deletions openedx_filters/learning/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,26 @@ def test_halt_xblock_render(self, xblock_render_exception, attributes):

self.assertDictContainsSubset(attributes, exception.__dict__)

@data(
(
RenderXBlockStarted.RenderCustomResponse,
{
"message": "Danger, Will Robinson!"
}
)
)
@unpack
def test_halt_xblock_render_custom_response(self, xblock_render_exception, attributes):
"""
Test for xblock render exception attributes.
Expected behavior:
- The exception must have the attributes specified.
"""
exception = xblock_render_exception(**attributes)

self.assertDictContainsSubset(attributes, exception.__dict__)

def test_account_settings_render_started(self):
"""
Test AccountSettingsRenderStarted filter behavior under normal conditions.
Expand Down

0 comments on commit c585d5b

Please sign in to comment.