import pytest from fastapi.testclient import TestClient from app import app @pytest.fixture def client(): return TestClient(app) def test_health_check(client): response = client.get("/health") assert response.status_code == 200 assert response.json() == {"status": "ok"} def test_pdf_generation(client): request_data = {"html": "

Hello, World!

", "filename": "testfile"} response = client.post("/pdf", json=request_data) assert response.status_code == 200 assert response.headers["Content-Type"] == "application/pdf" assert ( response.headers["Content-Disposition"] == 'attachment; filename="testfile.pdf"' ) def test_pdf_generation_default_filename(client): request_data = {"html": "

Hello, World!

", "filename": None} response = client.post("/pdf", json=request_data) assert response.status_code == 200 assert response.headers["Content-Type"] == "application/pdf" assert ( response.headers["Content-Disposition"] == 'attachment; filename="hinpdof.pdf"' ) def test_pdf_generation_invalid_html(client): request_data = {"html": "", "filename": "testfile"} response = client.post("/pdf", json=request_data) assert response.status_code == 422 # Unprocessable Entity due to invalid input def test_pdf_generation_missing_html(client): request_data = {"filename": "testfile"} response = client.post("/pdf", json=request_data) assert ( response.status_code == 422 ) # Unprocessable Entity due to missing required field def test_pdf_generation_large_html(client): large_html = "

" + "Hello, World! " * 1000 + "

" request_data = {"html": large_html, "filename": "largefile"} response = client.post("/pdf", json=request_data) assert response.status_code == 200 assert response.headers["Content-Type"] == "application/pdf" assert ( response.headers["Content-Disposition"] == 'attachment; filename="largefile.pdf"' ) def test_pdf_generation_invalid_filename(client): request_data = {"html": "

Hello, World!

", "filename": "invalid/filename"} response = client.post("/pdf", json=request_data) assert response.status_code == 200 assert response.headers["Content-Type"] == "application/pdf" assert ( response.headers["Content-Disposition"] == 'attachment; filename="invalid_filename.pdf"' ) def test_pdf_generation_missing_filename(client): request_data = {"html": "

Hello, World!

"} response = client.post("/pdf", json=request_data) assert response.status_code == 200 assert response.headers["Content-Type"] == "application/pdf" assert ( response.headers["Content-Disposition"] == 'attachment; filename="hinpdof.pdf"' )