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
100c1961
Commit
100c1961
authored
Jul 15, 2014
by
Andrew Dekker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit tests
parent
a73c688f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
2 deletions
+107
-2
submissions/api.py
+1
-1
submissions/tests/test_api.py
+106
-1
No files found.
submissions/api.py
View file @
100c1961
...
...
@@ -387,7 +387,7 @@ def get_top_submissions(course_id, item_id, item_type, number_of_top_scores):
course_id
,
item_id
,
item_type
)
logger
.
exception
(
msg
)
raise
Submission
NotFound
Error
(
msg
)
raise
Submission
Internal
Error
(
msg
)
topsubmissions
=
[]
for
score
in
scores
:
answer
=
SubmissionSerializer
(
score
.
submission
)
.
data
[
'answer'
]
...
...
submissions/tests/test_api.py
View file @
100c1961
...
...
@@ -10,7 +10,7 @@ from mock import patch
import
pytz
from
submissions
import
api
as
api
from
submissions.models
import
ScoreSummary
,
Submission
,
StudentItem
from
submissions.models
import
ScoreSummary
,
Submission
,
StudentItem
,
Score
from
submissions.serializers
import
StudentItemSerializer
STUDENT_ITEM
=
dict
(
...
...
@@ -282,6 +282,111 @@ class TestSubmissionsApi(TestCase):
}
)
def
test_get_top_submissions
(
self
):
student_item
=
copy
.
deepcopy
(
STUDENT_ITEM
)
student_item
[
"course_id"
]
=
"get_scores_course"
student_item
[
"item_id"
]
=
"i4x://a/b/c/s1"
student_1
=
api
.
create_submission
(
student_item
,
"Hello World"
)
student_2
=
api
.
create_submission
(
student_item
,
"Hello World"
)
student_3
=
api
.
create_submission
(
student_item
,
"Hello World"
)
api
.
set_score
(
student_1
[
'uuid'
],
8
,
10
)
api
.
set_score
(
student_2
[
'uuid'
],
4
,
10
)
api
.
set_score
(
student_3
[
'uuid'
],
2
,
10
)
#Get top scores works correctly
with
self
.
assertNumQueries
(
4
):
top_scores
=
api
.
get_top_submissions
(
student_item
[
"course_id"
],
student_item
[
"item_id"
],
"Peer_Submission"
,
3
)
print
top_scores
self
.
assertEqual
(
top_scores
,
[
{
'content'
:
"Hello World"
,
'score'
:
8
},
{
'content'
:
"Hello World"
,
'score'
:
4
},
{
'content'
:
"Hello World"
,
'score'
:
2
},
]
)
#Fewer top scores available than the number requested.
top_scores
=
api
.
get_top_submissions
(
student_item
[
"course_id"
],
student_item
[
"item_id"
],
"Peer_Submission"
,
10
)
print
top_scores
self
.
assertEqual
(
top_scores
,
[
{
'content'
:
"Hello World"
,
'score'
:
8
},
{
'content'
:
"Hello World"
,
'score'
:
4
},
{
'content'
:
"Hello World"
,
'score'
:
2
},
]
)
#More top scores available than the number requested.
top_scores
=
api
.
get_top_submissions
(
student_item
[
"course_id"
],
student_item
[
"item_id"
],
"Peer_Submission"
,
2
)
print
top_scores
self
.
assertEqual
(
top_scores
,
[
{
'content'
:
"Hello World"
,
'score'
:
8
},
{
'content'
:
"Hello World"
,
'score'
:
4
}
]
)
@raises
(
api
.
SubmissionRequestError
)
def
test_error_on_get_top_submissions_too_few
(
self
):
student_item
=
copy
.
deepcopy
(
STUDENT_ITEM
)
student_item
[
"course_id"
]
=
"get_scores_course"
student_item
[
"item_id"
]
=
"i4x://a/b/c/s1"
api
.
get_top_submissions
(
student_item
[
"course_id"
],
student_item
[
"item_id"
],
"Peer_Submission"
,
-
1
)
@raises
(
api
.
SubmissionRequestError
)
def
test_error_on_get_top_submissions_too_many
(
self
):
student_item
=
copy
.
deepcopy
(
STUDENT_ITEM
)
student_item
[
"course_id"
]
=
"get_scores_course"
student_item
[
"item_id"
]
=
"i4x://a/b/c/s1"
api
.
get_top_submissions
(
student_item
[
"course_id"
],
student_item
[
"item_id"
],
"Peer_Submission"
,
api
.
MAX_TOP_SUBMISSIONS
+
1
)
@patch.object
(
Score
.
objects
,
'filter'
)
@raises
(
api
.
SubmissionInternalError
)
def
test_error_on_get_top_submissions_db_error
(
self
,
mock_filter
):
mock_filter
.
side_effect
=
DatabaseError
(
"Bad things happened"
)
student_item
=
copy
.
deepcopy
(
STUDENT_ITEM
)
api
.
get_top_submissions
(
student_item
[
"course_id"
],
student_item
[
"item_id"
],
"Peer_Submission"
,
1
)
@patch.object
(
ScoreSummary
.
objects
,
'filter'
)
@raises
(
api
.
SubmissionInternalError
)
def
test_error_on_get_scores
(
self
,
mock_filter
):
...
...
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