Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions openedx_filters/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""


class HookFilterException(Exception):
class OpenEdxFilterException(Exception):
"""
Base exception for filters.

Expand All @@ -20,7 +20,7 @@ class HookFilterException(Exception):

def __init__(self, message="", redirect_to=None, status_code=None, **kwargs):
"""
Init method for HookFilterException.
Init method for OpenEdxFilterException.

It's designed to allow flexible instantiation through **kwargs.
"""
Expand All @@ -33,6 +33,6 @@ def __init__(self, message="", redirect_to=None, status_code=None, **kwargs):

def __str__(self):
"""
Show string representation of HookFilterException using its message.
Show string representation of OpenEdxFilterException using its message.
"""
return "HookFilterException: {}".format(self.message)
return "OpenEdxFilterException: {}".format(self.message)
6 changes: 3 additions & 3 deletions openedx_filters/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from logging import getLogger

from openedx_filters.exceptions import HookFilterException
from openedx_filters.exceptions import OpenEdxFilterException
from openedx_filters.utils import get_functions_for_pipeline, get_pipeline_configuration

log = getLogger(__name__)
Expand Down Expand Up @@ -41,7 +41,7 @@ def run_pipeline(filter_name, *args, **kwargs):
an object different than Dict or None.

Exceptions raised:
HookFilterException: custom exception re-raised when a function raises
OpenEdxFilterException: custom exception re-raised when a function raises
an exception of this type and raise_exception is set to True. This
behavior is common when using filters.

Expand All @@ -67,7 +67,7 @@ def run_pipeline(filter_name, *args, **kwargs):
)
return result
out.update(result)
except HookFilterException as exc:
except OpenEdxFilterException as exc:
if raise_exception:
log.exception(
"Exception raised while running '%s':\n %s", function.__name__, exc,
Expand Down
12 changes: 6 additions & 6 deletions openedx_filters/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
"""
from django.test import TestCase

from openedx_filters.exceptions import HookFilterException
from openedx_filters.exceptions import OpenEdxFilterException


class TestCustomHookFilterException(TestCase):
class TestCustomOpenEdxFilterException(TestCase):
"""
Test class used to check flexibility when using HookFilterException.
Test class used to check flexibility when using OpenEdxFilterException.
"""

def test_exception_extra_arguments(self):
"""
This method raises HookFilterException with custom dynamic arguments.
This method raises OpenEdxFilterException with custom dynamic arguments.

Expected behavior:
Custom parameters can be accessed as instance arguments.
"""
hook_exception = HookFilterException(custom_arg="custom_argument")
filter_exception = OpenEdxFilterException(custom_arg="custom_argument")

self.assertEqual(
hook_exception.custom_arg, "custom_argument", # pylint: disable=no-member
filter_exception.custom_arg, "custom_argument", # pylint: disable=no-member
)
18 changes: 9 additions & 9 deletions openedx_filters/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.test import TestCase

from openedx_filters.exceptions import HookFilterException
from openedx_filters.exceptions import OpenEdxFilterException
from openedx_filters.pipeline import run_pipeline


Expand Down Expand Up @@ -51,10 +51,10 @@ def test_run_empty_pipeline(self, get_functions_mock, get_configuration_mock):

@patch("openedx_filters.pipeline.get_pipeline_configuration")
@patch("openedx_filters.pipeline.get_functions_for_pipeline")
def test_raise_hook_exception(self, get_functions_mock, get_configuration_mock):
def test_raise_filter_exception(self, get_functions_mock, get_configuration_mock):
"""
This method runs a pipeline with a function that raises
HookFilterException. This means that fail_silently must be set to
OpenEdxFilterException. This means that fail_silently must be set to
False.

Expected behavior:
Expand All @@ -65,25 +65,25 @@ def test_raise_hook_exception(self, get_functions_mock, get_configuration_mock):
"fail_silently": False,
}
exception_message = "There was an error executing filter X."
function = Mock(side_effect=HookFilterException(message=exception_message))
function = Mock(side_effect=OpenEdxFilterException(message=exception_message))
function.__name__ = "function_name"
get_functions_mock.return_value = [function]
log_message = "Exception raised while running '{func_name}':\n HookFilterException: {exc_msg}".format(
log_message = "Exception raised while running '{func_name}':\n OpenEdxFilterException: {exc_msg}".format(
func_name="function_name", exc_msg=exception_message,
)

with self.assertRaises(HookFilterException), self.assertLogs() as captured:
with self.assertRaises(OpenEdxFilterException), self.assertLogs() as captured:
run_pipeline(self.filter_name, **self.kwargs)
self.assertEqual(
captured.records[0].getMessage(), log_message,
)

@patch("openedx_filters.pipeline.get_pipeline_configuration")
@patch("openedx_filters.pipeline.get_functions_for_pipeline")
def test_not_raise_hook_exception(self, get_functions_mock, get_filter_config_mock):
def test_not_raise_filter_exception(self, get_functions_mock, get_filter_config_mock):
"""
This method runs a pipeline with a function that raises
HookFilterException but raise_exception is set to False. This means
OpenEdxFilterException but raise_exception is set to False. This means
fail_silently must be set to True or not defined.

Expected behavior:
Expand All @@ -96,7 +96,7 @@ def test_not_raise_hook_exception(self, get_functions_mock, get_filter_config_mo
return_value = {
"request": Mock(),
}
function_with_exception = Mock(side_effect=HookFilterException)
function_with_exception = Mock(side_effect=OpenEdxFilterException)
function_without_exception = Mock(return_value=return_value)
get_functions_mock.return_value = [
function_with_exception,
Expand Down
2 changes: 1 addition & 1 deletion openedx_filters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_filter_config(filter_name):
the pipeline are defined.
- fail_silently (bool): determines whether the pipeline can
raise exceptions while executing. If its value is True then
exceptions (HookFilterException) are caught and the execution
exceptions (OpenEdxFilterException) are caught and the execution
continues, if False then exceptions are re-raised and the
execution fails.

Expand Down