-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from edx/efischer/annotation_serialization
Serialize annotation information with scores
- Loading branch information
Showing
3 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,72 @@ | ||
""" | ||
Tests for submissions serializers. | ||
""" | ||
import ddt | ||
from django.test import TestCase | ||
from submissions.models import Score, StudentItem | ||
from submissions.models import Score, ScoreAnnotation, StudentItem, Submission | ||
from submissions.serializers import ScoreSerializer | ||
|
||
|
||
@ddt.ddt | ||
class ScoreSerializerTest(TestCase): | ||
""" | ||
Tests for the score serializer. | ||
""" | ||
|
||
def test_score_with_null_submission(self): | ||
item = StudentItem.objects.create( | ||
def setUp(self): | ||
super(ScoreSerializerTest, self).setUp() | ||
self.item = StudentItem.objects.create( | ||
student_id="score_test_student", | ||
course_id="score_test_course", | ||
item_id="i4x://mycourse/special_presentation" | ||
) | ||
self.submission = Submission.objects.create(student_item=self.item, attempt_number=1) | ||
|
||
self.score = Score.objects.create( | ||
student_item=self.item, | ||
submission=self.submission, | ||
points_earned=2, | ||
points_possible=6, | ||
) | ||
|
||
|
||
def test_score_with_null_submission(self): | ||
# Create a score with a null submission | ||
score = Score.objects.create( | ||
student_item=item, | ||
null_sub_score = Score.objects.create( | ||
student_item=self.item, | ||
submission=None, | ||
points_earned=2, | ||
points_possible=6 | ||
points_earned=3, | ||
points_possible=8, | ||
) | ||
score_dict = ScoreSerializer(score).data | ||
null_sub_score_dict = ScoreSerializer(null_sub_score).data | ||
self.assertIs(null_sub_score_dict['submission_uuid'], None) | ||
self.assertEqual(null_sub_score_dict['points_earned'], 3) | ||
self.assertEqual(null_sub_score_dict['points_possible'], 8) | ||
|
||
self.assertIs(score_dict['submission_uuid'], None) | ||
self.assertEqual(score_dict['points_earned'], 2) | ||
self.assertEqual(score_dict['points_possible'], 6) | ||
@ddt.data(['test_annotation_1', 'test_annotation_2'], []) | ||
def test_score_annotations(self, annotation_types): | ||
""" | ||
Ensure that annotation types are returned with serialized scores. | ||
""" | ||
annotation_kwargs = { | ||
'creator': 'test_annotator', | ||
'reason': 'tests for the test god' | ||
} | ||
for test_type in annotation_types: | ||
ScoreAnnotation.objects.create( | ||
score=self.score, | ||
annotation_type=test_type, | ||
**annotation_kwargs | ||
) | ||
score_dict = ScoreSerializer(self.score).data | ||
self.assertEqual( | ||
score_dict['annotations'], | ||
[ | ||
{ | ||
'reason': annotation_kwargs['reason'], | ||
'annotation_type': annotation_type, | ||
'creator': annotation_kwargs['creator'], | ||
} | ||
for annotation_type in annotation_types | ||
] | ||
) |