mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Refa: Test configs (#8220)
### What problem does this PR solve? - Move common constants (HOST_ADDRESS, INVALID_API_TOKEN, etc.) to configs.py - Update test imports to use centralized configs - Clean up duplicate constant definitions across test files This improves maintainability by centralizing configuration. ### Type of change - [x] Refactoring test case
This commit is contained in:
@ -14,15 +14,14 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from configs import HOST_ADDRESS
|
||||||
from requests_toolbelt import MultipartEncoder
|
from requests_toolbelt import MultipartEncoder
|
||||||
from utils.file_utils import create_txt_file
|
from utils.file_utils import create_txt_file
|
||||||
|
|
||||||
HEADERS = {"Content-Type": "application/json"}
|
HEADERS = {"Content-Type": "application/json"}
|
||||||
HOST_ADDRESS = os.getenv("HOST_ADDRESS", "http://127.0.0.1:9380")
|
|
||||||
DATASETS_API_URL = "/api/v1/datasets"
|
DATASETS_API_URL = "/api/v1/datasets"
|
||||||
FILE_API_URL = "/api/v1/datasets/{dataset_id}/documents"
|
FILE_API_URL = "/api/v1/datasets/{dataset_id}/documents"
|
||||||
FILE_CHUNK_API_URL = "/api/v1/datasets/{dataset_id}/chunks"
|
FILE_CHUNK_API_URL = "/api/v1/datasets/{dataset_id}/chunks"
|
||||||
@ -31,12 +30,6 @@ CHAT_ASSISTANT_API_URL = "/api/v1/chats"
|
|||||||
SESSION_WITH_CHAT_ASSISTANT_API_URL = "/api/v1/chats/{chat_id}/sessions"
|
SESSION_WITH_CHAT_ASSISTANT_API_URL = "/api/v1/chats/{chat_id}/sessions"
|
||||||
SESSION_WITH_AGENT_API_URL = "/api/v1/agents/{agent_id}/sessions"
|
SESSION_WITH_AGENT_API_URL = "/api/v1/agents/{agent_id}/sessions"
|
||||||
|
|
||||||
INVALID_API_TOKEN = "invalid_key_123"
|
|
||||||
DATASET_NAME_LIMIT = 128
|
|
||||||
DOCUMENT_NAME_LIMIT = 128
|
|
||||||
CHAT_ASSISTANT_NAME_LIMIT = 255
|
|
||||||
SESSION_WITH_CHAT_NAME_LIMIT = 255
|
|
||||||
|
|
||||||
|
|
||||||
# DATASET MANAGEMENT
|
# DATASET MANAGEMENT
|
||||||
def create_dataset(auth, payload=None, *, headers=HEADERS, data=None):
|
def create_dataset(auth, payload=None, *, headers=HEADERS, data=None):
|
||||||
|
|||||||
@ -15,7 +15,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import CHAT_ASSISTANT_NAME_LIMIT, INVALID_API_TOKEN, create_chat_assistant
|
from common import create_chat_assistant
|
||||||
|
from configs import CHAT_ASSISTANT_NAME_LIMIT, INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from utils import encode_avatar
|
from utils import encode_avatar
|
||||||
from utils.file_utils import create_image_file
|
from utils.file_utils import create_image_file
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, batch_create_chat_assistants, delete_chat_assistants, list_chat_assistants
|
from common import batch_create_chat_assistants, delete_chat_assistants, list_chat_assistants
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, delete_datasets, list_chat_assistants
|
from common import delete_datasets, list_chat_assistants
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from utils import is_sorted
|
from utils import is_sorted
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,8 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import pytest
|
import pytest
|
||||||
from common import CHAT_ASSISTANT_NAME_LIMIT, INVALID_API_TOKEN, list_chat_assistants, update_chat_assistant
|
from common import list_chat_assistants, update_chat_assistant
|
||||||
|
from configs import CHAT_ASSISTANT_NAME_LIMIT, INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from utils import encode_avatar
|
from utils import encode_avatar
|
||||||
from utils.file_utils import create_image_file
|
from utils.file_utils import create_image_file
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, add_chunk, delete_documents, list_chunks
|
from common import add_chunk, delete_documents, list_chunks
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, batch_add_chunks, delete_chunks, list_chunks
|
from common import batch_add_chunks, delete_chunks, list_chunks
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,8 @@ import os
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, batch_add_chunks, list_chunks
|
from common import batch_add_chunks, list_chunks
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,8 @@ import os
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import (
|
from common import retrieval_chunks
|
||||||
INVALID_API_TOKEN,
|
from configs import INVALID_API_TOKEN
|
||||||
retrieval_chunks,
|
|
||||||
)
|
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,8 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, delete_documents, update_chunk
|
from common import delete_documents, update_chunk
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,11 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import (
|
from common import (
|
||||||
INVALID_API_TOKEN,
|
|
||||||
batch_create_datasets,
|
batch_create_datasets,
|
||||||
delete_datasets,
|
delete_datasets,
|
||||||
list_datasets,
|
list_datasets,
|
||||||
)
|
)
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,8 @@ import uuid
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, list_datasets
|
from common import list_datasets
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from utils import is_sorted
|
from utils import is_sorted
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, bulk_upload_documents, delete_documents, list_documents
|
from common import bulk_upload_documents, delete_documents, list_documents
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,8 @@ import json
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, bulk_upload_documents, download_document, upload_documents
|
from common import bulk_upload_documents, download_document, upload_documents
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from requests import codes
|
from requests import codes
|
||||||
from utils import compare_by_hash
|
from utils import compare_by_hash
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, list_documents
|
from common import list_documents
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from utils import is_sorted
|
from utils import is_sorted
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, bulk_upload_documents, list_documents, parse_documents
|
from common import bulk_upload_documents, list_documents, parse_documents
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from utils import wait_for
|
from utils import wait_for
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,8 @@ from concurrent.futures import ThreadPoolExecutor
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, bulk_upload_documents, list_documents, parse_documents, stop_parse_documents
|
from common import bulk_upload_documents, list_documents, parse_documents, stop_parse_documents
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from utils import wait_for
|
from utils import wait_for
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import DOCUMENT_NAME_LIMIT, INVALID_API_TOKEN, list_documents, update_document
|
from common import list_documents, update_document
|
||||||
|
from configs import DOCUMENT_NAME_LIMIT, INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,8 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
from common import DOCUMENT_NAME_LIMIT, FILE_API_URL, HOST_ADDRESS, INVALID_API_TOKEN, list_datasets, upload_documents
|
from common import FILE_API_URL, list_datasets, upload_documents
|
||||||
|
from configs import DOCUMENT_NAME_LIMIT, HOST_ADDRESS, INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from requests_toolbelt import MultipartEncoder
|
from requests_toolbelt import MultipartEncoder
|
||||||
from utils.file_utils import create_txt_file
|
from utils.file_utils import create_txt_file
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, SESSION_WITH_CHAT_NAME_LIMIT, create_session_with_chat_assistant, delete_chat_assistants, list_session_with_chat_assistants
|
from common import create_session_with_chat_assistant, delete_chat_assistants, list_session_with_chat_assistants
|
||||||
|
from configs import INVALID_API_TOKEN, SESSION_WITH_CHAT_NAME_LIMIT
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, batch_add_sessions_with_chat_assistant, delete_session_with_chat_assistants, list_session_with_chat_assistants
|
from common import batch_add_sessions_with_chat_assistant, delete_session_with_chat_assistants, list_session_with_chat_assistants
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, delete_chat_assistants, list_session_with_chat_assistants
|
from common import delete_chat_assistants, list_session_with_chat_assistants
|
||||||
|
from configs import INVALID_API_TOKEN
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
from utils import is_sorted
|
from utils import is_sorted
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,8 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from common import INVALID_API_TOKEN, SESSION_WITH_CHAT_NAME_LIMIT, delete_chat_assistants, list_session_with_chat_assistants, update_session_with_chat_assistant
|
from common import delete_chat_assistants, list_session_with_chat_assistants, update_session_with_chat_assistant
|
||||||
|
from configs import INVALID_API_TOKEN, SESSION_WITH_CHAT_NAME_LIMIT
|
||||||
from libs.auth import RAGFlowHttpApiAuth
|
from libs.auth import RAGFlowHttpApiAuth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user