-
Notifications
You must be signed in to change notification settings - Fork 32
feat: enable producing to event bus via settings #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
navinkarkera
merged 2 commits into
openedx:main
from
open-craft:navin/configurable-handler
Aug 28, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,4 @@ | |
| more information about the project. | ||
| """ | ||
|
|
||
| __version__ = "8.5.0" | ||
| __version__ = "8.6.0" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| """ | ||
| Test for producer configuration. | ||
| """ | ||
| from unittest.mock import Mock, patch | ||
|
|
||
| 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 | ||
| from openedx_events.exceptions import ProducerConfigurationError | ||
|
|
||
|
|
||
| @ddt.ddt | ||
| class ProducerConfiguratonTest(TestCase): | ||
| """ | ||
| Tests to make sure EVENT_BUS_PRODUCER_CONFIG setting connects required signals to appropriate handlers. | ||
|
|
||
| Attributes: | ||
| xblock_info: dummy XBlockData. | ||
| """ | ||
| def setUp(self) -> None: | ||
| super().setUp() | ||
| self.xblock_info = XBlockData( | ||
| usage_key='block-v1:edx+DemoX+Demo_course+type@video+block@UaEBjyMjcLW65gaTXggB93WmvoxGAJa0JeHRrDThk', | ||
| block_type='video', | ||
| ) | ||
|
|
||
| @patch('openedx_events.apps.get_producer') | ||
| def test_enabled_disabled_events(self, mock_producer): | ||
| """ | ||
| Check whether XBLOCK_PUBLISHED is connected to the handler and the handler only publishes enabled events. | ||
|
|
||
| Args: | ||
| mock_producer: mock get_producer to inspect the arguments. | ||
| """ | ||
| mock_send = Mock() | ||
| mock_producer.return_value = mock_send | ||
| # XBLOCK_PUBLISHED has three configurations where 2 configurations have set enabled as True. | ||
| XBLOCK_PUBLISHED.send_event(xblock_info=self.xblock_info) | ||
| mock_send.send.assert_called() | ||
| mock_send.send.call_count = 2 | ||
|
|
||
| # check that call_args_list only consists of enabled topics. | ||
| call_args = mock_send.send.call_args_list[0][1] | ||
| self.assertDictContainsSubset( | ||
| {'topic': 'content-authoring-xblock-lifecycle', 'event_key_field': 'xblock_info.usage_key'}, | ||
| call_args | ||
| ) | ||
| call_args = mock_send.send.call_args_list[1][1] | ||
| self.assertDictContainsSubset( | ||
| {'topic': 'content-authoring-all-status', 'event_key_field': 'xblock_info.usage_key'}, | ||
| call_args | ||
| ) | ||
|
|
||
| @patch('openedx_events.apps.get_producer') | ||
| @override_settings(EVENT_BUS_PRODUCER_CONFIG={}) | ||
| def test_events_not_in_config(self, mock_producer): | ||
| """ | ||
| Check whether events not included in the configuration are not published as expected. | ||
|
|
||
| Args: | ||
| mock_producer: mock get_producer to inspect the arguments. | ||
| """ | ||
| mock_send = Mock() | ||
| mock_producer.return_value = mock_send | ||
| XBLOCK_PUBLISHED.send_event(xblock_info=self.xblock_info) | ||
| mock_producer.assert_not_called() | ||
| mock_send.send.assert_not_called() | ||
|
|
||
| def test_configuration_is_validated(self): | ||
| """ | ||
| Check whether EVENT_BUS_PRODUCER_CONFIG setting is validated before connecting handlers. | ||
| """ | ||
| with override_settings(EVENT_BUS_PRODUCER_CONFIG=[]): | ||
| with pytest.raises(ProducerConfigurationError, match="should be a dictionary"): | ||
| apps.get_app_config("openedx_events").ready() | ||
|
|
||
| with override_settings(EVENT_BUS_PRODUCER_CONFIG={"invalid.event.type": []}): | ||
| with pytest.raises(ProducerConfigurationError, match="No OpenEdxPublicSignal of type"): | ||
| apps.get_app_config("openedx_events").ready() | ||
|
|
||
| with override_settings(EVENT_BUS_PRODUCER_CONFIG={"org.openedx.content_authoring.xblock.deleted.v1": ""}): | ||
| with pytest.raises(ProducerConfigurationError, match="should be a list or a tuple"): | ||
| apps.get_app_config("openedx_events").ready() | ||
|
|
||
| with override_settings(EVENT_BUS_PRODUCER_CONFIG={"org.openedx.content_authoring.xblock.deleted.v1": [""]}): | ||
| with pytest.raises(ProducerConfigurationError, match="object is not a dictionary"): | ||
| apps.get_app_config("openedx_events").ready() | ||
|
|
||
| with override_settings( | ||
| EVENT_BUS_PRODUCER_CONFIG={ | ||
| "org.openedx.content_authoring.xblock.deleted.v1": [{"topic": "some", "enabled": True}] | ||
| } | ||
| ): | ||
| with pytest.raises(ProducerConfigurationError, match="missing 'event_key_field' key."): | ||
| apps.get_app_config("openedx_events").ready() | ||
|
|
||
| with override_settings( | ||
| EVENT_BUS_PRODUCER_CONFIG={ | ||
| "org.openedx.content_authoring.xblock.deleted.v1": [ | ||
| {"topic": "some", "enabled": 1, "event_key_field": "some"} | ||
| ] | ||
| } | ||
| ): | ||
| with pytest.raises( | ||
| ProducerConfigurationError, | ||
| match="Expected type: <class 'bool'> for 'enabled', found: <class 'int'>" | ||
| ): | ||
| apps.get_app_config("openedx_events").ready() | ||
|
|
||
| @patch('openedx_events.apps.get_producer') | ||
| def test_event_data_key_in_handler(self, mock_producer): | ||
| """ | ||
| Check whether event_data is constructed properly in handlers. | ||
| """ | ||
| mock_send = Mock() | ||
| mock_producer.return_value = mock_send | ||
| XBLOCK_DELETED.send_event(xblock_info=self.xblock_info) | ||
| mock_send.send.assert_called_once() | ||
|
|
||
| call_args = mock_send.send.call_args_list[0][1] | ||
| self.assertIn("xblock_info", call_args["event_data"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.