port print-web-form app to nested flask structure
Replace stub print/ app with full PDF web print service from ~/print-web-form. Adapt UPLOAD_FOLDER to use Path(__file__).parent, add pypdf dependency, port all tests (10 passing), remove unused static/.
This commit is contained in:
parent
af5d3f148d
commit
b0c19d5642
9 changed files with 340 additions and 0 deletions
59
print/tests/conftest.py
Normal file
59
print/tests/conftest.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue