feat: deprecate track_function and publish in ModuleSystem [BD-13] (#30046)

* feat: delete `track_function` from ModuleSystem

* feat: delete `publish` argument from ModuleSystem
This commit is contained in:
Piotr Surowiec
2022-11-15 16:46:24 +01:00
committed by GitHub
parent eb8f3b6750
commit f419d6b194
16 changed files with 189 additions and 206 deletions

View File

@@ -23,7 +23,7 @@ from xblock.runtime import KvsFieldData, MemoryIdManager, Runtime
from xmodule.errortracker import make_error_tracker
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.django import ModuleI18nService
from xmodule.services import RebindUserService
from xmodule.services import EventPublishingService, RebindUserService
from xmodule.util.sandboxing import SandboxService
from common.djangoapps.edxmako.services import MakoService
from common.djangoapps.static_replace.services import ReplaceURLService
@@ -266,6 +266,8 @@ class XBlockRuntime(RuntimeShim, Runtime):
track_function=make_track_function(),
request_token=request_token(crum.get_current_request()),
)
elif service_name == 'publish':
return EventPublishingService(self.user, context_key, make_track_function())
# Check if the XBlockRuntimeSystem wants to handle this:
service = self.system.get_service(block, service_name)

View File

@@ -297,19 +297,6 @@ class RuntimeShim:
result['default_value'] = field.to_json(field.default)
return result
def track_function(self, title, event_info):
"""
Publish an event to the tracking log.
This is deprecated in favor of runtime.publish
See https://git.io/JeGLf and https://git.io/JeGLY for context.
"""
warnings.warn(
"runtime.track_function is deprecated. Use runtime.publish() instead.",
DeprecationWarning, stacklevel=2,
)
self.publish(self._active_block, title, event_info)
@property
def user_location(self):
"""

View File

@@ -49,10 +49,11 @@ from bs4 import BeautifulSoup
from django.conf import settings
from django.urls import reverse
from xblock.plugin import Plugin
import xmodule.services
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
import lms.djangoapps.lms_xblock.runtime
from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase
@@ -100,26 +101,26 @@ class XBlockEventTestMixin:
"""
super().setUp()
saved_init = lms.djangoapps.lms_xblock.runtime.LmsModuleSystem.__init__
saved_init = xmodule.services.EventPublishingService.__init__
def patched_init(runtime_self, **kwargs):
def patched_init(runtime_self, user, course_id, track_function, **kwargs):
"""
Swap out publish in the __init__
Swap out track_function in the __init__
"""
old_publish = kwargs["publish"]
old_track_function = track_function
def publish(block, event_type, event):
def new_track_function(event_type, event):
"""
Log the event, and call the original publish
Log the event, and call the original track_function.
"""
self.events.append({"event": event, "event_type": event_type})
old_publish(block, event_type, event)
kwargs['publish'] = publish
return saved_init(runtime_self, **kwargs)
old_track_function(event_type, event)
track_function = new_track_function
return saved_init(runtime_self, user, course_id, track_function, **kwargs)
self.events = []
lms_sys = "lms.djangoapps.lms_xblock.runtime.LmsModuleSystem.__init__"
patcher = mock.patch(lms_sys, patched_init)
publish_service = "xmodule.services.EventPublishingService.__init__"
patcher = mock.patch(publish_service, patched_init)
patcher.start()
self.addCleanup(patcher.stop)