Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Jul 19, 2023
1 parent 424e18a commit 14d23f1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Change Log
Unreleased
----------

[8.3.0] - 2023-07-19
--------------------
Added
~~~~~
* Added generic handler to allow producing to event bus via django settings.

[8.2.0] - 2023-06-08
--------------------
Changed
Expand Down
2 changes: 1 addition & 1 deletion docs/how-tos/adding-events-to-event-bus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ adding a new event to the event bus:
Producing to event bus
^^^^^^^^^^^^^^^^^^^^^^

In the producing/host application, include ``openedx_events`` in ``INSTALLED_APPS`` settings and add ``EVENT_BUS_PRODUCER_CONFIG`` setting. For example, below snippet is to push ``XBLOCK_PUBLISHED`` to two different topics and ``XBLOCK_DELETED`` signal to one topic in event bus.
In the producing/host application, **include ``openedx_events`` in ``INSTALLED_APPS`` settings** and add ``EVENT_BUS_PRODUCER_CONFIG`` setting. For example, below snippet is to push ``XBLOCK_PUBLISHED`` to two different topics and ``XBLOCK_DELETED`` signal to one topic in event bus.

.. code-block:: python
Expand Down
2 changes: 1 addition & 1 deletion openedx_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
more information about the project.
"""

__version__ = "8.2.0"
__version__ = "8.3.0"
21 changes: 16 additions & 5 deletions openedx_events/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def general_signal_handler(sender, signal, **kwargs): # pylint: disable=unused-argument
"""
Generic signal handler for publishing events to configured event bus.
Signal handler for publishing events to configured event bus.
"""
configurations = getattr(settings, "EVENT_BUS_PRODUCER_CONFIG", {}).get(signal.event_type, ())
event_data = {key: kwargs.get(key) for key in signal.init_data}
Expand All @@ -36,7 +36,10 @@ class OpenedxEventsConfig(AppConfig):

def _ensure_signal_config_format(self, event_type, configurations):
"""
Validate signal configuration format. Raises ProducerConfigurationError.
Validate signal configuration format.
Raises:
ProducerConfigurationError: If configuration is not valid.
"""
if type(configurations) not in (list, tuple):
raise ProducerConfigurationError(
Expand All @@ -60,15 +63,23 @@ def _ensure_signal_config_format(self, event_type, configurations):
raise ProducerConfigurationError(
event_type=event_type,
message=(f"Expected type: {expected_type} for '{expected_key}', "
f"found: {type(configuration[expected_key])}")
f"found: {type(configuration[expected_key])}")
)

def ready(self):
"""
Read `EVENT_BUS_PRODUCER_CONFIG` setting and connects appropriate handlers to the events based on it.
Raises:
ProducerConfigurationError: If `EVENT_BUS_PRODUCER_CONFIG` is not valid.
"""
load_all_signals()
signals_config = getattr(settings, "EVENT_BUS_PRODUCER_CONFIG", {})
if not isinstance(signals_config, dict):
raise ProducerConfigurationError(message=("Setting 'EVENT_BUS_PRODUCER_CONFIG' should be a"
" dictionary with event_type as key and list or tuple of config dictionaries as values"))
raise ProducerConfigurationError(
message=("Setting 'EVENT_BUS_PRODUCER_CONFIG' should be a dictionary with event_type as"
" key and list or tuple of config dictionaries as values")
)
for event_type, configurations in signals_config.items():
self._ensure_signal_config_format(event_type, configurations)
signal = OpenEdxPublicSignal.get_signal_by_type(event_type)
Expand Down
4 changes: 2 additions & 2 deletions openedx_events/tests/test_producer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Test for producer configuration.
"""
from unittest.mock import Mock, patch
from django.apps import apps
from django.test import TestCase, override_settings

import ddt
import pytest
from django.apps import apps
from django.test import TestCase, override_settings

from openedx_events.content_authoring.data import XBlockData
from openedx_events.content_authoring.signals import XBLOCK_DELETED, XBLOCK_PUBLISHED
Expand Down

0 comments on commit 14d23f1

Please sign in to comment.