Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Add tests for frontend API (#3552)

liuhuabf9ebda3c830
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 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/.env
sudo docker compose -f docker/docker-compose.yml up -d
- - name: Run tests against Elasticsearch
+ - name: Run sdk 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
@@ -78,7 +78,18 @@ jobs:
echo "Waiting for service to be available..."
sleep 5
done
- 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:dev
if: 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 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
@@ -97,7 +118,7 @@ jobs:
echo "Waiting for service to be available..."
sleep 5
done
- 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:dev
if: always() # always run this step even if previous steps failed
diff --git a/sdk/python/test/conftest.py b/sdk/python/test/conftest.py
index bcad88f14c..444d5c9bf2 100644
--- a/sdk/python/test/conftest.py
+++ b/sdk/python/test/conftest.py
@@ -16,9 +16,6 @@ PASSWORD='''ctAseGvejiaSWWZ88T/m4FQVOpQyUvP+x7sXtdv3feqZACiQleuewkUi35E16wSd5C5Q
fN33jCHRoDUW81IH9zjij/vaw8IbVyb6vuwg6MX6inOEBRRzVbRYxXOu1wkWY6SsI8X70oF9aeLFp/PzQpjoe/YbSqpTq8qqrmHzn9vO+yvyYyvmDsphXe
X8f7fp9c7vUsfOCkM+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 EMAIL
diff --git a/sdk/python/test/common.py b/sdk/python/test/test_frontend_api/common.py
similarity index 100%
rename from sdk/python/test/common.py
rename to sdk/python/test/test_frontend_api/common.py
diff --git a/sdk/python/test/test_frontend_api/get_email.py b/sdk/python/test/test_frontend_api/get_email.py
new file mode 100644
index 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 file
diff --git a/sdk/python/test/test_frontend_api/test_dataset.py b/sdk/python/test/test_frontend_api/test_dataset.py
new file mode 100644
index 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.py
new file mode 100644
index 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 file
diff --git a/sdk/python/test/test_sdk_api/get_email.py b/sdk/python/test/test_sdk_api/get_email.py
new file mode 100644
index 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 file
diff --git a/sdk/python/test/t_chat.py b/sdk/python/test/test_sdk_api/t_chat.py
similarity index 91%
rename from sdk/python/test/t_chat.py
rename to sdk/python/test/test_sdk_api/t_chat.py
index 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.py
similarity index 96%
rename from sdk/python/test/t_chunk.py
rename to sdk/python/test/test_sdk_api/t_chunk.py
index 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_fixture
rag = 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.py
similarity index 100%
rename from sdk/python/test/t_dataset.py
rename to sdk/python/test/test_sdk_api/t_dataset.py
diff --git a/sdk/python/test/t_document.py b/sdk/python/test/test_sdk_api/t_document.py
similarity index 91%
rename from sdk/python/test/t_document.py
rename to sdk/python/test/test_sdk_api/t_document.py
index 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_fi
API_KEY = get_api_key_fixture
rag = 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_f
API_KEY = get_api_key_fixture
rag = 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_fixture
rag = 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_fi
API_KEY = get_api_key_fixture
rag = 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_fixture
rag = 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_fi
API_KEY = get_api_key_fixture
rag = 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_fix
API_KEY = get_api_key_fixture
rag = 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_f
API_KEY = get_api_key_fixture
rag = 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_fi
API_KEY = get_api_key_fixture
rag = 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_f
API_KEY = get_api_key_fixture
rag = 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.py
similarity index 92%
rename from sdk/python/test/t_session.py
rename to sdk/python/test/test_sdk_api/t_session.py
index 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.txt
similarity index 100%
rename from sdk/python/test/ragflow.txt
rename to sdk/python/test/test_sdk_api/test_data/ragflow.txt
diff --git a/sdk/python/test/test_data/ragflow_test.txt b/sdk/python/test/test_sdk_api/test_data/ragflow_test.txt
similarity index 100%
rename from sdk/python/test/test_data/ragflow_test.txt
rename to sdk/python/test/test_sdk_api/test_data/ragflow_test.txt
diff --git a/sdk/python/test/test_data/test.docx b/sdk/python/test/test_sdk_api/test_data/test.docx
similarity index 100%
rename from sdk/python/test/test_data/test.docx
rename to sdk/python/test/test_sdk_api/test_data/test.docx
diff --git a/sdk/python/test/test_data/test.html b/sdk/python/test/test_sdk_api/test_data/test.html
similarity index 100%
rename from sdk/python/test/test_data/test.html
rename to sdk/python/test/test_sdk_api/test_data/test.html
diff --git a/sdk/python/test/test_data/test.jpg b/sdk/python/test/test_sdk_api/test_data/test.jpg
similarity index 100%
rename from sdk/python/test/test_data/test.jpg
rename to sdk/python/test/test_sdk_api/test_data/test.jpg
diff --git a/sdk/python/test/test_data/test.json b/sdk/python/test/test_sdk_api/test_data/test.json
similarity index 100%
rename from sdk/python/test/test_data/test.json
rename to sdk/python/test/test_sdk_api/test_data/test.json
diff --git a/sdk/python/test/test_data/test.md b/sdk/python/test/test_sdk_api/test_data/test.md
similarity index 100%
rename from sdk/python/test/test_data/test.md
rename to sdk/python/test/test_sdk_api/test_data/test.md
diff --git a/sdk/python/test/test_data/test.pdf b/sdk/python/test/test_sdk_api/test_data/test.pdf
similarity index 100%
rename from sdk/python/test/test_data/test.pdf
rename to sdk/python/test/test_sdk_api/test_data/test.pdf
diff --git a/sdk/python/test/test_data/test.ppt b/sdk/python/test/test_sdk_api/test_data/test.ppt
similarity index 100%
rename from sdk/python/test/test_data/test.ppt
rename to sdk/python/test/test_sdk_api/test_data/test.ppt
diff --git a/sdk/python/test/test_data/test.txt b/sdk/python/test/test_sdk_api/test_data/test.txt
similarity index 100%
rename from sdk/python/test/test_data/test.txt
rename to sdk/python/test/test_sdk_api/test_data/test.txt
diff --git a/sdk/python/test/test_data/test.xlsx b/sdk/python/test/test_sdk_api/test_data/test.xlsx
similarity index 100%
rename from sdk/python/test/test_data/test.xlsx
rename to sdk/python/test/test_sdk_api/test_data/test.xlsx