Commit fbce67a8 by VikParuchuri

Merge pull request #1519 from MITx/diana/fix-self-assessment-test

Fix test so we don't have to skip it anymore.
parents d2e97d23 a789d6c3
...@@ -106,7 +106,7 @@ class MockPeerGradingService(object): ...@@ -106,7 +106,7 @@ class MockPeerGradingService(object):
'max_score': 4}) 'max_score': 4})
def save_grade(self, location, grader_id, submission_id, def save_grade(self, location, grader_id, submission_id,
score, feedback, submission_key): score, feedback, submission_key, rubric_scores, submission_flagged):
return json.dumps({'success': True}) return json.dumps({'success': True})
def is_student_calibrated(self, problem_location, grader_id): def is_student_calibrated(self, problem_location, grader_id):
...@@ -122,7 +122,8 @@ class MockPeerGradingService(object): ...@@ -122,7 +122,8 @@ class MockPeerGradingService(object):
'max_score': 4}) 'max_score': 4})
def save_calibration_essay(self, problem_location, grader_id, def save_calibration_essay(self, problem_location, grader_id,
calibration_essay_id, submission_key, score, feedback): calibration_essay_id, submission_key, score,
feedback, rubric_scores):
return {'success': True, 'actual_score': 2} return {'success': True, 'actual_score': 2}
def get_problem_list(self, course_id, grader_id): def get_problem_list(self, course_id, grader_id):
......
import json import json
from mock import Mock from mock import Mock, MagicMock
import unittest import unittest
from xmodule.open_ended_grading_classes.self_assessment_module import SelfAssessmentModule from xmodule.open_ended_grading_classes.self_assessment_module import SelfAssessmentModule
from xmodule.modulestore import Location from xmodule.modulestore import Location
from lxml import etree from lxml import etree
from nose.plugins.skip import SkipTest
from . import test_system from . import test_system
...@@ -64,13 +63,21 @@ class SelfAssessmentTest(unittest.TestCase): ...@@ -64,13 +63,21 @@ class SelfAssessmentTest(unittest.TestCase):
self.assertTrue("This is sample prompt text" in html) self.assertTrue("This is sample prompt text" in html)
def test_self_assessment_flow(self): def test_self_assessment_flow(self):
raise SkipTest() responses = {'assessment': '0', 'score_list[]': ['0', '0']}
def get_fake_item(name):
return responses[name]
mock_query_dict = MagicMock()
mock_query_dict.__getitem__.side_effect = get_fake_item
mock_query_dict.getlist = get_fake_item
self.assertEqual(self.module.get_score()['score'], 0) self.assertEqual(self.module.get_score()['score'], 0)
self.module.save_answer({'student_answer': "I am an answer"}, test_system) self.module.save_answer({'student_answer': "I am an answer"}, test_system)
self.assertEqual(self.module.state, self.module.ASSESSING) self.assertEqual(self.module.state, self.module.ASSESSING)
self.module.save_assessment({'assessment': '0'}, test_system) self.module.save_assessment(mock_query_dict, test_system)
self.assertEqual(self.module.state, self.module.DONE) self.assertEqual(self.module.state, self.module.DONE)
...@@ -80,5 +87,6 @@ class SelfAssessmentTest(unittest.TestCase): ...@@ -80,5 +87,6 @@ class SelfAssessmentTest(unittest.TestCase):
# if we now assess as right, skip the REQUEST_HINT state # if we now assess as right, skip the REQUEST_HINT state
self.module.save_answer({'student_answer': 'answer 4'}, test_system) self.module.save_answer({'student_answer': 'answer 4'}, test_system)
self.module.save_assessment({'assessment': '1'}, test_system) responses['assessment'] = '1'
self.module.save_assessment(mock_query_dict, test_system)
self.assertEqual(self.module.state, self.module.DONE) self.assertEqual(self.module.state, self.module.DONE)
...@@ -16,7 +16,7 @@ import courseware.tests.tests as ct ...@@ -16,7 +16,7 @@ import courseware.tests.tests as ct
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
import xmodule.modulestore.django import xmodule.modulestore.django
from nose import SkipTest from nose import SkipTest
from mock import patch, Mock from mock import patch, Mock, MagicMock
import json import json
from xmodule.x_module import ModuleSystem from xmodule.x_module import ModuleSystem
from mitxmako.shortcuts import render_to_string from mitxmako.shortcuts import render_to_string
...@@ -169,23 +169,35 @@ class TestPeerGradingService(ct.PageLoader): ...@@ -169,23 +169,35 @@ class TestPeerGradingService(ct.PageLoader):
def test_get_next_submission_missing_location(self): def test_get_next_submission_missing_location(self):
data = {} data = {}
r = self.peer_module.get_next_submission(data) d = self.peer_module.get_next_submission(data)
d = r
self.assertFalse(d['success']) self.assertFalse(d['success'])
self.assertEqual(d['error'], "Missing required keys: location") self.assertEqual(d['error'], "Missing required keys: location")
def test_save_grade_success(self): def test_save_grade_success(self):
raise SkipTest() data = {
data = 'rubric_scores[]=1|rubric_scores[]=2|location=' + self.location + '|submission_id=1|submission_key=fake key|score=2|feedback=feedback|submission_flagged=False' 'rubric_scores[]': [0, 0],
qdict = QueryDict(data.replace("|", "&")) 'location': self.location,
'submission_id': 1,
'submission_key': 'fake key',
'score': 2,
'feedback': 'feedback',
'submission_flagged': 'false'
}
qdict = MagicMock()
def fake_get_item(key):
return data[key]
qdict.__getitem__.side_effect = fake_get_item
qdict.getlist = fake_get_item
qdict.keys = data.keys
r = self.peer_module.save_grade(qdict) r = self.peer_module.save_grade(qdict)
d = r d = json.loads(r)
self.assertTrue(d['success']) self.assertTrue(d['success'])
def test_save_grade_missing_keys(self): def test_save_grade_missing_keys(self):
data = {} data = {}
r = self.peer_module.save_grade(data) d = self.peer_module.save_grade(data)
d = r
self.assertFalse(d['success']) self.assertFalse(d['success'])
self.assertTrue(d['error'].find('Missing required keys:') > -1) self.assertTrue(d['error'].find('Missing required keys:') > -1)
...@@ -198,8 +210,7 @@ class TestPeerGradingService(ct.PageLoader): ...@@ -198,8 +210,7 @@ class TestPeerGradingService(ct.PageLoader):
def test_is_calibrated_failure(self): def test_is_calibrated_failure(self):
data = {} data = {}
r = self.peer_module.is_student_calibrated(data) d = self.peer_module.is_student_calibrated(data)
d = r
self.assertFalse(d['success']) self.assertFalse(d['success'])
self.assertFalse('calibrated' in d) self.assertFalse('calibrated' in d)
...@@ -219,25 +230,36 @@ class TestPeerGradingService(ct.PageLoader): ...@@ -219,25 +230,36 @@ class TestPeerGradingService(ct.PageLoader):
def test_show_calibration_essay_missing_key(self): def test_show_calibration_essay_missing_key(self):
data = {} data = {}
r = self.peer_module.show_calibration_essay(data) d = self.peer_module.show_calibration_essay(data)
d = r
self.assertFalse(d['success']) self.assertFalse(d['success'])
self.assertEqual(d['error'], "Missing required keys: location") self.assertEqual(d['error'], "Missing required keys: location")
def test_save_calibration_essay_success(self): def test_save_calibration_essay_success(self):
raise SkipTest() data = {
data = 'rubric_scores[]=1|rubric_scores[]=2|location=' + self.location + '|submission_id=1|submission_key=fake key|score=2|feedback=feedback|submission_flagged=False' 'rubric_scores[]': [0, 0],
qdict = QueryDict(data.replace("|", "&")) 'location': self.location,
r = self.peer_module.save_calibration_essay(qdict) 'submission_id': 1,
d = r 'submission_key': 'fake key',
'score': 2,
'feedback': 'feedback',
'submission_flagged': 'false'
}
qdict = MagicMock()
def fake_get_item(key):
return data[key]
qdict.__getitem__.side_effect = fake_get_item
qdict.getlist = fake_get_item
qdict.keys = data.keys
d = self.peer_module.save_calibration_essay(qdict)
self.assertTrue(d['success']) self.assertTrue(d['success'])
self.assertTrue('actual_score' in d) self.assertTrue('actual_score' in d)
def test_save_calibration_essay_missing_keys(self): def test_save_calibration_essay_missing_keys(self):
data = {} data = {}
r = self.peer_module.save_calibration_essay(data) d = self.peer_module.save_calibration_essay(data)
d = r
self.assertFalse(d['success']) self.assertFalse(d['success'])
self.assertTrue(d['error'].find('Missing required keys:') > -1) self.assertTrue(d['error'].find('Missing required keys:') > -1)
self.assertFalse('actual_score' in d) self.assertFalse('actual_score' in d)
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