Commit e4c4eaeb by Eric Fischer Committed by GitHub

Merge pull request #51 from edx/efischer/send_time

send created time
parents 718a1d39 66955966
......@@ -33,7 +33,7 @@ def load_requirements(*requirements_paths):
setup(
name='edx-submissions',
version='1.1.3',
version='1.1.4',
author='edX',
description='An API for creating submissions and scores.',
url='http://github.com/edx/edx-submissions.git',
......
......@@ -737,13 +737,14 @@ def reset_score(student_id, course_id, item_id, clear_state=False):
# Create a "reset" score
try:
Score.create_reset_score(student_item)
score = 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,
created_at=score.created_at,
)
if clear_state:
......@@ -860,6 +861,7 @@ def set_score(submission_uuid, points_earned, points_possible,
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,
created_at=score_model.created_at,
)
except IntegrityError:
pass
......
......@@ -25,12 +25,12 @@ 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'
'course_id', 'item_id', 'created_at'
])
# Signal to inform listeners that a score has been reset
score_reset = Signal(
providing_args=['anonymous_user_id', 'course_id', 'item_id']
providing_args=['anonymous_user_id', 'course_id', 'item_id', 'created_at']
)
......
......@@ -7,6 +7,7 @@ import ddt
from django.db import DatabaseError, connection, transaction
from django.core.cache import cache
from django.test import TestCase
from freezegun import freeze_time
from nose.tools import raises
from mock import patch
import pytz
......@@ -301,6 +302,7 @@ class TestSubmissionsApi(TestCase):
self._assert_score(score, 11, 12)
self.assertFalse(ScoreAnnotation.objects.all().exists())
@freeze_time(datetime.datetime.now())
@patch.object(score_set, 'send')
def test_set_score_signal(self, send_mock):
submission = api.create_submission(STUDENT_ITEM, ANSWER_ONE)
......@@ -313,7 +315,8 @@ class TestSubmissionsApi(TestCase):
points_earned=11,
anonymous_user_id=STUDENT_ITEM['student_id'],
course_id=STUDENT_ITEM['course_id'],
item_id=STUDENT_ITEM['item_id']
item_id=STUDENT_ITEM['item_id'],
created_at=datetime.datetime.now().replace(tzinfo=pytz.UTC),
)
@ddt.data(u"First score was incorrect", u"☃")
......
......@@ -4,13 +4,16 @@ Test reset scores.
import copy
from mock import patch
from datetime import datetime
from django.test import TestCase
import ddt
from django.core.cache import cache
from django.db import DatabaseError
from django.dispatch import Signal
from freezegun import freeze_time
from submissions import api as sub_api
from submissions.models import Score, score_reset
import pytz
@ddt.ddt
......@@ -167,6 +170,7 @@ class TestResetScore(TestCase):
self.STUDENT_ITEM['item_id'],
)
@freeze_time(datetime.now())
@patch.object(score_reset, 'send')
def test_reset_score_signal(self, send_mock):
# Create a submission for the student and score it
......@@ -185,5 +189,6 @@ class TestResetScore(TestCase):
sender = None,
anonymous_user_id=self.STUDENT_ITEM['student_id'],
course_id=self.STUDENT_ITEM['course_id'],
item_id=self.STUDENT_ITEM['item_id']
item_id=self.STUDENT_ITEM['item_id'],
created_at=datetime.now().replace(tzinfo=pytz.UTC),
)
ddt==0.8.0
django-nose==1.4.1
freezegun==0.1.11
mock==1.0.1
nose==1.3.3
coverage==4.0.2
python-dateutil==2.1
# Quality
pep8==1.6.2
......
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