-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds LmsUrlCreationStarted filter
- Loading branch information
1 parent
71ce314
commit e95d591
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Package where unittest for content_authoring subdomain filters are located. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) |