mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Test: Refactor test fixtures and test cases (#6709)
### What problem does this PR solve? Refactor test fixtures and test cases ### Type of change - [ ] Refactoring test cases
This commit is contained in:
@ -27,6 +27,7 @@ DATASETS_API_URL = "/api/v1/datasets"
|
||||
FILE_API_URL = "/api/v1/datasets/{dataset_id}/documents"
|
||||
FILE_CHUNK_API_URL = "/api/v1/datasets/{dataset_id}/chunks"
|
||||
CHUNK_API_URL = "/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks"
|
||||
CHAT_ASSISTANT_API_URL = "/api/v1/chats"
|
||||
|
||||
INVALID_API_TOKEN = "invalid_key_123"
|
||||
DATASET_NAME_LIMIT = 128
|
||||
@ -39,7 +40,7 @@ def create_dataset(auth, payload=None):
|
||||
return res.json()
|
||||
|
||||
|
||||
def list_dataset(auth, params=None):
|
||||
def list_datasets(auth, params=None):
|
||||
res = requests.get(url=f"{HOST_ADDRESS}{DATASETS_API_URL}", headers=HEADERS, auth=auth, params=params)
|
||||
return res.json()
|
||||
|
||||
@ -49,7 +50,7 @@ def update_dataset(auth, dataset_id, payload=None):
|
||||
return res.json()
|
||||
|
||||
|
||||
def delete_dataset(auth, payload=None):
|
||||
def delete_datasets(auth, payload=None):
|
||||
res = requests.delete(url=f"{HOST_ADDRESS}{DATASETS_API_URL}", headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
@ -105,7 +106,7 @@ def download_document(auth, dataset_id, document_id, save_path):
|
||||
return res
|
||||
|
||||
|
||||
def list_documnet(auth, dataset_id, params=None):
|
||||
def list_documnets(auth, dataset_id, params=None):
|
||||
url = f"{HOST_ADDRESS}{FILE_API_URL}".format(dataset_id=dataset_id)
|
||||
res = requests.get(url=url, headers=HEADERS, auth=auth, params=params)
|
||||
return res.json()
|
||||
@ -117,19 +118,19 @@ def update_documnet(auth, dataset_id, document_id, payload=None):
|
||||
return res.json()
|
||||
|
||||
|
||||
def delete_documnet(auth, dataset_id, payload=None):
|
||||
def delete_documnets(auth, dataset_id, payload=None):
|
||||
url = f"{HOST_ADDRESS}{FILE_API_URL}".format(dataset_id=dataset_id)
|
||||
res = requests.delete(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
|
||||
def parse_documnet(auth, dataset_id, payload=None):
|
||||
def parse_documnets(auth, dataset_id, payload=None):
|
||||
url = f"{HOST_ADDRESS}{FILE_CHUNK_API_URL}".format(dataset_id=dataset_id)
|
||||
res = requests.post(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
|
||||
def stop_parse_documnet(auth, dataset_id, payload=None):
|
||||
def stop_parse_documnets(auth, dataset_id, payload=None):
|
||||
url = f"{HOST_ADDRESS}{FILE_CHUNK_API_URL}".format(dataset_id=dataset_id)
|
||||
res = requests.delete(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
@ -184,3 +185,36 @@ def batch_add_chunks(auth, dataset_id, document_id, num):
|
||||
res = add_chunk(auth, dataset_id, document_id, {"content": f"chunk test {i}"})
|
||||
chunk_ids.append(res["data"]["chunk"]["id"])
|
||||
return chunk_ids
|
||||
|
||||
|
||||
# CHAT ASSISTANT MANAGEMENT
|
||||
def create_chat_assistant(auth, payload=None):
|
||||
url = f"{HOST_ADDRESS}{CHAT_ASSISTANT_API_URL}"
|
||||
res = requests.post(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
|
||||
def list_chat_assistants(auth, params=None):
|
||||
url = f"{HOST_ADDRESS}{CHAT_ASSISTANT_API_URL}"
|
||||
res = requests.get(url=url, headers=HEADERS, auth=auth, params=params)
|
||||
return res.json()
|
||||
|
||||
|
||||
def update_chat_assistant(auth, chat_assistant_id, payload=None):
|
||||
url = f"{HOST_ADDRESS}{CHAT_ASSISTANT_API_URL}/{chat_assistant_id}"
|
||||
res = requests.put(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
|
||||
def delete_chat_assistants(auth, payload=None):
|
||||
url = f"{HOST_ADDRESS}{CHAT_ASSISTANT_API_URL}"
|
||||
res = requests.delete(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
|
||||
def batch_create_chat_assistants(auth, num):
|
||||
chat_assistant_ids = []
|
||||
for i in range(num):
|
||||
res = create_chat_assistant(auth, {"name": f"test_chat_assistant_{i}"})
|
||||
chat_assistant_ids.append(res["data"]["id"])
|
||||
return chat_assistant_ids
|
||||
|
||||
Reference in New Issue
Block a user