Skip to content

Commit 40cc190

Browse files
committed
test: Add test for read_attachment_content route with presigned URL redirect
1 parent e74e709 commit 40cc190

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

backend/app/tests/api/routes/test_attachments.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,46 @@ def test_list_attachments(
113113
assert len(content["data"]) >= 2
114114

115115

116+
def test_read_attachment_content(
117+
client: TestClient, superuser_token_headers: Dict[str, str], db: Session, mocker
118+
) -> None:
119+
# Create test patient
120+
patient = Patient(
121+
name="Test Patient",
122+
dob=datetime(2000, 1, 1),
123+
contact_info="[email protected]"
124+
)
125+
db.add(patient)
126+
db.commit()
127+
db.refresh(patient)
128+
129+
# Create test attachment
130+
attachment = Attachment(
131+
file_name="test.pdf",
132+
mime_type="application/pdf",
133+
storage_path="test/path/test.pdf",
134+
patient_id=patient.id
135+
)
136+
db.add(attachment)
137+
db.commit()
138+
db.refresh(attachment)
139+
140+
# Mock the S3 presigned URL generation
141+
mock_url = "https://example.com/presigned-url"
142+
mocker.patch(
143+
"app.api.deps.s3_client.generate_presigned_url",
144+
return_value=mock_url
145+
)
146+
147+
response = client.get(
148+
f"/api/v1/attachments/{attachment.id}/content",
149+
headers=superuser_token_headers,
150+
follow_redirects=False
151+
)
152+
153+
assert response.status_code == 302 # Redirect status code
154+
assert response.headers["location"] == mock_url
155+
116156
def test_attachment_not_found(
117157
client: TestClient, superuser_token_headers: Dict[str, str]
118158
) -> None:

0 commit comments

Comments
 (0)