Skip to content

Commit

Permalink
fix: change trigger_name to hook_name
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed May 7, 2021
1 parent b53c1f8 commit a3109ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions openedx_filters/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
log = getLogger(__name__)


def run_pipeline(trigger_name, *args, **kwargs):
def run_pipeline(hook_name, *args, **kwargs):
"""
Execute filters in order.
Expand All @@ -31,7 +31,7 @@ def run_pipeline(trigger_name, *args, **kwargs):
}
Arguments:
trigger_name (str): determines which trigger we are listening to.
hook_name (str): determines which trigger we are listening to.
It also specifies which hook configuration defined through settings.
Returns:
Expand All @@ -49,7 +49,7 @@ def run_pipeline(trigger_name, *args, **kwargs):
information check their Github repository:
https://github.com/python-social-auth/social-core
"""
pipeline, raise_exception = get_pipeline_configuration(trigger_name)
pipeline, raise_exception = get_pipeline_configuration(hook_name)

if not pipeline:
return kwargs
Expand Down
14 changes: 7 additions & 7 deletions openedx_filters/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"request": Mock(),
}
self.pipeline = Mock()
self.trigger_name = "openedx.service.context.location.type.vi"
self.hook_name = "openedx.service.context.location.type.vi"

@patch("openedx_filters.pipeline.get_pipeline_configuration")
@patch("openedx_filters.pipeline.get_functions_for_pipeline")
Expand All @@ -41,7 +41,7 @@ def test_run_empty_pipeline(self, get_functions_mock, get_configuration_mock):
)
get_functions_mock.return_value = []

result = run_pipeline(self.trigger_name, **self.kwargs)
result = run_pipeline(self.hook_name, **self.kwargs)

get_configuration_mock.assert_called_once_with(
"openedx.service.context.location.type.vi",
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_raise_hook_exception(self, get_functions_mock, get_configuration_mock):
)

with self.assertRaises(HookFilterException), self.assertLogs() as captured:
run_pipeline(self.trigger_name, **self.kwargs)
run_pipeline(self.hook_name, **self.kwargs)
self.assertEqual(
captured.records[0].getMessage(), log_message,
)
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_not_raise_hook_exception(self, get_functions_mock, get_hook_config_mock
function_without_exception,
]

result = run_pipeline(self.trigger_name, **self.kwargs)
result = run_pipeline(self.hook_name, **self.kwargs)

self.assertDictEqual(result, return_value)
function_without_exception.assert_called_once_with(**self.kwargs)
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_not_raise_common_exception(self, get_functions_mock, get_hook_config_mo
)

with self.assertLogs() as captured:
result = run_pipeline(self.trigger_name, **self.kwargs)
result = run_pipeline(self.hook_name, **self.kwargs)

self.assertEqual(
captured.records[0].getMessage(), log_message,
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_getting_pipeline_result(self, get_functions_mock, get_hook_config_mock)
second_function,
]

result = run_pipeline(self.trigger_name, **self.kwargs)
result = run_pipeline(self.hook_name, **self.kwargs)

first_function.assert_called_once_with(**self.kwargs)
second_function.assert_called_once_with(**return_value_1st)
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_partial_pipeline(self, get_functions_mock, get_hook_config_mock):
log_message = "Pipeline stopped by 'first_function' for returning an object."

with self.assertLogs() as captured:
result = run_pipeline(self.trigger_name, **self.kwargs)
result = run_pipeline(self.hook_name, **self.kwargs)

self.assertEqual(
captured.records[0].getMessage(), log_message,
Expand Down
4 changes: 2 additions & 2 deletions openedx_filters/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_get_empty_hook_config(self):
Expected behavior:
Returns an empty dictionary.
"""
result = get_filter_config("trigger_name")
result = get_filter_config("hook_name")

self.assertEqual(result, {})

Expand Down Expand Up @@ -198,6 +198,6 @@ def test_get_pipeline_config(self, config, expected_result, get_filter_config_mo
"""
get_filter_config_mock.return_value = config

result = get_pipeline_configuration("trigger_name")
result = get_pipeline_configuration("hook_name")

self.assertTupleEqual(result, expected_result)
12 changes: 6 additions & 6 deletions openedx_filters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_functions_for_pipeline(pipeline):
return function_list


def get_pipeline_configuration(trigger_name):
def get_pipeline_configuration(hook_name):
"""
Get pipeline configuration from filter settings.
Expand All @@ -66,7 +66,7 @@ def get_pipeline_configuration(trigger_name):
)
Arguments:
trigger_name (str): determines which is the trigger of this
hook_name (str): determines which is the trigger of this
pipeline.
Returns:
Expand All @@ -77,7 +77,7 @@ def get_pipeline_configuration(trigger_name):
fail_silently configuration, True meaning it won't raise exceptions and
False the opposite.
"""
hook_config = get_filter_config(trigger_name)
hook_config = get_filter_config(hook_name)

if not hook_config:
return [], False
Expand All @@ -99,7 +99,7 @@ def get_pipeline_configuration(trigger_name):
return pipeline, raise_exception


def get_filter_config(trigger_name):
def get_filter_config(hook_name):
"""
Get filters configuration from settings.
Expand Down Expand Up @@ -128,12 +128,12 @@ def get_filter_config(trigger_name):
execution fails.
Arguments:
trigger_name (str): determines which configuration to use.
hook_name (str): determines which configuration to use.
Returns:
hooks configuration (dict): taken from Django settings
containing hooks configuration.
"""
hooks_config = getattr(settings, "HOOK_FILTERS_CONFIG", {})

return hooks_config.get(trigger_name, {})
return hooks_config.get(hook_name, {})

0 comments on commit a3109ed

Please sign in to comment.