RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Add tests for frontend API (#3552)
liuhuabf9ebda3c830
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex ff4ff47d78..713f68b205 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -70,7 +70,7 @@ jobs:echo "RAGFLOW_IMAGE=infiniflow/ragflow:dev" >> docker/.envsudo docker compose -f docker/docker-compose.yml up -d- - name: Run tests against Elasticsearch+ - name: Run sdk tests against Elasticsearchrun: |export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY=""export HOST_ADDRESS=http://host.docker.internal:9380@@ -78,7 +78,18 @@ jobs:echo "Waiting for service to be available..."sleep 5done- cd sdk/python && poetry install && source .venv/bin/activate && cd test && pytest --tb=short t_dataset.py t_chat.py t_session.py t_document.py t_chunk.py+ cd sdk/python && poetry install && source .venv/bin/activate && cd test/test_sdk_api && pytest -s --tb=short get_email.py t_dataset.py t_chat.py t_session.py t_document.py t_chunk.py++ - name: Run frontend api tests against Elasticsearch+ run: |+ export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY=""+ export HOST_ADDRESS=http://host.docker.internal:9380+ until sudo docker exec ragflow-server curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do+ echo "Waiting for service to be available..."+ sleep 5+ done+ cd sdk/python && poetry install && source .venv/bin/activate && cd test/test_frontend_api && pytest -s --tb=short get_email.py test_dataset.py+- name: Stop ragflow:devif: always() # always run this step even if previous steps failed@@ -89,7 +100,17 @@ jobs:run: |sudo DOC_ENGINE=infinity docker compose -f docker/docker-compose.yml up -d- - name: Run tests against Infinity+ - name: Run sdk tests against Infinity+ run: |+ export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY=""+ export HOST_ADDRESS=http://host.docker.internal:9380+ until sudo docker exec ragflow-server curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do+ echo "Waiting for service to be available..."+ sleep 5+ done+ cd sdk/python && poetry install && source .venv/bin/activate && cd test/test_sdk_api && pytest -s --tb=short get_email.py t_dataset.py t_chat.py t_session.py t_document.py t_chunk.py++ - name: Run frontend api tests against Infinityrun: |export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY=""export HOST_ADDRESS=http://host.docker.internal:9380@@ -97,7 +118,7 @@ jobs:echo "Waiting for service to be available..."sleep 5done- cd sdk/python && poetry install && source .venv/bin/activate && cd test && pytest --tb=short t_dataset.py t_chat.py t_session.py t_document.py t_chunk.py+ cd sdk/python && poetry install && source .venv/bin/activate && cd test/test_frontend_api && pytest -s --tb=short get_email.py test_dataset.py- name: Stop ragflow:devif: always() # always run this step even if previous steps faileddiff --git a/sdk/python/test/conftest.py b/sdk/python/test/conftest.pyindex bcad88f14c..444d5c9bf2 100644--- a/sdk/python/test/conftest.py+++ b/sdk/python/test/conftest.py@@ -16,9 +16,6 @@ PASSWORD='''ctAseGvejiaSWWZ88T/m4FQVOpQyUvP+x7sXtdv3feqZACiQleuewkUi35E16wSd5C5QfN33jCHRoDUW81IH9zjij/vaw8IbVyb6vuwg6MX6inOEBRRzVbRYxXOu1wkWY6SsI8X70oF9aeLFp/PzQpjoe/YbSqpTq8qqrmHzn9vO+yvyYyvmDsphXeX8f7fp9c7vUsfOCkM+gHY3PadG+QHa7KI7mzTKgUTZImK6BZtfRBATDTthEUbbaTewY4H0MnWiCeeDhcbeQao6cFy1To8pE3RpmxnGnS8BsBn8w=='''-def get_email():- return EMAIL-def register():url = HOST_ADDRESS + "/v1/user/register"name = "user"@@ -50,3 +47,12 @@ def get_api_key_fixture():raise Exception(res.get("message"))return res["data"].get("token")[email protected](scope="session")+def get_auth():+ register()+ auth = login()+ return auth+[email protected](scope="session")+def get_email():+ return EMAILdiff --git a/sdk/python/test/common.py b/sdk/python/test/test_frontend_api/common.pysimilarity index 100%rename from sdk/python/test/common.pyrename to sdk/python/test/test_frontend_api/common.pydiff --git a/sdk/python/test/test_frontend_api/get_email.py b/sdk/python/test/test_frontend_api/get_email.pynew file mode 100644index 0000000000..df053fa768--- /dev/null+++ b/sdk/python/test/test_frontend_api/get_email.py@@ -0,0 +1,3 @@+def test_get_email(get_email):+ print(f"\nEmail account:",flush=True)+ print(f"{get_email}\n",flush=True)\ No newline at end of filediff --git a/sdk/python/test/test_frontend_api/test_dataset.py b/sdk/python/test/test_frontend_api/test_dataset.pynew file mode 100644index 0000000000..de81e6824a--- /dev/null+++ b/sdk/python/test/test_frontend_api/test_dataset.py@@ -0,0 +1,10 @@+from common import HOST_ADDRESS+import requests+def test_create_dataset(get_auth):+ authorization={"Authorization": get_auth}+ url = f"{HOST_ADDRESS}/v1/kb/create"+ json = {"name":"test_create_dataset"}+ res = requests.post(url=url,headers=authorization,json=json)+ res = res.json()+ assert res.get("code") == 0,f"{res.get('message')}"+diff --git a/sdk/python/test/test_sdk_api/common.py b/sdk/python/test/test_sdk_api/common.pynew file mode 100644index 0000000000..a5bc8ad32b--- /dev/null+++ b/sdk/python/test/test_sdk_api/common.py@@ -0,0 +1,2 @@+import os+HOST_ADDRESS=os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380')\ No newline at end of filediff --git a/sdk/python/test/test_sdk_api/get_email.py b/sdk/python/test/test_sdk_api/get_email.pynew file mode 100644index 0000000000..df053fa768--- /dev/null+++ b/sdk/python/test/test_sdk_api/get_email.py@@ -0,0 +1,3 @@+def test_get_email(get_email):+ print(f"\nEmail account:",flush=True)+ print(f"{get_email}\n",flush=True)\ No newline at end of filediff --git a/sdk/python/test/t_chat.py b/sdk/python/test/test_sdk_api/t_chat.pysimilarity index 91%rename from sdk/python/test/t_chat.pyrename to sdk/python/test/test_sdk_api/t_chat.pyindex cf2f426be5..785081b65d 100644--- a/sdk/python/test/t_chat.py+++ b/sdk/python/test/test_sdk_api/t_chat.py@@ -6,7 +6,7 @@ def test_create_chat_with_name(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_create_chat")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name":displayed_name,"blob":blob}documents = []@@ -22,7 +22,7 @@ def test_update_chat_with_name(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_update_chat")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name": displayed_name, "blob": blob}documents = []@@ -39,7 +39,7 @@ def test_delete_chats_with_success(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_delete_chat")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name": displayed_name, "blob": blob}documents = []@@ -55,7 +55,7 @@ def test_list_chats_with_success(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_list_chats")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name": displayed_name, "blob": blob}documents = []diff --git a/sdk/python/test/t_chunk.py b/sdk/python/test/test_sdk_api/t_chunk.pysimilarity index 96%rename from sdk/python/test/t_chunk.pyrename to sdk/python/test/test_sdk_api/t_chunk.pyindex 5c2b5f205b..13b4c06d78 100644--- a/sdk/python/test/t_chunk.py+++ b/sdk/python/test/test_sdk_api/t_chunk.py@@ -7,7 +7,7 @@ def test_parse_document_with_txt(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_parse_document")name = 'ragflow_test.txt'- with open("test_data/ragflow_test.txt","rb") as file :+ with open("test_data/ragflow_test.txt", "rb") as file :blob = file.read()docs = ds.upload_documents([{"displayed_name": name, "blob": blob}])doc = docs[0]@@ -26,7 +26,7 @@ def test_parse_and_cancel_document(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_parse_and_cancel_document")name = 'ragflow_test.txt'- with open("test_data/ragflow_test.txt","rb") as file :+ with open("test_data/ragflow_test.txt", "rb") as file :blob = file.read()docs=ds.upload_documents([{"displayed_name": name, "blob": blob}])doc = docs[0]@@ -40,7 +40,7 @@ def test_bulk_parse_documents(get_api_key_fixture):API_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_bulk_parse_and_cancel_documents")- with open("ragflow.txt","rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()documents = [{'displayed_name': 'test1.txt', 'blob': blob},diff --git a/sdk/python/test/t_dataset.py b/sdk/python/test/test_sdk_api/t_dataset.pysimilarity index 100%rename from sdk/python/test/t_dataset.pyrename to sdk/python/test/test_sdk_api/t_dataset.pydiff --git a/sdk/python/test/t_document.py b/sdk/python/test/test_sdk_api/t_document.pysimilarity index 91%rename from sdk/python/test/t_document.pyrename to sdk/python/test/test_sdk_api/t_document.pyindex c8d5165c55..581e04032a 100644--- a/sdk/python/test/t_document.py+++ b/sdk/python/test/test_sdk_api/t_document.py@@ -7,7 +7,7 @@ def test_upload_document_with_success(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_upload_document")blob = b"Sample document content for test."- with open("ragflow.txt","rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob_2=file.read()document_infos = []document_infos.append({"displayed_name": "test_1.txt","blob": blob})@@ -63,7 +63,7 @@ def test_upload_and_parse_pdf_documents_with_general_parse_method(get_api_key_fiAPI_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_pdf_document")- with open("test_data/test.pdf","rb") as file:+ with open("test_data/test.pdf", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.pdf","blob": blob}]docs=ds.upload_documents(document_infos)@@ -74,7 +74,7 @@ def test_upload_and_parse_docx_documents_with_general_parse_method(get_api_key_fAPI_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_docx_document")- with open("test_data/test.docx","rb") as file:+ with open("test_data/test.docx", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.docx","blob": blob}]docs=ds.upload_documents(document_infos)@@ -84,7 +84,7 @@ def test_upload_and_parse_excel_documents_with_general_parse_method(get_api_key_API_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_excel_document")- with open("test_data/test.xlsx","rb") as file:+ with open("test_data/test.xlsx", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.xlsx","blob": blob}]docs=ds.upload_documents(document_infos)@@ -94,7 +94,7 @@ def test_upload_and_parse_ppt_documents_with_general_parse_method(get_api_key_fiAPI_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_ppt_document")- with open("test_data/test.ppt","rb") as file:+ with open("test_data/test.ppt", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.ppt","blob": blob}]docs=ds.upload_documents(document_infos)@@ -104,7 +104,7 @@ def test_upload_and_parse_image_documents_with_general_parse_method(get_api_key_API_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_image_document")- with open("test_data/test.jpg","rb") as file:+ with open("test_data/test.jpg", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.jpg","blob": blob}]docs=ds.upload_documents(document_infos)@@ -114,7 +114,7 @@ def test_upload_and_parse_txt_documents_with_general_parse_method(get_api_key_fiAPI_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_txt_document")- with open("test_data/test.txt","rb") as file:+ with open("test_data/test.txt", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.txt","blob": blob}]docs=ds.upload_documents(document_infos)@@ -124,7 +124,7 @@ def test_upload_and_parse_md_documents_with_general_parse_method(get_api_key_fixAPI_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_md_document")- with open("test_data/test.md","rb") as file:+ with open("test_data/test.md", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.md","blob": blob}]docs=ds.upload_documents(document_infos)@@ -135,7 +135,7 @@ def test_upload_and_parse_json_documents_with_general_parse_method(get_api_key_fAPI_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_json_document")- with open("test_data/test.json","rb") as file:+ with open("test_data/test.json", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.json","blob": blob}]docs=ds.upload_documents(document_infos)@@ -147,7 +147,7 @@ def test_upload_and_parse_eml_documents_with_general_parse_method(get_api_key_fiAPI_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_eml_document")- with open("test_data/test.eml","rb") as file:+ with open("test_data/test.eml", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.eml","blob": blob}]docs=ds.upload_documents(document_infos)@@ -158,7 +158,7 @@ def test_upload_and_parse_html_documents_with_general_parse_method(get_api_key_fAPI_KEY = get_api_key_fixturerag = RAGFlow(API_KEY, HOST_ADDRESS)ds = rag.create_dataset(name="test_html_document")- with open("test_data/test.html","rb") as file:+ with open("test_data/test.html", "rb") as file:blob=file.read()document_infos = [{"displayed_name": "test.html","blob": blob}]docs=ds.upload_documents(document_infos)diff --git a/sdk/python/test/t_session.py b/sdk/python/test/test_sdk_api/t_session.pysimilarity index 92%rename from sdk/python/test/t_session.pyrename to sdk/python/test/test_sdk_api/t_session.pyindex 45984f5aa9..2e46669cfb 100644--- a/sdk/python/test/t_session.py+++ b/sdk/python/test/test_sdk_api/t_session.py@@ -8,7 +8,7 @@ def test_create_session_with_success(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_create_session")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name":displayed_name,"blob":blob}documents = []@@ -25,7 +25,7 @@ def test_create_conversation_with_success(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_create_conversation")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name": displayed_name, "blob": blob}documents = []@@ -47,7 +47,7 @@ def test_delete_sessions_with_success(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_delete_session")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name":displayed_name,"blob":blob}documents = []@@ -65,7 +65,7 @@ def test_update_session_with_name(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_update_session")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name": displayed_name, "blob": blob}documents = []@@ -83,7 +83,7 @@ def test_list_sessions_with_success(get_api_key_fixture):rag = RAGFlow(API_KEY, HOST_ADDRESS)kb = rag.create_dataset(name="test_list_session")displayed_name = "ragflow.txt"- with open("ragflow.txt", "rb") as file:+ with open("test_data/ragflow.txt", "rb") as file:blob = file.read()document = {"displayed_name":displayed_name,"blob":blob}documents = []diff --git a/sdk/python/test/ragflow.txt b/sdk/python/test/test_sdk_api/test_data/ragflow.txtsimilarity index 100%rename from sdk/python/test/ragflow.txtrename to sdk/python/test/test_sdk_api/test_data/ragflow.txtdiff --git a/sdk/python/test/test_data/ragflow_test.txt b/sdk/python/test/test_sdk_api/test_data/ragflow_test.txtsimilarity index 100%rename from sdk/python/test/test_data/ragflow_test.txtrename to sdk/python/test/test_sdk_api/test_data/ragflow_test.txtdiff --git a/sdk/python/test/test_data/test.docx b/sdk/python/test/test_sdk_api/test_data/test.docxsimilarity index 100%rename from sdk/python/test/test_data/test.docxrename to sdk/python/test/test_sdk_api/test_data/test.docxdiff --git a/sdk/python/test/test_data/test.html b/sdk/python/test/test_sdk_api/test_data/test.htmlsimilarity index 100%rename from sdk/python/test/test_data/test.htmlrename to sdk/python/test/test_sdk_api/test_data/test.htmldiff --git a/sdk/python/test/test_data/test.jpg b/sdk/python/test/test_sdk_api/test_data/test.jpgsimilarity index 100%rename from sdk/python/test/test_data/test.jpgrename to sdk/python/test/test_sdk_api/test_data/test.jpgdiff --git a/sdk/python/test/test_data/test.json b/sdk/python/test/test_sdk_api/test_data/test.jsonsimilarity index 100%rename from sdk/python/test/test_data/test.jsonrename to sdk/python/test/test_sdk_api/test_data/test.jsondiff --git a/sdk/python/test/test_data/test.md b/sdk/python/test/test_sdk_api/test_data/test.mdsimilarity index 100%rename from sdk/python/test/test_data/test.mdrename to sdk/python/test/test_sdk_api/test_data/test.mddiff --git a/sdk/python/test/test_data/test.pdf b/sdk/python/test/test_sdk_api/test_data/test.pdfsimilarity index 100%rename from sdk/python/test/test_data/test.pdfrename to sdk/python/test/test_sdk_api/test_data/test.pdfdiff --git a/sdk/python/test/test_data/test.ppt b/sdk/python/test/test_sdk_api/test_data/test.pptsimilarity index 100%rename from sdk/python/test/test_data/test.pptrename to sdk/python/test/test_sdk_api/test_data/test.pptdiff --git a/sdk/python/test/test_data/test.txt b/sdk/python/test/test_sdk_api/test_data/test.txtsimilarity index 100%rename from sdk/python/test/test_data/test.txtrename to sdk/python/test/test_sdk_api/test_data/test.txtdiff --git a/sdk/python/test/test_data/test.xlsx b/sdk/python/test/test_sdk_api/test_data/test.xlsxsimilarity index 100%rename from sdk/python/test/test_data/test.xlsxrename to sdk/python/test/test_sdk_api/test_data/test.xlsx