From e95d5917a8d4ddf15a9cd1d3c6d40b80665771d3 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Palma Date: Thu, 18 Jul 2024 19:52:29 -0400 Subject: [PATCH] feat: adds LmsUrlCreationStarted filter --- openedx_filters/content_authoring/__init__.py | 6 ++ openedx_filters/content_authoring/filters.py | 33 ++++++++++ .../content_authoring/tests/__init__.py | 3 + .../content_authoring/tests/test_filters.py | 64 +++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 openedx_filters/content_authoring/__init__.py create mode 100644 openedx_filters/content_authoring/filters.py create mode 100644 openedx_filters/content_authoring/tests/__init__.py create mode 100644 openedx_filters/content_authoring/tests/test_filters.py diff --git a/openedx_filters/content_authoring/__init__.py b/openedx_filters/content_authoring/__init__.py new file mode 100644 index 00000000..b8f6141b --- /dev/null +++ b/openedx_filters/content_authoring/__init__.py @@ -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. +""" diff --git a/openedx_filters/content_authoring/filters.py b/openedx_filters/content_authoring/filters.py new file mode 100644 index 00000000..a9271638 --- /dev/null +++ b/openedx_filters/content_authoring/filters.py @@ -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") diff --git a/openedx_filters/content_authoring/tests/__init__.py b/openedx_filters/content_authoring/tests/__init__.py new file mode 100644 index 00000000..6f28cd75 --- /dev/null +++ b/openedx_filters/content_authoring/tests/__init__.py @@ -0,0 +1,3 @@ +""" +Package where unittest for content_authoring subdomain filters are located. +""" diff --git a/openedx_filters/content_authoring/tests/test_filters.py b/openedx_filters/content_authoring/tests/test_filters.py new file mode 100644 index 00000000..0f6c9880 --- /dev/null +++ b/openedx_filters/content_authoring/tests/test_filters.py @@ -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__)