Skip to content

Commit

Permalink
Added submission unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Osccu committed Apr 7, 2015
1 parent cf727d0 commit 3d3fd08
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 48 deletions.
2 changes: 1 addition & 1 deletion exercise/exercise_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def submit(self, submission):
return page


# TODO: REFACTOR - If this only accepts ExerciseWithAttachment objects it should be a method of that class instead (with one less parameters)
# TODO: REFACTOR - If this only accepts ExerciseWithAttachment objects it should be a method of that class instead (with one parameter less)
def build_upload_dir(instance, filename):
"""
Returns the path where the attachement should be saved.
Expand Down
6 changes: 1 addition & 5 deletions exercise/staff_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,7 @@ def list_deadline_rule_deviations(request, course_instance):

deviations = DeadlineRuleDeviation.objects.filter(exercise__course_module__course_instance=course_instance)

return render_to_response("exercise/list_deadline_rule_deviations.html", CourseContext(
request,
course_instance=course_instance,
deviations=deviations)
)
return render_to_response("exercise/list_deadline_rule_deviations.html", CourseContext(request, course_instance=course_instance, deviations=deviations))

@login_required
def remove_deadline_rule_deviation(request, deadline_rule_deviation_id):
Expand Down
45 changes: 14 additions & 31 deletions exercise/submission_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ class Submission(models.Model):
# Relations
exercise = models.ForeignKey(exercise_models.BaseExercise, related_name="submissions")
submitters = models.ManyToManyField(UserProfile, related_name="submissions")
grader = models.ForeignKey(UserProfile,
related_name="graded_submissions",
blank=True,
null=True)
grader = models.ForeignKey(UserProfile, related_name="graded_submissions", blank=True, null=True)

# Grading specific
feedback = models.TextField(blank=True)
assistant_feedback = models.TextField(blank=True)
status = models.CharField(max_length=32,
default=_status_choices[0][0],
choices=_status_choices)
status = models.CharField(max_length=32, default=_status_choices[0][0], choices=_status_choices)
grade = models.IntegerField(default=0)
grading_time = models.DateTimeField(blank=True, null=True)

Expand All @@ -64,8 +59,8 @@ def add_submitters(self, user_profiles):
@param user_profiles: an iterable with UserProfile objects
"""
for u_p in user_profiles:
self.add_submitter(u_p)
for user_profile in user_profiles:
self.add_submitter(user_profile)

def add_files(self, files):
"""
Expand Down Expand Up @@ -139,17 +134,15 @@ def set_points(self, points, max_points, no_penalties=False):

# Scale the given points to the maximum points for the exercise
if max_points > 0:
adjusted_grade = (1.0 * self.exercise.max_points
* points / max_points)
adjusted_grade = (1.0 * self.exercise.max_points * points / max_points)
else:
adjusted_grade = 0.0

# Check if this submission was done late. If it was, reduce the points
# with late submission penalty. No less than 0 points are given. This
# is not done if no_penalties is True.
if not no_penalties and self.is_submitted_late():
adjusted_grade -= (adjusted_grade
* self.exercise.get_late_submission_penalty())
adjusted_grade -= (adjusted_grade * self.exercise.get_late_submission_penalty())

self.grade = round(adjusted_grade)

Expand All @@ -162,10 +155,7 @@ def is_submitted_late(self):
# The submission is not saved and the submission_time field is not
# set yet so this method takes the liberty to set it.
self.submission_time = datetime.now()

return self.exercise.course_module.is_expired() and \
not self.exercise.is_open_for(students=self.submitters.all(),
when=self.submission_time)
return self.exercise.course_module.is_expired(when=self.submission_time) and not self.exercise.is_open_for(students=self.submitters.all(), when=self.submission_time)


def set_grading_data(self, grading_dict):
Expand All @@ -185,8 +175,7 @@ def submitter_string(self):
student_id_str = " (%s)" % profile.student_id
else:
student_id_str = ""
submitter_strs.append(profile.user.get_full_name()
+ student_id_str)
submitter_strs.append(profile.user.get_full_name() + student_id_str)

return ", ".join(submitter_strs)

Expand All @@ -195,6 +184,7 @@ def __unicode__(self):

# Status methods. The status indicates whether this submission is just
# created, waiting for grading, ready or erroneous.
# TODO: REFACTOR - _set_status allow faulty status values
def _set_status(self, new_status):
self.status = new_status

Expand All @@ -217,14 +207,12 @@ def get_absolute_url(self):
return reverse("exercise.views.view_submission", kwargs={"submission_id": self.id})

def get_callback_url(self):
# TODO: REFACTOR - variable identifier is never used? Should it be used instead of self.id as submission_id?
identifier = "s.%d.%d.%s" % (self.id, self.exercise.id, self.hash)
return reverse("exercise.async_views.grade_async_submission",
kwargs={"submission_id": self.id,
"hash": self.hash})
return reverse("exercise.async_views.grade_async_submission", kwargs={"submission_id": self.id, "hash": self.hash})

def get_staff_url(self):
return reverse("exercise.staff_views.inspect_exercise_submission",
kwargs={"submission_id": self.id})
return reverse("exercise.staff_views.inspect_exercise_submission", kwargs={"submission_id": self.id})

def submit_to_service(self, files=None):
# Get the exercise as an instance of its real leaf class
Expand All @@ -246,7 +234,7 @@ class Meta:
app_label = 'exercise'
ordering = ['-submission_time']


# TODO: REFACTOR - If this only accepts SubmittedFile objects it should be a method of that class instead (with one parameter less)
def build_upload_dir(instance, filename):
"""
Returns the path to a directory where the file should be saved.
Expand All @@ -264,12 +252,7 @@ def build_upload_dir(instance, filename):
# Collect submitter ids in a list of strings
submitter_ids = [str(profile.id) for profile in instance.submission.submitters.all()]

return "submissions/course_instance_%d/exercise_%d/users_%s/submission_%d/%s" % \
(course_instance.id,
exercise.id,
"-".join(submitter_ids), # Join submitter ids using dash as a separator
instance.submission.id,
filename)
return "submissions/course_instance_%d/exercise_%d/users_%s/submission_%d/%s" % (course_instance.id, exercise.id, "-".join(submitter_ids), instance.submission.id, filename)


class SubmittedFile(models.Model):
Expand Down
Loading

0 comments on commit 3d3fd08

Please sign in to comment.