Commit 6c4e7445 by Stephen Sanchez

Adding some quick doc to the functions

parent 516df4f1
...@@ -18,6 +18,10 @@ class SubmissionInternalError(Exception): ...@@ -18,6 +18,10 @@ class SubmissionInternalError(Exception):
pass pass
class SubmissionNotFoundError(Exception):
pass
class SubmissionRequestError(Exception): class SubmissionRequestError(Exception):
def __init__(self, field_errors): def __init__(self, field_errors):
self.field_errors = copy.deepcopy(field_errors) self.field_errors = copy.deepcopy(field_errors)
...@@ -30,10 +34,6 @@ class SubmissionRequestError(Exception): ...@@ -30,10 +34,6 @@ class SubmissionRequestError(Exception):
return "SubmissionRequestError({!r})".format(self.field_errors) return "SubmissionRequestError({!r})".format(self.field_errors)
class SubmissionNotFoundError(Exception):
pass
def create_submission(student_item_dict, answer, submitted_at=None, def create_submission(student_item_dict, answer, submitted_at=None,
attempt_number=None): attempt_number=None):
"""Creates a submission for evaluation. """Creates a submission for evaluation.
...@@ -151,6 +151,25 @@ def set_score(student_item): ...@@ -151,6 +151,25 @@ def set_score(student_item):
def _get_or_create_student_item(student_item_dict): def _get_or_create_student_item(student_item_dict):
"""Gets or creates a Student Item that matches the values specified.
Attempts to get the specified Student Item. If it does not exist, the
specified parameters are validated, and a new Student Item is created.
Args:
student_item_dict (dict): The dict containing the student_id, item_id,
course_id, and item_type that uniquely defines a student item.
Returns:
StudentItem: The student item that was retrieved or created.
Raises:
SubmissionInternalError: Thrown if there was an internal error while
attempting to create or retrieve the specified student item.
SubmissionRequestError: Thrown if the given student item parameters fail
validation.
"""
try: try:
try: try:
student_item_model = StudentItem.objects.get(**student_item_dict) student_item_model = StudentItem.objects.get(**student_item_dict)
......
import datetime import datetime
from django.db import DatabaseError
from django.db import DatabaseError
from django.test import TestCase from django.test import TestCase
from nose.tools import raises from nose.tools import raises
from mock import patch from mock import patch
...@@ -72,7 +72,6 @@ class TestApi(TestCase): ...@@ -72,7 +72,6 @@ class TestApi(TestCase):
mock_create.side_effect = DatabaseError("Bad things happened") mock_create.side_effect = DatabaseError("Bad things happened")
create_submission(STUDENT_ITEM, ANSWER_ONE) create_submission(STUDENT_ITEM, ANSWER_ONE)
def _assert_submission(self, submission, expected_answer, expected_item, def _assert_submission(self, submission, expected_answer, expected_item,
expected_attempt): expected_attempt):
self.assertIsNotNone(submission) self.assertIsNotNone(submission)
......
__author__ = 'stephensanchez'
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