Skip to content

Commit

Permalink
Include created_at time in score_set/reset signals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Eric Fischer committed Dec 6, 2016
1 parent 718a1d3 commit b35dbb1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion submissions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions submissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
)


Expand Down
5 changes: 4 additions & 1 deletion submissions/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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"☃")
Expand Down
7 changes: 6 additions & 1 deletion submissions/tests/test_reset_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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),
)
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b35dbb1

Please sign in to comment.