You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

t_dataset.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from ragflow_sdk import RAGFlow
  2. import random
  3. import pytest
  4. from common import HOST_ADDRESS
  5. def test_create_dataset_with_name(get_api_key_fixture):
  6. API_KEY = get_api_key_fixture
  7. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  8. rag.create_dataset("test_create_dataset_with_name")
  9. def test_create_dataset_with_duplicated_name(get_api_key_fixture):
  10. API_KEY = get_api_key_fixture
  11. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  12. rag.create_dataset("test_create_dataset_with_duplicated_name")
  13. with pytest.raises(Exception) as exc_info:
  14. rag.create_dataset("test_create_dataset_with_duplicated_name")
  15. assert str(exc_info.value) == "Duplicated dataset name in creating dataset."
  16. def test_create_dataset_with_random_chunk_method(get_api_key_fixture):
  17. API_KEY = get_api_key_fixture
  18. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  19. valid_chunk_methods = ["naive","manual","qa","table","paper","book","laws","presentation","picture","one","knowledge_graph","email"]
  20. random_chunk_method = random.choice(valid_chunk_methods)
  21. rag.create_dataset("test_create_dataset_with_random_chunk_method",chunk_method=random_chunk_method)
  22. def test_create_dataset_with_invalid_parameter(get_api_key_fixture):
  23. API_KEY = get_api_key_fixture
  24. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  25. valid_chunk_methods = ["naive", "manual", "qa", "table", "paper", "book", "laws", "presentation", "picture", "one",
  26. "knowledge_graph", "email"]
  27. chunk_method = "invalid_chunk_method"
  28. with pytest.raises(Exception) as exc_info:
  29. rag.create_dataset("test_create_dataset_with_invalid_chunk_method",chunk_method=chunk_method)
  30. assert str(exc_info.value) == f"'{chunk_method}' is not in {valid_chunk_methods}"
  31. def test_update_dataset_with_name(get_api_key_fixture):
  32. API_KEY = get_api_key_fixture
  33. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  34. ds = rag.create_dataset("test_update_dataset")
  35. ds.update({"name": "updated_dataset"})
  36. def test_delete_datasets_with_success(get_api_key_fixture):
  37. API_KEY = get_api_key_fixture
  38. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  39. ds = rag.create_dataset("test_delete_dataset")
  40. rag.delete_datasets(ids=[ds.id])
  41. def test_list_datasets_with_success(get_api_key_fixture):
  42. API_KEY = get_api_key_fixture
  43. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  44. rag.list_datasets()