From 8fb6181bf7cacf9a80af708a05b24867d9b3ea54 Mon Sep 17 00:00:00 2001 From: andrey-canon Date: Wed, 22 Nov 2023 12:46:54 -0500 Subject: [PATCH 1/4] feat!: add transformer to filter arguments. This improves the filter usability by adding the transformer to the filter arguments, basically this allows the filter client to access to extra data given by the transformer instance --- .../processors/openedx_filters/decorators.py | 1 + .../processors/openedx_filters/filters.py | 5 +++-- .../processors/tests/openedx_filters/test_filters.py | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/event_routing_backends/processors/openedx_filters/decorators.py b/event_routing_backends/processors/openedx_filters/decorators.py index ff64a3dc..adb1b4fe 100644 --- a/event_routing_backends/processors/openedx_filters/decorators.py +++ b/event_routing_backends/processors/openedx_filters/decorators.py @@ -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), ) diff --git a/event_routing_backends/processors/openedx_filters/filters.py b/event_routing_backends/processors/openedx_filters/filters.py index c00028df..7f02aa18 100644 --- a/event_routing_backends/processors/openedx_filters/filters.py +++ b/event_routing_backends/processors/openedx_filters/filters.py @@ -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: @@ -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) diff --git a/event_routing_backends/processors/tests/openedx_filters/test_filters.py b/event_routing_backends/processors/tests/openedx_filters/test_filters.py index eec91e4d..6f186ad8 100644 --- a/event_routing_backends/processors/tests/openedx_filters/test_filters.py +++ b/event_routing_backends/processors/tests/openedx_filters/test_filters.py @@ -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 @@ -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): @@ -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) From f59859a23f060bc33d0d14dfe552f1c079789aa1 Mon Sep 17 00:00:00 2001 From: andrey-canon Date: Wed, 29 Nov 2023 17:45:38 -0500 Subject: [PATCH 2/4] chore: update changelog and bumpversion --- CHANGELOG.rst | 5 +++++ event_routing_backends/__init__.py | 2 +- setup.cfg | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ae135f65..b346d96b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,11 @@ Change Log Unreleased ~~~~~~~~~~ +[8.0.0] +~~~~~~~ + +* Add transformer argument to openedx dynamic filter. + [7.2.0] ~~~~~~~ diff --git a/event_routing_backends/__init__.py b/event_routing_backends/__init__.py index 90339be4..445132b5 100644 --- a/event_routing_backends/__init__.py +++ b/event_routing_backends/__init__.py @@ -2,4 +2,4 @@ Various backends for receiving edX LMS events.. """ -__version__ = '7.2.0' +__version__ = '8.0.0' diff --git a/setup.cfg b/setup.cfg index f554d7b8..5fdd2a45 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 7.2.0 +current_version = 8.0.0 commit = False tag = False From eb51090d427538da061b66990aca48f50ba70d20 Mon Sep 17 00:00:00 2001 From: andrey-canon Date: Wed, 6 Dec 2023 10:18:28 -0500 Subject: [PATCH 3/4] chore: mark change as breaking change --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b346d96b..3341d679 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,7 +17,7 @@ Unreleased [8.0.0] ~~~~~~~ -* Add transformer argument to openedx dynamic filter. +* **BREAKING CHANGE**: Add transformer argument to openedx dynamic filter. [7.2.0] ~~~~~~~ From 637812e8c4751c33bc62b32d7020300936f74e82 Mon Sep 17 00:00:00 2001 From: andrey-canon Date: Wed, 6 Dec 2023 16:24:01 -0500 Subject: [PATCH 4/4] fix: include readthedocs fix from cookiecutter https://github.com/openedx/edx-cookiecutters/pull/419 --- .readthedocs.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 0f029d2f..363472a3 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -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