Verified Commit d7bcb4c1 authored by Hugo Kerstens's avatar Hugo Kerstens
Browse files

Test for single page entries

parent acd1e1df
......@@ -3,10 +3,11 @@ import zipfile
from io import BytesIO
from PIL import Image
from pathlib import Path
from zesje.raw_scans import create_copy
from zesje.scans import _process_scan
from zesje.database import db, Exam, Student, Submission, Scan, Problem, ProblemWidget, ExamLayout
from zesje.raw_scans import create_copy, process_page
from zesje.scans import _process_scan, exam_metadata
from zesje.database import db, Exam, Student, Submission, Scan, Problem, ProblemWidget, ExamLayout, Copy, Page
@pytest.fixture
......@@ -72,3 +73,34 @@ def test_zip_process(app_with_data, zip_file):
assert len(copy.pages) == 1
page = copy.pages[0]
assert page.number == 0
def test_reupload_page(app_with_data, zip_file):
app, exam, students = app_with_data
student = students[0]
file_name = 'old.txt'
sub = Submission(exam=exam, student_id=student.id, validated=True)
copy = Copy(submission=sub, number=1)
page = Page(copy=copy, number=0, path=file_name)
db.session.add_all([sub, copy, page])
db.session.commit()
old_path = Path(app.config['DATA_DIRECTORY']) / file_name
old_path.write_text('old image data')
image = Image.new('RGB', (10, 10))
page_info = (student.id, page.number, copy.number)
file_info = [f'{student.id}-{page.number+1}-{page.copy.number}.jpg']
exam_config = exam_metadata(exam)
output_directory = app.config['DATA_DIRECTORY']
process_page(image, page_info, file_info, exam_config, output_directory)
# Only a single page entry
assert Page.query.filter(Page.copy == copy, Page.number == page.number).one()
# Path was updated and only new image still exists
assert page.path != file_name
assert not old_path.exists()
assert Path(page.abs_path).exists()
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