Make WordCloud indexable

This commit is contained in:
Ahmad Bilal Khalid
2020-07-18 00:05:18 +05:00
parent fc0694397e
commit 7a03d064ba
2 changed files with 45 additions and 1 deletions

View File

@@ -23,7 +23,9 @@ class WordCloudBlockTest(TestCase):
raw_field_data = {
'all_words': {'cat': 10, 'dog': 5, 'mom': 1, 'dad': 2},
'top_words': {'cat': 10, 'dog': 5, 'dad': 2},
'submitted': False
'submitted': False,
'display_name': 'Word Cloud Block',
'instructions': 'Enter some random words that comes to your mind'
}
def test_xml_import_export_cycle(self):
@@ -102,3 +104,21 @@ class WordCloudBlockTest(TestCase):
)
self.assertEqual(100.0, sum(i['percent'] for i in response['top_words']))
def test_indexibility(self):
"""
Test indexibility of Word Cloud
"""
module_system = get_test_system()
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())
self.assertEqual(
block.index_dictionary(),
{
'content_type': 'Word Cloud',
'content': {
'display_name': 'Word Cloud Block',
'instructions': 'Enter some random words that comes to your mind'
}
}
)

View File

@@ -309,3 +309,27 @@ class WordCloudBlock( # pylint: disable=abstract-method
add_webpack_to_fragment(fragment, 'WordCloudBlockStudio')
shim_xmodule_js(fragment, self.studio_js_module_name)
return fragment
def index_dictionary(self):
"""
Return dictionary prepared with module content and type for indexing.
"""
# return key/value fields in a Python dict object
# values may be numeric / string or dict
# default implementation is an empty dict
xblock_body = super(WordCloudBlock, self).index_dictionary()
index_body = {
"display_name": self.display_name,
"instructions": self.instructions,
}
if "content" in xblock_body:
xblock_body["content"].update(index_body)
else:
xblock_body["content"] = index_body
xblock_body["content_type"] = "Word Cloud"
return xblock_body