Commit 95e1a581 by Will Daly

Fix error when rendering XBlock in preview

parent be916197
......@@ -252,8 +252,13 @@ def get_score(student_item):
}]
"""
student_item_model = StudentItem.objects.get(**student_item)
scores = Score.objects.filter(student_item=student_item_model)
try:
student_item_model = StudentItem.objects.get(**student_item)
scores = Score.objects.filter(student_item=student_item_model)
except StudentItem.DoesNotExist:
return None
return ScoreSerializer(scores, many=True).data
......
import datetime
import copy
from ddt import ddt, file_data
from django.db import DatabaseError
......@@ -134,6 +135,11 @@ class TestApi(TestCase):
scores = api.get_score(STUDENT_ITEM)
self._assert_score(scores[0], 11, 12)
def test_get_score_no_student_id(self):
student_item = copy.deepcopy(STUDENT_ITEM)
student_item['student_id'] = None
self.assertIs(api.get_score(student_item), None)
def _assert_score(
self,
score,
......@@ -141,4 +147,4 @@ class TestApi(TestCase):
expected_points_possible):
self.assertIsNotNone(score)
self.assertEqual(score["points_earned"], expected_points_earned)
self.assertEqual(score["points_possible"], expected_points_possible)
\ No newline at end of file
self.assertEqual(score["points_possible"], expected_points_possible)
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