Skip to content

Commit

Permalink
Merge pull request #374 from nelc/and/add_transformer_to_dymanic_filter
Browse files Browse the repository at this point in the history
feat!: add transformer to filter arguments.
  • Loading branch information
Ian2012 authored Dec 6, 2023
2 parents 2013ee0 + 637812e commit b8883f9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
7 changes: 6 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ version: 2
sphinx:
configuration: docs/conf.py

# Set the version of python needed to build these docs.
build:
os: "ubuntu-22.04"
tools:
python: "3.8"

python:
version: 3.8
install:
- requirements: requirements/doc.txt
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Change Log
Unreleased
~~~~~~~~~~

[8.0.0]
~~~~~~~

* **BREAKING CHANGE**: Add transformer argument to openedx dynamic filter.

[7.2.0]
~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion event_routing_backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Various backends for receiving edX LMS events..
"""

__version__ = '7.2.0'
__version__ = '8.0.0'
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def inner_wrapper(*args, **kwargs):
dynamic_filter = ProcessorBaseFilter.generate_dynamic_filter(filter_type=filter_type)

return dynamic_filter.run_filter(
transformer=args[0],
result=func(*args, **kwargs),
)

Expand Down
5 changes: 3 additions & 2 deletions event_routing_backends/processors/openedx_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ def generate_dynamic_filter(cls, filter_type):
return type("DynamicFilter", (cls,), {"filter_type": filter_type})

@classmethod
def run_filter(cls, result):
def run_filter(cls, transformer, result):
"""
Executes a filter after validating the right class configuration.
Arguments:
transformer: XApiTransformer instance.
result: Result to be modified or extended.
Returns:
Expand All @@ -45,6 +46,6 @@ def run_filter(cls, result):
if not cls.filter_type:
raise InvalidFilterType("Parameter filter_type has not been set.")

data = super().run_pipeline(result=result)
data = super().run_pipeline(transformer=transformer, result=result)

return data.get("result", result)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test cases for the filters file."""
from django.test import TestCase
from mock import patch
from mock import Mock, patch
from openedx_filters.tooling import OpenEdxPublicFilter

from event_routing_backends.processors.openedx_filters.exceptions import InvalidFilterType
Expand All @@ -17,7 +17,7 @@ def test_invalid_configuration(self):
Expected behavior:
- InvalidFilterType exception is raised
"""
self.assertRaises(InvalidFilterType, ProcessorBaseFilter.run_filter, "dummy_value")
self.assertRaises(InvalidFilterType, ProcessorBaseFilter.run_filter, Mock(), "dummy_value")

@patch.object(OpenEdxPublicFilter, "run_pipeline")
def test_expected_value(self, run_pipeline_mock):
Expand All @@ -28,13 +28,14 @@ def test_expected_value(self, run_pipeline_mock):
- run_pipeline is called with the right key and value
- run_filter returns the value of the result key
"""
transformer = Mock()
run_pipeline_mock.return_value = {
"result": "expected_value"
}
input_value = "dummy_value"
openedx_filter = ProcessorBaseFilter.generate_dynamic_filter(filter_type="test_filter")

result = openedx_filter.run_filter(result=input_value)
result = openedx_filter.run_filter(transformer=transformer, result=input_value)

run_pipeline_mock.assert_called_once_with(result=input_value)
run_pipeline_mock.assert_called_once_with(transformer=transformer, result=input_value)
self.assertEqual(run_pipeline_mock()["result"], result)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 7.2.0
current_version = 8.0.0
commit = False
tag = False

Expand Down

0 comments on commit b8883f9

Please sign in to comment.