Commit a0e355fb by Vasyl Nakvasiuk

add PollModuleTest for testing `handle_ajax`

parent 268e3e63
# -*- coding: utf-8 -*-
import json
import unittest
from xmodule.poll_module import PollModule
class LogicTest(unittest.TestCase):
"""Base class for testing xmodule logic."""
xmodule_class = None
raw_model_data = {}
def setUp(self):
self.system = None
self.location = None
self.descriptor = None
self.xmodule = self.xmodule_class(self.system, self.location,
self.descriptor, self.raw_model_data)
def ajax_request(self, dispatch, get):
return json.loads(self.xmodule.handle_ajax(dispatch, get))
class PollModuleTest(LogicTest):
xmodule_class = PollModule
raw_model_data = {
'poll_answers': {'Yes': 1, 'Dont_know': 0, 'No': 0},
'voted': False,
'poll_answer': ''
}
def test_bad_ajax_request(self):
response = self.ajax_request('bad_answer', {})
self.assertDictEqual(response, {'error': 'Unknown Command!'})
def test_good_ajax_request(self):
response = self.ajax_request('No', {})
poll_answers = response['poll_answers']
total = response['total']
callback = response['callback']
self.assertDictEqual(poll_answers, {'Yes': 1, 'Dont_know': 0, 'No': 1})
self.assertEqual(total, 2)
self.assertDictEqual(callback, {'objectName': 'Conditional'})
self.assertEqual(self.xmodule.poll_answer, 'No')
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