Commit 71130ce8 by Stephen Sanchez

Added a uuid to the submission model object

parent 58733b0d
...@@ -62,7 +62,7 @@ class PeerEvaluationInternalError(PeerEvaluationError): ...@@ -62,7 +62,7 @@ class PeerEvaluationInternalError(PeerEvaluationError):
pass pass
def create_evaluation(submission_id, scorer_id, assessment_dict, def create_evaluation(submission_uuid, scorer_id, assessment_dict,
scored_at=None): scored_at=None):
"""Creates an evaluation on the given submission. """Creates an evaluation on the given submission.
...@@ -70,8 +70,8 @@ def create_evaluation(submission_id, scorer_id, assessment_dict, ...@@ -70,8 +70,8 @@ def create_evaluation(submission_id, scorer_id, assessment_dict,
rubric. rubric.
Args: Args:
submission_id (str): The submission id this assessment is associated submission_uuid (str): The submission uuid this assessment is associated
with. The submission_id is required and must already exist in the with. The submission uuid is required and must already exist in the
Submission model. Submission model.
scorer_id (str): The user ID for the user giving this assessment. This scorer_id (str): The user ID for the user giving this assessment. This
is required to create an assessment on a submission. is required to create an assessment on a submission.
...@@ -110,7 +110,7 @@ def create_evaluation(submission_id, scorer_id, assessment_dict, ...@@ -110,7 +110,7 @@ def create_evaluation(submission_id, scorer_id, assessment_dict,
""" """
try: try:
submission = Submission.objects.get(pk=submission_id) submission = Submission.objects.get(pk=submission_uuid)
peer_evaluation = { peer_evaluation = {
"scorer_id": scorer_id, "scorer_id": scorer_id,
"submission": submission.pk, "submission": submission.pk,
...@@ -130,7 +130,7 @@ def create_evaluation(submission_id, scorer_id, assessment_dict, ...@@ -130,7 +130,7 @@ def create_evaluation(submission_id, scorer_id, assessment_dict,
except DatabaseError: except DatabaseError:
error_message = u"An error occurred while creating evaluation {} for submission: {} by: {}".format( error_message = u"An error occurred while creating evaluation {} for submission: {} by: {}".format(
assessment_dict, assessment_dict,
submission_id, submission_uuid,
scorer_id scorer_id
) )
logger.exception(error_message) logger.exception(error_message)
......
...@@ -28,9 +28,9 @@ THURSDAY = datetime.datetime(2007, 9, 16, 0, 0, 0, 0, pytz.UTC) ...@@ -28,9 +28,9 @@ THURSDAY = datetime.datetime(2007, 9, 16, 0, 0, 0, 0, pytz.UTC)
@ddt @ddt
class TestApi(TestCase): class TestApi(TestCase):
def test_create_evaluation(self): def test_create_evaluation(self):
create_submission(STUDENT_ITEM, ANSWER_ONE) submission = create_submission(STUDENT_ITEM, ANSWER_ONE)
evaluation = api.create_evaluation( evaluation = api.create_evaluation(
"1", submission["uuid"],
STUDENT_ITEM["student_id"], STUDENT_ITEM["student_id"],
ASSESSMENT_DICT ASSESSMENT_DICT
) )
...@@ -38,33 +38,40 @@ class TestApi(TestCase): ...@@ -38,33 +38,40 @@ class TestApi(TestCase):
@file_data('test_valid_evaluations.json') @file_data('test_valid_evaluations.json')
def test_get_evaluations(self, assessment_dict): def test_get_evaluations(self, assessment_dict):
create_submission(STUDENT_ITEM, ANSWER_ONE) submission = create_submission(STUDENT_ITEM, ANSWER_ONE)
api.create_evaluation("1", STUDENT_ITEM["student_id"], assessment_dict) api.create_evaluation(
evaluations = api.get_evaluations("1") submission["uuid"],
STUDENT_ITEM["student_id"],
assessment_dict
)
evaluations = api.get_evaluations(submission["uuid"])
self.assertEqual(1, len(evaluations)) self.assertEqual(1, len(evaluations))
self._assert_evaluation(evaluations[0], **assessment_dict) self._assert_evaluation(evaluations[0], **assessment_dict)
@file_data('test_valid_evaluations.json') @file_data('test_valid_evaluations.json')
def test_get_evaluations_with_date(self, assessment_dict): def test_get_evaluations_with_date(self, assessment_dict):
create_submission(STUDENT_ITEM, ANSWER_ONE) submission = create_submission(STUDENT_ITEM, ANSWER_ONE)
api.create_evaluation( api.create_evaluation(
"1", STUDENT_ITEM["student_id"], assessment_dict, MONDAY submission["uuid"],
STUDENT_ITEM["student_id"],
assessment_dict,
MONDAY
) )
evaluations = api.get_evaluations("1") evaluations = api.get_evaluations(submission["uuid"])
self.assertEqual(1, len(evaluations)) self.assertEqual(1, len(evaluations))
self._assert_evaluation(evaluations[0], **assessment_dict) self._assert_evaluation(evaluations[0], **assessment_dict)
self.assertEqual(evaluations[0]["scored_at"], MONDAY) self.assertEqual(evaluations[0]["scored_at"], MONDAY)
def test_student_finished_evaluating(self): def test_student_finished_evaluating(self):
self._create_student_and_submission("Bob", "Bob's answer") bob = self._create_student_and_submission("Bob", "Bob's answer")
self._create_student_and_submission("Sally", "Sally's answer") sally = self._create_student_and_submission("Sally", "Sally's answer")
self._create_student_and_submission("Jim", "Jim's answer") jim = self._create_student_and_submission("Jim", "Jim's answer")
self.assertFalse(api.has_finished_required_evaluating("Tim", 3)) self.assertFalse(api.has_finished_required_evaluating("Tim", 3))
api.create_evaluation("1", "Tim", ASSESSMENT_DICT) api.create_evaluation(bob["uuid"], "Tim", ASSESSMENT_DICT)
api.create_evaluation("2", "Tim", ASSESSMENT_DICT) api.create_evaluation(sally["uuid"], "Tim", ASSESSMENT_DICT)
self.assertFalse(api.has_finished_required_evaluating("Tim", 3)) self.assertFalse(api.has_finished_required_evaluating("Tim", 3))
api.create_evaluation("3", "Tim", ASSESSMENT_DICT) api.create_evaluation(jim["uuid"], "Tim", ASSESSMENT_DICT)
self.assertTrue(api.has_finished_required_evaluating("Tim", 3)) self.assertTrue(api.has_finished_required_evaluating("Tim", 3))
@raises(api.PeerEvaluationRequestError) @raises(api.PeerEvaluationRequestError)
...@@ -97,25 +104,32 @@ class TestApi(TestCase): ...@@ -97,25 +104,32 @@ class TestApi(TestCase):
@raises(api.PeerEvaluationInternalError) @raises(api.PeerEvaluationInternalError)
def test_error_on_evaluation_creation(self, mock_filter): def test_error_on_evaluation_creation(self, mock_filter):
mock_filter.side_effect = DatabaseError("Bad things happened") mock_filter.side_effect = DatabaseError("Bad things happened")
create_submission(STUDENT_ITEM, ANSWER_ONE) submission = create_submission(STUDENT_ITEM, ANSWER_ONE)
api.create_evaluation( api.create_evaluation(
"1", STUDENT_ITEM["student_id"], ASSESSMENT_DICT, MONDAY submission["uuid"],
STUDENT_ITEM["student_id"],
ASSESSMENT_DICT,
MONDAY
) )
@patch.object(PeerEvaluation.objects, 'filter') @patch.object(PeerEvaluation.objects, 'filter')
@raises(api.PeerEvaluationInternalError) @raises(api.PeerEvaluationInternalError)
def test_error_on_get_evaluation(self, mock_filter): def test_error_on_get_evaluation(self, mock_filter):
create_submission(STUDENT_ITEM, ANSWER_ONE) submission = create_submission(STUDENT_ITEM, ANSWER_ONE)
api.create_evaluation("1", STUDENT_ITEM["student_id"], ASSESSMENT_DICT, api.create_evaluation(
MONDAY) submission["uuid"],
STUDENT_ITEM["student_id"],
ASSESSMENT_DICT,
MONDAY
)
mock_filter.side_effect = DatabaseError("Bad things happened") mock_filter.side_effect = DatabaseError("Bad things happened")
api.get_evaluations("1") api.get_evaluations(submission["uuid"])
@staticmethod @staticmethod
def _create_student_and_submission(student, answer, date=None): def _create_student_and_submission(student, answer, date=None):
new_student_item = STUDENT_ITEM.copy() new_student_item = STUDENT_ITEM.copy()
new_student_item["student_id"] = student new_student_item["student_id"] = student
create_submission(new_student_item, answer, date) return create_submission(new_student_item, answer, date)
def _assert_evaluation(self, evaluation, points_earned, points_possible, def _assert_evaluation(self, evaluation, points_earned, points_possible,
feedback): feedback):
......
...@@ -5,6 +5,7 @@ different problem types, and is therefore ignorant of ORA workflow. ...@@ -5,6 +5,7 @@ different problem types, and is therefore ignorant of ORA workflow.
""" """
from django.db import models from django.db import models
from django.utils.timezone import now from django.utils.timezone import now
from django_extensions.db.fields import UUIDField
class StudentItem(models.Model): class StudentItem(models.Model):
...@@ -52,6 +53,8 @@ class Submission(models.Model): ...@@ -52,6 +53,8 @@ class Submission(models.Model):
because it makes caching trivial. because it makes caching trivial.
""" """
uuid = UUIDField(primary_key=True)
student_item = models.ForeignKey(StudentItem) student_item = models.ForeignKey(StudentItem)
# Which attempt is this? Consecutive Submissions do not necessarily have # Which attempt is this? Consecutive Submissions do not necessarily have
......
...@@ -15,7 +15,14 @@ class StudentItemSerializer(serializers.ModelSerializer): ...@@ -15,7 +15,14 @@ class StudentItemSerializer(serializers.ModelSerializer):
class SubmissionSerializer(serializers.ModelSerializer): class SubmissionSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Submission model = Submission
fields = ('student_item', 'attempt_number', 'submitted_at', 'created_at', 'answer') fields = (
'uuid',
'student_item',
'attempt_number',
'submitted_at',
'created_at',
'answer'
)
class ScoreSerializer(serializers.ModelSerializer): class ScoreSerializer(serializers.ModelSerializer):
......
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