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