Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdullah13521 committed Dec 5, 2024
1 parent 271e0f7 commit 28e2b1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 0 additions & 1 deletion web/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ async def _prep_document(
else:
# It's a regular file
logger.info(f"Fetching document from URL: {self.url}")
# document_data = await self._fetch_document()
if "application/pdf" in content_type:
extension = "pdf"
else:
Expand Down
22 changes: 22 additions & 0 deletions web/api/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2478,3 +2478,25 @@ async def test_convert_url_non_200_response():
with patch(AIOHTTP_POST_PATH, return_value=mock_response):
with pytest.raises(DjangoValidationError):
await document._convert_url_to_pdf("https://example.com/doc.pdf")


async def test_fetch_document_200_response():
AIOHTTP_GET_PATH = "api.models.aiohttp.ClientSession.get"

# Mock response with non-200 status
mock_response = AsyncMock()
mock_response.status = 200
mock_response.headers = {
"Content-Type": "application/pdf",
"Content-Disposition": "", # Empty content disposition
"Content-Length": "1000",
}
mock_response.__aenter__.return_value = mock_response

document = Document(url="https://examplepdf.com")

with patch(AIOHTTP_GET_PATH, return_value=mock_response):
content_type, filename, data = await document._fetch_document()

assert content_type == "application/pdf"
assert filename == "downloaded_file"

0 comments on commit 28e2b1b

Please sign in to comment.