Skip to content

Commit d8cb2d9

Browse files
author
jiangpeiling
committed
♻️ refactor me model module.
1 parent df6cc0d commit d8cb2d9

File tree

2 files changed

+77
-287
lines changed

2 files changed

+77
-287
lines changed

test/backend/app/test_me_model_managment_app.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ async def mock_list_models_with_filter(type: str = Query(None)):
196196
async def test_get_me_models_not_found_filter():
197197
# Patch the service impl to raise NotFoundException so the route returns 404
198198
with patch('backend.apps.me_model_managment_app.get_me_models_impl') as mock_impl:
199-
mock_impl.side_effect = NotFoundException("No models found with type 'nonexistent'.")
199+
mock_impl.side_effect = NotFoundException(
200+
"No models found with type 'nonexistent'.")
200201
response = client.get("/me/model/list?type=nonexistent")
201202

202203
# Assertions - route maps NotFoundException -> 404 and returns message/data
@@ -245,6 +246,30 @@ async def test_get_me_models_exception():
245246
assert "__aenter__" in response_data["message"]
246247

247248

249+
@pytest.mark.asyncio
250+
async def test_get_me_models_success_response():
251+
"""Test successful model list retrieval with proper JSONResponse format"""
252+
# Mock the service implementation to return test data
253+
with patch('backend.apps.me_model_managment_app.get_me_models_impl') as mock_impl:
254+
mock_impl.return_value = [
255+
{"name": "model1", "type": "embed", "version": "1.0"},
256+
{"name": "model2", "type": "chat", "version": "1.0"}
257+
]
258+
259+
# Test the endpoint
260+
response = client.get("/me/model/list")
261+
262+
# Assertions
263+
assert response.status_code == HTTPStatus.OK
264+
response_data = response.json()
265+
assert response_data["message"] == "Successfully retrieved"
266+
assert response_data["data"] == [
267+
{"name": "model1", "type": "embed", "version": "1.0"},
268+
{"name": "model2", "type": "chat", "version": "1.0"}
269+
]
270+
assert len(response_data["data"]) == 2
271+
272+
248273
@pytest.mark.asyncio
249274
async def test_check_me_connectivity_success():
250275
"""Test successful ME connectivity check"""
@@ -307,6 +332,23 @@ async def test_check_me_connectivity_timeout():
307332
assert body["connect_status"] == "unavailable"
308333

309334

335+
@pytest.mark.asyncio
336+
async def test_check_me_connectivity_generic_exception():
337+
"""Test ME connectivity check with generic exception"""
338+
# Mock the impl to raise a generic Exception so the route returns 500
339+
with patch('backend.apps.me_model_managment_app.check_me_connectivity_impl') as mock_connectivity:
340+
mock_connectivity.side_effect = Exception("Unexpected error occurred")
341+
342+
response = client.get("/me/healthcheck")
343+
344+
# Assertions - route maps generic Exception -> 500 and returns status/desc/connect_status
345+
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
346+
body = response.json()
347+
assert body["status"] == "Disconnected"
348+
assert body["desc"] == "Unknown error occurred: Unexpected error occurred"
349+
assert body["connect_status"] == "unavailable"
350+
351+
310352
@pytest.mark.asyncio
311353
async def test_save_config_with_error():
312354
# This is a placeholder for the example test function the user requested

0 commit comments

Comments
 (0)