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_document.py 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. from api.settings import RetCode
  2. from test_sdkbase import TestSdk
  3. from ragflow import RAGFlow
  4. import pytest
  5. from common import API_KEY, HOST_ADDRESS
  6. from api.contants import NAME_LENGTH_LIMIT
  7. class TestFile(TestSdk):
  8. """
  9. This class contains a suite of tests for the content management functionality within the dataset.
  10. It ensures that the following functionalities as expected:
  11. 1. upload local files
  12. 2. upload remote files
  13. 3. download a file
  14. 4. delete a file
  15. 5. enable rename
  16. 6. list files
  17. 7. start parsing
  18. 8. end parsing
  19. 9. check the status of the file
  20. 10. list the chunks
  21. 11. delete a chunk
  22. 12. insert a new chunk
  23. 13. edit the status of chunk
  24. 14. get the specific chunk
  25. 15. retrieval test
  26. """
  27. # ----------------------------upload local files-----------------------------------------------------
  28. def test_upload_two_files(self):
  29. """
  30. Test uploading two files with success.
  31. """
  32. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  33. created_res = ragflow.create_dataset("test_upload_two_files")
  34. dataset_id = created_res['data']['dataset_id']
  35. file_paths = ["test_data/test.txt", "test_data/test1.txt"]
  36. res = ragflow.upload_local_file(dataset_id, file_paths)
  37. assert res['code'] == RetCode.SUCCESS and res['data'] is True and res['message'] == 'success'
  38. def test_upload_one_file(self):
  39. """
  40. Test uploading one file with success.
  41. """
  42. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  43. created_res = ragflow.create_dataset("test_upload_one_file")
  44. dataset_id = created_res['data']['dataset_id']
  45. file_paths = ["test_data/test.txt"]
  46. res = ragflow.upload_local_file(dataset_id, file_paths)
  47. assert res['code'] == RetCode.SUCCESS and res['data'] is True and res['message'] == 'success'
  48. def test_upload_nonexistent_files(self):
  49. """
  50. Test uploading a file which does not exist.
  51. """
  52. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  53. created_res = ragflow.create_dataset("test_upload_nonexistent_files")
  54. dataset_id = created_res['data']['dataset_id']
  55. file_paths = ["test_data/imagination.txt"]
  56. res = ragflow.upload_local_file(dataset_id, file_paths)
  57. assert res['code'] == RetCode.DATA_ERROR and "does not exist" in res['message']
  58. def test_upload_file_if_dataset_does_not_exist(self):
  59. """
  60. Test uploading files if the dataset id does not exist.
  61. """
  62. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  63. file_paths = ["test_data/test.txt"]
  64. res = ragflow.upload_local_file("111", file_paths)
  65. assert res['code'] == RetCode.DATA_ERROR and res['message'] == "Can't find this dataset"
  66. def test_upload_file_without_name(self):
  67. """
  68. Test uploading files that do not have name.
  69. """
  70. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  71. created_res = ragflow.create_dataset("test_upload_file_without_name")
  72. dataset_id = created_res['data']['dataset_id']
  73. file_paths = ["test_data/.txt"]
  74. res = ragflow.upload_local_file(dataset_id, file_paths)
  75. assert res['code'] == RetCode.SUCCESS
  76. def test_upload_file_without_name1(self):
  77. """
  78. Test uploading files that do not have name.
  79. """
  80. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  81. created_res = ragflow.create_dataset("test_upload_file_without_name")
  82. dataset_id = created_res['data']['dataset_id']
  83. file_paths = ["test_data/.txt", "test_data/empty.txt"]
  84. res = ragflow.upload_local_file(dataset_id, file_paths)
  85. assert res['code'] == RetCode.SUCCESS
  86. def test_upload_files_exceeding_the_number_limit(self):
  87. """
  88. Test uploading files whose number exceeds the limit.
  89. """
  90. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  91. created_res = ragflow.create_dataset("test_upload_files_exceeding_the_number_limit")
  92. dataset_id = created_res['data']['dataset_id']
  93. file_paths = ["test_data/test.txt", "test_data/test1.txt"] * 256
  94. res = ragflow.upload_local_file(dataset_id, file_paths)
  95. assert (res['message'] ==
  96. 'You try to upload 512 files, which exceeds the maximum number of uploading files: 256'
  97. and res['code'] == RetCode.DATA_ERROR)
  98. def test_upload_files_without_files(self):
  99. """
  100. Test uploading files without files.
  101. """
  102. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  103. created_res = ragflow.create_dataset("test_upload_files_without_files")
  104. dataset_id = created_res['data']['dataset_id']
  105. file_paths = [None]
  106. res = ragflow.upload_local_file(dataset_id, file_paths)
  107. assert (res['message'] == 'None is not string.' and res['code'] == RetCode.ARGUMENT_ERROR)
  108. def test_upload_files_with_two_files_with_same_name(self):
  109. """
  110. Test uploading files with the same name.
  111. """
  112. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  113. created_res = ragflow.create_dataset("test_upload_files_with_two_files_with_same_name")
  114. dataset_id = created_res['data']['dataset_id']
  115. file_paths = ['test_data/test.txt'] * 2
  116. res = ragflow.upload_local_file(dataset_id, file_paths)
  117. assert (res['message'] == 'success' and res['code'] == RetCode.SUCCESS)
  118. def test_upload_files_with_file_paths(self):
  119. """
  120. Test uploading files with only specifying the file path's repo.
  121. """
  122. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  123. created_res = ragflow.create_dataset("test_upload_files_with_file_paths")
  124. dataset_id = created_res['data']['dataset_id']
  125. file_paths = ['test_data/']
  126. res = ragflow.upload_local_file(dataset_id, file_paths)
  127. assert (res['message'] == 'The file test_data/ does not exist' and res['code'] == RetCode.DATA_ERROR)
  128. def test_upload_files_with_remote_file_path(self):
  129. """
  130. Test uploading files with remote files.
  131. """
  132. ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
  133. created_res = ragflow.create_dataset("test_upload_files_with_remote_file_path")
  134. dataset_id = created_res['data']['dataset_id']
  135. file_paths = ['https://github.com/genostack/ragflow']
  136. res = ragflow.upload_local_file(dataset_id, file_paths)
  137. assert res['code'] == RetCode.ARGUMENT_ERROR and res['message'] == 'Remote files have not unsupported.'
  138. # ----------------------------upload remote files-----------------------------------------------------
  139. # ----------------------------download a file-----------------------------------------------------
  140. # ----------------------------delete a file-----------------------------------------------------
  141. # ----------------------------enable rename-----------------------------------------------------
  142. # ----------------------------list files-----------------------------------------------------
  143. # ----------------------------start parsing-----------------------------------------------------
  144. # ----------------------------stop parsing-----------------------------------------------------
  145. # ----------------------------show the status of the file-----------------------------------------------------
  146. # ----------------------------list the chunks of the file-----------------------------------------------------
  147. # ----------------------------delete the chunk-----------------------------------------------------
  148. # ----------------------------edit the status of the chunk-----------------------------------------------------
  149. # ----------------------------insert a new chunk-----------------------------------------------------
  150. # ----------------------------upload a file-----------------------------------------------------
  151. # ----------------------------get a specific chunk-----------------------------------------------------
  152. # ----------------------------retrieval test-----------------------------------------------------