-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Emit COURSE_CATALOG_INFO_CHANGED signal on course publish
Implements #30682 Produce signal only once transaction for a course publish is committed, and only for actual courses (not libraries). - Use newer openedx-events version that has a fix for None datetime and that has CourseCatalogData without org, number. - Add edx-event-bus-kafka -- specify recent version that drops confluent-kafka from explicit deps - New functionality behind toggle As per openedx/openedx-events#88 we're going to try explicit dependencies on implementations for now, rather than solve all the problems we'd encounter by using private dependencies.
- Loading branch information
Showing
9 changed files
with
212 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
83 changes: 83 additions & 0 deletions
83
cms/djangoapps/contentstore/signals/tests/test_handlers.py
This file contains 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,83 @@ | ||
""" | ||
Tests for signal handlers in the contentstore. | ||
""" | ||
|
||
from datetime import datetime | ||
from unittest.mock import patch | ||
|
||
from django.test.utils import override_settings | ||
from opaque_keys.edx.locator import CourseLocator, LibraryLocator | ||
from openedx_events.content_authoring.data import CourseCatalogData, CourseScheduleData | ||
|
||
import cms.djangoapps.contentstore.signals.handlers as sh | ||
from xmodule.modulestore.django import SignalHandler | ||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase | ||
from xmodule.modulestore.tests.factories import SampleCourseFactory | ||
|
||
|
||
class TestCatalogInfoSignal(ModuleStoreTestCase): | ||
""" | ||
Test functionality of triggering catalog info signals (and events) from course_published signal. | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.course = SampleCourseFactory.create( | ||
org='TestU', | ||
number='sig101', | ||
display_name='Signals 101', | ||
run='Summer2022', | ||
) | ||
self.course_key = self.course.id | ||
|
||
self.expected_data = CourseCatalogData( | ||
course_key=CourseLocator(org='TestU', course='sig101', run='Summer2022', branch=None, version_guid=None), | ||
name='Signals 101', | ||
schedule_data=CourseScheduleData( | ||
start=datetime.fromisoformat('2030-01-01T00:00+00:00'), | ||
pacing='instructor', | ||
end=None, | ||
enrollment_start=None, | ||
enrollment_end=None), | ||
short_description=None, | ||
effort=None, | ||
hidden=False, | ||
invitation_only=False | ||
) | ||
|
||
@patch( | ||
'cms.djangoapps.contentstore.signals.handlers.transaction.on_commit', | ||
autospec=True, side_effect=lambda func: func(), # run right away | ||
) | ||
@patch('cms.djangoapps.contentstore.signals.handlers.emit_catalog_info_changed_signal', autospec=True) | ||
def test_signal_chain(self, mock_emit, _mock_on_commit): | ||
""" | ||
Test that the course_published signal handler invokes the catalog info signal emitter. | ||
I tested this in a bit of a weird way because I couldn't get the transaction on-commit | ||
to run during the test, so instead I capture it and call the callbacks right away. | ||
""" | ||
with SignalHandler.course_published.for_state(is_enabled=True): | ||
SignalHandler.course_published.send(TestCatalogInfoSignal, course_key=self.course_key) | ||
mock_emit.assert_called_once_with(self.course_key) | ||
|
||
@override_settings(SEND_CATALOG_INFO_SIGNAL=True) | ||
@patch('cms.djangoapps.contentstore.signals.handlers.COURSE_CATALOG_INFO_CHANGED', autospec=True) | ||
def test_emit_regular_course(self, mock_signal): | ||
"""On a normal course publish, send an event.""" | ||
sh.emit_catalog_info_changed_signal(self.course_key) | ||
mock_signal.send_event.assert_called_once_with(catalog_info=self.expected_data) | ||
|
||
@override_settings(SEND_CATALOG_INFO_SIGNAL=True) | ||
@patch('cms.djangoapps.contentstore.signals.handlers.COURSE_CATALOG_INFO_CHANGED', autospec=True) | ||
def test_ignore_library(self, mock_signal): | ||
"""When course key is actually a library, don't send.""" | ||
sh.emit_catalog_info_changed_signal(LibraryLocator(org='SomeOrg', library='stuff')) | ||
mock_signal.send_event.assert_not_called() | ||
|
||
@override_settings(SEND_CATALOG_INFO_SIGNAL=False) | ||
@patch('cms.djangoapps.contentstore.signals.handlers.COURSE_CATALOG_INFO_CHANGED', autospec=True) | ||
def test_disabled(self, mock_signal): | ||
"""When toggle is disabled, don't send.""" | ||
sh.emit_catalog_info_changed_signal(self.course_key) | ||
mock_signal.send_event.assert_not_called() |
This file contains 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 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 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 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 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 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