|
5 | 5 | """ |
6 | 6 | import os |
7 | 7 | import sys |
| 8 | +import pytest |
| 9 | +from unittest.mock import patch, MagicMock, ANY |
| 10 | +from fastapi.testclient import TestClient |
| 11 | +from fastapi import FastAPI |
| 12 | + |
| 13 | +from typing import List |
| 14 | +from pydantic import BaseModel |
8 | 15 |
|
9 | 16 | # Dynamically determine the backend path and add it to sys.path |
10 | 17 | current_dir = os.path.dirname(os.path.abspath(__file__)) |
11 | 18 | backend_dir = os.path.abspath(os.path.join(current_dir, "../../../backend")) |
12 | 19 | sys.path.insert(0, backend_dir) |
13 | 20 |
|
14 | | -from fastapi.testclient import TestClient |
15 | | -from fastapi import FastAPI |
16 | | -from backend.apps.elasticsearch_app import router |
17 | | -from nexent.vector_database.elasticsearch_core import ElasticSearchCore |
| 21 | +# Patch boto3 and other dependencies before importing anything from backend |
| 22 | +boto3_mock = MagicMock() |
| 23 | +sys.modules['boto3'] = boto3_mock |
18 | 24 |
|
19 | | -import pytest |
20 | | -from unittest.mock import patch, MagicMock, ANY |
21 | | -from typing import List |
22 | | -from pydantic import BaseModel |
| 25 | +# Mock MinioClient before importing backend modules |
| 26 | +with patch('backend.database.client.MinioClient') as minio_mock: |
| 27 | + minio_mock.return_value = MagicMock() |
| 28 | + # Now we can safely import the function to test |
| 29 | + from backend.apps.elasticsearch_app import router |
| 30 | + from nexent.vector_database.elasticsearch_core import ElasticSearchCore |
23 | 31 |
|
24 | 32 |
|
25 | 33 | class SearchRequest(BaseModel): |
|
0 commit comments