Commit 1aa68838 authored by Adrià Labay's avatar Adrià Labay
Browse files

fix use of layout name in tests and example data

parent 798d5db0
......@@ -290,7 +290,7 @@ def add_templated_exam(client, pages):
content_type='multipart/form-data',
data={
'exam_name': exam_name,
'layout': ExamLayout.templated.value,
'layout': ExamLayout.templated.name,
'pdf': pdf_file}).get_json()['id']
return exam_id, problems + mc_problems
......@@ -309,7 +309,7 @@ def add_unstructured_exam(client, pages):
content_type='multipart/form-data',
data={
'exam_name': exam_name,
'layout': ExamLayout.unstructured.value}
'layout': ExamLayout.unstructured.name}
).get_json()['id']
return exam_id, problems
......@@ -318,9 +318,9 @@ def add_unstructured_exam(client, pages):
def design_exam(app, client, layout, pages, students, grade, solve, multiple_copies, skip_processing):
register_fonts()
if layout == ExamLayout.templated:
if layout == ExamLayout.templated.name:
exam_id, problems = add_templated_exam(client, pages)
elif layout == ExamLayout.unstructured:
elif layout == ExamLayout.unstructured.name:
exam_id, problems = add_unstructured_exam(client, pages)
else:
return None
......@@ -372,7 +372,7 @@ def design_exam(app, client, layout, pages, students, grade, solve, multiple_cop
student_ids = student_ids[:students]
copies_per_student = [2 if random.random() < multiple_copies else 1 for _ in range(students)]
if layout == ExamLayout.templated:
if layout == ExamLayout.templated.name:
# Download PDFs
generated = client.get(f'api/exams/{exam_id}/generated_pdfs',
data={"copies_start": 1, "copies_end": sum(copies_per_student), 'type': 'pdf'})
......@@ -388,7 +388,7 @@ def design_exam(app, client, layout, pages, students, grade, solve, multiple_cop
print('\tProcessing scans (this may take a while).',)
handle_pdf_processing(app, exam_id, submission_pdf, pages, student_ids, copies_per_student, skip_processing)
elif layout == ExamLayout.unstructured:
elif layout == ExamLayout.unstructured.name:
handle_pdf_processing(app, exam_id, None, pages, student_ids, copies_per_student, True)
# Validate signatures
......@@ -459,10 +459,10 @@ if __name__ == '__main__':
parser.add_argument('--skip-processing', action='store_true', help='fakes the pdf processing to reduce time. \
As a drawback, blanks will not be detected.')
parser.add_argument('--exams', type=int, default=1, help='number of exams to add')
parser.add_argument('--layout', type=int, default=ExamLayout.templated.value,
choices=[layout.value for layout in ExamLayout],
help='the layout of the exams: '
+ ', '.join(f'{layout.value} for {layout.name}' for layout in ExamLayout))
parser.add_argument('--layout', type=str, default=ExamLayout.templated.name,
choices=[layout.name for layout in ExamLayout],
help='the layout of the exams, any of: '
+ ', '.join(layout.name for layout in ExamLayout))
parser.add_argument('--pages', type=int, default=3, help='number of pages per exam (min is 1)')
parser.add_argument('--students', type=int, default=30, help='number of students per exam')
parser.add_argument('--graders', type=int, default=4, help='number of graders (min is 1)')
......
......@@ -26,7 +26,7 @@ def add_test_data(app):
def test_add_templated_exam(datadir, test_client):
with open(os.path.join(datadir, 'blank-a4-2pages.pdf'), 'rb') as pdf:
response = test_client.post('/api/exams',
data={'exam_name': 'The Exam', 'pdf': pdf, 'layout': ExamLayout.templated.value})
data={'exam_name': 'The Exam', 'pdf': pdf, 'layout': ExamLayout.templated.name})
assert response.status_code == 200
......@@ -35,19 +35,19 @@ def test_add_templated_exam(datadir, test_client):
assert len(data) == 1
assert data[0]['layout']['value'] == ExamLayout.templated.value
assert data[0]['layout']['value'] == ExamLayout.templated.name
def test_add_templated_exam_without_pdf(datadir, test_client):
response = test_client.post('/api/exams',
data={'exam_name': 'The Exam', 'layout': ExamLayout.templated.value})
data={'exam_name': 'The Exam', 'layout': ExamLayout.templated.name})
assert response.status_code == 400
def test_add_unstructured_exam(test_client):
response = test_client.post('/api/exams',
data={'exam_name': 'The Exam', 'layout': ExamLayout.unstructured.value})
data={'exam_name': 'The Exam', 'layout': ExamLayout.unstructured.name})
assert response.status_code == 200
response = test_client.get('/api/exams')
......@@ -55,7 +55,7 @@ def test_add_unstructured_exam(test_client):
assert len(data) == 1
assert data[0]['layout']['value'] == ExamLayout.unstructured.value
assert data[0]['layout']['value'] == ExamLayout.unstructured.name
assert data[0]['finalized']
......@@ -158,7 +158,7 @@ def test_get_exams(test_client, no_with_subs, no_without_subs):
def test_exam_types(test_client):
response = test_client.get('/api/exams/types')
response = test_client.get('/api/exams/layouts')
assert response.status_code == 200
......
......@@ -6,6 +6,6 @@ from example_data import create_exams # noqa E402
def test_example_data_script(test_client, app):
exams = create_exams(app, test_client, 1, 1, 2, 1, 2, 0.95, 0.85, 1, True)
exams = create_exams(app, test_client, 1, 'templated', 1, 1, 2, 0.95, 0.85, 1, True)
assert len(exams) == 1
assert len(exams[0]['problems']) == 7
assert len(exams[0]['problems']) == 3
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