Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cms/djangoapps/contentstore/views/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@
"edit-title-button", "edit-upstream-alert",
]

DEFAULT_ADVANCED_MODULES = [
'google-calendar',
'google-document',
'lti_consumer',
'poll',
'split_test',
'survey',
'word_cloud',
]


def _advanced_component_types(show_unsupported):
"""
Expand Down Expand Up @@ -445,7 +455,7 @@ def create_support_legend_dict():
# These modules should be specified as a list of strings, where the strings
# are the names of the modules in ADVANCED_COMPONENT_TYPES that should be
# enabled for the course.
course_advanced_keys = courselike.advanced_modules
course_advanced_keys = list(dict.fromkeys(courselike.advanced_modules + DEFAULT_ADVANCED_MODULES))
advanced_component_templates = {
"type": "advanced",
"templates": [],
Expand Down
54 changes: 39 additions & 15 deletions cms/djangoapps/contentstore/views/tests/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
from openedx.core.djangoapps.content_tagging import api as tagging_api

from ..component import component_handler, get_component_templates
from ..component import component_handler, DEFAULT_ADVANCED_MODULES, get_component_templates
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import (
ALWAYS,
VisibilityState,
Expand Down Expand Up @@ -2903,6 +2903,16 @@ def setUp(self):

self.templates = get_component_templates(self.course)

self.default_advanced_modules_titles = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding this means the test is not resilient to the list of advanced modules changing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added DEFAULT_ADVANCED_MODULES to cms/envs/test.py, so changing them in other settings shouldn't break tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine for now, if the tests become brittle we can improve them in the future. This doesn't have to block merging this change.

"Google Calendar",
"Google Document",
"LTI Consumer",
"Poll",
"Content Experiment",
"Survey",
"Word cloud",
]

def get_templates_of_type(self, template_type):
"""
Returns the templates for the specified type, or None if none is found.
Expand Down Expand Up @@ -2956,7 +2966,11 @@ def test_basic_components(self):
self.assertGreater(len(self.get_templates_of_type("library")), 0)
self.assertGreater(len(self.get_templates_of_type("html")), 0)
self.assertGreater(len(self.get_templates_of_type("problem")), 0)
self.assertIsNone(self.get_templates_of_type("advanced"))

# Check for default advanced modules
advanced_templates = self.get_templates_of_type("advanced")
advanced_module_keys = [t['category'] for t in advanced_templates]
self.assertCountEqual(advanced_module_keys, DEFAULT_ADVANCED_MODULES)

# Now fully disable video through XBlockConfiguration
XBlockConfiguration.objects.create(name="video", enabled=False)
Expand Down Expand Up @@ -3004,29 +3018,38 @@ def test_advanced_components(self):
"""
Test the handling of advanced component templates.
"""
self.course.advanced_modules.append("word_cloud")
self.course.advanced_modules.append("done")
EXPECTED_ADVANCED_MODULES_LENGTH = len(DEFAULT_ADVANCED_MODULES) + 1
self.templates = get_component_templates(self.course)
advanced_templates = self.get_templates_of_type("advanced")
self.assertEqual(len(advanced_templates), 1)
world_cloud_template = advanced_templates[0]
self.assertEqual(world_cloud_template.get("category"), "word_cloud")
self.assertEqual(world_cloud_template.get("display_name"), "Word cloud")
self.assertIsNone(world_cloud_template.get("boilerplate_name", None))
self.assertEqual(len(advanced_templates), EXPECTED_ADVANCED_MODULES_LENGTH)
done_template = advanced_templates[0]
self.assertEqual(done_template.get("category"), "done")
self.assertEqual(done_template.get("display_name"), "Completion")
self.assertIsNone(done_template.get("boilerplate_name", None))

# Verify that non-advanced components are not added twice
# Verify that components are not added twice
self.course.advanced_modules.append("video")
self.course.advanced_modules.append("drag-and-drop-v2")
# Already defined advanced modules
self.course.advanced_modules.append("poll")
self.course.advanced_modules.append("google-document")
self.course.advanced_modules.append("survey")

self.templates = get_component_templates(self.course)
advanced_templates = self.get_templates_of_type("advanced")
self.assertEqual(len(advanced_templates), 1)
self.assertEqual(len(advanced_templates), EXPECTED_ADVANCED_MODULES_LENGTH)
only_template = advanced_templates[0]
self.assertNotEqual(only_template.get("category"), "video")
self.assertNotEqual(only_template.get("category"), "drag-and-drop-v2")
self.assertNotEqual(only_template.get("category"), "poll")
self.assertNotEqual(only_template.get("category"), "google-document")
self.assertNotEqual(only_template.get("category"), "survey")

# Now fully disable word_cloud through XBlockConfiguration
XBlockConfiguration.objects.create(name="word_cloud", enabled=False)
# Now fully disable done through XBlockConfiguration
XBlockConfiguration.objects.create(name="done", enabled=False)
self.templates = get_component_templates(self.course)
self.assertIsNone(self.get_templates_of_type("advanced"))
self.assertTrue((not any(item.get("category") == "done" for item in self.get_templates_of_type("advanced"))))

def test_advanced_problems(self):
"""
Expand Down Expand Up @@ -3087,8 +3110,9 @@ def test_create_support_level_flag_off(self):
XBlockConfiguration) if XBlockStudioConfigurationFlag is False.
"""
XBlockStudioConfigurationFlag.objects.create(enabled=False)
self.course.advanced_modules.extend(["annotatable", "survey"])
self._verify_advanced_xblocks(["Annotation", "Survey"], [True, True])
self.course.advanced_modules.extend(["annotatable", "done"])
expected_xblocks = ["Annotation", "Completion"] + self.default_advanced_modules_titles
self._verify_advanced_xblocks(expected_xblocks, [True] * len(expected_xblocks))

def test_xblock_masquerading_as_problem(self):
"""
Expand Down