Exemplo n.º 1
0
def add_test_submissions(app):
    student = Student(first_name='Harry', last_name='Lewis')
    student2 = Student(first_name='bob', last_name='alice')
    student3 = Student(first_name='Charlie', last_name='Bob')

    grader = Grader(id=1, name='Zesje', oauth_id='Zesje')
    grader2 = Grader(id=2, name='Alice', oauth_id='Smith')

    sub = Submission(id=25, student=student, exam_id=42)
    sub2 = Submission(id=26, student=student2, exam_id=42)
    sub3 = Submission(id=27, student=student3, exam_id=42)

    sol = Solution(problem_id=20,
                   submission=sub,
                   graded_by=grader,
                   graded_at=datetime.now())
    db.session.add(sol)
    sol2 = Solution(problem_id=20,
                    submission=sub2,
                    graded_by=grader2,
                    graded_at=datetime.now())
    db.session.add(sol2)
    sol3 = Solution(problem_id=20,
                    submission=sub3,
                    graded_by=grader2,
                    graded_at=datetime.now())
    db.session.add(sol3)
    yield app
Exemplo n.º 2
0
def test_find_length(add_test_data, get_first_feedback, get_second_feedback):
    student = Student(first_name='Harry', last_name='Lewis')
    student2 = Student(first_name='bob', last_name='alice')
    student3 = Student(first_name='Charlie', last_name='Bob')

    grader = Grader(id=1, name='Zesje', oauth_id='Zesje')
    grader2 = Grader(id=2, name='Alice', oauth_id='Smith')

    sub = Submission(id=25, student=student, exam_id=42)
    sub2 = Submission(id=26, student=student2, exam_id=42)
    sub3 = Submission(id=27, student=student3, exam_id=42)

    sol = Solution(problem_id=20,
                   submission=sub,
                   graded_by=grader,
                   graded_at=datetime.now())
    db.session.add(sol)
    sol2 = Solution(problem_id=20,
                    submission=sub2,
                    graded_by=grader2,
                    graded_at=datetime.now())
    db.session.add(sol2)
    sol3 = Solution(problem_id=20,
                    submission=sub3,
                    graded_by=grader2,
                    graded_at=datetime.now())
    db.session.add(sol3)

    sol.feedback = get_first_feedback
    sol2.feedback = get_second_feedback
    sol3.feedback = get_first_feedback

    result = find_number_of_matches(Problem.query.get(20), False, [1], [], 2)
    assert result == 1
Exemplo n.º 3
0
def test_has_all_required(get_first_feedback):
    student = Student(first_name='', last_name='')
    grader = Grader(name='Zesje', oauth_id='Zesje')
    sub = Submission(student=student, exam_id=42)
    sol = Solution(problem_id=20,
                   submission=sub,
                   graded_by=grader,
                   graded_at=datetime.now())
    sol.feedback = get_first_feedback

    assert has_all_required_feedback(sol, set([1, 2]), set([3]))
Exemplo n.º 4
0
def _fake_process_pdf(app, exam, scan, pages, student_ids, copies_per_student):
    validate = exam.layout == ExamLayout.unstructured
    copy_number = 0
    for student_id, number_of_copies in zip(student_ids, copies_per_student):
        for _ in range(number_of_copies):
            copy_number += 1
            copy = Copy(number=copy_number)

            base_copy_path = os.path.join(app.config['DATA_DIRECTORY'],
                                          f'{exam.id}_data', 'submissions', f'{copy_number}')
            os.makedirs(base_copy_path)
            for page in range(pages + 1):
                path = os.path.join(base_copy_path, f'page{page:02d}.jpeg')
                generate_random_page_image(path, A4)
                db.session.add(Page(path=path, copy=copy, number=page))

            sub = Submission(copies=[copy], exam=scan.exam, student_id=student_id, validated=validate)
            db.session.add(sub)

            for problem in scan.exam.problems:
                db.session.add(Solution(problem=problem, submission=sub))

    scan.status = 'success'
    scan.message = 'Successfully skipped processing.'
    db.session.commit()
Exemplo n.º 5
0
def add_test_data(app):
    """Adds test data to the db.

    The feedback tree for problem 1 is (+: non-exlcusive; -: exclusive):
    + root(id=0)
        + A(id=1)
            + A1(id=11)
            + A2(id=12)
        + B(id=2)
            - B1(id=21)
            - B2(id=22)
    """
    exam = Exam(id=1, name='exam', finalized=True, layout="unstructured")
    db.session.add(exam)

    problem = Problem(id=1, name='Problem', exam=exam)
    db.session.add(problem)

    student = Student(id=1, first_name='Harry', last_name='Lewis')
    db.session.add(student)

    grader = Grader(id=1, name='Zesje', oauth_id='Zesje')
    db.session.add(grader)

    sub = Submission(id=1, student=student, exam=exam)
    db.session.add(sub)

    sol = Solution(id=1, submission=sub, problem=problem)
    db.session.add(sol)
    db.session.commit()

    root = problem.root_feedback

    for i in range(2):
        fo_parent = FeedbackOption(id=i + 1,
                                   problem=problem,
                                   text=chr(i + 65),
                                   description='',
                                   score=i,
                                   parent=root,
                                   mut_excl_children=i == 1)
        db.session.add(fo_parent)
        db.session.commit()
        for j in range(1, 3):
            fo = FeedbackOption(id=(i + 1) * 10 + j,
                                problem=problem,
                                text=chr(i + 65) + chr(j + 65),
                                description='',
                                score=-1 * i * j,
                                parent_id=i + 1)
            db.session.add(fo)

    db.session.commit()

    yield app
Exemplo n.º 6
0
def test_find_next(add_test_data, get_first_feedback, get_second_feedback):
    student = Student(first_name='', last_name='')
    student2 = Student(first_name='bob', last_name='alice')

    grader = Grader(name='Zesje', oauth_id='Zesje')

    sub = Submission(id=25, student=student, exam_id=42)
    sub2 = Submission(id=26, student=student2, exam_id=42)

    sol = Solution(problem_id=20,
                   submission=sub,
                   graded_by=grader,
                   graded_at=datetime.now())
    db.session.add(sol)
    sol2 = Solution(problem_id=20,
                    submission=sub2,
                    graded_by=grader,
                    graded_at=datetime.now())
    db.session.add(sol2)

    sol.feedback = get_first_feedback
    sol2.feedback = get_second_feedback

    result = _find_submission(sub, Problem.query.get(20), 1, 'next', False,
                              set([3]), set([2]), None)
    assert result == sub2
Exemplo n.º 7
0
def test_find_next_graded_by(add_test_data):
    student = Student(first_name='', last_name='')
    student2 = Student(first_name='bob', last_name='alice')

    grader = Grader(id=1, name='Zesje', oauth_id='Zesje')
    grader2 = Grader(id=2, name='Alice', oauth_id='Smith')

    sub = Submission(id=25, student=student, exam_id=42)
    sub2 = Submission(id=26, student=student2, exam_id=42)

    sol = Solution(problem_id=20,
                   submission=sub,
                   graded_by=grader,
                   graded_at=datetime.now())
    db.session.add(sol)
    sol2 = Solution(problem_id=20,
                    submission=sub2,
                    graded_by=grader2,
                    graded_at=datetime.now())
    db.session.add(sol2)

    result = _find_submission(sub, Problem.query.get(20), 1, 'next', False,
                              set(), set(), 2)
    assert result == sub2
Exemplo n.º 8
0
def test_delete_problem_graded(test_client, add_test_data, exam_id,
                               problem_id):
    student = Student(first_name='', last_name='')
    db.session.add(student)
    grader = Grader(name='Zesje', oauth_id='zesje')
    db.session.add(grader)
    db.session.commit()
    sub = Submission(student=student, exam_id=exam_id)
    db.session.add(sub)
    db.session.commit()
    sol = Solution(problem_id=problem_id,
                   submission=sub,
                   graded_by=grader,
                   graded_at=datetime.now())
    db.session.add(sol)
    db.session.commit()

    result = test_client.delete(f'/api/problems/{problem_id}')

    assert result.status_code == 403
    assert Problem.query.get(problem_id) is not None
Exemplo n.º 9
0
def solution():
    return Solution()