Skip to content

Commit 333942e

Browse files
author
jiangpeiling
committed
♻️ Reconstruct the app layer and service layer to comply with the MVC three-layer architecture.
1 parent 71bf5b9 commit 333942e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

test/backend/app/test_elasticsearch_app.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,29 @@
55
"""
66
import os
77
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
815

916
# Dynamically determine the backend path and add it to sys.path
1017
current_dir = os.path.dirname(os.path.abspath(__file__))
1118
backend_dir = os.path.abspath(os.path.join(current_dir, "../../../backend"))
1219
sys.path.insert(0, backend_dir)
1320

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
1824

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
2331

2432

2533
class SearchRequest(BaseModel):

0 commit comments

Comments
 (0)