mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-12 02:29:03 +08:00
Add tests for frontend API (#3552)
### What problem does this PR solve? Add tests for frontend API ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: liuhua <10215101452@stu.ecun.edu.cn>
This commit is contained in:
parent
85dd9fde43
commit
bf9ebda3c8
29
.github/workflows/tests.yml
vendored
29
.github/workflows/tests.yml
vendored
@ -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,7 @@ 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
|
||||
@ -97,7 +108,17 @@ 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 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_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
|
||||
|
@ -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")
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def get_auth():
|
||||
register()
|
||||
auth = login()
|
||||
return auth
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def get_email():
|
||||
return EMAIL
|
||||
|
3
sdk/python/test/test_frontend_api/get_email.py
Normal file
3
sdk/python/test/test_frontend_api/get_email.py
Normal file
@ -0,0 +1,3 @@
|
||||
def test_get_email(get_email):
|
||||
print(f"\nEmail account:",flush=True)
|
||||
print(f"{get_email}\n",flush=True)
|
10
sdk/python/test/test_frontend_api/test_dataset.py
Normal file
10
sdk/python/test/test_frontend_api/test_dataset.py
Normal file
@ -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')}"
|
||||
|
2
sdk/python/test/test_sdk_api/common.py
Normal file
2
sdk/python/test/test_sdk_api/common.py
Normal file
@ -0,0 +1,2 @@
|
||||
import os
|
||||
HOST_ADDRESS=os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380')
|
3
sdk/python/test/test_sdk_api/get_email.py
Normal file
3
sdk/python/test/test_sdk_api/get_email.py
Normal file
@ -0,0 +1,3 @@
|
||||
def test_get_email(get_email):
|
||||
print(f"\nEmail account:",flush=True)
|
||||
print(f"{get_email}\n",flush=True)
|
@ -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 = []
|
@ -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},
|
@ -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)
|
@ -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 = []
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
Loading…
x
Reference in New Issue
Block a user