-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_report.py
More file actions
50 lines (41 loc) · 1.74 KB
/
Copy pathtest_report.py
File metadata and controls
50 lines (41 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import pytest
from fastapi.testclient import TestClient
from app.main import app
# filepath: /home/ibrahim/MyPc/Projects/GSoC/ASL-Parameter-Generator/apps/backend/tests/test_report.py
client = TestClient(app)
def test_get_report_bids_no_files():
response = client.post("/api/report/process/bids", data={"modality": "ASL"})
assert response.status_code == 200
assert isinstance(response.json(), dict)
def test_get_report_bids_invalid_modality():
response = client.post("/api/report/process/bids", data={"modality": "INVALID"})
assert response.status_code == 400
assert response.json()["detail"] == "Unsupported modality: INVALID"
def test_get_report_dicom_no_files():
response = client.post("/api/report/process/dicom", data={"modality": "ASL"})
assert response.status_code == 400
assert response.json()["detail"] == "No DICOM files provided"
def test_get_report_dicom_with_invalid_file(tmp_path):
# Create a dummy non-dicom file
file_path = tmp_path / "not_a_dicom.txt"
file_path.write_text("not a dicom")
with open(file_path, "rb") as f:
response = client.post(
"/report/process/dicom",
files={"dcm_files": ("not_a_dicom.txt", f, "text/plain")},
data={"modality": "ASL"}
)
# Should still return 500 due to invalid dicom
assert response.status_code in [500, 200]
def test_report_pdf_endpoint():
# Minimal valid report_data for rendering
report_data = {
"report_data": {
"asl_parameters": {"param1": "value1"},
"other": "test"
}
}
response = client.post("/api/report/report-pdf", json=report_data)
assert response.status_code == 200
assert response.headers["content-type"] == "application/pdf"