mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-04 01:25:07 +08:00
Test: get message content testcase (#12403)
### What problem does this PR solve? Testcase for get_message_content api. ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
@ -22,7 +22,27 @@ from test_web_api.common import create_memory, list_memory, add_message, delete_
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="class")
|
@pytest.fixture(scope="class")
|
||||||
def add_memory_with_multiple_message_func(request, WebApiAuth):
|
def add_empty_raw_type_memory(request, WebApiAuth):
|
||||||
|
def cleanup():
|
||||||
|
memory_list_res = list_memory(WebApiAuth)
|
||||||
|
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
|
||||||
|
for _memory_id in exist_memory_ids:
|
||||||
|
delete_memory(WebApiAuth, _memory_id)
|
||||||
|
request.addfinalizer(cleanup)
|
||||||
|
payload = {
|
||||||
|
"name": "test_memory_0",
|
||||||
|
"memory_type": ["raw"],
|
||||||
|
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
|
||||||
|
"llm_id": "glm-4-flash@ZHIPU-AI"
|
||||||
|
}
|
||||||
|
res = create_memory(WebApiAuth, payload)
|
||||||
|
memory_id = res["data"]["id"]
|
||||||
|
request.cls.memory_id = memory_id
|
||||||
|
return memory_id
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="class")
|
||||||
|
def add_memory_with_multiple_type_message_func(request, WebApiAuth):
|
||||||
def cleanup():
|
def cleanup():
|
||||||
memory_list_res = list_memory(WebApiAuth)
|
memory_list_res = list_memory(WebApiAuth)
|
||||||
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
|
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
|
||||||
@ -56,6 +76,7 @@ Key Point of Confusion: The naming differs by region. In North America, "coriand
|
|||||||
add_message(WebApiAuth, message_payload)
|
add_message(WebApiAuth, message_payload)
|
||||||
request.cls.memory_id = memory_id
|
request.cls.memory_id = memory_id
|
||||||
request.cls.agent_id = agent_id
|
request.cls.agent_id = agent_id
|
||||||
|
time.sleep(2) # make sure refresh to index before search
|
||||||
return memory_id
|
return memory_id
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,51 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
import random
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from test_web_api.common import get_message_content, get_recent_message
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
|
from libs.auth import RAGFlowWebApiAuth
|
||||||
|
|
||||||
|
class TestAuthorization:
|
||||||
|
@pytest.mark.p1
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"invalid_auth, expected_code, expected_message",
|
||||||
|
[
|
||||||
|
(None, 401, "<Unauthorized '401: Unauthorized'>"),
|
||||||
|
(RAGFlowWebApiAuth(INVALID_API_TOKEN), 401, "<Unauthorized '401: Unauthorized'>"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_auth_invalid(self, invalid_auth, expected_code, expected_message):
|
||||||
|
res = get_message_content(invalid_auth, "empty_memory_id", 0)
|
||||||
|
assert res["code"] == expected_code, res
|
||||||
|
assert res["message"] == expected_message, res
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("add_memory_with_multiple_type_message_func")
|
||||||
|
class TestGetMessageContent:
|
||||||
|
|
||||||
|
@pytest.mark.p1
|
||||||
|
def test_get_message_content(self, WebApiAuth):
|
||||||
|
memory_id = self.memory_id
|
||||||
|
recent_messages = get_recent_message(WebApiAuth, {"memory_id": memory_id})
|
||||||
|
assert len(recent_messages["data"]) > 0, recent_messages
|
||||||
|
message = random.choice(recent_messages["data"])
|
||||||
|
message_id = message["message_id"]
|
||||||
|
content_res = get_message_content(WebApiAuth, memory_id, message_id)
|
||||||
|
for field in ["content", "content_embed"]:
|
||||||
|
assert field in content_res["data"]
|
||||||
|
assert content_res["data"][field] is not None, content_res
|
||||||
|
|||||||
Reference in New Issue
Block a user