From 7a03d064ba0acce6e784cafd41b60bf7bf952059 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Khalid Date: Sat, 18 Jul 2020 00:05:18 +0500 Subject: [PATCH] Make WordCloud indexable --- .../xmodule/xmodule/tests/test_word_cloud.py | 22 ++++++++++++++++- .../lib/xmodule/xmodule/word_cloud_module.py | 24 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/tests/test_word_cloud.py b/common/lib/xmodule/xmodule/tests/test_word_cloud.py index 835815a215..3b56ee36cf 100644 --- a/common/lib/xmodule/xmodule/tests/test_word_cloud.py +++ b/common/lib/xmodule/xmodule/tests/test_word_cloud.py @@ -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' + } + } + ) diff --git a/common/lib/xmodule/xmodule/word_cloud_module.py b/common/lib/xmodule/xmodule/word_cloud_module.py index 8f23c84a8a..a32efa1ffb 100644 --- a/common/lib/xmodule/xmodule/word_cloud_module.py +++ b/common/lib/xmodule/xmodule/word_cloud_module.py @@ -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