mirror of
https://github.com/langgenius/dify.git
synced 2026-05-10 05:56:31 +08:00
tests
Signed-off-by: xr843 <137012659+xr843@users.noreply.github.com>
This commit is contained in:
parent
60f8e93ee7
commit
6ef7685f5c
@ -514,7 +514,7 @@ class TestFileService:
|
||||
|
||||
db_session_with_containers.commit()
|
||||
|
||||
result = FileService(engine).get_file_preview(file_id=upload_file.id)
|
||||
result = FileService(engine).get_file_preview(file_id=upload_file.id, tenant_id=upload_file.tenant_id)
|
||||
|
||||
assert result == "extracted text content"
|
||||
mock_external_service_dependencies["extract_processor"].load_from_upload_file.assert_called_once()
|
||||
@ -529,7 +529,7 @@ class TestFileService:
|
||||
non_existent_id = str(fake.uuid4())
|
||||
|
||||
with pytest.raises(NotFound, match="File not found"):
|
||||
FileService(engine).get_file_preview(file_id=non_existent_id)
|
||||
FileService(engine).get_file_preview(file_id=non_existent_id, tenant_id=str(fake.uuid4()))
|
||||
|
||||
def test_get_file_preview_unsupported_file_type(
|
||||
self, db_session_with_containers: Session, engine, mock_external_service_dependencies
|
||||
@ -549,7 +549,7 @@ class TestFileService:
|
||||
db_session_with_containers.commit()
|
||||
|
||||
with pytest.raises(UnsupportedFileTypeError):
|
||||
FileService(engine).get_file_preview(file_id=upload_file.id)
|
||||
FileService(engine).get_file_preview(file_id=upload_file.id, tenant_id=upload_file.tenant_id)
|
||||
|
||||
def test_get_file_preview_text_truncation(
|
||||
self, db_session_with_containers: Session, engine, mock_external_service_dependencies
|
||||
@ -572,7 +572,7 @@ class TestFileService:
|
||||
long_text = "x" * 5000 # Longer than PREVIEW_WORDS_LIMIT
|
||||
mock_external_service_dependencies["extract_processor"].load_from_upload_file.return_value = long_text
|
||||
|
||||
result = FileService(engine).get_file_preview(file_id=upload_file.id)
|
||||
result = FileService(engine).get_file_preview(file_id=upload_file.id, tenant_id=upload_file.tenant_id)
|
||||
|
||||
assert len(result) == 3000 # PREVIEW_WORDS_LIMIT
|
||||
assert result == "x" * 3000
|
||||
|
||||
@ -221,7 +221,7 @@ class TestFileService:
|
||||
mock_extract.return_value = "Extracted text content"
|
||||
|
||||
# Execute
|
||||
result = file_service.get_file_preview("file_id")
|
||||
result = file_service.get_file_preview("file_id", "tenant_id")
|
||||
|
||||
# Assert
|
||||
assert result == "Extracted text content"
|
||||
@ -229,7 +229,7 @@ class TestFileService:
|
||||
def test_get_file_preview_not_found(self, file_service, mock_db_session):
|
||||
mock_db_session.scalar.return_value = None
|
||||
with pytest.raises(NotFound, match="File not found"):
|
||||
file_service.get_file_preview("non_existent")
|
||||
file_service.get_file_preview("non_existent", "tenant_id")
|
||||
|
||||
def test_get_file_preview_unsupported_type(self, file_service, mock_db_session):
|
||||
upload_file = MagicMock(spec=UploadFile)
|
||||
@ -237,7 +237,7 @@ class TestFileService:
|
||||
upload_file.extension = "exe"
|
||||
mock_db_session.scalar.return_value = upload_file
|
||||
with pytest.raises(UnsupportedFileTypeError):
|
||||
file_service.get_file_preview("file_id")
|
||||
file_service.get_file_preview("file_id", "tenant_id")
|
||||
|
||||
def test_get_image_preview_success(self, file_service, mock_db_session):
|
||||
# Setup
|
||||
|
||||
Loading…
Reference in New Issue
Block a user