Commit 36c8af61 by Vasyl Nakvasiuk

use user_state, add test_logic test

parent 9b974916
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
import json import json
import unittest import unittest
from django.http import QueryDict
from xmodule.poll_module import PollDescriptor from xmodule.poll_module import PollDescriptor
from xmodule.conditional_module import ConditionalDescriptor from xmodule.conditional_module import ConditionalDescriptor
from xmodule.word_cloud_module import WordCloudDescriptor
class LogicTest(unittest.TestCase): class LogicTest(unittest.TestCase):
...@@ -64,3 +67,23 @@ class ConditionalModuleTest(LogicTest): ...@@ -64,3 +67,23 @@ class ConditionalModuleTest(LogicTest):
html = response['html'] html = response['html']
self.assertEqual(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', {})
...@@ -29,8 +29,8 @@ class WordCloudFields(object): ...@@ -29,8 +29,8 @@ class WordCloudFields(object):
num_inputs = Integer(help="Number of inputs", scope=Scope.settings, default=5) 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) 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) 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.student_state, default=[]) student_words= List(help="Student answer", scope=Scope.user_state, default=[])
all_words = Object(help="All possible words from other students", scope=Scope.content) 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) top_words = Object(help="Top N words for word cloud", scope=Scope.content)
...@@ -57,7 +57,7 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -57,7 +57,7 @@ class WordCloudModule(WordCloudFields, XModule):
word:self.all_words[word] for word:self.all_words[word] for
word in self.student_words 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) 'top_words': self.prepare_words(self.top_words)
}) })
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment