Fix some issues with tests
This commit is contained in:
@@ -384,12 +384,12 @@ class PeerGradingModule(XModule):
|
||||
return self._err_response(message)
|
||||
grader_id = self.system.anonymous_student_id
|
||||
|
||||
location = get['location']
|
||||
calibration_essay_id = get['submission_id']
|
||||
submission_key = get['submission_key']
|
||||
score = get['score']
|
||||
feedback = get['feedback']
|
||||
rubric_scores = get['rubric_scores[]']
|
||||
location = get.get('location')
|
||||
calibration_essay_id = get.get('submission_id')
|
||||
submission_key = get.get('submission_key')
|
||||
score = get.get('score')
|
||||
feedback = get.get('feedback')
|
||||
rubric_scores = get.getlist('rubric_scores[]')
|
||||
|
||||
try:
|
||||
response = self.peer_gs.save_calibration_essay(location, grader_id, calibration_essay_id,
|
||||
|
||||
@@ -39,12 +39,12 @@ class PeerGradingService(GradingService):
|
||||
def get_data_for_location(self, problem_location, student_id):
|
||||
response = self.get(self.get_data_for_location_url,
|
||||
{'location': problem_location, 'student_id': student_id})
|
||||
return response
|
||||
return self.try_to_decode(response)
|
||||
|
||||
def get_next_submission(self, problem_location, grader_id):
|
||||
response = self.get(self.get_next_submission_url,
|
||||
{'location': problem_location, 'grader_id': grader_id})
|
||||
return self._render_rubric(response)
|
||||
return self.try_to_decode(self._render_rubric(response))
|
||||
|
||||
def save_grade(self, location, grader_id, submission_id, score, feedback, submission_key, rubric_scores, submission_flagged):
|
||||
data = {'grader_id' : grader_id,
|
||||
@@ -56,16 +56,16 @@ class PeerGradingService(GradingService):
|
||||
'rubric_scores': rubric_scores,
|
||||
'rubric_scores_complete': True,
|
||||
'submission_flagged' : submission_flagged}
|
||||
return self.post(self.save_grade_url, data)
|
||||
return self.try_to_decode(self.post(self.save_grade_url, data))
|
||||
|
||||
def is_student_calibrated(self, problem_location, grader_id):
|
||||
params = {'problem_id' : problem_location, 'student_id': grader_id}
|
||||
return self.get(self.is_student_calibrated_url, params)
|
||||
return self.try_to_decode(self.get(self.is_student_calibrated_url, params))
|
||||
|
||||
def show_calibration_essay(self, problem_location, grader_id):
|
||||
params = {'problem_id' : problem_location, 'student_id': grader_id}
|
||||
response = self.get(self.show_calibration_essay_url, params)
|
||||
return self._render_rubric(response)
|
||||
return self.try_to_decode(self._render_rubric(response))
|
||||
|
||||
def save_calibration_essay(self, problem_location, grader_id, calibration_essay_id, submission_key,
|
||||
score, feedback, rubric_scores):
|
||||
@@ -77,17 +77,17 @@ class PeerGradingService(GradingService):
|
||||
'feedback': feedback,
|
||||
'rubric_scores[]': rubric_scores,
|
||||
'rubric_scores_complete': True}
|
||||
return self.post(self.save_calibration_essay_url, data)
|
||||
return self.try_to_decode(self.post(self.save_calibration_essay_url, data))
|
||||
|
||||
def get_problem_list(self, course_id, grader_id):
|
||||
params = {'course_id': course_id, 'student_id': grader_id}
|
||||
response = self.get(self.get_problem_list_url, params)
|
||||
return response
|
||||
return self.try_to_decode(response)
|
||||
|
||||
def get_notifications(self, course_id, grader_id):
|
||||
params = {'course_id': course_id, 'student_id': grader_id}
|
||||
response = self.get(self.get_notifications_url, params)
|
||||
return response
|
||||
return self.try_to_decode(response)
|
||||
|
||||
def _login(self):
|
||||
"""
|
||||
@@ -113,47 +113,6 @@ class PeerGradingService(GradingService):
|
||||
|
||||
return text
|
||||
|
||||
def post(self, url, data, allow_redirects=False):
|
||||
"""
|
||||
Make a post request to the grading controller
|
||||
"""
|
||||
try:
|
||||
op = lambda: self.session.post(url, data=data,
|
||||
allow_redirects=allow_redirects)
|
||||
r = self._try_with_login(op)
|
||||
except (RequestException, ConnectionError, HTTPError) as err:
|
||||
# reraise as promised GradingServiceError, but preserve stacktrace.
|
||||
raise GradingServiceError, str(err), sys.exc_info()[2]
|
||||
|
||||
text = r.text
|
||||
try:
|
||||
text= json.loads(text)
|
||||
except:
|
||||
pass
|
||||
|
||||
return text
|
||||
|
||||
def get(self, url, params, allow_redirects=False):
|
||||
"""
|
||||
Make a get request to the grading controller
|
||||
"""
|
||||
op = lambda: self.session.get(url,
|
||||
allow_redirects=allow_redirects,
|
||||
params=params)
|
||||
try:
|
||||
r = self._try_with_login(op)
|
||||
except (RequestException, ConnectionError, HTTPError) as err:
|
||||
# reraise as promised GradingServiceError, but preserve stacktrace.
|
||||
raise GradingServiceError, str(err), sys.exc_info()[2]
|
||||
|
||||
text = r.text
|
||||
try:
|
||||
text= json.loads(text)
|
||||
except:
|
||||
pass
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def _try_with_login(self, operation):
|
||||
"""
|
||||
|
||||
@@ -171,7 +171,7 @@ class TestPeerGradingService(ct.PageLoader):
|
||||
self.assertEqual(d['error'], "Missing required keys: location")
|
||||
|
||||
def test_save_grade_success(self):
|
||||
data = 'rubric_scores[]=1|rubric_scores[]=2|location=' + location + '|submission_id=1|submission_key=fake key|score=2|feedback=feedback|submission_flagged=False'
|
||||
data = 'rubric_scores[]=1|rubric_scores[]=2|location=' + self.location + '|submission_id=1|submission_key=fake key|score=2|feedback=feedback|submission_flagged=False'
|
||||
qdict = QueryDict(data.replace("|","&"))
|
||||
r = self.peer_module.save_grade(qdict)
|
||||
d = r
|
||||
@@ -203,6 +203,8 @@ class TestPeerGradingService(ct.PageLoader):
|
||||
|
||||
r = self.peer_module.show_calibration_essay(data)
|
||||
d = r
|
||||
log.debug(d)
|
||||
log.debug(type(d))
|
||||
self.assertTrue(d['success'])
|
||||
self.assertIsNotNone(d['submission_id'])
|
||||
self.assertIsNotNone(d['prompt'])
|
||||
@@ -219,13 +221,9 @@ class TestPeerGradingService(ct.PageLoader):
|
||||
self.assertEqual(d['error'], "Missing required keys: location")
|
||||
|
||||
def test_save_calibration_essay_success(self):
|
||||
data = {'location': self.location,
|
||||
'submission_id': '1',
|
||||
'submission_key': 'fake key',
|
||||
'score': '2',
|
||||
'feedback': 'This is feedback',
|
||||
'rubric_scores[]': [1, 2]}
|
||||
r = self.peer_module.save_calibration_essay(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'
|
||||
qdict = QueryDict(data.replace("|","&"))
|
||||
r = self.peer_module.save_calibration_essay(qdict)
|
||||
d = r
|
||||
self.assertTrue(d['success'])
|
||||
self.assertTrue('actual_score' in d)
|
||||
|
||||
Reference in New Issue
Block a user