Skip to content
Snippets Groups Projects

Backend tests

Merged Jan Maximilian Michal requested to merge backend-tests into master
8 files
+ 73
21
Compare changes
  • Side-by-side
  • Inline
Files
8
+ 84
0
""" A set of factory methods that make testing easier. Each method creates all
reuired subfields if not provided by via kwargs. """
from core.models import (ExamType, Feedback, Reviewer, Student, Submission,
SubmissionType, Tutor, UserAccount)
# These methods are meant to be used to provide data to insert into the test
# database
def make_user(username='user01',
password='p',
fullname='us er01',
is_admin=False):
user = UserAccount.objects.create(username=username,
fullname=fullname,
is_admin=is_admin)
user.set_password(password)
user.save()
return user
def make_exam(module_reference='TestExam B.Inf.0042',
total_score=42,
pass_score=21,
**kwargs):
return ExamType.objects.create(module_reference=module_reference,
total_score=total_score,
pass_score=pass_score, **kwargs)
def make_submission_type(name='problem01',
full_score=10,
description='Very hard',
solution='Impossible!'):
return SubmissionType.objects.create(name=name,
full_score=full_score,
description=description,
solution=solution)
def make_student(user=None, exam=None):
if user is None:
user = make_user()
if exam is None:
exam = make_exam()
return Student.objects.create(user=user, exam=exam)
def make_tutor(user=None):
if user is None:
user = make_user()
return Tutor.objects.create(user=user)
def make_reviewer(user=None):
if user is None:
user = make_user()
return Reviewer.objects.create(user=user)
def make_submission(type=None, student=None, text='Too hard for me ;-('):
if type is None:
type = make_submission_type()
if student is None:
student = make_student()
return Submission.objects.create(text=text, type=type, student=student)
def make_feedback(of_tutor, of_submission=None, text='Very bad!', score=3):
if of_submission is None:
of_submission = make_submission()
return Feedback.objects.create(of_tutor=of_tutor,
of_submission=of_submission,
text=text,
score=score)
def make_minimal_exam():
# also creates default examType, submissionType and student
submission = make_submission()
tutor = make_tutor(user=make_user(username='tutor01'))
feedback = make_feedback(of_tutor=tutor, of_submission=submission)
return submission, tutor, feedback
Loading