use user_state, add test_logic test
This commit is contained in:
@@ -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', {})
|
||||
|
||||
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user