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
835b7904
Commit
835b7904
authored
Apr 25, 2015
by
Phil McGachey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding signals for scoring events.
parent
8fb070d2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
4 deletions
+72
-4
AUTHORS
+1
-0
submissions/api.py
+18
-1
submissions/models.py
+12
-1
submissions/tests/test_api.py
+18
-1
submissions/tests/test_reset_score.py
+23
-1
No files found.
AUTHORS
View file @
835b7904
...
...
@@ -2,3 +2,4 @@ Joe Blaylock <jrbl@stanford.edu>
Will Daly <will@edx.org>
David Ormsbee <dave@edx.org>
Stephen Sanchez <steve@edx.org>
Phil McGachey <phil_mcgachey@harvard.edu>
submissions/api.py
View file @
835b7904
...
...
@@ -14,7 +14,7 @@ from dogapi import dog_stats_api
from
submissions.serializers
import
(
SubmissionSerializer
,
StudentItemSerializer
,
ScoreSerializer
,
JsonFieldError
)
from
submissions.models
import
Submission
,
StudentItem
,
Score
,
ScoreSummary
from
submissions.models
import
Submission
,
StudentItem
,
Score
,
ScoreSummary
,
score_set
,
score_reset
logger
=
logging
.
getLogger
(
"submissions.api"
)
...
...
@@ -636,6 +636,14 @@ def reset_score(student_id, course_id, item_id):
# Create a "reset" score
try
:
Score
.
create_reset_score
(
student_item
)
# Send a signal out to any listeners who are waiting for scoring events.
score_reset
.
send
(
sender
=
None
,
anonymous_user_id
=
student_id
,
course_id
=
course_id
,
item_id
=
item_id
,
)
except
DatabaseError
:
msg
=
(
u"Error occurred while reseting scores for"
...
...
@@ -716,6 +724,15 @@ def set_score(submission_uuid, points_earned, points_possible):
try
:
score_model
=
score
.
save
()
_log_score
(
score_model
)
# Send a signal out to any listeners who are waiting for scoring events.
score_set
.
send
(
sender
=
None
,
points_possible
=
points_possible
,
points_earned
=
points_earned
,
anonymous_user_id
=
submission_model
.
student_item
.
student_id
,
course_id
=
submission_model
.
student_item
.
course_id
,
item_id
=
submission_model
.
student_item
.
item_id
,
)
except
IntegrityError
:
pass
...
...
submissions/models.py
View file @
835b7904
...
...
@@ -14,13 +14,24 @@ import logging
from
django.db
import
models
,
DatabaseError
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
,
Signal
from
django.utils.timezone
import
now
from
django_extensions.db.fields
import
UUIDField
logger
=
logging
.
getLogger
(
__name__
)
# Signal to inform listeners that a score has been changed
score_set
=
Signal
(
providing_args
=
[
'points_possible'
,
'points_earned'
,
'anonymous_user_id'
,
'course_id'
,
'item_id'
]
)
# Signal to inform listeners that a score has been reset
score_reset
=
Signal
(
providing_args
=
[
'anonymous_user_id'
,
'course_id'
,
'item_id'
]
)
class
StudentItem
(
models
.
Model
):
"""Represents a single item for a single course for a single user.
...
...
submissions/tests/test_api.py
View file @
835b7904
...
...
@@ -3,6 +3,7 @@ import copy
from
ddt
import
ddt
,
file_data
from
django.db
import
DatabaseError
from
django.dispatch
import
Signal
from
django.core.cache
import
cache
from
django.test
import
TestCase
from
nose.tools
import
raises
...
...
@@ -10,7 +11,7 @@ from mock import patch
import
pytz
from
submissions
import
api
as
api
from
submissions.models
import
ScoreSummary
,
Submission
,
StudentItem
,
Score
from
submissions.models
import
ScoreSummary
,
Submission
,
StudentItem
,
Score
,
score_set
from
submissions.serializers
import
StudentItemSerializer
STUDENT_ITEM
=
dict
(
...
...
@@ -226,6 +227,21 @@ class TestSubmissionsApi(TestCase):
score
=
api
.
get_latest_score_for_submission
(
submission
[
"uuid"
])
self
.
_assert_score
(
score
,
11
,
12
)
@patch.object
(
score_set
,
'send'
)
def
test_set_score_signal
(
self
,
send_mock
):
submission
=
api
.
create_submission
(
STUDENT_ITEM
,
ANSWER_ONE
)
api
.
set_score
(
submission
[
'uuid'
],
11
,
12
)
# Verify that the send method was properly called
send_mock
.
assert_called_with
(
sender
=
None
,
points_possible
=
12
,
points_earned
=
11
,
anonymous_user_id
=
STUDENT_ITEM
[
'student_id'
],
course_id
=
STUDENT_ITEM
[
'course_id'
],
item_id
=
STUDENT_ITEM
[
'item_id'
]
)
def
test_get_score
(
self
):
submission
=
api
.
create_submission
(
STUDENT_ITEM
,
ANSWER_ONE
)
api
.
set_score
(
submission
[
"uuid"
],
11
,
12
)
...
...
@@ -553,3 +569,4 @@ class TestSubmissionsApi(TestCase):
self
.
assertIsNotNone
(
score
)
self
.
assertEqual
(
score
[
"points_earned"
],
expected_points_earned
)
self
.
assertEqual
(
score
[
"points_possible"
],
expected_points_possible
)
submissions/tests/test_reset_score.py
View file @
835b7904
...
...
@@ -8,8 +8,9 @@ from django.test import TestCase
import
ddt
from
django.core.cache
import
cache
from
django.db
import
DatabaseError
from
django.dispatch
import
Signal
from
submissions
import
api
as
sub_api
from
submissions.models
import
Score
from
submissions.models
import
Score
,
score_reset
@ddt.ddt
...
...
@@ -165,3 +166,24 @@ class TestResetScore(TestCase):
self
.
STUDENT_ITEM
[
'course_id'
],
self
.
STUDENT_ITEM
[
'item_id'
],
)
@patch.object
(
score_reset
,
'send'
)
def
test_reset_score_signal
(
self
,
send_mock
):
# Create a submission for the student and score it
submission
=
sub_api
.
create_submission
(
self
.
STUDENT_ITEM
,
'test answer'
)
sub_api
.
set_score
(
submission
[
'uuid'
],
1
,
2
)
# Reset scores
sub_api
.
reset_score
(
self
.
STUDENT_ITEM
[
'student_id'
],
self
.
STUDENT_ITEM
[
'course_id'
],
self
.
STUDENT_ITEM
[
'item_id'
],
)
# Verify that the send method was properly called
send_mock
.
assert_called_with
(
sender
=
None
,
anonymous_user_id
=
self
.
STUDENT_ITEM
[
'student_id'
],
course_id
=
self
.
STUDENT_ITEM
[
'course_id'
],
item_id
=
self
.
STUDENT_ITEM
[
'item_id'
]
)
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