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.

test_dataset.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. from test_sdkbase import TestSdk
  2. from ragflow import RAGFlow
  3. import pytest
  4. from common import API_KEY, HOST_ADDRESS
  5. class TestDataset(TestSdk):
  6. def test_create_dataset(self):
  7. '''
  8. 1. create a kb
  9. 2. list the kb
  10. 3. get the detail info according to the kb id
  11. 4. update the kb
  12. 5. delete the kb
  13. '''
  14. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  15. # create a kb
  16. res = ragflow.create_dataset("kb1")
  17. assert res['code'] == 0 and res['message'] == 'success'
  18. dataset_name = res['data']['dataset_name']
  19. def test_list_dataset_success(self):
  20. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  21. # Call the list_datasets method
  22. response = ragflow.list_dataset()
  23. code, datasets = response
  24. assert code == 200
  25. def test_list_dataset_with_checking_size_and_name(self):
  26. datasets_to_create = ["dataset1", "dataset2", "dataset3"]
  27. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  28. created_response = [ragflow.create_dataset(name) for name in datasets_to_create]
  29. real_name_to_create = set()
  30. for response in created_response:
  31. assert 'data' in response, "Response is missing 'data' key"
  32. dataset_name = response['data']['dataset_name']
  33. real_name_to_create.add(dataset_name)
  34. status_code, listed_data = ragflow.list_dataset(0, 3)
  35. listed_data = listed_data['data']
  36. listed_names = {d['name'] for d in listed_data}
  37. assert listed_names == real_name_to_create
  38. assert status_code == 200
  39. assert len(listed_data) == len(datasets_to_create)
  40. def test_list_dataset_with_getting_empty_result(self):
  41. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  42. datasets_to_create = []
  43. created_response = [ragflow.create_dataset(name) for name in datasets_to_create]
  44. real_name_to_create = set()
  45. for response in created_response:
  46. assert 'data' in response, "Response is missing 'data' key"
  47. dataset_name = response['data']['dataset_name']
  48. real_name_to_create.add(dataset_name)
  49. status_code, listed_data = ragflow.list_dataset(0, 0)
  50. listed_data = listed_data['data']
  51. listed_names = {d['name'] for d in listed_data}
  52. assert listed_names == real_name_to_create
  53. assert status_code == 200
  54. assert len(listed_data) == 0
  55. def test_list_dataset_with_creating_100_knowledge_bases(self):
  56. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  57. datasets_to_create = ["dataset1"] * 100
  58. created_response = [ragflow.create_dataset(name) for name in datasets_to_create]
  59. real_name_to_create = set()
  60. for response in created_response:
  61. assert 'data' in response, "Response is missing 'data' key"
  62. dataset_name = response['data']['dataset_name']
  63. real_name_to_create.add(dataset_name)
  64. status_code, listed_data = ragflow.list_dataset(0, 100)
  65. listed_data = listed_data['data']
  66. listed_names = {d['name'] for d in listed_data}
  67. assert listed_names == real_name_to_create
  68. assert status_code == 200
  69. assert len(listed_data) == 100
  70. def test_list_dataset_with_showing_one_dataset(self):
  71. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  72. response = ragflow.list_dataset(0, 1)
  73. code, response = response
  74. datasets = response['data']
  75. assert len(datasets) == 1
  76. def test_list_dataset_failure(self):
  77. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  78. response = ragflow.list_dataset(-1, -1)
  79. _, res = response
  80. assert "IndexError" in res['message']
  81. def test_delete_one_dataset_with_success(self):
  82. # get the real name of the created dataset
  83. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  84. res = ragflow.create_dataset("kb0")
  85. real_dataset_name = res['data']['dataset_name']
  86. print("name", real_dataset_name)
  87. # delete this dataset
  88. result = ragflow.delete_dataset(real_dataset_name)
  89. print(result)
  90. assert result["success"] is True
  91. def test_delete_dataset_with_not_existing_dataset(self):
  92. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  93. res = ragflow.delete_dataset("weird_dataset")
  94. assert res["success"] is False