This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_export_xlsx_and_pdf(app):
|
||||
with TestClient(app) as client:
|
||||
register = client.post(
|
||||
"/auth/register",
|
||||
json={"email": "export@example.com", "password": "strongpasswordExport1"},
|
||||
)
|
||||
assert register.status_code == 200
|
||||
csrf = register.json()["csrf_token"]
|
||||
|
||||
create = client.post(
|
||||
"/time-entries",
|
||||
headers={"x-csrf-token": csrf},
|
||||
json={
|
||||
"date": "2026-03-03",
|
||||
"start_time": "08:30",
|
||||
"end_time": "15:00",
|
||||
"break_minutes": 30,
|
||||
},
|
||||
)
|
||||
assert create.status_code == 200
|
||||
|
||||
export_xlsx = client.post(
|
||||
"/export",
|
||||
data={
|
||||
"from_date": "2026-03-01",
|
||||
"to_date": "2026-03-10",
|
||||
"format": "xlsx",
|
||||
"csrf_token": csrf,
|
||||
},
|
||||
)
|
||||
assert export_xlsx.status_code == 200
|
||||
assert "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" in export_xlsx.headers["content-type"]
|
||||
assert "attachment;" in export_xlsx.headers["content-disposition"]
|
||||
assert len(export_xlsx.content) > 200
|
||||
|
||||
export_pdf = client.post(
|
||||
"/export",
|
||||
data={
|
||||
"from_date": "2026-03-01",
|
||||
"to_date": "2026-03-10",
|
||||
"format": "pdf",
|
||||
"csrf_token": csrf,
|
||||
},
|
||||
)
|
||||
assert export_pdf.status_code == 200
|
||||
assert "application/pdf" in export_pdf.headers["content-type"]
|
||||
assert export_pdf.content.startswith(b"%PDF")
|
||||
Reference in New Issue
Block a user