| langfuse_mock = <MagicMock name='Langfuse' id='5170124448'>, client = <starlette.testclient.TestClient object at 0x10edf16a0>
|
|
|
| @mock.patch("frontiers_review_assistant.services.llm_handler.Langfuse")
|
| async def test_upload(langfuse_mock: MagicMock, client: TestClient):
|
| """
|
| Tests the behavior of PDF upload functionality and the integration with mocked Langfuse
|
| authentication checks.
|
|
|
| This test ensures that a PDF document can be successfully uploaded via a POST request,
|
| and that the response is correctly formatted as a text/event-stream. It simulates an
|
| authentication check via mocking and prepares the necessary test environment, including
|
| appropriate configurations for handling OCR.
|
|
|
| :param langfuse_mock: Mocked instance of the Langfuse service, used to simulate
|
| authentication checks.
|
| :param client: Instance of TestClient used to simulate API requests in the test environment.
|
| :return: None
|
| """
|
| langfuse_mock.return_value = MagicMock(auth_check=MagicMock(return_value=True))
|
| from frontiers_review_assistant.core.config import settings
|
|
|
| settings.OCR_TYPE = "llm_ocr"
|
|
|
| async with aiofiles.open(Path(__file__).parent / "data/chat_with_doc.pdf", "rb") as document:
|
| data = await document.read()
|
| response = client.post(
|
| url="/api/v1/upload/pdf",
|
| params={"api_key": "test_api_key"},
|
| files={"file": ("chat_with_doc.pdf", io.BytesIO(data), "application/pdf")},
|
| data={
|
| "article_id": "1",
|
| "session_id": "2",
|
| "user_id": "3",
|
| },
|
| )
|
|
|
| > assert response.status_code == 200
|
| E assert 403 == 200
|
| E + where 403 = <Response [403 Forbidden]>.status_code
|
|
|
| tests/test_01_upload.py:44: AssertionError
|