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.

conftest.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import pytest
  17. from common import bulk_upload_documents, delete_document, list_documents
  18. @pytest.fixture(scope="function")
  19. def add_document_func(request, WebApiAuth, add_dataset, ragflow_tmp_dir):
  20. def cleanup():
  21. res = list_documents(WebApiAuth, {"kb_id": dataset_id})
  22. for doc in res["data"]["docs"]:
  23. delete_document(WebApiAuth, {"doc_id": doc["id"]})
  24. request.addfinalizer(cleanup)
  25. dataset_id = add_dataset
  26. return dataset_id, bulk_upload_documents(WebApiAuth, dataset_id, 1, ragflow_tmp_dir)[0]
  27. @pytest.fixture(scope="class")
  28. def add_documents(request, WebApiAuth, add_dataset, ragflow_tmp_dir):
  29. def cleanup():
  30. res = list_documents(WebApiAuth, {"kb_id": dataset_id})
  31. for doc in res["data"]["docs"]:
  32. delete_document(WebApiAuth, {"doc_id": doc["id"]})
  33. request.addfinalizer(cleanup)
  34. dataset_id = add_dataset
  35. return dataset_id, bulk_upload_documents(WebApiAuth, dataset_id, 5, ragflow_tmp_dir)
  36. @pytest.fixture(scope="function")
  37. def add_documents_func(request, WebApiAuth, add_dataset_func, ragflow_tmp_dir):
  38. def cleanup():
  39. res = list_documents(WebApiAuth, {"kb_id": dataset_id})
  40. for doc in res["data"]["docs"]:
  41. delete_document(WebApiAuth, {"doc_id": doc["id"]})
  42. request.addfinalizer(cleanup)
  43. dataset_id = add_dataset_func
  44. return dataset_id, bulk_upload_documents(WebApiAuth, dataset_id, 3, ragflow_tmp_dir)