Merge pull request #27162 from open-craft/raul/fal-249-dndv2-blockstore-translations

FAL-249: fixes the blockstore runtime to set the correct translator
This commit is contained in:
Sarina Canelake
2021-03-31 15:50:23 -04:00
committed by GitHub
2 changed files with 10 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
Test the Blockstore-based XBlock runtime and content libraries together.
"""
import json
from gettext import GNUTranslations
from completion.test_utils import CompletionWaffleTestMixin
from django.db import connections
@@ -101,6 +102,13 @@ class ContentLibraryRuntimeTest(ContentLibraryContentTestMixin, TestCase):
assert library_api.get_library_block_olx(unit_block_key) == library_api.get_library_block_olx(unit_block2_key)
assert unit_block.children != unit_block2.children
def test_dndv2_sets_translator(self):
dnd_block_key = library_api.create_library_block(self.library.key, "drag-and-drop-v2", "dnd1").usage_key
library_api.publish_changes(self.library.key)
dnd_block = xblock_api.load_block(dnd_block_key, self.student_a)
i18n_service = dnd_block.runtime.service(dnd_block, 'i18n')
assert isinstance(i18n_service.translator, GNUTranslations)
def test_has_score(self):
"""
Test that the LMS-specific 'has_score' attribute is getting added to

View File

@@ -78,9 +78,6 @@ class XBlockRuntime(RuntimeShim, Runtime):
LmsBlockMixin, # Adds Non-deprecated LMS/Studio functionality
XBlockShim, # Adds deprecated LMS/Studio functionality / backwards compatibility
),
services={
"i18n": ModuleI18nService(),
},
default_class=None,
select=None,
id_generator=system.id_generator,
@@ -229,6 +226,8 @@ class XBlockRuntime(RuntimeShim, Runtime):
elif service_name == "completion":
context_key = block.scope_ids.usage_id.context_key
return CompletionService(user=self.user, context_key=context_key)
elif service_name == "i18n":
return ModuleI18nService(block=block)
# Check if the XBlockRuntimeSystem wants to handle this:
service = self.system.get_service(block, service_name)
# Otherwise, fall back to the base implementation which loads services