Skip to content

Commit 28e2b1b

Browse files
author
Abdullah Nassar
committed
update tests
1 parent 271e0f7 commit 28e2b1b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

web/api/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ async def _prep_document(
507507
else:
508508
# It's a regular file
509509
logger.info(f"Fetching document from URL: {self.url}")
510-
# document_data = await self._fetch_document()
511510
if "application/pdf" in content_type:
512511
extension = "pdf"
513512
else:

web/api/tests/tests.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,3 +2478,25 @@ async def test_convert_url_non_200_response():
24782478
with patch(AIOHTTP_POST_PATH, return_value=mock_response):
24792479
with pytest.raises(DjangoValidationError):
24802480
await document._convert_url_to_pdf("https://example.com/doc.pdf")
2481+
2482+
2483+
async def test_fetch_document_200_response():
2484+
AIOHTTP_GET_PATH = "api.models.aiohttp.ClientSession.get"
2485+
2486+
# Mock response with non-200 status
2487+
mock_response = AsyncMock()
2488+
mock_response.status = 200
2489+
mock_response.headers = {
2490+
"Content-Type": "application/pdf",
2491+
"Content-Disposition": "", # Empty content disposition
2492+
"Content-Length": "1000",
2493+
}
2494+
mock_response.__aenter__.return_value = mock_response
2495+
2496+
document = Document(url="https://examplepdf.com")
2497+
2498+
with patch(AIOHTTP_GET_PATH, return_value=mock_response):
2499+
content_type, filename, data = await document._fetch_document()
2500+
2501+
assert content_type == "application/pdf"
2502+
assert filename == "downloaded_file"

0 commit comments

Comments
 (0)