Skip to content

Commit

Permalink
feat: adds LmsUrlCreationStarted filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jignaciopm committed Aug 7, 2024
1 parent 71ce314 commit e95d591
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
6 changes: 6 additions & 0 deletions openedx_filters/content_authoring/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
Package where filters related to the content_authoring subdomain are implemented.
The content_authoring subdomain corresponds to {Architecture Subdomain} defined in
the OEP-41.
"""
33 changes: 33 additions & 0 deletions openedx_filters/content_authoring/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Package where filters related to the content authoring architectural subdomain are implemented.
"""

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


class LmsUrlCreationStarted(OpenEdxPublicFilter):
"""
Custom class used to create lms url creation link render filters and its custom methods.
"""

filter_type = "org.openedx.course_authoring.lms.url.creation.started.v1"

class PreventLmsUrlCreationRender(OpenEdxFilterException):
"""
Custom class used to stop lms url creation link render process.
"""

@classmethod
def run_filter(cls, context, org, val_name, default):
"""
Execute a filter with the signature specified.
Arguments:
context (str): rendering context value
org (str): Course org filter, this value will be used to filter out the correct lms url configuration.
val_name (str): Name of the key for which to return configuration value.
default: default value to return if key is not present in the configuration
"""
data = super().run_pipeline(context=context, org=org, val_name=val_name, default=default)
return data.get("context")
3 changes: 3 additions & 0 deletions openedx_filters/content_authoring/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Package where unittest for content_authoring subdomain filters are located.
"""
64 changes: 64 additions & 0 deletions openedx_filters/content_authoring/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Tests for content authoring subdomain filters.
"""
from unittest.mock import Mock

from ddt import data, ddt, unpack
from django.test import TestCase

from openedx_filters.content_authoring.filters import LmsUrlCreationStarted


@ddt
class TestRenderingFilters(TestCase):
"""
Test class to verify standard behavior of the filters located in rendering views.
You'll find test suites for:
- LmsUrlCreationStarted
"""

def setUp(self):
"""
Setup common conditions for every test case.
"""
super().setUp()
self.template_name = "custom-template-name.html"
self.context = {
"user": Mock(),
}

def test_lms_url_creation_started(self):
"""
Test LmsUrlCreationStarted filter behavior under normal conditions.
Expected behavior:
- The filter should return lms url creation context.
"""
context = Mock()
org = Mock()
val_name = Mock()
default = Mock()

result = LmsUrlCreationStarted.run_filter(context, org, val_name, default)
print(result)

self.assertEqual(context, result)

@data(
(
LmsUrlCreationStarted.PreventLmsUrlCreationRender,
{
"message": "Can't render lms url creation."
}
)
)
@unpack
def test_halt_lms_url_creation(self, lms_url_creation_exception, attributes):
"""
Test for lms url creation exceptions attributes.
Expected behavior:
- The exception must have the attributes specified.
"""
exception = lms_url_creation_exception(**attributes)

self.assertDictContainsSubset(attributes, exception.__dict__)

0 comments on commit e95d591

Please sign in to comment.