Пример #1
0
def test_get_exams(test_client, no_with_subs, no_without_subs):
    for i in range(no_without_subs):
        db.session.add(Exam(name=f'No Submissions {i}'))

    for i in range(no_with_subs):
        exam = Exam(name=f'Submissions {i}')
        db.session.add(exam)
        for _ in range(i):
            db.session.add(Submission(exam=exam))

    db.session.commit()

    response = test_client.get('/api/exams')

    assert response.status_code == 200

    data = json.loads(response.data)
    exams = {exam['name']: exam['submissions'] for exam in data}

    assert len(exams) == no_with_subs + no_without_subs

    for i in range(no_without_subs):
        exam_name = f'No Submissions {i}'
        assert exam_name in exams
        assert exams[exam_name] == 0

    for i in range(no_with_subs):
        exam_name = f'Submissions {i}'
        assert exam_name in exams
        assert exams[exam_name] == i
Пример #2
0
def add_test_data(app):
    for layout in ExamLayout:
        id = layout.value
        exam = Exam(id=id,
                    name=f'exam {layout.name}',
                    finalized=True,
                    layout=layout)
        db.session.add(exam)

        problem = Problem(id=id, name=f'Problem {layout.name}', exam_id=id)
        db.session.add(problem)

        problem_widget = ProblemWidget(id=id,
                                       name=f'problem widget {layout.name}',
                                       problem_id=id,
                                       page=2,
                                       width=100,
                                       height=150,
                                       x=40,
                                       y=200,
                                       type='problem_widget')
        db.session.add(problem_widget)
        db.session.commit()

        feedback_option = FeedbackOption(id=id,
                                         problem_id=id,
                                         text='text',
                                         description='desc',
                                         score=1)
        db.session.add(feedback_option)
        db.session.commit()

    yield app
Пример #3
0
def add_test_data(app):
    exam = Exam(id=42, name='exam f', finalized=True, layout="unstructured")
    db.session.add(exam)

    problem = Problem(id=20, name='Problem sad', exam_id=42)
    db.session.add(problem)
    db.session.commit()
    yield app
Пример #4
0
def app_with_data(app):
    exam = Exam(name='')
    students = [Student(id=i+1, first_name='', last_name='') for i in range(2)]
    db.session.add(exam)
    for student in students:
        db.session.add(student)
    db.session.commit()
    yield app, exam, students
Пример #5
0
def test_generate_single_pdf(datadir, tmpdir, config_app, monkeypatch_exam_generate_data):
    with NamedTemporaryFile() as tempfile:
        pdf_generation.generate_single_pdf(Exam(token='ABCDEFGHIJKL'), 1, 3, tempfile)
        tempfile.seek(0)

        exam_pdf = PdfReader(tempfile)
        pagecount = len(exam_pdf.pages)

        assert pagecount == 6
Пример #6
0
def test_submission_from_different_exam(test_client, add_test_data,
                                        add_test_submissions):
    exam = Exam(id=43, name='exam g', finalized=True, layout="unstructured")
    db.session.add(exam)
    problem = Problem(id=21, name='Problem sadder', exam_id=43)
    db.session.add(problem)

    res = test_client.get('/api/submissions/43/25')
    assert res.status_code == 400
Пример #7
0
def add_test_data(app):
    exam1 = Exam(name='exam 1', finalized=False)
    exam2 = Exam(name='exam 2', finalized=True)

    db.session.add(exam1)
    db.session.add(exam2)

    problem1 = Problem(name='Problem 1', exam=exam1)
    problem2 = Problem(name='Problem 2', exam=exam2)

    db.session.add(problem1)
    db.session.add(problem2)

    problem_widget_1 = ProblemWidget(name='problem widget', problem=problem1, page=2,
                                     width=100, height=150, x=40, y=200, type='problem_widget')
    db.session.add(problem_widget_1)

    db.session.commit()
    return [(exam1, exam2), (problem1, problem2), (problem_widget_1)]
Пример #8
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
Пример #9
0
def add_test_data(app):
    exam1 = Exam(id=1, name='exam 1', finalized=False)
    db.session.add(exam1)
    db.session.commit()

    problem1 = Problem(id=1, name='Problem 1', exam_id=1)
    db.session.add(problem1)
    db.session.commit()

    problem_widget_1 = ProblemWidget(id=1, name='problem widget', problem_id=1, page=2,
                                     width=100, height=150, x=40, y=200, type='problem_widget')
    db.session.add(problem_widget_1)
    db.session.commit()
Пример #10
0
def test_delete_exam(test_client, finalized, status_code):
    exam = Exam(name='finalized', finalized=finalized)
    db.session.add(exam)
    db.session.commit()

    response = test_client.delete(f'/api/exams/{exam.id}')

    assert response.status_code == status_code

    response = test_client.get('/api/exams')
    data = response.get_json()
    print(data)

    assert len(data) == (1 if finalized else 0)
Пример #11
0
def app_with_data(app):
    exam = Exam(name='', layout=ExamLayout.unstructured)
    problem = Problem(exam=exam, name='Problem')
    widget = ProblemWidget(problem=problem, x=0, y=0, width=0, height=0)
    students = [
        Student(id=i + 1000000, first_name='', last_name='') for i in range(2)
    ]
    db.session.add(exam)
    db.session.add(problem)
    db.session.add(widget)
    for student in students:
        db.session.add(student)
    db.session.commit()
    yield app, exam, students
Пример #12
0
def test_solution_pdf(app, datadir, layout, anonymous):
    exam = Exam(name='Email', layout=layout, finalized=True)
    student = Student(id=1234323,
                      first_name='Jamy',
                      last_name='Macgiver',
                      email='*****@*****.**')
    db.session.add(exam)
    db.session.add(student)
    db.session.commit()

    if layout == ExamLayout.templated:
        db.session.add(
            ExamWidget(
                name='student_id_widget',
                x=50,
                y=50,
                exam=exam,
            ))
        db.session.commit()

    sub = Submission(exam=exam, student=student, validated=True)
    db.session.add(sub)

    copy = Copy(submission=sub, number=1)
    db.session.add(copy)

    for index, filepath in enumerate(
        ['studentnumbers/1234323.jpg', 'studentnumbers/4300947.jpg']):
        page = Page(number=index, path=os.path.join(datadir, filepath))
        db.session.add(page)
        copy.pages.append(page)
    db.session.commit()

    with Pdf.open(solution_pdf(exam.id, student.id,
                               anonymous=anonymous)) as pdf:
        pagecount = len(pdf.pages)
        assert pagecount == 2

        if anonymous and layout == ExamLayout.templated:
            image = extract_image_pikepdf(pdf.pages[0])
            _, coords = exam_student_id_widget(exam.id)
            widget_area = get_box(np.array(image),
                                  np.array(coords, dtype=float) / 72,
                                  padding=-.3)
            w, h, *_ = widget_area.shape

            assert 145 < (np.mean(widget_area[:w // 2]) +
                          np.mean(widget_area[:, :h // 2])) / 2 < 155
Пример #13
0
def add_test_data(app):
    exam1 = Exam(id=1, name='exam 1', finalized=False)
    db.session.add(exam1)

    problem1 = Problem(id=1, name='Problem 1', exam_id=1)
    db.session.add(problem1)

    problem_widget_1 = ProblemWidget(id=1, name='problem widget', problem_id=1, page=2,
                                     width=100, height=150, x=40, y=200, type='problem_widget')
    db.session.add(problem_widget_1)
    db.session.commit()

    fo1 = FeedbackOption(id=5, problem_id=1, text='fully incorrect', score=2, parent=problem1.root_feedback)
    db.session.add(fo1)
    db.session.commit()

    yield problem1.root_feedback.id
Пример #14
0
def add_test_data(app):
    exam1 = Exam(id=1, name='exam 1', finalized=True)
    db.session.add(exam1)

    problem1 = Problem(id=1, name='Problem 1', exam_id=1)
    db.session.add(problem1)

    problem_widget_1 = ProblemWidget(id=1, name='problem widget', problem_id=1, page=2,
                                     width=100, height=150, x=40, y=200, type='problem_widget')
    db.session.add(problem_widget_1)
    db.session.commit()

    feedback_option = FeedbackOption(id=1, problem_id=1, text='text', description='desc', score=1)
    db.session.add(feedback_option)
    db.session.commit()

    mc_option = MultipleChoiceOption(id=2, label='a', feedback_id=1, x=10, y=30, name='mco', type='mcq_widget')
    db.session.add(mc_option)
    db.session.commit()
Пример #15
0
def test_get_solution(test_client, add_test_data):
    res = test_client.get('/api/solution/1/1/1')
    assert res.status_code == 200

    # exam does not exist
    res = test_client.get('/api/solution/18428/1/1')
    assert res.status_code == 404

    # submission does not exist
    res = test_client.get('/api/solution/1/965/1')
    assert res.status_code == 404

    # no solution for this problem id
    res = test_client.get('/api/solution/1/1/87841')
    assert res.status_code == 404

    db.session.add(Exam(id=2, name='exam2', finalized=True, layout="unstructured"))
    # exam exist but submission does not belong to it
    res = test_client.get('/api/solution/2/1/1')
    assert res.status_code == 400
Пример #16
0
def add_test_data(app):
    exam = Exam(name='exam 1', finalized=True)
    db.session.add(exam)

    problem1 = Problem(name='Problem 1', exam=exam)
    problem2 = Problem(name='Problem 2', exam=exam)
    db.session.add(problem1)
    db.session.add(problem2)

    feedback_option = FeedbackOption(problem=problem1,
                                     text='text',
                                     description='desc',
                                     score=5)
    db.session.add(feedback_option)

    student = Student(id=1000001, first_name='', last_name='')
    db.session.add(student)

    sub = Submission(exam=exam, student=student, copies=[], validated=True)
    db.session.add(sub)
    db.session.commit()

    yield app, exam
Пример #17
0
def exam():
    return Exam(name='')
Пример #18
0
def app_with_data(app):
    exam = Exam(name='', finalized=True, layout=ExamLayout.unstructured)
    db.session.add(exam)
    db.session.commit()
    yield app, exam