diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py
index c6fdc00301..bc8975eb5d 100644
--- a/cms/djangoapps/contentstore/tests/test_libraries.py
+++ b/cms/djangoapps/contentstore/tests/test_libraries.py
@@ -326,6 +326,99 @@ class TestLibraries(LibraryTestCase):
html_block = modulestore().get_item(lc_block.children[0])
self.assertEqual(html_block.data, data_value)
+ def test_refreshes_children_if_libraries_change(self):
+ library2key = self._create_library("org2", "lib2", "Library2")
+ library2 = modulestore().get_library(library2key)
+ data1, data2 = "Hello world!", "Hello other world!"
+ ItemFactory.create(
+ category="html",
+ parent_location=self.library.location,
+ user_id=self.user.id,
+ publish_item=False,
+ display_name="Lib1: HTML BLock",
+ data=data1,
+ )
+
+ ItemFactory.create(
+ category="html",
+ parent_location=library2.location,
+ user_id=self.user.id,
+ publish_item=False,
+ display_name="Lib 2: HTML BLock",
+ data=data2,
+ )
+
+ # Create a course:
+ with modulestore().default_store(ModuleStoreEnum.Type.split):
+ course = CourseFactory.create()
+
+ # Add a LibraryContent block to the course:
+ lc_block = self._add_library_content_block(course, self.lib_key)
+ lc_block = self._refresh_children(lc_block)
+ self.assertEqual(len(lc_block.children), 1)
+
+ # Now, change the block settings to have an invalid library key:
+ resp = self._update_item(
+ lc_block.location,
+ {"source_libraries": [[str(library2key)]]},
+ )
+ self.assertEqual(resp.status_code, 200)
+ lc_block = modulestore().get_item(lc_block.location)
+
+ self.assertEqual(len(lc_block.children), 1)
+ html_block = modulestore().get_item(lc_block.children[0])
+ self.assertEqual(html_block.data, data2)
+
+ def test_refreshes_children_if_capa_type_change(self):
+ name1, name2 = "Option Problem", "Multiple Choice Problem"
+ ItemFactory.create(
+ category="problem",
+ parent_location=self.library.location,
+ user_id=self.user.id,
+ publish_item=False,
+ display_name=name1,
+ data="",
+ )
+ ItemFactory.create(
+ category="problem",
+ parent_location=self.library.location,
+ user_id=self.user.id,
+ publish_item=False,
+ display_name=name2,
+ data="",
+ )
+
+ # Create a course:
+ with modulestore().default_store(ModuleStoreEnum.Type.split):
+ course = CourseFactory.create()
+
+ # Add a LibraryContent block to the course:
+ lc_block = self._add_library_content_block(course, self.lib_key)
+ lc_block = self._refresh_children(lc_block)
+ self.assertEqual(len(lc_block.children), 2)
+
+ resp = self._update_item(
+ lc_block.location,
+ {"capa_type": 'optionresponse'},
+ )
+ self.assertEqual(resp.status_code, 200)
+ lc_block = modulestore().get_item(lc_block.location)
+
+ self.assertEqual(len(lc_block.children), 1)
+ html_block = modulestore().get_item(lc_block.children[0])
+ self.assertEqual(html_block.display_name, name1)
+
+ resp = self._update_item(
+ lc_block.location,
+ {"capa_type": 'multiplechoiceresponse'},
+ )
+ self.assertEqual(resp.status_code, 200)
+ lc_block = modulestore().get_item(lc_block.location)
+
+ self.assertEqual(len(lc_block.children), 1)
+ html_block = modulestore().get_item(lc_block.children[0])
+ self.assertEqual(html_block.display_name, name2)
+
@ddt.ddt
class TestLibraryAccess(LibraryTestCase):
diff --git a/common/lib/xmodule/xmodule/library_content_module.py b/common/lib/xmodule/xmodule/library_content_module.py
index 218272de8a..1b68e27a59 100644
--- a/common/lib/xmodule/xmodule/library_content_module.py
+++ b/common/lib/xmodule/xmodule/library_content_module.py
@@ -360,8 +360,8 @@ class LibraryContentDescriptor(LibraryContentFields, MakoModuleDescriptor, XmlDe
# TODO: change this to action_runtime_event='...' once the unit page supports that feature.
# See https://openedx.atlassian.net/browse/TNL-993
action_class='library-update-btn',
- # Translators: ↻ is an UTF icon symbol, no need translating it.
- action_label=_(u"{0} Update now.").format(u"↻")
+ # Translators: {refresh_icon} placeholder is substituted to "↻" (without double quotes)
+ action_label=_(u"{refresh_icon} Update now.").format(refresh_icon=u"↻")
)
)
return False
@@ -445,7 +445,7 @@ class LibraryContentDescriptor(LibraryContentFields, MakoModuleDescriptor, XmlDe
def editor_saved(self, user, old_metadata, old_content):
"""
- If source_libraries has been edited, refresh_children automatically.
+ If source_libraries or capa_type has been edited, refresh_children automatically.
"""
old_source_libraries = LibraryList().from_json(old_metadata.get('source_libraries', []))
if (set(old_source_libraries) != set(self.source_libraries) or