From 36c8af611b25ab4df7c550b687418ca57056786e Mon Sep 17 00:00:00 2001 From: Vasyl Nakvasiuk Date: Tue, 9 Apr 2013 19:29:06 +0300 Subject: [PATCH] use user_state, add test_logic test --- .../lib/xmodule/xmodule/tests/test_logic.py | 23 +++++++++++++++++++ .../lib/xmodule/xmodule/word_cloud_module.py | 12 +++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/common/lib/xmodule/xmodule/tests/test_logic.py b/common/lib/xmodule/xmodule/tests/test_logic.py index 018b40427e..ebe1e93d06 100644 --- a/common/lib/xmodule/xmodule/tests/test_logic.py +++ b/common/lib/xmodule/xmodule/tests/test_logic.py @@ -3,8 +3,11 @@ import json import unittest +from django.http import QueryDict + from xmodule.poll_module import PollDescriptor from xmodule.conditional_module import ConditionalDescriptor +from xmodule.word_cloud_module import WordCloudDescriptor class LogicTest(unittest.TestCase): @@ -64,3 +67,23 @@ class ConditionalModuleTest(LogicTest): html = response['html'] self.assertEqual(html, []) + + +class WordCloudModuleTest(LogicTest): + descriptor_class = WordCloudDescriptor + raw_model_data = { + 'all_words': {'Yes': 1, 'Dont_know': 0, 'No': 0}, + 'top_words': {'Yes': 1, 'Dont_know': 0, 'No': 0}, + 'submitted': False, + 'student_words': ['mom', 'dad', 'cat'] + } + + def test_bad_ajax_request(self): + response = self.ajax_request('bad_dispatch', {}) + self.assertDictEqual(response, { + 'status': 'fail', + 'error': 'Unknown Command!' + }) + + # def test_good_ajax_request(self): + # response = self.ajax_request('submit', {}) diff --git a/common/lib/xmodule/xmodule/word_cloud_module.py b/common/lib/xmodule/xmodule/word_cloud_module.py index d2e6e3fc1b..c718ca9575 100644 --- a/common/lib/xmodule/xmodule/word_cloud_module.py +++ b/common/lib/xmodule/xmodule/word_cloud_module.py @@ -29,8 +29,8 @@ class WordCloudFields(object): num_inputs = Integer(help="Number of inputs", scope=Scope.settings, default=5) num_top_words = Integer(help="Number of inputs", scope=Scope.settings, default=250) - submitted = Boolean(help="Whether this student has posted words to the cloud", scope=Scope.student_state, default=False) - student_words= List(help="Student answer", scope=Scope.student_state, default=[]) + submitted = Boolean(help="Whether this student has posted words to the cloud", scope=Scope.user_state, default=False) + student_words= List(help="Student answer", scope=Scope.user_state, default=[]) all_words = Object(help="All possible words from other students", scope=Scope.content) top_words = Object(help="Top N words for word cloud", scope=Scope.content) @@ -57,7 +57,7 @@ class WordCloudModule(WordCloudFields, XModule): word:self.all_words[word] for word in self.student_words }, - 'total_count': sum(self.all_words.values()) + 'total_count': sum(self.all_words.values()), 'top_words': self.prepare_words(self.top_words) }) else: @@ -140,9 +140,9 @@ class WordCloudModule(WordCloudFields, XModule): return self.get_state_json() else: return json.dumps({ - 'status': 'fail', - 'error': 'Unknown Command!' - }) + 'status': 'fail', + 'error': 'Unknown Command!' + }) def get_html(self): """Renders parameters to template."""