feat: 增强日历功能并集成 AgentScope 代理服务
This commit is contained in:
@@ -44,7 +44,10 @@ class FakeFriendshipRepo:
|
||||
self._inbox_messages = inbox_messages or []
|
||||
|
||||
async def create_request(
|
||||
self, initiator_id: UUID, recipient_id: UUID
|
||||
self,
|
||||
initiator_id: UUID,
|
||||
recipient_id: UUID,
|
||||
content: str | None = None,
|
||||
) -> tuple[Friendship, InboxMessage]:
|
||||
friendship = MagicMock(spec=Friendship)
|
||||
friendship.id = uuid4()
|
||||
@@ -62,7 +65,34 @@ class FakeFriendshipRepo:
|
||||
inbox.status = InboxMessageStatus.PENDING
|
||||
inbox.message_type = InboxMessageType.FRIEND_REQUEST
|
||||
inbox.friendship_id = friendship.id
|
||||
inbox.content = None
|
||||
inbox.content = content
|
||||
self._inbox_messages.append(inbox)
|
||||
|
||||
return friendship, inbox
|
||||
|
||||
async def reactivate_request(
|
||||
self,
|
||||
friendship: Friendship,
|
||||
initiator_id: UUID,
|
||||
content: str | None = None,
|
||||
) -> tuple[Friendship, InboxMessage]:
|
||||
friendship.status = FriendshipStatus.PENDING
|
||||
friendship.initiator_id = initiator_id
|
||||
|
||||
recipient_id = (
|
||||
friendship.user_low_id
|
||||
if initiator_id == friendship.user_high_id
|
||||
else friendship.user_high_id
|
||||
)
|
||||
|
||||
inbox = MagicMock(spec=InboxMessage)
|
||||
inbox.id = uuid4()
|
||||
inbox.recipient_id = recipient_id
|
||||
inbox.sender_id = initiator_id
|
||||
inbox.status = InboxMessageStatus.PENDING
|
||||
inbox.message_type = InboxMessageType.FRIEND_REQUEST
|
||||
inbox.friendship_id = friendship.id
|
||||
inbox.content = content
|
||||
self._inbox_messages.append(inbox)
|
||||
|
||||
return friendship, inbox
|
||||
@@ -124,12 +154,6 @@ class FakeUserRepo:
|
||||
async def get_by_user_id(self, user_id: UUID) -> MagicMock | None:
|
||||
return self._profiles.get(user_id)
|
||||
|
||||
async def get_by_username(self, username: str) -> MagicMock | None:
|
||||
for profile in self._profiles.values():
|
||||
if profile.username == username:
|
||||
return profile
|
||||
return None
|
||||
|
||||
|
||||
_repo_check: FriendshipRepository = FakeFriendshipRepo()
|
||||
_user_repo_check: UserRepository = FakeUserRepo()
|
||||
@@ -189,6 +213,28 @@ class TestSendRequest:
|
||||
assert result is not None
|
||||
mock_session.commit.assert_awaited_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_request_persists_content_to_inbox(
|
||||
self,
|
||||
mock_session: AsyncMock,
|
||||
mock_friendship_repo: FakeFriendshipRepo,
|
||||
mock_user_repo: FakeUserRepo,
|
||||
current_user: CurrentUser,
|
||||
) -> None:
|
||||
service = FriendshipService(
|
||||
repository=mock_friendship_repo,
|
||||
user_repository=mock_user_repo,
|
||||
session=mock_session,
|
||||
current_user=current_user,
|
||||
)
|
||||
|
||||
content = "你好,我是张三"
|
||||
result = await service.send_request(
|
||||
FriendRequestCreate(target_user_id=USER_B, content=content)
|
||||
)
|
||||
|
||||
assert result.content == content
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_request_to_self_raises_400(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user