Skip to content

Commit

Permalink
chore: Adds waffle flag on word cloud xblock
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed Nov 13, 2024
1 parent 9fa7a0c commit 1df53ab
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
13 changes: 8 additions & 5 deletions xmodule/tests/test_word_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from webob.multidict import MultiDict
from xblock.field_data import DictFieldData

from xmodule.word_cloud_block import WordCloudBlock
from . import get_test_descriptor_system, get_test_system


Expand All @@ -19,6 +18,10 @@ class WordCloudBlockTest(TestCase):
Logic tests for Word Cloud Block.
"""

def setUp(self):
from xmodule.word_cloud_block import WordCloudBlock
self.WordCloudBlock = WordCloudBlock

raw_field_data = {
'all_words': {'cat': 10, 'dog': 5, 'mom': 1, 'dad': 2},
'top_words': {'cat': 10, 'dog': 5, 'dad': 2},
Expand All @@ -42,7 +45,7 @@ def test_xml_import_export_cycle(self):

olx_element = etree.fromstring(original_xml)
runtime.id_generator = Mock()
block = WordCloudBlock.parse_xml(olx_element, runtime, None)
block = self.WordCloudBlock.parse_xml(olx_element, runtime, None)
block.location = BlockUsageLocator(
CourseLocator('org', 'course', 'run', branch='revision'), 'word_cloud', 'block_id'
)
Expand All @@ -67,7 +70,7 @@ def test_bad_ajax_request(self):
"""

module_system = get_test_system()
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())
block = self.WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())

response = json.loads(block.handle_ajax('bad_dispatch', {}))
self.assertDictEqual(response, {
Expand All @@ -81,7 +84,7 @@ def test_good_ajax_request(self):
"""

module_system = get_test_system()
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())
block = self.WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())

post_data = MultiDict(('student_words[]', word) for word in ['cat', 'cat', 'dog', 'sun'])
response = json.loads(block.handle_ajax('submit', post_data))
Expand Down Expand Up @@ -110,7 +113,7 @@ def test_indexibility(self):
"""

module_system = get_test_system()
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())
block = self.WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())
assert block.index_dictionary() ==\
{'content_type': 'Word Cloud',
'content': {'display_name': 'Word Cloud Block',
Expand Down
54 changes: 52 additions & 2 deletions xmodule/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,62 @@
# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34840 is done.
# .. toggle_use_cases: temporary
# .. toggle_default: False
# .. toggle_implementation:
# .. toggle_creation_date: 10th Nov, 2024
USE_EXTRACTED_WORD_CLOUD_BLOCK = WaffleFlag('xmodule.use_extracted_block.word_cloud', __name__)
# TODO: Add flag docs once above approved
# .. toggle_name: USE_EXTRACTED_ANNOTATABLE_BLOCK
# .. toggle_description: Enables the use of the extracted annotatable XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34841 is done.
# .. toggle_use_cases: temporary
# .. toggle_default: False
# .. toggle_implementation:
# .. toggle_creation_date: 10th Nov, 2024
USE_EXTRACTED_ANNOTATABLE_BLOCK = WaffleFlag('xmodule.use_extracted_block.annotatable', __name__)
USE_EXTRACTED_POLL_BLOCK = WaffleFlag('xmodule.use_extracted_block.poll', __name__)
# .. toggle_name: USE_EXTRACTED_POLL_QUESTION_BLOCK
# .. toggle_description: Enables the use of the extracted poll question XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34839 is done.
# .. toggle_use_cases: temporary
# .. toggle_default: False
# .. toggle_implementation:
# .. toggle_creation_date: 10th Nov, 2024
USE_EXTRACTED_POLL_QUESTION_BLOCK = WaffleFlag('xmodule.use_extracted_block.poll_question', __name__)
# .. toggle_name: USE_EXTRACTED_LTI_BLOCK
# .. toggle_description: Enables the use of the extracted lti XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_use_cases: temporary
# .. toggle_default: False
# .. toggle_implementation:
# .. toggle_creation_date: 10th Nov, 2024
USE_EXTRACTED_LTI_BLOCK = WaffleFlag('xmodule.use_extracted_block.lti', __name__)
# .. toggle_name: USE_EXTRACTED_HTML_BLOCK
# .. toggle_description: Enables the use of the extracted html XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_use_cases: temporary
# .. toggle_default: False
# .. toggle_implementation:
# .. toggle_creation_date: 10th Nov, 2024
USE_EXTRACTED_HTML_BLOCK = WaffleFlag('xmodule.use_extracted_block.html', __name__)
# .. toggle_name: USE_EXTRACTED_DISCUSSION_BLOCK
# .. toggle_description: Enables the use of the extracted discussion XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_use_cases: temporary
# .. toggle_default: False
# .. toggle_implementation:
# .. toggle_creation_date: 10th Nov, 2024
USE_EXTRACTED_DISCUSSION_BLOCK = WaffleFlag('xmodule.use_extracted_block.discussion', __name__)
# .. toggle_name: USE_EXTRACTED_PROBLEM_BLOCK
# .. toggle_description: Enables the use of the extracted problem XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_use_cases: temporary
# .. toggle_default: False
# .. toggle_implementation:
# .. toggle_creation_date: 10th Nov, 2024
USE_EXTRACTED_PROBLEM_BLOCK = WaffleFlag('xmodule.use_extracted_block.problem', __name__)
# .. toggle_name: USE_EXTRACTED_VIDEO_BLOCK
# .. toggle_description: Enables the use of the extracted video XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_use_cases: temporary
# .. toggle_default: False
# .. toggle_implementation:
# .. toggle_creation_date: 10th Nov, 2024
USE_EXTRACTED_VIDEO_BLOCK = WaffleFlag('xmodule.use_extracted_block.video', __name__)
12 changes: 11 additions & 1 deletion xmodule/word_cloud_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from xblock.fields import Boolean, Dict, Integer, List, Scope, String
from xmodule.editing_block import EditingMixin
from xmodule.raw_block import EmptyDataRawMixin
from xmodule.toggles import USE_EXTRACTED_WORD_CLOUD_BLOCK
from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_css_to_fragment
from xmodule.xml_block import XmlMixin
from xmodule.x_module import (
Expand All @@ -23,6 +24,7 @@
XModuleMixin,
XModuleToXBlockMixin,
)
from xblocks_contrib.word_cloud import WordCloudBlock as _ExtractedWordCloudBlock
log = logging.getLogger(__name__)

# Make '_' a no-op so we can scrape strings. Using lambda instead of
Expand All @@ -41,7 +43,7 @@ def pretty_bool(value):


@XBlock.needs('mako')
class WordCloudBlock( # pylint: disable=abstract-method
class _BuiltInWordCloudBlock( # pylint: disable=abstract-method
EmptyDataRawMixin,
XmlMixin,
EditingMixin,
Expand All @@ -53,6 +55,8 @@ class WordCloudBlock( # pylint: disable=abstract-method
Word Cloud XBlock.
"""

is_extracted = False

display_name = String(
display_name=_("Display Name"),
help=_("The display name for this component."),
Expand Down Expand Up @@ -308,3 +312,9 @@ def index_dictionary(self):
xblock_body["content_type"] = "Word Cloud"

return xblock_body


WordCloudBlock = (
_ExtractedWordCloudBlock if USE_EXTRACTED_WORD_CLOUD_BLOCK.is_enabled()
else _BuiltInWordCloudBlock
)

0 comments on commit 1df53ab

Please sign in to comment.