From b35dbb1fa3b3f56bd8f25983f17419264a7e516c Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 6 Dec 2016 10:13:43 -0500 Subject: [PATCH 1/2] Include created_at time in score_set/reset signals This data is needed for robust grades work, and is easy enough to include in the providing signals. I've also added the freezegun library to test-requirements.txt to test this functionality. --- submissions/api.py | 4 +++- submissions/models.py | 4 ++-- submissions/tests/test_api.py | 5 ++++- submissions/tests/test_reset_score.py | 7 ++++++- test-requirements.txt | 2 ++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/submissions/api.py b/submissions/api.py index 70e8728..7cd8551 100644 --- a/submissions/api.py +++ b/submissions/api.py @@ -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 diff --git a/submissions/models.py b/submissions/models.py index 17e30e1..2818d63 100644 --- a/submissions/models.py +++ b/submissions/models.py @@ -25,12 +25,12 @@ # 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'] ) diff --git a/submissions/tests/test_api.py b/submissions/tests/test_api.py index f38929e..ef71fe9 100644 --- a/submissions/tests/test_api.py +++ b/submissions/tests/test_api.py @@ -7,6 +7,7 @@ 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 @@ def test_create_score(self): 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 @@ def test_set_score_signal(self, send_mock): 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"☃") diff --git a/submissions/tests/test_reset_score.py b/submissions/tests/test_reset_score.py index 6cdffbc..07eb7ae 100644 --- a/submissions/tests/test_reset_score.py +++ b/submissions/tests/test_reset_score.py @@ -4,13 +4,16 @@ 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 @@ def test_database_error(self, create_mock): 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 @@ def test_reset_score_signal(self, send_mock): 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), ) diff --git a/test-requirements.txt b/test-requirements.txt index 0689134..3de9863 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,8 +1,10 @@ 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 From 6695596663541acaaf76ff67a22f892fd7a80d1f Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 6 Dec 2016 15:03:54 -0500 Subject: [PATCH 2/2] Version 1.1.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d854c08..93e02ce 100644 --- a/setup.py +++ b/setup.py @@ -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',