Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-submissions
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-submissions
Commits
68ed567f
Commit
68ed567f
authored
Dec 02, 2016
by
Eric Fischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Serialize annotation information with scores
parent
d85fd0a0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
12 deletions
+75
-12
submissions/serializers.py
+24
-1
submissions/tests/test_serializers.py
+51
-11
No files found.
submissions/serializers.py
View file @
68ed567f
...
...
@@ -6,7 +6,7 @@ import json
from
rest_framework
import
serializers
from
rest_framework.fields
import
Field
,
DateTimeField
,
IntegerField
from
submissions.models
import
StudentItem
,
Submission
,
Score
from
submissions.models
import
StudentItem
,
Submission
,
Score
,
ScoreAnnotation
class
RawField
(
Field
):
...
...
@@ -85,11 +85,33 @@ class SubmissionSerializer(serializers.ModelSerializer):
)
class
ScoreAnnotationSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
ScoreAnnotation
fields
=
(
'creator'
,
'reason'
,
'annotation_type'
,
)
class
ScoreSerializer
(
serializers
.
ModelSerializer
):
# Ensure that the created_at datetime is not converted to a string.
created_at
=
DateTimeField
(
format
=
None
,
required
=
False
)
annotations
=
serializers
.
SerializerMethodField
()
def
get_annotations
(
self
,
obj
):
"""
Inspect ScoreAnnotations to attach all relevant annotations.
"""
annotations
=
ScoreAnnotation
.
objects
.
filter
(
score_id
=
obj
.
id
)
return
[
ScoreAnnotationSerializer
(
instance
=
annotation
)
.
data
for
annotation
in
annotations
]
class
Meta
:
model
=
Score
fields
=
(
...
...
@@ -101,4 +123,5 @@ class ScoreSerializer(serializers.ModelSerializer):
# Computed
'submission_uuid'
,
'annotations'
,
)
submissions/tests/test_serializers.py
View file @
68ed567f
"""
Tests for submissions serializers.
"""
import
ddt
from
django.test
import
TestCase
from
submissions.models
import
Score
,
S
tudentItem
from
submissions.models
import
Score
,
S
coreAnnotation
,
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
]
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment