feat(backend): 重构 HTTP 错误处理为 RFC7807 标准并优化多个 service
This commit is contained in:
@@ -6,7 +6,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
from core.http.errors import ApiProblemError
|
||||
|
||||
from core.auth.models import CurrentUser
|
||||
from models.friendships import Friendship, FriendshipStatus
|
||||
@@ -293,7 +293,7 @@ class TestSendRequest:
|
||||
current_user=current_user,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.send_request(
|
||||
FriendRequestCreate(target_user_id=current_user.id, content=None)
|
||||
)
|
||||
@@ -322,7 +322,7 @@ class TestSendRequest:
|
||||
current_user=current_user,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.send_request(
|
||||
FriendRequestCreate(target_user_id=USER_B, content=None)
|
||||
)
|
||||
@@ -351,7 +351,7 @@ class TestSendRequest:
|
||||
current_user=current_user,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.send_request(
|
||||
FriendRequestCreate(target_user_id=USER_B, content=None)
|
||||
)
|
||||
@@ -411,7 +411,7 @@ class TestAcceptRequest:
|
||||
current_user=current_user,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.accept_request(uuid4())
|
||||
|
||||
assert exc_info.value.status_code == 404
|
||||
@@ -447,7 +447,7 @@ class TestAcceptRequest:
|
||||
current_user=current_user,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.accept_request(friendship.id)
|
||||
|
||||
assert exc_info.value.status_code == 403
|
||||
@@ -669,7 +669,7 @@ class TestRemoveFriend:
|
||||
current_user=current_user,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.remove_friend(uuid4())
|
||||
|
||||
assert exc_info.value.status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user