import io import tempfile import pypdf import pytest from app import app as flask_app, get_pdf_page_count @pytest.fixture def app(): flask_app.config["TESTING"] = True flask_app.config["UPLOAD_FOLDER"] = tempfile.mkdtemp() flask_app.config["SECRET_KEY"] = "test-secret" yield flask_app @pytest.fixture def client(app): return app.test_client() def _make_pdf(num_pages=3): writer = pypdf.PdfWriter() for _ in range(num_pages): writer.add_blank_page(width=612, height=792) buf = io.BytesIO() writer.write(buf) buf.seek(0) return buf @pytest.fixture def sample_pdf(): return _make_pdf(3).read() @pytest.fixture def large_pdf(): return _make_pdf(15).read() @pytest.fixture def corrupt_file(): return b"This is not a PDF at all" @pytest.fixture def sample_pdf_path(tmp_path): path = tmp_path / "test.pdf" path.write_bytes(_make_pdf(3).read()) return str(path) @pytest.fixture def corrupt_file_path(tmp_path): path = tmp_path / "corrupt.pdf" path.write_bytes(b"not a pdf") return str(path)