Skip to content

Commit f809ce8

Browse files
committed
adding max time limit test case
1 parent c775c90 commit f809ce8

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

backend/app/tests/api/routes/documents/test_route_document_upload.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55
from tempfile import NamedTemporaryFile
66
from urllib.parse import urlparse
7-
from unittest.mock import patch
7+
from unittest.mock import patch, MagicMock
88

99
import pytest
1010
from moto import mock_aws
@@ -301,6 +301,50 @@ def test_transformation_job_created_in_database(
301301
# Check that start_job was called with the right arguments
302302
assert "transformer_name" in kwargs or len(args) >= 4
303303

304+
def test_upload_file_within_size_limit(
305+
self,
306+
db: Session,
307+
route: Route,
308+
scratch: Path,
309+
uploader: WebUploader,
310+
) -> None:
311+
"""Test that a file within the size limit uploads successfully."""
312+
aws = AmazonCloudStorageClient()
313+
aws.create()
314+
315+
# Mock calculate_file_size to return a value just under the 25 MB limit (in KB)
316+
with patch(
317+
"app.api.routes.documents.calculate_file_size",
318+
return_value=25 * 1024 - 1, # 25 MB - 1 KB
319+
):
320+
response = uploader.put(route, scratch)
321+
322+
assert response.status_code == 200
323+
324+
def test_upload_file_exceeds_size_limit(
325+
self,
326+
db: Session,
327+
route: Route,
328+
scratch: Path,
329+
uploader: WebUploader,
330+
) -> None:
331+
"""Test that a file exceeding 25 MB returns a 413 error."""
332+
aws = AmazonCloudStorageClient()
333+
aws.create()
334+
335+
# Mock calculate_file_size to return a value over the 25 MB limit (in KB)
336+
with patch(
337+
"app.api.routes.documents.calculate_file_size",
338+
return_value=25 * 1024 + 1, # 25 MB + 1 KB
339+
):
340+
response = uploader.put(route, scratch)
341+
342+
assert response.status_code == 413
343+
print("response =", response.json())
344+
error_detail = response.json()["error"]
345+
assert "exceeds the maximum allowed size" in error_detail
346+
assert "25" in error_detail
347+
304348
def test_upload_response_structure_without_transformation(
305349
self,
306350
db: Session,

0 commit comments

Comments
 (0)